From df499a051715ca1ac6468aec5956bd870f07f587 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 1 May 2024 15:07:09 +0800 Subject: [PATCH] fix the problem that sometimes the startup fails when booting. --- electron/main/index.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/electron/main/index.ts b/electron/main/index.ts index 07c5e64..33185c0 100644 --- a/electron/main/index.ts +++ b/electron/main/index.ts @@ -1,6 +1,6 @@ import { app, BrowserWindow, dialog } from "electron"; import { release } from "node:os"; -import { join, dirname } from "node:path"; +import { join, dirname, basename } from "node:path"; import indexIpcEvent from "./main/ipcEvent"; import classificationIpcEvent from "./classification/ipcEvent"; import { init as classificationDataInit } from "./classification/data"; @@ -105,6 +105,16 @@ app.whenReady().then(() => { } // 设置快捷键 setShortcutKey(); + // 每次开启软件时都设置一次开机启动选项 + if (process.env.NODE_ENV !== "development") { + const exeName = basename(process.execPath); + app.setLoginItemSettings({ + openAtLogin: global.setting.general.startup, + openAsHidden: false, + path: process.execPath, + args: ["--processStart", `"${exeName}"`], + }); + } } catch (e) { if (process.env.NODE_ENV === "development") { console.log(e);