diff --git a/desktop/src/main.js b/desktop/src/main.js index 3be917d..40b9ed9 100644 --- a/desktop/src/main.js +++ b/desktop/src/main.js @@ -21,7 +21,7 @@ function updateMenu() { { label: '启动服务', enabled: !isRunning, click: startBackend }, { label: '停止服务', enabled: isRunning, click: () => stopBackend() }, { type: 'separator' }, - { label: '退出', click: () => { killBackend(); app.quit() } }, + { label: '退出', click: () => { shutdownBackend(); app.quit() } }, ])) } @@ -52,6 +52,11 @@ function killBackend() { updateMenu() } +function shutdownBackend() { + if (!backend) return + http.get('http://localhost:3000/api/shutdown').on('error', () => {}) +} + app.whenReady().then(() => { tray = new Tray(ICON.resize({ width: 16, height: 16 })) tray.setToolTip('质量追溯系统') @@ -60,4 +65,4 @@ app.whenReady().then(() => { }) app.on('window-all-closed', () => {}) -app.on('before-quit', () => killBackend()) +app.on('before-quit', () => shutdownBackend())