forked from tisfeng/Easydict
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppDelegate.m
49 lines (37 loc) · 1.53 KB
/
AppDelegate.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//
// AppDelegate.m
// EasydictHelper
//
// Created by ripper on 2019/12/10.
// Copyright © 2019 ripperhe. All rights reserved.
//
#import "AppDelegate.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSString *identifier = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"];
identifier = [identifier stringByReplacingOccurrencesOfString:@"Helper" withString:@""];
__block BOOL alreadyRunning = NO;
[NSWorkspace.sharedWorkspace.runningApplications enumerateObjectsUsingBlock:^(NSRunningApplication *_Nonnull obj, NSUInteger idx, BOOL *_Nonnull stop) {
if ([obj.bundleIdentifier isEqualToString:identifier]) {
alreadyRunning = YES;
*stop = YES;
}
}];
if (!alreadyRunning) {
NSURL *appURL = [[NSWorkspace sharedWorkspace] URLForApplicationWithBundleIdentifier:identifier];
NSWorkspaceOpenConfiguration *config = [NSWorkspaceOpenConfiguration configuration];
[config setActivates:NO];
[[NSWorkspace sharedWorkspace] openApplicationAtURL:appURL configuration:config completionHandler:^(NSRunningApplication * _Nullable app, NSError * _Nullable error) {
if (error) {
NSLog(@"Helper 启动 %@ 报错\n%@", identifier, error);
}
}];
}
[NSApp terminate:nil];
}
- (void)applicationWillTerminate:(NSNotification *)aNotification {
// Insert code here to tear down your application
}
@end