windows/mac
下开机自启,electron
官方已经实现。文档地址-
linux
下自启。下载插件
npm install easy-auto-launch -S
创建
auto-launch.ts
文件,写入内容import AutoLaunch from "easy-auto-launch"; import {app} from "electron"; /** * 获取开机启动状态 */ export const getAutoLaunchState = async () => { if (process.platform === "linux") { const autoLauncher = new AutoLaunch({ name: app.getName(), isHidden: false, path: process.env.APPIMAGE }); return await autoLauncher.isEnabled(); } return app.getLoginItemSettings().openAtLogin; } /** * 更新开机启动 * @param isAutoLaunchEnabled */ export const updateAutoLaunch = async (isAutoLaunchEnabled: boolean = true) => { const electronIsDev = !app.isPackaged; // Don't run this in development if (electronIsDev) { return; } // `setLoginItemSettings` doesn't support linux if (process.platform === "linux") { const autoLauncher = new AutoLaunch({ name: app.getName(), isHidden: false, path: process.env.APPIMAGE }); if (isAutoLaunchEnabled) { await autoLauncher.enable(); } else { await autoLauncher.disable(); } return; } app.setLoginItemSettings({ openAtLogin: isAutoLaunchEnabled, openAsHidden: true, }); }
在主进程main中调用就好了。
app.whenReady().then(async () => { // enable auto launch await updateAutoLaunch(); await createWindow() });
electron开机自启
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。