From 20b23338f780f5d327855776b452981339dde15f Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Sun, 11 May 2014 20:16:27 -0300 Subject: [PATCH] Shutdown from GUI (ref #192) --- cmd/syncthing/gui.go | 9 +++++++-- cmd/syncthing/main.go | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/cmd/syncthing/gui.go b/cmd/syncthing/gui.go index 09622a2e8..ac89d6f7d 100644 --- a/cmd/syncthing/gui.go +++ b/cmd/syncthing/gui.go @@ -53,6 +53,7 @@ func startGUI(cfg GUIConfiguration, m *Model) error { router.Post("/rest/config", restPostConfig) router.Post("/rest/restart", restPostRestart) router.Post("/rest/reset", restPostReset) + router.Post("/rest/shutdown", restPostShutdown) router.Post("/rest/error", restPostError) router.Post("/rest/error/clear", restClearErrors) @@ -156,15 +157,19 @@ func restGetConfigInSync(w http.ResponseWriter) { json.NewEncoder(w).Encode(map[string]bool{"configInSync": configInSync}) } -func restPostRestart(req *http.Request) { +func restPostRestart() { go restart() } -func restPostReset(req *http.Request) { +func restPostReset() { resetRepositories() go restart() } +func restPostShutdown() { + go shutdown() +} + var cpuUsagePercent [10]float64 // The last ten seconds var cpuUsageLock sync.RWMutex diff --git a/cmd/syncthing/main.go b/cmd/syncthing/main.go index 250f6bf43..b18360849 100644 --- a/cmd/syncthing/main.go +++ b/cmd/syncthing/main.go @@ -431,6 +431,10 @@ func restart() { stop <- true } +func shutdown() { + stop <- true +} + var saveConfigCh = make(chan struct{}) func saveConfigLoop(cfgFile string) {