Skip to content

Commit 3fc78d7

Browse files
committed
get mediaAccess from main process
1 parent c6ed1f3 commit 3fc78d7

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

app/main.dev.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
*
1111
* @flow
1212
*/
13-
import { app, BrowserWindow, ipcMain } from 'electron';
13+
import { app, BrowserWindow, ipcMain, systemPreferences } from 'electron';
1414
import { autoUpdater } from 'electron-updater';
1515
import log from 'electron-log';
1616
import MenuBuilder from './menu';
1717
import { CliLocal } from './mainProcess/cliLocal';
1818
import fs from "fs";
19-
import { GUI_LOG_FILE } from './const';
19+
import { GUI_LOG_FILE, IPC_CAMERA } from './const';
2020

2121

2222
export default class AppUpdater {
@@ -91,6 +91,20 @@ else {
9191
}
9292
});
9393

94+
ipcMain.on(IPC_CAMERA.REQUEST, async (event) => {
95+
if (process.platform !== 'darwin' || systemPreferences.getMediaAccessStatus("camera") !== "granted") {
96+
event.reply(IPC_CAMERA.GRANTED)
97+
} else {
98+
const granted = await systemPreferences.askForMediaAccess("camera");
99+
100+
if (granted) {
101+
event.reply(IPC_CAMERA.GRANTED)
102+
} else {
103+
event.reply(IPC_CAMERA.DENIED)
104+
}
105+
}
106+
});
107+
94108
// init cliLocal
95109
const guiLogStream = fs.createWriteStream(GUI_LOG_FILE, { flags: 'a' })
96110
new CliLocal(ipcMain, mainWindow.webContents, guiLogStream)

0 commit comments

Comments
 (0)