mirror of
https://github.com/wavetermdev/wails.git
synced 2026-08-05 13:53:43 -07:00
[darwin] add support for quitting app
This commit is contained in:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user