github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/updater/osx/Updater/AppDelegate.m (about)

     1  //
     2  //  AppDelegate.m
     3  //  Updater
     4  //
     5  //  Created by Gabriel on 4/7/16.
     6  //  Copyright © 2016 Keybase. All rights reserved.
     7  //
     8  
     9  #import "AppDelegate.h"
    10  
    11  #import "Defines.h"
    12  #import "Prompt.h"
    13  
    14  @implementation AppDelegate
    15  
    16  - (void)applicationDidFinishLaunching:(NSNotification *)notification {
    17    // Check if test environment
    18    if ([self isRunningTests]) return;
    19  
    20    // Run as accessory (no dock or menu).
    21    // The update prompt window will still be modal but won't take focus away from
    22    // other apps when it pops up.
    23    [NSApp setActivationPolicy:NSApplicationActivationPolicyAccessory];
    24  
    25    dispatch_async(dispatch_get_main_queue(), ^{
    26      [self run];
    27    });
    28  }
    29  
    30  - (void)run {
    31    NSString *inputString = @"{}";
    32  
    33    NSArray *args = NSProcessInfo.processInfo.arguments;
    34    if (args.count > 0) {
    35      NSArray *subargs = [args subarrayWithRange:NSMakeRange(1, args.count-1)];
    36      if (subargs.count >= 1) {
    37        inputString = subargs[0];
    38      }
    39    }
    40  
    41    [Prompt showPromptWithInputString:inputString presenter:^NSModalResponse(NSAlert *alert) {
    42      return [alert runModal];
    43    } completion:^(NSData *output) {
    44      if (!!output) {
    45        [[NSFileHandle fileHandleWithStandardOutput] writeData:output];
    46      }
    47      fflush(stdout);
    48      fflush(stderr);
    49      exit(0);
    50    }];
    51  }
    52  
    53  - (BOOL)isRunningTests {
    54    // The Xcode test environment is a little awkward. Instead of using TEST preprocessor macro, check env.
    55    NSDictionary *environment = [[NSProcessInfo processInfo] environment];
    56    NSString *testFilePath = environment[@"XCTestConfigurationFilePath"];
    57    return !!testFilePath;
    58  }
    59  
    60  @end