Skip to content
This repository has been archived by the owner on Apr 19, 2024. It is now read-only.

Commit

Permalink
save to registry when profile is toggle instead of on shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
zllovesuki committed Aug 19, 2020
1 parent d62f7df commit 2c2aa63
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 21 deletions.
21 changes: 3 additions & 18 deletions controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"log"
"os"
"os/exec"
"syscall"
"time"
Expand Down Expand Up @@ -33,7 +32,6 @@ var (

type Controller interface {
Run() int
Shutdown()
}

var _ Controller = &controller{}
Expand Down Expand Up @@ -122,8 +120,6 @@ func (c *controller) handleSystemControlInterface(wParam uintptr) {

func (c *controller) wndProc(hwnd win.HWND, msg uint32, wParam, lParam uintptr) uintptr {
switch msg {
case win.WM_DESTROY:
c.Shutdown()
case pAPCI:
c.handleSystemControlInterface(wParam)
}
Expand Down Expand Up @@ -226,6 +222,9 @@ func (c *controller) handleDebounce() {
title: "Toggle Thermal Plan",
message: message,
}
if err := c.Config.Registry.Save(); err != nil {
log.Println("error saving to registry", err)
}
}
}
}
Expand All @@ -244,17 +243,3 @@ func (c *controller) Run() int {

return c.eventLoop()
}

func (c *controller) Shutdown() {
// TODO: revisit this
c.notifyQueue <- notification{
title: "Saving Settings to Registry",
message: fmt.Sprintf("Thermal Plan: %s", c.Config.Thermal.CurrentProfile().Name),
}
time.Sleep(time.Millisecond * 50)

if err := c.Config.Registry.Save(); err != nil {
log.Fatalln(err)
}
os.Exit(0)
}
5 changes: 2 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,8 @@ func main() {
syscall.SIGTERM,
syscall.SIGQUIT)
go func() {
s := <-sigc
log.Printf("graceful shutdown on %+v\n", s)
control.Shutdown()
<-sigc
os.Exit(0)
}()

os.Exit(control.Run())
Expand Down

0 comments on commit 2c2aa63

Please sign in to comment.