From 547353c2a123bd067588778f18c4c080807e49e0 Mon Sep 17 00:00:00 2001 From: Eduardo Gomes Heleno Date: Thu, 29 Sep 2022 01:04:34 -0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20create=20a=20setting=20that=20makes?= =?UTF-8?q?=20the=20app=20initialize=20when=20the=20system=20starts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/index.js | 14 +++++++++++- .../components/drawer/Drawer-settings.vue | 22 +++++++++++++++++++ src/renderer/store/modules/View.js | 5 +++++ src/renderer/utils/LocalStore.js | 1 + 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/main/index.js b/src/main/index.js index b16e9f3..dd56b14 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -37,8 +37,9 @@ app.whenReady().then(() => { createWindow() const minToTray = localStore.get('minToTray') const alwaysOnTop = localStore.get('alwaysOnTop') + const openOnStart = localStore.get('openOnStart') - if (minToTray) { + if (minToTray || openOnStart) { createTray() } @@ -48,6 +49,10 @@ app.whenReady().then(() => { // remove menu to stop the window being closed on Ctrl+W. See #121 mainWindow.setMenu(null) + if (openOnStart) { + mainWindow.hide() + } + // load shortcuts from storage loadGlobalShortcuts(localStore.get('globalShortcuts')) @@ -119,6 +124,13 @@ ipcMain.on('reload-global-shortcuts', (event, shortcuts) => { loadGlobalShortcuts(shortcuts) }) +ipcMain.on('open-on-start', (event, status) => { + electron.app.setLoginItemSettings({ + openAtLogin: status, + path: electron.app.getPath('exe') + }) +}) + function getNewWindowPosition() { const windowBounds = mainWindow.getBounds() const trayBounds = tray.getBounds() diff --git a/src/renderer/components/drawer/Drawer-settings.vue b/src/renderer/components/drawer/Drawer-settings.vue index 536fa2c..cfef810 100644 --- a/src/renderer/components/drawer/Drawer-settings.vue +++ b/src/renderer/components/drawer/Drawer-settings.vue @@ -76,6 +76,14 @@ :class="minToTrayOnClose ? 'is-active' : 'is-inactive'" > +
+

Open when system starts

+
+

Global Shortcuts

@@ -135,6 +143,10 @@ export default { return this.$store.getters.minToTrayOnClose }, + openOnStart() { + return this.$store.getters.openOnStart + }, + notifications() { return this.$store.getters.notifications }, @@ -219,6 +231,16 @@ export default { this.$store.dispatch('setViewState', payload) }, + selectOpenOnStart() { + const payload = { + key: 'openOnStart', + val: !this.openOnStart + } + ipcRenderer.send('open-on-start', !this.openOnStart) + this.$store.dispatch('setSetting', payload) + this.$store.dispatch('setViewState', payload) + }, + selectNotifications() { const payload = { key: 'notifications', diff --git a/src/renderer/store/modules/View.js b/src/renderer/store/modules/View.js index 77f1c89..421d8ee 100644 --- a/src/renderer/store/modules/View.js +++ b/src/renderer/store/modules/View.js @@ -15,6 +15,7 @@ const state = { breakAlwaysOnTop: localStore.get('breakAlwaysOnTop'), minToTray: localStore.get('minToTray'), minToTrayOnClose: localStore.get('minToTrayOnClose'), + openOnStart: localStore.get('openOnStart'), notifications: localStore.get('notifications'), os: process.platform, theme: localStore.get('theme') || 'Pomotroid' @@ -53,6 +54,10 @@ const getters = { return state.minToTrayOnClose }, + openOnStart() { + return state.openOnStart + }, + notifications() { return state.notifications }, diff --git a/src/renderer/utils/LocalStore.js b/src/renderer/utils/LocalStore.js index 5c4a80d..e45d4e8 100644 --- a/src/renderer/utils/LocalStore.js +++ b/src/renderer/utils/LocalStore.js @@ -18,6 +18,7 @@ function generateSettings() { autoStartBreakTimer: true, minToTray: false, minToTrayOnClose: false, + openOnStart: false, notifications: true, workRounds: 4, theme: null,