Files
JamBuddy/electron/main.cjs
T
vadimwit fab385a612 fix(dev): pin dev server, wait-on gate, and Electron loadURL to 127.0.0.1
With plain localhost, node >=17 can bind the Vite dev server to ::1
only; on this machine IPv4/IPv6 loopback mismatch made the browser,
wait-on, and the Electron window all see connection-refused while Vite
reported ready. Explicit 127.0.0.1 on all three ends fixes dev startup
(user-verified: electron:dev window now opens).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-09 23:40:44 +01:00

56 lines
1.5 KiB
JavaScript

const { app, BrowserWindow, systemPreferences } = require('electron')
const path = require('path')
const isDev = !app.isPackaged
async function handlePermissions() {
// macOS requires an explicit native request for microphone access in packaged apps
if (process.platform === 'darwin') {
try {
const status = systemPreferences.getMediaAccessStatus('microphone')
if (status !== 'granted') {
await systemPreferences.askForMediaAccess('microphone')
}
} catch (err) {
console.error('[Main] Microphone permission error:', err)
}
}
}
function createWindow() {
const win = new BrowserWindow({
width: 1280,
height: 900,
minWidth: 620,
minHeight: 600,
title: 'WhatTheFlat ♭? - JamBuddy',
icon: path.join(__dirname, '../assets/whattheflat-logo.png'),
webPreferences: {
preload: path.join(__dirname, 'preload.cjs'),
contextIsolation: true,
nodeIntegration: false,
sandbox: false, // allows renderer getUserMedia to work on all platforms
},
})
if (isDev) {
win.loadURL('http://127.0.0.1:5173')
win.webContents.openDevTools()
} else {
win.loadFile(path.join(__dirname, '../dist/index.html'))
}
}
app.whenReady().then(async () => {
await handlePermissions()
createWindow()
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit()
})