From 97912c805dfff1fe81f414c293c0be48d0df074f Mon Sep 17 00:00:00 2001 From: Daniel Andrei Date: Wed, 13 Feb 2019 11:38:12 +0200 Subject: [PATCH] Use ts definition from electron; Remove `launch as hidden` option, defaults to true --- source/app-login-settings.d.ts | 4 ---- source/menu.ts | 37 +++++++++------------------------- 2 files changed, 9 insertions(+), 32 deletions(-) delete mode 100644 source/app-login-settings.d.ts diff --git a/source/app-login-settings.d.ts b/source/app-login-settings.d.ts deleted file mode 100644 index 028d207ab..000000000 --- a/source/app-login-settings.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -interface AppLoginSettings { - openAtLogin: bool; - openAsHidden: bool; -} diff --git a/source/menu.ts b/source/menu.ts index 25358fe02..c133a9247 100644 --- a/source/menu.ts +++ b/source/menu.ts @@ -1,6 +1,6 @@ import * as path from 'path'; import {existsSync, writeFileSync} from 'fs'; -import {app, shell, Menu, MenuItemConstructorOptions} from 'electron'; +import {app, shell, Menu, MenuItemConstructorOptions, LoginItemSettings} from 'electron'; import { is, appMenu, @@ -13,21 +13,12 @@ import config from './config'; import {sendAction, showRestartDialog} from './util'; import {generateSubmenu as generateEmojiSubmenu} from './emoji'; -const appFolder = path.dirname(process.execPath); -const updateExe = path.resolve(appFolder, '..', 'Update.exe'); - -function setLoginSettings({openAtLogin, openAsHidden}: AppLoginSettings): void { - app.setLoginItemSettings({ - openAtLogin, - openAsHidden, - path: updateExe - }); +function setLoginSettings(settings: LoginItemSettings): void { + app.setLoginItemSettings(settings); } -function getLoginSettings(): AppLoginSettings { - return app.getLoginItemSettings({ - path: updateExe - }); +function getLoginSettings(): LoginItemSettings { + return app.getLoginItemSettings(); } export default function updateMenu(): Menu { @@ -145,7 +136,7 @@ Press Command/Ctrl+R in Caprine to see your changes. } ]; - const {openAtLogin, openAsHidden} = getLoginSettings(); + const settings: LoginItemSettings = getLoginSettings(); const preferencesSubmenu: MenuItemConstructorOptions[] = [ { @@ -210,21 +201,11 @@ Press Command/Ctrl+R in Caprine to see your changes. } }, { + label: 'Launch at Login', type: 'checkbox', - label: 'Launch at login', - checked: openAtLogin, - click(item) { - setLoginSettings({openAtLogin: item.checked, openAsHidden}); - updateMenu(); - } - }, - { - type: 'checkbox', - label: 'Launch as hidden', - checked: openAsHidden, - enabled: openAtLogin, + checked: settings.openAtLogin, click(item) { - setLoginSettings({openAtLogin, openAsHidden: item.checked}); + setLoginSettings({...settings, openAtLogin: item.checked, openAsHidden: item.checked}); } }, {