Post

Replies

Boosts

Views

Activity

Reply to NSWindowDelegate windowShouldClose on Catalyst
I solved this issue by creating an OSX Bundle for my catalyst app. Although I can set my Principal class within the bundle as an NSWindowDelegate, the delegate does not respond to the windowShouldClose function. Interestingly the NSApplicationDelegate that use to work pre Ventura will now crash the app under Ventura. The only solution I could find was to override the close button and substitute my own action when the user presses the close button. In the Bundle's Principal Class: // schedule a timer to complete the setup - apparently // we need to stabilize the app before setting delegates Timer.scheduledTimer(withTimeInterval: 1.0, repeats: false) {_ in let sharedApp = NSApplication.shared // NSApplicationDelegate seems incompatible with the new Ventura // release so it is commented out now. If the NSApplicationDelegate // is activated then any main menu bar selection results in an // app crash. // sharedApp.delegate = self self.mainWindow = sharedApp.windows.first self.mainWindow?.delegate = self // override the app close button as we can't use the app delegate's // applicationShouldTerminateAfterLastWindowClosed method or the // NSWindowDelegate's windowShouldClose method. let closeButton = self.mainWindow?.standardWindowButton(NSWindow.ButtonType.closeButton) closeButton?.target = self closeButton?.action = #selector(self.terminateAppOverride(_close:)) }
Oct ’22