fix: Add microphone permission handlers for Electron

Added session.setPermissionRequestHandler and setPermissionCheckHandler
to automatically grant media/audio capture permissions. This fixes the
"could not start audio source" error when trying to start recording.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
egg
2025-12-17 15:54:44 +08:00
parent 744cfd1d27
commit e565951bf6

View File

@@ -1,4 +1,4 @@
const { app, BrowserWindow, ipcMain } = require("electron");
const { app, BrowserWindow, ipcMain, session } = require("electron");
const path = require("path");
const fs = require("fs");
const { spawn } = require("child_process");
@@ -445,6 +445,24 @@ app.whenReady().then(async () => {
// Load configuration first
loadConfig();
// Grant microphone permission automatically
session.defaultSession.setPermissionRequestHandler((webContents, permission, callback) => {
const allowedPermissions = ['media', 'mediaKeySystem', 'audioCapture'];
if (allowedPermissions.includes(permission)) {
console.log(`Granting permission: ${permission}`);
callback(true);
} else {
console.log(`Denying permission: ${permission}`);
callback(false);
}
});
// Also handle permission check (for some Electron versions)
session.defaultSession.setPermissionCheckHandler((webContents, permission) => {
const allowedPermissions = ['media', 'mediaKeySystem', 'audioCapture'];
return allowedPermissions.includes(permission);
});
// Start backend sidecar if embedded mode is enabled
startBackendSidecar();