diff --git a/desktop/src/main.js b/desktop/src/main.js index 3afd7e7..b8a1cfc 100644 --- a/desktop/src/main.js +++ b/desktop/src/main.js @@ -1,116 +1,45 @@ -const { app, Tray, BrowserWindow, nativeImage } = require('electron') +const { app, Tray, Menu, nativeImage } = require('electron') const { spawn, exec } = require('child_process') const path = require('path') const PROJECT_DIR = path.resolve(__dirname, '../../project') +const ENTRY = path.join(PROJECT_DIR, 'dist', 'index.js') let backend = null let tray = null -let isRunning = false -let popup = null const ICON = nativeImage.createFromBuffer(Buffer.from( 'iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAL0lEQVR4nO3OIQEAAAgDMHJg6Ul1iHEzMb/q2UsqAQEBAQEBAQEBAQEBAQGBdOABvyXoW2Q1L3wAAAAASUVORK5CYII=', 'base64' )) -function togglePopup() { - if (popup && !popup.isDestroyed() && popup.isVisible()) { - popup.hide() - return - } - createPopup() +function startBackend() { + if (backend) return + backend = spawn('node', [ENTRY], { + cwd: PROJECT_DIR, + stdio: 'ignore', + env: { ...process.env }, + windowsHide: true, + }) + backend.on('exit', () => { backend = null }) } -function createPopup() { - if (popup && !popup.isDestroyed()) popup.close() - - const bounds = tray.getBounds() - popup = new BrowserWindow({ - width: 180, - height: 175, - x: Math.round(bounds.x + bounds.width / 2 - 90), - y: Math.round(bounds.y - 175), - frame: false, - resizable: false, - skipTaskbar: true, - alwaysOnTop: true, - show: false, - transparent: false, - focusable: true, - webPreferences: { nodeIntegration: true, contextIsolation: false }, - }) - - popup.loadURL(`data:text/html;charset=utf-8,${encodeURIComponent(popupHTML())}`) - - popup.once('ready-to-show', () => popup.show()) - - popup.on('blur', () => { - setTimeout(() => { if (popup && !popup.isDestroyed()) popup.hide() }, 100) - }) -} - -function popupHTML() { - const s = !isRunning - return `
- -