docs: Update Squirrel Run at Login docs to be modern (#44487)

Update Squirrel Run at Login docs to be modern

The current docs for setting up Run at Login use the legacy way that
Squirrel does shortcuts. This was replaced by an easier method, let's
use that instead
This commit is contained in:
Ani Betts 2024-11-02 21:56:02 +01:00 committed by GitHub
parent 7fea537fbf
commit d9a9d5b8fe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1302,23 +1302,24 @@ Returns `Object`:
Set the app's login item settings.
To work with Electron's `autoUpdater` on Windows, which uses [Squirrel][Squirrel-Windows],
you'll want to set the launch path to Update.exe, and pass arguments that specify your
application name. For example:
you'll want to set the launch path to your executable's name but a directory up, which is
a stub application automatically generated by Squirrel which will automatically launch the
latest version.
``` js
const { app } = require('electron')
const path = require('node:path')
const appFolder = path.dirname(process.execPath)
const updateExe = path.resolve(appFolder, '..', 'Update.exe')
const exeName = path.basename(process.execPath)
const ourExeName = path.basename(process.execPath)
const stubLauncher = path.resolve(appFolder, '..', ourExeName)
app.setLoginItemSettings({
openAtLogin: true,
path: updateExe,
path: stubLauncher,
args: [
'--processStart', `"${exeName}"`,
'--process-start-args', '"--hidden"'
// You might want to pass a parameter here indicating that this
// app was launched via login, but you don't have to
]
})
```