Skip to content

Commit

Permalink
refactored: Background tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
middaysan committed May 28, 2024
1 parent 54aea23 commit dd1120d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func main() {
}

go autoCleanStandbyList(stopChan)
go autoUpdateTooltip(stopChan)

systray.Run(tray.OnReady, onExit)
}
Expand All @@ -49,23 +50,31 @@ func onExit() {
//
// Note: The function assumes the availability of the windowsapi package.
func autoCleanStandbyList(stopChan chan struct{}) {
// Initial sleep to allow the systray to be ready
time.Sleep(2 * time.Second)

for {
select {
case <-stopChan:
return
default:
time.Sleep(autoCleanupCooldown)
standbyList, freeRAM, _ := windowsapi.GetStanbyListAndFreeRAMSize()
percent := (standbyList * 100) / freeRAM

if (percent > percentThreshold) {
windowsapi.CleanStandbyList()
}
}
}
}

// autoUpdateTooltip periodically updates the tooltip text of the system tray icon.
func autoUpdateTooltip(stopChan chan struct{}) {
for {
select {
case <-stopChan:
return
default:
time.Sleep(2 * time.Second)
tray.UpdateTooltip()
time.Sleep(autoCleanupCooldown)
}
}
}
Binary file removed foo.txt
Binary file not shown.

0 comments on commit dd1120d

Please sign in to comment.