diff --git a/linux_press_daemon.go b/linux_press_daemon.go index 4de6c20..e65af1f 100644 --- a/linux_press_daemon.go +++ b/linux_press_daemon.go @@ -10,6 +10,7 @@ package main import ( + "context" "net/http" "os" "sync" @@ -234,3 +235,13 @@ func (a *App) resetFailedLinuxPressCycle(cycle uint64) { pressState.holdMode = false pressState.detectingHold = false } + +func stopLinuxPressDaemon() { + if linuxPressServer != nil { + ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) + defer cancel() + if err := linuxPressServer.Shutdown(ctx); err != nil { + logger.Error("Error shutting down Linux press daemon: %v", err) + } + } +}