12345678910111213141516171819202122232425262728293031323334353637383940 |
- //
- // AppDelegate.m
- // BaconBarHelper
- //
- // Created by Thomas Buck on 28.12.13.
- // Copyright (c) 2013 xythobuz. All rights reserved.
- //
-
- #import "AppDelegate.h"
-
- @implementation AppDelegate
-
- -(void)applicationDidFinishLaunching:(NSNotification *)aNotification
- {
- // Check if main app is already running; if yes, do nothing and terminate helper app
- BOOL alreadyRunning = NO;
- NSString *appName = [(NSString *)([[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"]) stringByReplacingOccurrencesOfString:@"Helper" withString:@""];
- NSArray *running = [[NSWorkspace sharedWorkspace] runningApplications];
- for (NSRunningApplication *app in running) {
- if ([[app bundleIdentifier] isEqualToString:appName]) {
- alreadyRunning = YES;
- }
- }
-
- if (!alreadyRunning) {
- NSString *path = [[NSBundle mainBundle] bundlePath];
- NSArray *p = [path pathComponents];
- NSMutableArray *pathComponents = [NSMutableArray arrayWithArray:p];
- [pathComponents removeLastObject];
- [pathComponents removeLastObject];
- [pathComponents removeLastObject];
- [pathComponents addObject:@"MacOS"];
- [pathComponents addObject:@"BaconBar"];
- NSString *newPath = [NSString pathWithComponents:pathComponents];
- [[NSWorkspace sharedWorkspace] launchApplication:newPath];
- }
- [NSApp terminate:nil];
- }
-
- @end
|