From 69543243fce9ba1e6152cd52c4bcbc7cbde8870d Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Sat, 31 Dec 2022 00:25:52 +0530 Subject: setting status text when server starts/stops --- main.go | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'main.go') diff --git a/main.go b/main.go index ce6ae8e..41d69c8 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,7 @@ import ( "github.com/gotk3/gotk3/gtk" "context" "sync" + "fmt" ) func serve(port, dir string, wg *sync.WaitGroup) *http.Server { @@ -67,6 +68,7 @@ func onActivate(app *gtk.Application) { var on = false var server *http.Server buttonSwitch.Connect("clicked", func() { + // TODO: validate dir and port port, _ := portInput.GetText() dir, _ := dirInput.GetText() @@ -77,11 +79,16 @@ func onActivate(app *gtk.Application) { killServerDone := &sync.WaitGroup{} server = serve(port, dir, killServerDone) killServerDone.Add(1) + // do this after server starts on = true buttonSwitch.SetLabel("Stop") + statusLabel.SetText(fmt.Sprintf("Serving directory '%s' on PORT %s", dir, port)) + killServerDone.Wait() + // do this after server shuts down on = false buttonSwitch.SetLabel("Start") + statusLabel.SetText("") }() } }) -- cgit v1.2.3