electron-archive / grunt-electron-installer

Grunt plugin to build Windows installers for Electron apps
MIT License
402 stars 106 forks source link

How to get Electron app to start on system startup? #115

Open hyperh opened 8 years ago

hyperh commented 8 years ago

I'm having some trouble getting my Electron app to start on system startup, does anyone know how this could be done?

Ideally, I could provide users with an ability to toggle this functionality in the Electron main window menu.

philipgiuliani commented 8 years ago

There is a npm package which works great with electron for that! https://www.npmjs.com/package/auto-launch

zeke commented 8 years ago

Yep. auto-launch works like a charm!

ananyaojha commented 7 years ago

Can you please help me out with step wise commands to create an auto-launch electron app?

I have some way of doing that. Kindly have a look and let me know what to change in this as I'm getting error with npm install electron-prebuilt --save-dev command ?

Please go through this link https://stackoverflow.com/questions/45632502/getting-error-while-executing-npm-install-save-dev-electron-prebuilt?noredirect=1#comment78224205_45632502 to see exactly what is happening when I run this command

STEPS :

mkdir dirname cd dirname npm init npm install electron-prebuilt --save-dev Create index.js npm install electron-packager --save-dev npm start npm run build OR electron-packager . --all

Thank you for your support in advance.

zeke commented 7 years ago

Since this issue was opened, an API has been added to Electron for starting the app at login: https://electron.atom.io/docs/api/app/#appsetloginitemsettingssettings-macos-windows

luoboding commented 6 years ago

@zeke thank you, i tried it like this,

const exeName = path.basename(process.execPath); app.setLoginItemSettings({ openAtLogin: true, path: process.execPath, args: [ '--processStart', "${exeName}", '--process-start-args', "--hidden" ] });

it works for me on windows. but the demo of this api in doc is not correct, the path should be the folder of your app which you want to auto startup.

zeke commented 6 years ago

the demo of this api in doc is not correct, the path should be the folder of your app which you want to auto startup.

@luoboding you mean in the electron/electron docs? If so, would you be able to open a pull request that corrects it?

luoboding commented 6 years ago

sorry @zeke , my mistake, i think i misunderstand 'process, execPath' which means the path of app you are running, not the folder, i test the official demo, it works fine. sorry about that.

RedDeathAt614 commented 6 years ago

Question for Windows (NSIS):

What @luoboding is doing only works for me after I have run the app manually at least once. This means that if I'm using perMachine: true I have to manually open the app once for all users. In our case this means doing this manually for hundreds of users at one of our clients call centers. This is not feasible for us or for our client.

It would seem that all I need to do is to add the app to the Startup menu in the Windows start menu as a part of the installer. Surely this must be possible somehow? Yet has eluded me for some time now. Anybody knows how to pull this off?

luoboding commented 6 years ago

@RedDeathAt614 i use NSIS to pack my app, app will be opened automatically when installation is finished.

RedDeathAt614 commented 6 years ago

Thanks @luoboding

If anybody's interested I ended up solving it by setting perMachine: true and then include an installer.nsh file in the build directory which looks like this:

 !macro customInstall
   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Run" "CortiRespond" "C:\Program Files\Corti\Corti Respond\Corti Respond.exe"
 !macroend

 !macro customUnInstall
   DeleteRegValue HKLM "Software\Microsoft\Windows\CurrentVersion\Run" "CortiRespond"
 !macroend

Hence just setting a key in the registry database to start the app on login and remove it again when the app is uninstalled. This seems to work nicely.

zhao2258 commented 6 years ago

请问如何禁止让项目在安装的时候自动启动?

luoboding commented 6 years ago

@zhao2258 you should open a new issue.

luoboding commented 6 years ago

@zhao2258 i hope this could help you. https://www.electron.build/configuration/nsis

jadhavrani123 commented 4 years ago

Sir I want to close my developer tool on click cntrl + shift + I

WebPreferences = new WebPreferences { DevTools = false } I am use this code........but it not work for me

erickximenes commented 4 years ago

Senhor, quero fechar minha ferramenta de desenvolvedor clicando em cntrl + shift + I

WebPreferences = new WebPreferences { DevTools = false } Estou usando este código ........ mas não funciona para mim

In the index.js file, comment out this line: //mainWindow.webContents.openDevTools();