Skip to content

Commit

Permalink
Regularly update tray
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxGfeller committed Jun 24, 2021
1 parent 0d98b3a commit 4b26752
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const {
Tray,
app,
ipcMain,
systemPreferences,
shell,
nativeTheme
} = require('electron')
Expand All @@ -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', () => {
Expand All @@ -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()
Expand All @@ -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()
}

Expand Down Expand Up @@ -245,7 +256,7 @@ ipcMain.on('login', (evt, values) => {
preferencesWindow.hide()
}, 2000)

initTray()
initApp()
})
})

Expand Down

0 comments on commit 4b26752

Please sign in to comment.