Merge pull request #1007 from Ironpark/feature/on_before_close

[v2] feature / on-before-close resolve #978
This commit is contained in:
Lea Anthony
2021-12-04 14:17:58 +11:00
committed by GitHub
5 changed files with 18 additions and 9 deletions

View File

@@ -12,16 +12,15 @@
#import "WailsContext.h"
@implementation WindowDelegate
- (BOOL)windowShouldClose:(WailsWindow *)sender {
[sender orderOut:nil];
if( self.hideOnClose == false ) {
processMessage("Q");
if( self.hideOnClose ) {
[NSApp hide:nil];
return false;
}
return !self.hideOnClose;
processMessage("Q");
return false;
}
- (void)windowDidExitFullScreen:(NSNotification *)notification {
[self.ctx.mainWindow applyWindowConstraints];
}

View File

@@ -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()
}

View File

@@ -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()
}

View File

@@ -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)

View File

@@ -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