From a80068b04bbb80c05cd229a89d5be757f7936949 Mon Sep 17 00:00:00 2001 From: boksbc Date: Mon, 11 May 2026 22:09:19 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20main.js=20=E2=80=94=20wires=20tray,=20H?= =?UTF-8?q?UD,=20wakeword,=20shortcuts=20and=20IPC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/main.js | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 electron/main.js diff --git a/electron/main.js b/electron/main.js new file mode 100644 index 0000000..ac20559 --- /dev/null +++ b/electron/main.js @@ -0,0 +1,53 @@ +const { app, ipcMain, globalShortcut, nativeTheme } = require('electron'); +const { createTray } = require('./tray'); +const { createHud, showHud, hideHud } = require('./hud'); +const { startWakeword, stopWakeword } = require('./wakeword'); +const { executeMacCommand } = require('./mac-agent'); +const axios = require('axios'); + +const FOX_URL = process.env.FOX_URL || 'https://fox.pxo.at'; + +app.dock?.hide(); + +if (!app.requestSingleInstanceLock()) { + app.quit(); +} + +app.whenReady().then(() => { + nativeTheme.themeSource = 'dark'; + + createHud(); + + createTray({ + onShow: showHud, + onHide: hideHud, + onQuit: () => app.quit(), + }); + + globalShortcut.register('CommandOrControl+Shift+F', showHud); + + startWakeword({ onWake: showHud }); + + ipcMain.on('hide-hud', () => hideHud()); + + ipcMain.on('send-message', async (_, text) => { + try { + await axios.post(`${FOX_URL}/fox/message`, { text }); + } catch (err) { + console.error('[Fox] send-message fehlgeschlagen:', err.message); + } + }); + + ipcMain.handle('mac-command', async (_, command) => { + return await executeMacCommand(command); + }); +}); + +app.on('will-quit', () => { + globalShortcut.unregisterAll(); + stopWakeword(); +}); + +app.on('window-all-closed', (e) => { + e.preventDefault(); +});