Skip to content

Commit

Permalink
MacOs: properly request microphone and camera permission (#121)
Browse files Browse the repository at this point in the history
Co-authored-by: V <[email protected]>
  • Loading branch information
X1nto and Vendicated authored Oct 12, 2023
1 parent e29d293 commit c445c61
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ dist
node_modules
.env
.DS_Store
.idea/
.idea/
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -49,6 +50,8 @@ function init() {
if (process.platform === "win32") app.setAppUserModelId("dev.vencord.desktop");

registerScreenShareHandler();
registerMediaPermissionsHandler();

bootstrap();

app.on("activate", () => {
Expand Down
24 changes: 24 additions & 0 deletions src/main/mediaPermissions.ts
Original file line number Diff line number Diff line change
@@ -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);
});
}

0 comments on commit c445c61

Please sign in to comment.