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:
+13
-2
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user