From 52c3c49f25c3eb08f2ecf7b8403d1524ad187ed8 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Wed, 12 Jul 2023 21:27:58 +1000 Subject: [PATCH] [v3] Add window close hook example --- v3/examples/events/main.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/v3/examples/events/main.go b/v3/examples/events/main.go index d498a4035..449cded31 100644 --- a/v3/examples/events/main.go +++ b/v3/examples/events/main.go @@ -48,7 +48,7 @@ func main() { println("events.Common.ApplicationStarted fired!") }) - app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ + win1 := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ Title: "Events Demo", Mac: application.MacWindow{ Backdrop: application.MacBackdropTranslucent, @@ -56,6 +56,19 @@ func main() { InvisibleTitleBarHeight: 50, }, }) + + var countdown = 3 + + win1.RegisterHook(events.Common.WindowClosing, func(e *application.WindowEvent) { + countdown-- + if countdown == 0 { + println("Closing!") + return + } + println("Nope! Not closing!") + e.Cancel() + }) + win2 := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{ Title: "Events Demo", Mac: application.MacWindow{