From 40db8b84e6095b8f12b4399e76b70157785d231a Mon Sep 17 00:00:00 2001 From: Daniel Andrei Date: Wed, 13 Feb 2019 11:17:39 +0200 Subject: [PATCH] Remove config for login settings and add ts definition --- source/app-login-settings.d.ts | 4 ++++ source/index.ts | 10 ---------- source/menu.ts | 29 ++++++++++++++++------------- 3 files changed, 20 insertions(+), 23 deletions(-) create mode 100644 source/app-login-settings.d.ts diff --git a/source/app-login-settings.d.ts b/source/app-login-settings.d.ts new file mode 100644 index 000000000..028d207ab --- /dev/null +++ b/source/app-login-settings.d.ts @@ -0,0 +1,4 @@ +interface AppLoginSettings { + openAtLogin: bool; + openAsHidden: bool; +} diff --git a/source/index.ts b/source/index.ts index 03c157198..6fff952f0 100644 --- a/source/index.ts +++ b/source/index.ts @@ -48,16 +48,6 @@ app.setAppUserModelId('com.sindresorhus.caprine'); // https://github.com/electron/electron/issues/9671 app.commandLine.appendSwitch('disable-color-correct-rendering'); -const appFolder = path.dirname(process.execPath); -const updateExe = path.resolve(appFolder, '..', 'Update.exe'); - -const {openAtLogin, openAsHidden, wasOpenedAsHidden} = app.getLoginItemSettings({ - path: updateExe -}); - -config.set('openAtLogin', openAtLogin); -config.set('openAsHidden', openAsHidden || wasOpenedAsHidden); - if (!config.get('hardwareAcceleration')) { app.disableHardwareAcceleration(); } diff --git a/source/menu.ts b/source/menu.ts index 187318a1c..25358fe02 100644 --- a/source/menu.ts +++ b/source/menu.ts @@ -13,13 +13,10 @@ import config from './config'; import {sendAction, showRestartDialog} from './util'; import {generateSubmenu as generateEmojiSubmenu} from './emoji'; -function setLoginSettings(): void { - const appFolder = path.dirname(process.execPath); - const updateExe = path.resolve(appFolder, '..', 'Update.exe'); - - const openAtLogin = config.get('openAtLogin'); - const openAsHidden = config.get('openAsHidden'); +const appFolder = path.dirname(process.execPath); +const updateExe = path.resolve(appFolder, '..', 'Update.exe'); +function setLoginSettings({openAtLogin, openAsHidden}: AppLoginSettings): void { app.setLoginItemSettings({ openAtLogin, openAsHidden, @@ -27,6 +24,12 @@ function setLoginSettings(): void { }); } +function getLoginSettings(): AppLoginSettings { + return app.getLoginItemSettings({ + path: updateExe + }); +} + export default function updateMenu(): Menu { const newConversationItem: MenuItemConstructorOptions = { label: 'New Conversation', @@ -142,6 +145,8 @@ Press Command/Ctrl+R in Caprine to see your changes. } ]; + const {openAtLogin, openAsHidden} = getLoginSettings(); + const preferencesSubmenu: MenuItemConstructorOptions[] = [ { label: 'Bounce Dock on Message', @@ -207,21 +212,19 @@ Press Command/Ctrl+R in Caprine to see your changes. { type: 'checkbox', label: 'Launch at login', - checked: config.get('openAtLogin'), + checked: openAtLogin, click(item) { - config.set('openAtLogin', item.checked); - setLoginSettings(); + setLoginSettings({openAtLogin: item.checked, openAsHidden}); updateMenu(); } }, { type: 'checkbox', label: 'Launch as hidden', - checked: config.get('openAsHidden'), - enabled: config.get('openAtLogin'), + checked: openAsHidden, + enabled: openAtLogin, click(item) { - config.set('openAsHidden', item.checked); - setLoginSettings(); + setLoginSettings({openAtLogin, openAsHidden: item.checked}); } }, {