From c445c6194f6a0bd077bafc9e65f0aa79e2aa0945 Mon Sep 17 00:00:00 2001 From: Tornike Khintibidze <48173186+X1nto@users.noreply.github.com> Date: Thu, 12 Oct 2023 06:24:16 +0400 Subject: [PATCH] MacOs: properly request microphone and camera permission (#121) Co-authored-by: V --- .gitignore | 2 +- package.json | 8 +++++++- src/main/index.ts | 3 +++ src/main/mediaPermissions.ts | 24 ++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 src/main/mediaPermissions.ts diff --git a/.gitignore b/.gitignore index 683ca39..94c1776 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ dist node_modules .env .DS_Store -.idea/ \ No newline at end of file +.idea/ diff --git a/package.json b/package.json index 09b6f85..61b24da 100644 --- a/package.json +++ b/package.json @@ -94,7 +94,13 @@ ] } ], - "category": "Network" + "category": "Network", + "extendInfo": { + "NSMicrophoneUsageDescription": "This app needs access to the microphone", + "NSCameraUsageDescription": "This app needs access to the camera", + "com.apple.security.device.audio-input": true, + "com.apple.security.device.camera": true + } }, "nsis": { "include": "build/installer.nsh", diff --git a/src/main/index.ts b/src/main/index.ts index 10552f2..c37d433 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -12,6 +12,7 @@ import { checkUpdates } from "updater/main"; import { DATA_DIR } from "./constants"; import { createFirstLaunchTour } from "./firstLaunch"; import { createWindows, mainWin } from "./mainWindow"; +import { registerMediaPermissionsHandler } from "./mediaPermissions"; import { registerScreenShareHandler } from "./screenShare"; import { Settings } from "./settings"; @@ -49,6 +50,8 @@ function init() { if (process.platform === "win32") app.setAppUserModelId("dev.vencord.desktop"); registerScreenShareHandler(); + registerMediaPermissionsHandler(); + bootstrap(); app.on("activate", () => { diff --git a/src/main/mediaPermissions.ts b/src/main/mediaPermissions.ts new file mode 100644 index 0000000..1f6cf46 --- /dev/null +++ b/src/main/mediaPermissions.ts @@ -0,0 +1,24 @@ +/* + * SPDX-License-Identifier: GPL-3.0 + * Vesktop, a desktop app aiming to give you a snappier Discord Experience + * Copyright (c) 2023 Vendicated and Vencord contributors + */ + +import { session, systemPreferences } from "electron"; + +export function registerMediaPermissionsHandler() { + if (process.platform !== "darwin") return; + + session.defaultSession.setPermissionRequestHandler(async (_webContents, permission, callback, details) => { + let granted = true; + + if (details.mediaTypes?.includes("audio")) { + granted = await systemPreferences.askForMediaAccess("microphone"); + } + if (details.mediaTypes?.includes("video")) { + granted &&= await systemPreferences.askForMediaAccess("camera"); + } + + callback(granted); + }); +}