wails/v3/pkg/application/application_darwin_delegate.m
Lea Anthony 637713fae6 feat: adapt iOS and Android message processors to RuntimeRequest transport
Transport layer refactor adaptations for mobile platforms:

- Refactor processIOSMethod to use RuntimeRequest signature
- Refactor processAndroidMethod to use RuntimeRequest signature
- Add androidRequest constant (12) and handler to messageprocessor.go
- Update messageprocessor_mobile_stub.go for non-mobile builds
- Fix undefined windowID variable (use req.WebviewWindowID)
- Add iOS event generation to tasks/events/generate.go
- Add InvalidIOSCallError and InvalidAndroidCallError to errs package
- Update iOS delegate and webview files with generated event handlers

iOS methods refactored: Haptics.Impact, Device.Info, Scroll settings,
Navigation gestures, Link previews, Debug inspector, UserAgent

Android methods refactored: Haptics.Vibrate, Device.Info, Toast.Show

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-10 21:27:04 +11:00

207 lines
7.3 KiB
Objective-C

//go:build darwin && !ios
#import "application_darwin_delegate.h"
#import "../events/events_darwin.h"
#import <CoreServices/CoreServices.h> // For Apple Event constants
extern bool hasListeners(unsigned int);
extern bool shouldQuitApplication();
extern void cleanup();
extern void handleSecondInstanceData(char * message);
@implementation AppDelegate
- (void)dealloc
{
[super dealloc];
}
-(BOOL)application:(NSApplication *)sender openFile:(NSString *)filename
{
const char* utf8FileName = filename.UTF8String;
HandleOpenFile((char*)utf8FileName);
return YES;
}
- (BOOL)application:(NSApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<NSUserActivityRestoring>> * _Nullable))restorationHandler {
if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
NSURL *url = userActivity.webpageURL;
if (url) {
HandleOpenURL((char*)[[url absoluteString] UTF8String]);
return YES;
}
}
return NO;
}
// 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 { // Changed from NSApplication to NSNotification
if( hasListeners(EventApplicationShouldHandleReopen) ) {
processApplicationEvent(EventApplicationShouldHandleReopen, @{@"hasVisibleWindows": @(flag)});
}
return TRUE;
}
- (void)handleSecondInstanceNotification:(NSNotification *)note;
{
if (note.userInfo[@"message"] != nil) {
NSString *message = note.userInfo[@"message"];
const char* utf8Message = message.UTF8String;
handleSecondInstanceData((char*)utf8Message);
}
}
// 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)applicationDidResignActive:(NSNotification *)notification {
if( hasListeners(EventApplicationDidResignActive) ) {
processApplicationEvent(EventApplicationDidResignActive, 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
// Implementation for Apple Event based custom URL handling
@implementation CustomProtocolSchemeHandler
+ (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent {
NSString *urlStr = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];
if (urlStr) {
HandleOpenURL((char*)[urlStr UTF8String]);
}
}
@end
void StartCustomProtocolHandler(void) {
NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager];
[appleEventManager setEventHandler:[CustomProtocolSchemeHandler class]
andSelector:@selector(handleGetURLEvent:withReplyEvent:)
forEventClass:kInternetEventClass
andEventID: kAEGetURL];
}