电子应用程序在systemPreferences.askForMediaAccess('microphone')执行后崩溃
这是主要的项目依赖项:
包.json
"electron": "6.0.11",
"electron-builder": "21.2.0",
"electron-reload": "1.5.0",
Run Code Online (Sandbox Code Playgroud)
当地环境
在本地运行电子我使用:
electron .
在主脚本文件中,我有:
...
win.loadURL(format({
pathname: join(__dirname, 'dist/index.html'),
protocol: 'file:',
slashes: true,
hash: '/setup/test-code'
}));
...
// when script below is executed, application is crashed.
ipcMain.on('request-mic', async (event, serviceName) => {
const isAllowed: boolean = await systemPreferences.askForMediaAccess('microphone');
event.returnValue = isAllowed;
});
Run Code Online (Sandbox Code Playgroud)
为生产而构建(有效)
构建脚本:
electron-builder build --mac
Run Code Online (Sandbox Code Playgroud)
电子建造者.json
"mac": {
"icon": "dist",
"extendInfo": {
"NSMicrophoneUsageDescription": "text for mic access"
},
"target": [
"dmg"
]
},
Run Code Online (Sandbox Code Playgroud)
问题:如何修复我为本地开发运行的脚本?崩溃报告:
Process: Electron …Run Code Online (Sandbox Code Playgroud)