fix(window): add GTK close-request handler for graceful shutdown
Cmd+Q and window close button now properly trigger graceful shutdown instead of immediately killing the browser process. The close-request signal handler calls QuitMainLoop() which allows the deferred cleanup() function to run, properly closing database connections and cleaning up resources.
- commit
- 186f9905fa5c832667a3af7c68138c24b6bd1cc3
- author
- bnema · · 2025-10-17 04:29 UTC
- parent
- 1fa2de8
- signature
- GPG Unverified
2B82207D370127A0The key is unknown
2 files · +14 -0
M CHANGELOG.md +1 -0
| @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file. | |||
| 6 | 6 | ||
| 7 | 7 | ### Fixed | |
| 8 | 8 | - Dark mode flash on startup: Set GTK dark theme preference and WebView background color before window/content creation | |
| 9 | + | - Cmd+Q and window close button now trigger graceful shutdown instead of killing the browser process | |
| 9 | 10 | ||
| 10 | 11 | ## [0.12.0] - 2025-10-16 | |
| 11 | 12 | ||
| @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file. | |||||
| 6 | 6 | ||||
| 7 | ### Fixed | 7 | ### Fixed | ||
| 8 | - Dark mode flash on startup: Set GTK dark theme preference and WebView background color before window/content creation | 8 | - Dark mode flash on startup: Set GTK dark theme preference and WebView background color before window/content creation | ||
| 9 | + | - Cmd+Q and window close button now trigger graceful shutdown instead of killing the browser process | |||
| 9 | 10 | ||||
| 10 | ## [0.12.0] - 2025-10-16 | 11 | ## [0.12.0] - 2025-10-16 | ||
| 11 | 12 | ||||
M pkg/webkit/window.go +13 -0
| @@ -1,6 +1,8 @@ | |||
| 1 | 1 | package webkit | |
| 2 | 2 | ||
| 3 | 3 | import ( | |
| 4 | + | "log" | |
| 5 | + | ||
| 4 | 6 | "github.com/diamondburned/gotk4/pkg/gtk/v4" | |
| 5 | 7 | ) | |
| 6 | 8 | ||
| @@ -21,6 +23,17 @@ func NewWindow(title string) (*Window, error) { | |||
| 21 | 23 | win.SetTitle(title) | |
| 22 | 24 | win.SetDefaultSize(1024, 768) | |
| 23 | 25 | ||
| 26 | + | // Connect close-request signal to handle Cmd+Q and window close button | |
| 27 | + | // Returning true prevents the default close behavior and allows graceful shutdown | |
| 28 | + | win.ConnectCloseRequest(func() bool { | |
| 29 | + | log.Printf("[window] Close request received (Cmd+Q or close button) - initiating graceful shutdown") | |
| 30 | + | // Quit the main loop gracefully, which will trigger cleanup | |
| 31 | + | QuitMainLoop() | |
| 32 | + | // Return true to prevent GTK from destroying the window immediately | |
| 33 | + | // The cleanup process will handle window destruction | |
| 34 | + | return true | |
| 35 | + | }) | |
| 36 | + | ||
| 24 | 37 | return &Window{win: win}, nil | |
| 25 | 38 | } | |
| 26 | 39 | ||
| @@ -1,6 +1,8 @@ | |||||
| 1 | package webkit | 1 | package webkit | ||
| 2 | 2 | ||||
| 3 | import ( | 3 | import ( | ||
| 4 | + | "log" | |||
| 5 | + | ||||
| 4 | "github.com/diamondburned/gotk4/pkg/gtk/v4" | 6 | "github.com/diamondburned/gotk4/pkg/gtk/v4" | ||
| 5 | ) | 7 | ) | ||
| 6 | 8 | ||||
| @@ -21,6 +23,17 @@ func NewWindow(title string) (*Window, error) { | |||||
| 21 | win.SetTitle(title) | 23 | win.SetTitle(title) | ||
| 22 | win.SetDefaultSize(1024, 768) | 24 | win.SetDefaultSize(1024, 768) | ||
| 23 | 25 | ||||
| 26 | + | // Connect close-request signal to handle Cmd+Q and window close button | |||
| 27 | + | // Returning true prevents the default close behavior and allows graceful shutdown | |||
| 28 | + | win.ConnectCloseRequest(func() bool { | |||
| 29 | + | log.Printf("[window] Close request received (Cmd+Q or close button) - initiating graceful shutdown") | |||
| 30 | + | // Quit the main loop gracefully, which will trigger cleanup | |||
| 31 | + | QuitMainLoop() | |||
| 32 | + | // Return true to prevent GTK from destroying the window immediately | |||
| 33 | + | // The cleanup process will handle window destruction | |||
| 34 | + | return true | |||
| 35 | + | }) | |||
| 36 | + | ||||
| 24 | return &Window{win: win}, nil | 37 | return &Window{win: win}, nil | ||
| 25 | } | 38 | } | ||
| 26 | 39 | ||||