Open jheuel opened 8 years ago
If i understand correctly, you want the webserver to close, when the user closes a browser window. The correct way to handle this would be to listen to a window event
// In https://github.com/miketheprogrammer/go-thrust/blob/master/tutorials/basic_window_events/basic_window_events.go
/*
Here we use a CommandResponse callback just because we can, it provides us more data
than the EventResult callback
*/
onclose, err := thrust.NewEventHandler("closed", func(cr commands.EventResult) {
fmt.Println("Close Event Occured")
})
fmt.Println(onclose)
if err != nil {
fmt.Println(err)
connection.CleanExit()
}
In the above event you could do something like server.close or server.kill or whatever the API is for that stop server action.
However I should mention, depending on how you architected your app, you could have more than one window. Meaning you would have to keep track of all the windows and their events.
on evt: 'window.close' if (len(windows) === 1) { windows.remove(current) webserver.close } else { window.remove(current) }
I was just wondering why the program terminated in one case but not in the other case where solely the html was different.
Thanks for your input about window events I will look into that. Really like the work you have done. :-)
I was wondering why my net/http server does not terminate when I close the go-thrust window while using an index page like
<html><body>hi</body></html>
instead of the html given in basic_webserver_app.go.I would think that the web server should terminate without the webview part. Can you help me understand why go-thrust is working that way or is this behaviour not intended?
This is the basic_webserver_app.go example without the javascript block which does not terminate on my machine:
Tested on: