updating build config and main to make it easier to troubleshoot microphone permissions
This commit is contained in:
+32
-4
@@ -1,4 +1,4 @@
|
||||
import { app, BrowserWindow } from 'electron';
|
||||
import { app, BrowserWindow, systemPreferences } from 'electron';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
@@ -6,6 +6,26 @@ const isDev = !app.isPackaged;
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
async function handlePermissions() {
|
||||
// macOS requires an explicit request for microphone access in packaged apps
|
||||
if (process.platform === 'darwin') {
|
||||
try {
|
||||
const status = systemPreferences.getMediaAccessStatus('microphone');
|
||||
console.log(`[Main Process] Current Microphone Status: ${status}`);
|
||||
|
||||
if (status !== 'granted') {
|
||||
const granted = await systemPreferences.askForMediaAccess('microphone');
|
||||
console.log(`[Main Process] Microphone permission granted after request: ${granted}`);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('[Main Process] Error checking/requesting microphone access:', err);
|
||||
}
|
||||
} else {
|
||||
// Windows/Linux typically grant access by default or via the Renderer process
|
||||
console.log(`[Main Process] Platform is ${process.platform}, skipping native macOS permission prompt.`);
|
||||
}
|
||||
}
|
||||
|
||||
function createWindow() {
|
||||
const win = new BrowserWindow({
|
||||
width: 1024,
|
||||
@@ -13,20 +33,28 @@ function createWindow() {
|
||||
webPreferences: {
|
||||
preload: path.join(__dirname, 'preload.cjs'),
|
||||
contextIsolation: true,
|
||||
nodeIntegration: false
|
||||
nodeIntegration: false,
|
||||
// Ensure the browser engine treats the app as "secure" to allow microphone access
|
||||
sandbox: false
|
||||
}
|
||||
});
|
||||
|
||||
if (isDev) {
|
||||
const devUrl = process.env.ELECTRON_START_URL || 'http://localhost:5173';
|
||||
win.loadURL(devUrl);
|
||||
// Open DevTools automatically in dev
|
||||
win.webContents.openDevTools();
|
||||
} else {
|
||||
// In production, load the built index.html from the dist folder
|
||||
// This path assumes your structure is /electron/main.js and /dist/index.html
|
||||
win.loadFile(path.join(__dirname, '..', 'dist', 'index.html'));
|
||||
}
|
||||
}
|
||||
|
||||
app.whenReady().then(createWindow);
|
||||
app.whenReady().then(async () => {
|
||||
await handlePermissions();
|
||||
createWindow();
|
||||
});
|
||||
|
||||
app.on('window-all-closed', () => {
|
||||
if (process.platform !== 'darwin') app.quit();
|
||||
@@ -34,4 +62,4 @@ app.on('window-all-closed', () => {
|
||||
|
||||
app.on('activate', () => {
|
||||
if (BrowserWindow.getAllWindows().length === 0) createWindow();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user