mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-12 15:09:33 +08:00

This commit adds a robust teardown process for windows on application shutdown. It introduces a field to track the destruction state of each window and checks such before performing window operations. Also, it enhances the destroy functions within application for thorough clean up. Finally, redundant event handlers related to application termination were removed while fixing file generating challenge in go tasks.
161 lines
5.4 KiB
Objective-C
161 lines
5.4 KiB
Objective-C
//go:build darwin
|
|
#import "application_darwin_delegate.h"
|
|
#import "../events/events_darwin.h"
|
|
extern bool hasListeners(unsigned int);
|
|
extern void quitApplication();
|
|
|
|
@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 {
|
|
quitApplication();
|
|
return NSTerminateCancel;
|
|
}
|
|
- (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
|