github.com/AlpineAIO/wails/v2@v2.0.0-beta.32.0.20240505041856-1047a8fa5fef/internal/frontend/desktop/darwin/AppDelegate.m (about)

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