diff --git a/package.json b/package.json index 25e0cb9..fcca866 100644 --- a/package.json +++ b/package.json @@ -95,8 +95,8 @@ ], "category": "Network", "extendInfo": { - "NSMicrophoneUsageDescription": "Vesktop needs access to your microphone in order to transmit data in a voice chat", - "NSCameraUsageDescription": "Vesktop needs access to your camera in order to transmit data in a video call", + "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 } diff --git a/src/main/index.ts b/src/main/index.ts index 8489d5f..c37d433 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -6,12 +6,13 @@ import "./ipc"; -import { app, BrowserWindow, systemPreferences } from "electron"; +import { app, BrowserWindow } from "electron"; 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,15 +50,9 @@ function init() { if (process.platform === "win32") app.setAppUserModelId("dev.vencord.desktop"); registerScreenShareHandler(); - bootstrap(); - - //TODO we should only ask these permissions when the user joins a voice chat/video call for the first time - //TODO we should also handle the granted result respectively. How does this official client handle permissions? - systemPreferences.askForMediaAccess('microphone') - .then((granted) => console.log(`microphone permission granted: ${granted}`)); - systemPreferences.askForMediaAccess('camera') - .then((granted) => console.log(`camera permission granted: ${granted}`)); //TODO we should only ask this permission when the user joins a video call for the first time + registerMediaPermissionsHandler(); + bootstrap(); app.on("activate", () => { if (BrowserWindow.getAllWindows().length === 0) createWindows(); diff --git a/src/main/mediaPermissions.ts b/src/main/mediaPermissions.ts new file mode 100644 index 0000000..477fbae --- /dev/null +++ b/src/main/mediaPermissions.ts @@ -0,0 +1,22 @@ +/* + * 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((_webContents, permission, callback, details) => { + if (permission === "media") { + if (details.mediaTypes!.includes("audio")) { + systemPreferences.askForMediaAccess("microphone").then(callback); + } + if (details.mediaTypes!.includes("video")) { + systemPreferences.askForMediaAccess("camera").then(callback); + } + } + }); +}