[darwin] add support for quitting app

This commit is contained in:
Lea Anthony
2024-01-08 21:22:33 +11:00
parent df0419a7d6
commit 68e779d64e
8 changed files with 552 additions and 488 deletions
+5
View File
@@ -122,6 +122,11 @@ func New(appOptions Options) *App {
result.keyBindings = processKeyBindingOptions(result.options.KeyBindings)
}
// Handle the terminate event
result.On(events.Common.ApplicationTerminate, func(e *Event) {
result.Quit()
})
return result
}
@@ -1,6 +1,7 @@
//go:build darwin
#import "application_darwin_delegate.h"
#import "../events/events_darwin.h"
#import "message.h"
extern bool hasListeners(unsigned int);
@implementation AppDelegate
- (void)dealloc
@@ -17,7 +18,10 @@ extern bool hasListeners(unsigned int);
processApplicationEvent(EventApplicationDidChangeTheme, NULL);
}
}
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender {
processApplicationEvent(EventApplicationTerminate, NULL);
return NSTerminateCancel;
}
- (BOOL)applicationSupportsSecureRestorableState:(NSApplication *)app
{
return YES;
@@ -152,5 +156,11 @@ extern bool hasListeners(unsigned int);
}
}
- (void)applicationTerminate:(NSNotification *)notification {
if( hasListeners(EventApplicationTerminate) ) {
processApplicationEvent(EventApplicationTerminate, NULL);
}
}
// GENERATED EVENTS END
@end
@@ -7,6 +7,7 @@ import "github.com/wailsapp/wails/v3/pkg/events"
var commonApplicationEventMap = map[events.ApplicationEventType]events.ApplicationEventType{
events.Mac.ApplicationDidFinishLaunching: events.Common.ApplicationStarted,
events.Mac.ApplicationDidChangeTheme: events.Common.ThemeChanged,
events.Mac.ApplicationTerminate: events.Common.ApplicationTerminate,
}
func (m *macosApp) setupCommonEvents() {