Fall back to next port on EADDRINUSE; show dialog and update tray URL

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-26 10:08:15 -07:00
co-authored by Claude Sonnet 4.6
parent 65e871c16e
commit 6fd858347f
2 changed files with 57 additions and 10 deletions
+13 -2
View File
@@ -1,4 +1,4 @@
const { app, BrowserWindow, ipcMain } = require('electron');
const { app, BrowserWindow, ipcMain, dialog } = require('electron');
const path = require('path');
const { startServer } = require('./server');
const { createTray } = require('./tray');
@@ -40,6 +40,17 @@ async function createWindow() {
app.whenReady().then(async () => {
serverHandle = await startServer({ port: PORT, overlayDir: OVERLAY_DIR });
if (serverHandle.port !== PORT) {
const actual = serverHandle.port;
await dialog.showMessageBox({
type: 'info',
title: 'Port in use',
message: `Port ${PORT} was in use; using ${actual} instead.`,
detail: `If you have an OBS browser source pointed at this app, update it to http://localhost:${actual}/`,
buttons: ['OK'],
});
}
ipcMain.on('wtm:state', (_event, payload) => {
const next = serverHandle.setState(payload || { isPlaying: false });
if (tray) tray.update({ title: next.title, artist: next.artist });
@@ -48,7 +59,7 @@ app.whenReady().then(async () => {
await createWindow();
tray = createTray({
port: PORT,
port: serverHandle.port,
onShow: () => {
if (!mainWindow) return;
if (mainWindow.isMinimized()) mainWindow.restore();