native开机自启动(electron自带)electron原生自启动app.setLoginItemSettingsapp.setLoginItemSettings({openAtLogin:true,//BooleanstartstheapplicationatloginopenAsHidden:true,//Boolean(optional)mac表示以隐藏方式启动应用程序。~~~~//path:'',String(optional)Windows-登录时启动的可执行文件.默认为process.execPath.//args:[]StringWindows-传递给可执行文件的命令行参数。默认为空数组。注意将路径用引号括起来。})自实现的原理是修改注册表实现开机自启动,通过链接调用应用(类似百度网盘,点击链接打开应用)。说明中使用的插件node-regedityarnaddregedit将下例中的electronApp替换成你自己的应用别名(可以和exe名称不同),开机启动constregedit=require('regedit');const{app}=require('electron');constpath=require('path');//开机自启动//检查registry是否在开机后注册过electronAppregedit.list('HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run',(err,data)=>{if(err){console.log(err)}if(!data['HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run'].values.electronApp||data['HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run'].values.electronApp!==app.getPath('exe')){//如果未注册或注册地址与当前地址不一致则注册regedit.putValue({'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run':{'electronApp':{value:app.getPath('exe'),type:'REG_SZ'}}},(error)=>{if(error)console.log(error)})}});通过链接调用应用程序constregedit=require('regedit');const{app}=require('电子');/***把下面的`electronAPP`换成你想要的名字*使用时直接在html中使用
