From 4b26752d138b83732d36889ea48ee773bce641c9 Mon Sep 17 00:00:00 2001 From: Max Gfeller Date: Thu, 24 Jun 2021 17:56:40 +0200 Subject: [PATCH] Regularly update tray --- main.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/main.js b/main.js index fa80c60..6b0304b 100644 --- a/main.js +++ b/main.js @@ -4,7 +4,6 @@ const { Tray, app, ipcMain, - systemPreferences, shell, nativeTheme } = require('electron') @@ -25,6 +24,7 @@ var tray = null var preferencesWindow = null var client = null var interval = null +var intervalOverview = null var contextMenu = null app.on('ready', () => { @@ -45,12 +45,24 @@ app.on('ready', () => { }) client.overview((err, result) => { - if (!err) return initTray() + if (!err) return initApp() showPreferencesWindow() }) }) +function initApp () { + if (interval) { + clearInterval(interval) + clearInterval(intervalOverview) + } + + interval = setInterval(setCurrentTime, 1000 * 10) + intervalOverview = setInterval(initTray, 1000 * 60 * 10) + + initTray() +} + async function initTray () { hideDock() let autoLaunchEnabled = await autoLauncher.isEnabled() @@ -60,8 +72,7 @@ async function initTray () { tray = new Tray(path.join(__dirname, `/tray-icon-${darkMode ? 'dark' : 'light'}.png`)) tray.on('click', toggleTimer) tray.on('right-click', displayContextMenu) - if (interval) clearInterval(interval) - interval = setInterval(setCurrentTime, 1000 * 10) + setCurrentTime() } @@ -245,7 +256,7 @@ ipcMain.on('login', (evt, values) => { preferencesWindow.hide() }, 2000) - initTray() + initApp() }) })