fix: prevent IPC listener leak in preload, fix hud-show race on cold start
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>main
parent
03e4fd68d8
commit
71f7341974
|
|
@ -3,6 +3,8 @@ const path = require('path');
|
||||||
|
|
||||||
const HUD_URL = process.env.FOX_HUD_URL || 'https://fox.pxo.at/hud';
|
const HUD_URL = process.env.FOX_HUD_URL || 'https://fox.pxo.at/hud';
|
||||||
let hudWindow = null;
|
let hudWindow = null;
|
||||||
|
let hudLoaded = false;
|
||||||
|
let pendingShow = false;
|
||||||
|
|
||||||
function createHud() {
|
function createHud() {
|
||||||
const { width, height } = screen.getPrimaryDisplay().workAreaSize;
|
const { width, height } = screen.getPrimaryDisplay().workAreaSize;
|
||||||
|
|
@ -29,8 +31,22 @@ function createHud() {
|
||||||
|
|
||||||
hudWindow.setAlwaysOnTop(true, 'screen-saver');
|
hudWindow.setAlwaysOnTop(true, 'screen-saver');
|
||||||
hudWindow.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true });
|
hudWindow.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true });
|
||||||
|
|
||||||
|
hudWindow.webContents.once('did-finish-load', () => {
|
||||||
|
hudLoaded = true;
|
||||||
|
if (pendingShow) {
|
||||||
|
pendingShow = false;
|
||||||
|
hudWindow.webContents.send('hud-show');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
hudWindow.loadURL(HUD_URL);
|
hudWindow.loadURL(HUD_URL);
|
||||||
hudWindow.on('closed', () => { hudWindow = null; });
|
|
||||||
|
hudWindow.on('closed', () => {
|
||||||
|
hudWindow = null;
|
||||||
|
hudLoaded = false;
|
||||||
|
pendingShow = false;
|
||||||
|
});
|
||||||
|
|
||||||
return hudWindow;
|
return hudWindow;
|
||||||
}
|
}
|
||||||
|
|
@ -39,7 +55,11 @@ function showHud() {
|
||||||
if (!hudWindow) createHud();
|
if (!hudWindow) createHud();
|
||||||
hudWindow.show();
|
hudWindow.show();
|
||||||
hudWindow.focus();
|
hudWindow.focus();
|
||||||
|
if (hudLoaded) {
|
||||||
hudWindow.webContents.send('hud-show');
|
hudWindow.webContents.send('hud-show');
|
||||||
|
} else {
|
||||||
|
pendingShow = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function hideHud() {
|
function hideHud() {
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,24 @@ contextBridge.exposeInMainWorld('foxBridge', {
|
||||||
sendMessage: (text) => ipcRenderer.send('send-message', text),
|
sendMessage: (text) => ipcRenderer.send('send-message', text),
|
||||||
hideHud: () => ipcRenderer.send('hide-hud'),
|
hideHud: () => ipcRenderer.send('hide-hud'),
|
||||||
macCommand: (cmd) => ipcRenderer.invoke('mac-command', cmd),
|
macCommand: (cmd) => ipcRenderer.invoke('mac-command', cmd),
|
||||||
onFoxAction: (cb) => ipcRenderer.on('fox-action', (_, data) => cb(data)),
|
onFoxAction: (cb) => {
|
||||||
onHudShow: (cb) => ipcRenderer.on('hud-show', () => cb()),
|
ipcRenderer.removeAllListeners('fox-action');
|
||||||
onHudHide: (cb) => ipcRenderer.on('hud-hide', () => cb()),
|
ipcRenderer.on('fox-action', (_, data) => cb(data));
|
||||||
onStartListening: (cb) => ipcRenderer.on('start-listening', () => cb()),
|
},
|
||||||
onPlayAudio: (cb) => ipcRenderer.on('play-audio', (_, url) => cb(url)),
|
onHudShow: (cb) => {
|
||||||
|
ipcRenderer.removeAllListeners('hud-show');
|
||||||
|
ipcRenderer.on('hud-show', () => cb());
|
||||||
|
},
|
||||||
|
onHudHide: (cb) => {
|
||||||
|
ipcRenderer.removeAllListeners('hud-hide');
|
||||||
|
ipcRenderer.on('hud-hide', () => cb());
|
||||||
|
},
|
||||||
|
onStartListening: (cb) => {
|
||||||
|
ipcRenderer.removeAllListeners('start-listening');
|
||||||
|
ipcRenderer.on('start-listening', () => cb());
|
||||||
|
},
|
||||||
|
onPlayAudio: (cb) => {
|
||||||
|
ipcRenderer.removeAllListeners('play-audio');
|
||||||
|
ipcRenderer.on('play-audio', (_, url) => cb(url));
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue