mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-06 17:50:33 +08:00

This update allows the application shutdown to be cancelled. It implements the shouldQuit function, which can prevent the application from quitting if it returns false. Additional checks have been added to ensure cleanup and quit processes are performed only if required. The darwin delegate and linux and windows applications were modified to include this new functionality.
168 lines
5.5 KiB
Objective-C
168 lines
5.5 KiB
Objective-C
//go:build darwin
|
|
#import "application_darwin_delegate.h"
|
|
#import "../events/events_darwin.h"
|
|
extern bool hasListeners(unsigned int);
|
|
extern bool shouldQuitApplication();
|
|
extern void cleanup();
|
|
|
|
@implementation AppDelegate
|
|
- (void)dealloc
|
|
{
|
|
[super dealloc];
|
|
}
|
|
// Create the applicationShouldTerminateAfterLastWindowClosed: method
|
|
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication
|
|
{
|
|
return self.shouldTerminateWhenLastWindowClosed;
|
|
}
|
|
- (void)themeChanged:(NSNotification *)notification {
|
|
if( hasListeners(EventApplicationDidChangeTheme) ) {
|
|
processApplicationEvent(EventApplicationDidChangeTheme, NULL);
|
|
}
|
|
}
|
|
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender {
|
|
if( ! shouldQuitApplication() ) {
|
|
return NSTerminateCancel;
|
|
}
|
|
if( !self.shuttingDown ) {
|
|
self.shuttingDown = true;
|
|
cleanup();
|
|
}
|
|
return NSTerminateNow;
|
|
}
|
|
- (BOOL)applicationSupportsSecureRestorableState:(NSApplication *)app
|
|
{
|
|
return YES;
|
|
}
|
|
- (BOOL)applicationShouldHandleReopen:(NSNotification *)notification
|
|
hasVisibleWindows:(BOOL)flag {
|
|
if( hasListeners(EventApplicationShouldHandleReopen) ) {
|
|
processApplicationEvent(EventApplicationShouldHandleReopen, @{@"hasVisibleWindows": @(flag)});
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
// GENERATED EVENTS START
|
|
- (void)applicationDidBecomeActive:(NSNotification *)notification {
|
|
if( hasListeners(EventApplicationDidBecomeActive) ) {
|
|
processApplicationEvent(EventApplicationDidBecomeActive, NULL);
|
|
}
|
|
}
|
|
|
|
- (void)applicationDidChangeBackingProperties:(NSNotification *)notification {
|
|
if( hasListeners(EventApplicationDidChangeBackingProperties) ) {
|
|
processApplicationEvent(EventApplicationDidChangeBackingProperties, NULL);
|
|
}
|
|
}
|
|
|
|
- (void)applicationDidChangeEffectiveAppearance:(NSNotification *)notification {
|
|
if( hasListeners(EventApplicationDidChangeEffectiveAppearance) ) {
|
|
processApplicationEvent(EventApplicationDidChangeEffectiveAppearance, NULL);
|
|
}
|
|
}
|
|
|
|
- (void)applicationDidChangeIcon:(NSNotification *)notification {
|
|
if( hasListeners(EventApplicationDidChangeIcon) ) {
|
|
processApplicationEvent(EventApplicationDidChangeIcon, NULL);
|
|
}
|
|
}
|
|
|
|
- (void)applicationDidChangeOcclusionState:(NSNotification *)notification {
|
|
if( hasListeners(EventApplicationDidChangeOcclusionState) ) {
|
|
processApplicationEvent(EventApplicationDidChangeOcclusionState, NULL);
|
|
}
|
|
}
|
|
|
|
- (void)applicationDidChangeScreenParameters:(NSNotification *)notification {
|
|
if( hasListeners(EventApplicationDidChangeScreenParameters) ) {
|
|
processApplicationEvent(EventApplicationDidChangeScreenParameters, NULL);
|
|
}
|
|
}
|
|
|
|
- (void)applicationDidChangeStatusBarFrame:(NSNotification *)notification {
|
|
if( hasListeners(EventApplicationDidChangeStatusBarFrame) ) {
|
|
processApplicationEvent(EventApplicationDidChangeStatusBarFrame, NULL);
|
|
}
|
|
}
|
|
|
|
- (void)applicationDidChangeStatusBarOrientation:(NSNotification *)notification {
|
|
if( hasListeners(EventApplicationDidChangeStatusBarOrientation) ) {
|
|
processApplicationEvent(EventApplicationDidChangeStatusBarOrientation, NULL);
|
|
}
|
|
}
|
|
|
|
- (void)applicationDidFinishLaunching:(NSNotification *)notification {
|
|
if( hasListeners(EventApplicationDidFinishLaunching) ) {
|
|
processApplicationEvent(EventApplicationDidFinishLaunching, NULL);
|
|
}
|
|
}
|
|
|
|
- (void)applicationDidHide:(NSNotification *)notification {
|
|
if( hasListeners(EventApplicationDidHide) ) {
|
|
processApplicationEvent(EventApplicationDidHide, NULL);
|
|
}
|
|
}
|
|
|
|
- (void)applicationDidResignActiveNotification:(NSNotification *)notification {
|
|
if( hasListeners(EventApplicationDidResignActiveNotification) ) {
|
|
processApplicationEvent(EventApplicationDidResignActiveNotification, NULL);
|
|
}
|
|
}
|
|
|
|
- (void)applicationDidUnhide:(NSNotification *)notification {
|
|
if( hasListeners(EventApplicationDidUnhide) ) {
|
|
processApplicationEvent(EventApplicationDidUnhide, NULL);
|
|
}
|
|
}
|
|
|
|
- (void)applicationDidUpdate:(NSNotification *)notification {
|
|
if( hasListeners(EventApplicationDidUpdate) ) {
|
|
processApplicationEvent(EventApplicationDidUpdate, NULL);
|
|
}
|
|
}
|
|
|
|
- (void)applicationWillBecomeActive:(NSNotification *)notification {
|
|
if( hasListeners(EventApplicationWillBecomeActive) ) {
|
|
processApplicationEvent(EventApplicationWillBecomeActive, NULL);
|
|
}
|
|
}
|
|
|
|
- (void)applicationWillFinishLaunching:(NSNotification *)notification {
|
|
if( hasListeners(EventApplicationWillFinishLaunching) ) {
|
|
processApplicationEvent(EventApplicationWillFinishLaunching, NULL);
|
|
}
|
|
}
|
|
|
|
- (void)applicationWillHide:(NSNotification *)notification {
|
|
if( hasListeners(EventApplicationWillHide) ) {
|
|
processApplicationEvent(EventApplicationWillHide, NULL);
|
|
}
|
|
}
|
|
|
|
- (void)applicationWillResignActive:(NSNotification *)notification {
|
|
if( hasListeners(EventApplicationWillResignActive) ) {
|
|
processApplicationEvent(EventApplicationWillResignActive, NULL);
|
|
}
|
|
}
|
|
|
|
- (void)applicationWillTerminate:(NSNotification *)notification {
|
|
if( hasListeners(EventApplicationWillTerminate) ) {
|
|
processApplicationEvent(EventApplicationWillTerminate, NULL);
|
|
}
|
|
}
|
|
|
|
- (void)applicationWillUnhide:(NSNotification *)notification {
|
|
if( hasListeners(EventApplicationWillUnhide) ) {
|
|
processApplicationEvent(EventApplicationWillUnhide, NULL);
|
|
}
|
|
}
|
|
|
|
- (void)applicationWillUpdate:(NSNotification *)notification {
|
|
if( hasListeners(EventApplicationWillUpdate) ) {
|
|
processApplicationEvent(EventApplicationWillUpdate, NULL);
|
|
}
|
|
}
|
|
|
|
// GENERATED EVENTS END
|
|
@end
|