-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathLLManager.m
More file actions
78 lines (65 loc) · 2.16 KB
/
LLManager.m
File metadata and controls
78 lines (65 loc) · 2.16 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//
// LLManager.m
// LaunchAtLogin
//
// Created by David Keegan on 4/20/12.
// Copyright (c) 2012 David Keegan.
// Copyright (c) 2014 Jan Weiß.
// Some rights reserved: <http://opensource.org/licenses/mit-license.php>
//
#import "LLManager.h"
#import "LLStrings.h"
#import <ServiceManagement/ServiceManagement.h>
NSString * const LLManagerSetLaunchAtLoginFailedNotification = @"LLManagerSetLaunchAtLoginFailedNotification";
@implementation LLManager
+ (BOOL)launchAtLogin{
BOOL launch = NO;
CFArrayRef cfJobs = SMCopyAllJobDictionaries(kSMDomainUserLaunchd);
if(cfJobs == NULL) return NO;
#if __has_feature(objc_arc)
NSArray *jobs = CFBridgingRelease(cfJobs);
#else
NSArray *jobs = [NSArray arrayWithArray:(NSArray *)cfJobs];
CFRelease(cfJobs);
#endif
if([jobs count]){
for(NSDictionary *job in jobs){
if([job[@"Label"] isEqualToString:LLHelperBundleIdentifier]){
launch = [job[@"OnDemand"] boolValue];
break;
}
}
}
return launch;
}
+ (void)setLaunchAtLogin:(BOOL)value {
[self setLaunchAtLogin:value
notifyOnFailure:NO];
}
+ (void)setLaunchAtLogin:(BOOL)value
notifyOnFailure:(BOOL)wantFailureNotification {
#if __has_feature(objc_arc)
CFStringRef LLHelperBundleIdentifierCF = (__bridge CFStringRef)LLHelperBundleIdentifier;
#else
CFStringRef LLHelperBundleIdentifierCF = (CFStringRef)LLHelperBundleIdentifier;
#endif
if(!SMLoginItemSetEnabled(LLHelperBundleIdentifierCF, value)){
if(wantFailureNotification){
[[NSNotificationCenter defaultCenter] postNotificationName:LLManagerSetLaunchAtLoginFailedNotification object:self];
}
else {
NSLog(@"SMLoginItemSetEnabled failed!");
}
}
}
#pragma mark - Bindings support
- (BOOL)launchAtLogin {
return [[self class] launchAtLogin];
}
- (void)setLaunchAtLogin:(BOOL)launchAtLogin {
[self willChangeValueForKey:@"launchAtLogin"];
[[self class] setLaunchAtLogin:launchAtLogin
notifyOnFailure:self.notifyIfSetLaunchAtLoginFailed];
[self didChangeValueForKey:@"launchAtLogin"];
}
@end