updating build config and main to make it easier to troubleshoot microphone permissions

This commit is contained in:
itsamejms
2026-03-05 22:41:45 +00:00
parent 84145de2cc
commit 7cf92efe2f
3 changed files with 80 additions and 5 deletions
+14
View File
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.device.audio-input</key>
<true/>
<key>com.apple.security.cs.allow-jit</key>
<true/>
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
<true/>
<key>com.apple.security.cs.disable-library-validation</key>
<true/>
</dict>
</plist>
+31 -3
View File
@@ -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();
+33
View File
@@ -34,6 +34,39 @@
"build": {
"appId": "com.whattheflat.app",
"productName": "WhatTheFlat",
"mac": {
"hardenedRuntime": true,
"entitlements": "electron/entitlements.mac.plist",
"entitlementsInherit": "electron/entitlements.mac.plist",
"extendInfo": {
"NSMicrophoneUsageDescription": "WhatTheFlat needs access to your microphone to detect pitch and provide the tuner."
}
},
"win": {
"target": [
{
"target": "nsis",
"arch": [
"x64",
"ia32"
]
},
"zip"
]
},
"nsis": {
"oneClick": false,
"perMachine": false,
"allowElevation": true,
"allowToChangeInstallationDirectory": true
},
"linux": {
"target": [
"AppImage",
"deb"
],
"category": "Audio"
},
"files": [
"dist/**/*",
"electron/**/*",