gpt4 book ai didi

javascript - 如何使用自动启动在系统启动时启动应用程序?

转载 作者:行者123 更新时间:2023-11-30 07:01:54 25 4
gpt4 key购买 nike

package.json:

{
"name": "electronapp",
"version": "1.0.0",
"description": "electron auto-launch",
"main": "index.js",
"scripts": {
"start": "electron .",
"build": "electron-packager . --all"
},
"author": "ivie",
"license": "ISC",
"devDependencies": {
"Q": "^1.0.0",
"asar": "^0.13.0",
"electron": "^1.7.6",
"electron-packager": "^9.1.0",
"electron-prebuilt": "^1.4.13",
"fs-jetpack": "^1.2.0",
"grunt-electron-installer": "^2.1.0",
"rcedit": "^0.9.0"
},
"dependencies": {
"auto-launch": "^5.0.1"
}
}

index.js:

var electron = require('electron');
var app = electron.app;
var BrowserWindow = electron.BrowserWindow;
var path = require('path');

app.on('ready', ()=>{
var mainwindow = new BrowserWindow({
width: 1200,
height: 800,
icon: "favicon.ico",
frame:true,
title:'Menuboard',
fullscreen: false,
autoHideMenuBar: false
})
mainwindow.openDevTools();
mainwindow.loadURL('https://www.google.com');
mainwindow.on('closed', function() {
mainwindow = null;
});
});
app.on('window-all-closed', function() {
if(process.platform != 'darwin')
app.quit();
})

我使用这段代码生成了一个 electron .exe。当我双击它时它会被执行。但是,我想在 Windows 启动时运行它。我开始了解自动启动。但是,我不确定如何在我的应用程序中使用它?任何帮助将不胜感激。

最佳答案

加载自动启动模块:

const AutoLaunch = require('auto-launch');

然后在 app.on('ready', ()=>{ 之后添加:

  let autoLaunch = new AutoLaunch({
name: 'Your app name goes here',
path: app.getPath('exe'),
});
autoLaunch.isEnabled().then((isEnabled) => {
if (!isEnabled) autoLaunch.enable();
});

关于javascript - 如何使用自动启动在系统启动时启动应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46318177/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com