update permission handling
This commit is contained in:
parent
fbc5c2dfe2
commit
1953e4e078
3 changed files with 28 additions and 11 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
22
src/main/mediaPermissions.ts
Normal file
22
src/main/mediaPermissions.ts
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
Reference in a new issue