Skip to content

Commit

Permalink
Only set login element when it's changed (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
toto04 committed Sep 13, 2023
1 parent 54929f9 commit e2889dc
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,19 @@ async function setLoginItem(openAtLogin: boolean) {
if (process.platform === "linux") return

await app.whenReady()
debug(`Setting openAtLogin to ${openAtLogin}`)
app.setLoginItemSettings({
openAtLogin,
openAsHidden: true,
...windowsLoginSettings,
})

const loginItemSettings = app.getLoginItemSettings(windowsLoginSettings)
// only set the login item if it's different from the current one
if (openAtLogin !== loginItemSettings.openAtLogin) {
debug(`Setting openAtLogin to ${openAtLogin}`)
app.setLoginItemSettings({
openAtLogin,
openAsHidden: true,
...windowsLoginSettings,
})
} else {
debug(`openAtLogin is already ${openAtLogin}`)
}
}

loginManager.on("token", async () => {
Expand Down

0 comments on commit e2889dc

Please sign in to comment.