diff --git a/v2/internal/frontend/desktop/darwin/frontend.go b/v2/internal/frontend/desktop/darwin/frontend.go index 2d169da1..7e3b4bab 100644 --- a/v2/internal/frontend/desktop/darwin/frontend.go +++ b/v2/internal/frontend/desktop/darwin/frontend.go @@ -206,6 +206,9 @@ func (f *Frontend) WindowSetRGBA(col *options.RGBA) { } func (f *Frontend) Quit() { + if f.frontendOptions.OnBeforeClose != nil && f.frontendOptions.OnBeforeClose(f.ctx) { + return + } f.mainWindow.Quit() } diff --git a/v2/internal/frontend/desktop/linux/frontend.go b/v2/internal/frontend/desktop/linux/frontend.go index 8a94a82f..abcfcd44 100644 --- a/v2/internal/frontend/desktop/linux/frontend.go +++ b/v2/internal/frontend/desktop/linux/frontend.go @@ -208,6 +208,9 @@ func (f *Frontend) WindowSetRGBA(col *options.RGBA) { } func (f *Frontend) Quit() { + if f.frontendOptions.OnBeforeClose != nil && f.frontendOptions.OnBeforeClose(f.ctx) { + return + } f.mainWindow.Quit() } diff --git a/v2/internal/frontend/desktop/windows/frontend.go b/v2/internal/frontend/desktop/windows/frontend.go index 32245c12..eed02b39 100644 --- a/v2/internal/frontend/desktop/windows/frontend.go +++ b/v2/internal/frontend/desktop/windows/frontend.go @@ -261,6 +261,9 @@ func (f *Frontend) WindowSetRGBA(col *options.RGBA) { } func (f *Frontend) Quit() { + if f.frontendOptions.OnBeforeClose != nil && f.frontendOptions.OnBeforeClose(f.ctx) { + return + } // Exit must be called on the Main-Thread. It calls PostQuitMessage which sends the WM_QUIT message to the thread's // message queue and our message queue runs on the Main-Thread. f.mainWindow.Invoke(winc.Exit) diff --git a/v2/pkg/options/options.go b/v2/pkg/options/options.go index 91c1b329..717fd93d 100644 --- a/v2/pkg/options/options.go +++ b/v2/pkg/options/options.go @@ -45,9 +45,10 @@ type App struct { Menu *menu.Menu Logger logger.Logger `json:"-"` LogLevel logger.LogLevel - OnStartup func(ctx context.Context) `json:"-"` - OnDomReady func(ctx context.Context) `json:"-"` - OnShutdown func(ctx context.Context) `json:"-"` + OnStartup func(ctx context.Context) `json:"-"` + OnDomReady func(ctx context.Context) `json:"-"` + OnShutdown func(ctx context.Context) `json:"-"` + OnBeforeClose func(ctx context.Context) (prevent bool) `json:"-"` Bind []interface{} WindowStartState WindowStartState