Skip to content
This repository has been archived by the owner on Oct 22, 2023. It is now read-only.

Commit

Permalink
Fix login item.
Browse files Browse the repository at this point in the history
  • Loading branch information
megabitsenmzq committed Oct 20, 2021
1 parent 51af2ad commit 627ae1c
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions Notch Simulator/Notch Simulator Helper/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,25 @@
#import <Cocoa/Cocoa.h>

int main(int argc, const char * argv[]) {
NSArray *pathComponents = [[[NSBundle mainBundle] bundlePath] pathComponents];
pathComponents = [pathComponents subarrayWithRange:NSMakeRange(0, [pathComponents count] - 4)];
NSString *path = [NSString pathWithComponents:pathComponents];
[[NSWorkspace sharedWorkspace] launchApplication:path];

BOOL running = NO;
BOOL active = NO;

NSArray *applications = [NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.JinyuMeng.Notch-Simulator"];
if (applications.count > 0) {
NSRunningApplication *application = [applications firstObject];

running = YES;
active = [application isActive];
}

if (!running && !active) {
NSArray *pathComponents = [[[NSBundle mainBundle] bundlePath] pathComponents];
pathComponents = [pathComponents subarrayWithRange:NSMakeRange(0, [pathComponents count] - 4)];
NSString *path = [NSString pathWithComponents:pathComponents];
[[NSWorkspace sharedWorkspace] launchApplication:path];
}
[NSApp terminate:nil];
return NSApplicationMain(argc, argv);
}

0 comments on commit 627ae1c

Please sign in to comment.