github.com/secoba/wails/v2@v2.6.4/internal/frontend/desktop/darwin/ApDelegate.m (about) 1 // 2 // ApDelegate.m 3 // test 4 // 5 // Created by Lea Anthony on 10/10/21. 6 // 7 8 #import <Foundation/Foundation.h> 9 #import <Cocoa/Cocoa.h> 10 11 #import "ApDelegate.h" 12 13 @implementation ApDelegate 14 -(BOOL)application:(NSApplication *)sender openFile:(NSString *)filename 15 { 16 const char* utf8FileName = filename.UTF8String; 17 HandleOpenFile((char*)utf8FileName); 18 return YES; 19 } 20 21 - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender { 22 return NO; 23 } 24 25 - (void)applicationWillFinishLaunching:(NSNotification *)aNotification { 26 [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; 27 if (self.alwaysOnTop) { 28 [self.mainWindow setLevel:NSFloatingWindowLevel]; 29 } 30 if ( !self.startHidden ) { 31 [self.mainWindow makeKeyAndOrderFront:self]; 32 } 33 } 34 35 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { 36 [NSApp activateIgnoringOtherApps:YES]; 37 if ( self.startFullscreen ) { 38 NSWindowCollectionBehavior behaviour = [self.mainWindow collectionBehavior]; 39 behaviour |= NSWindowCollectionBehaviorFullScreenPrimary; 40 [self.mainWindow setCollectionBehavior:behaviour]; 41 [self.mainWindow toggleFullScreen:nil]; 42 } 43 44 if ( self.singleInstanceLockEnabled ) { 45 [[NSDistributedNotificationCenter defaultCenter] addObserver:self 46 selector:@selector(handleSecondInstanceNotification:) name:self.singleInstanceUniqueId object:nil]; 47 } 48 } 49 50 void SendDataToFirstInstance(char * singleInstanceUniqueId, char * message) { 51 // we pass message in object because otherwise sandboxing will prevent us from sending it https://developer.apple.com/forums/thread/129437 52 NSString * myString = [NSString stringWithUTF8String:message]; 53 [[NSDistributedNotificationCenter defaultCenter] 54 postNotificationName:[NSString stringWithUTF8String:singleInstanceUniqueId] 55 object:(__bridge const void *)(myString) 56 userInfo:nil 57 deliverImmediately:YES]; 58 } 59 60 char* GetMacOsNativeTempDir() { 61 NSString *tempDir = NSTemporaryDirectory(); 62 char *copy = strdup([tempDir UTF8String]); 63 64 return copy; 65 } 66 67 - (void)handleSecondInstanceNotification:(NSNotification *)note; 68 { 69 if (note.object != nil) { 70 NSString * message = (__bridge NSString *)note.object; 71 const char* utf8Message = message.UTF8String; 72 HandleSecondInstanceData((char*)utf8Message); 73 } 74 } 75 76 - (void)dealloc { 77 [super dealloc]; 78 } 79 80 @synthesize touchBar; 81 82 @end