Ignore:
Timestamp:
Jul 24, 2018 4:26:40 PM (2 years ago)
Author:
meeh <meeh@…>
Branches:
master
Children:
7338282b
Parents:
2ee1a21
Message:

Code changes:

  • Port check to see if i2p is already running.
  • All buttons in the menu should work now.
  • Rewrote some C++ to Objective-C, which fits better with the integration.
  • Misc cleanup.
  • Made the launch of router repeatable.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • launchers/macosx/obj-cpp/RouterTask.mm

    r2ee1a21 rf9fbc76  
    1414@end
    1515
    16 @implementation RouterTask
     16@implementation I2PRouterTask
    1717
     18
     19- (void)routerStdoutData:(NSNotification *)notification
     20{
     21    NSLog(@"%@", [[NSString alloc] initWithData:[notification.object availableData] encoding:NSUTF8StringEncoding]);
     22    [notification.object waitForDataInBackgroundAndNotify];
     23}
    1824
    1925- (instancetype) initWithOptions : (RTaskOptions*) options
    2026{
    21     self.userRequestedRestart = FALSE;
     27    self.userRequestedRestart = NO;
     28    self.isRouterRunning = NO;
    2229    self.input = [NSFileHandle fileHandleWithStandardInput];
    2330    self.routerTask = [NSTask new];
     
    3138    [self.routerTask setStandardOutput:self.processPipe];
    3239        [self.routerTask setStandardError:self.processPipe];
     40
     41    NSFileHandle *stdoutFileHandle = [self.processPipe fileHandleForReading];
     42    [[NSNotificationCenter defaultCenter] addObserver:self
     43        selector:@selector(routerStdoutData:)
     44        name:NSFileHandleDataAvailableNotification
     45        object:stdoutFileHandle];
     46
     47    [stdoutFileHandle waitForDataInBackgroundAndNotify];
     48
    3349    [self.routerTask setTerminationHandler:^(NSTask* task) {
    3450        NSLog(@"termHandler triggered!");
     51        NSBundle *launcherBundle = [NSBundle mainBundle];
     52        auto iconImage = [launcherBundle pathForResource:@"ItoopieTransparent" ofType:@"png"];
     53        sendUserNotification(APP_IDSTR, @"I2P Router has stopped", [NSImage imageNamed:iconImage]);
     54        // Cleanup
     55        self.isRouterRunning = NO;
    3556    }];
    3657/*
     
    5475- (void) requestRestart
    5576{
    56     self.userRequestedRestart = TRUE;
     77    self.userRequestedRestart = YES;
     78    kill([self.routerTask processIdentifier], SIGHUP);
    5779}
    5880
     
    6486- (int) execute
    6587{
    66     //@try {
     88    @try {
    6789        [self.routerTask launch];
    6890        watchPid([self.routerTask processIdentifier]);
    69         [self.input waitForDataInBackgroundAndNotify];
    70         [[self.processPipe fileHandleForReading] waitForDataInBackgroundAndNotify];
    71         [[NSNotificationCenter defaultCenter] addObserverForName:NSFileHandleDataAvailableNotification
    72                                                           object:[self.processPipe fileHandleForReading] queue:nil
    73                                                       usingBlock:^(NSNotification *note)
    74          {
    75              // Read from shell output
    76              NSData *outData = [[self.processPipe fileHandleForReading] availableData];
    77              NSString *outStr = [[NSString alloc] initWithData:outData encoding:NSUTF8StringEncoding];
    78              if ([outStr length] > 1) {
    79                  NSLog(@"output: %@", outStr);
    80              }
    81 
    82              // Continue waiting for shell output.
    83              [[self.processPipe fileHandleForReading] waitForDataInBackgroundAndNotify];
    84          }];
    85          //[self.routerTask waitUntilExit];
    86         //NSThread *thr = [[NSThread alloc] initWithTarget:self.routerTask selector:@selector(launch) object:nil];
    87         //[self.routerTask waitUntilExit];
     91        self.isRouterRunning = YES;
    8892        return 1;
    89     /*}
     93    }
    9094    @catch (NSException *e)
    9195        {
    9296                NSLog(@"Expection occurred %@", [e reason]);
    9397        return 0;
    94         }*/
     98        }
    9599}
    96100
Note: See TracChangeset for help on using the changeset viewer.