forked from muhqu/dterm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DTPrefsAXController.m
81 lines (66 loc) · 3.1 KB
/
DTPrefsAXController.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
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
79
80
81
// Copyright (c) 2007-2011 Decimus Software, Inc. All rights reserved.
#import "DTPrefsAXController.h"
#import "DTAppController.h"
#import "DTBlackRedStatusTransformer.h"
@interface DTPrefsAXController ()
@property (readwrite) BOOL axGeneralAccessEnabled;
@end
@implementation DTPrefsAXController
+ (void)initialize {
DTBlackRedStatusTransformer* vt = [[DTBlackRedStatusTransformer alloc] init];
[NSValueTransformer setValueTransformer:vt forName:@"DTBlackRedStatusTransformer"];
}
#pragma mark accessors
- (BOOL)axAppTrusted {
return (BOOL)[(DTAppController *)APP_DELEGATE isAXTrustedPromptIfNot:NO];
}
+ (NSSet*) keyPathsForValuesAffectingAxTrustStatusString {
return [NSSet setWithObject:@"axAppTrusted"];
}
- (NSString*)axTrustStatusString {
if(self.axAppTrusted)
return NSLocalizedString(@"trusted", @"Accessibility API trust status tag");
else
return NSLocalizedString(@"not trusted", @"Accessibility API trust status tag");
}
- (void)recheckGeneralAXAccess {
self.axGeneralAccessEnabled = (BOOL)[(DTAppController *)APP_DELEGATE isAXTrustedPromptIfNot:NO];
}
+ (NSSet*)keyPathsForValuesAffectingAxGeneralAccessEnabledString {
return [NSSet setWithObjects:
@"axGeneralAccessEnabled",
nil];
}
- (NSString*)axGeneralAccessEnabledString {
if(self.axGeneralAccessEnabled)
return NSLocalizedString(@"enabled", @"Accessibility API enabledness status tag");
else
return NSLocalizedString(@"disabled", @"Accessibility API enabledness status tag");
}
#pragma mark actions
- (IBAction)setAXTrusted:(id) __unused sender {
BOOL isTrusted = [(DTAppController *)APP_DELEGATE isAXTrustedPromptIfNot:YES];
if ( !isTrusted )
{
NSAlert* relaunchAlert = [NSAlert alertWithMessageText:NSLocalizedString(@"Trust settings updated", @"relaunch alert title")
defaultButton:NSLocalizedString(@"Relaunch now", @"relaunch alert default button")
alternateButton:NSLocalizedString(@"Relaunch later", @"relaunch alert alternate button")
otherButton:nil
informativeTextWithFormat:NSLocalizedString(@"The new trust settings will take effect when DTerm is next launched. Would you like to relaunch DTerm now?", @"relaunch alert text")];
if([relaunchAlert runModal] == NSAlertDefaultReturn) {
// This code borrowed from Sparkle, which was in turn borrowed from Allan Odgaard
NSString *currentAppPath = [[NSBundle mainBundle] bundlePath];
setenv("LAUNCH_PATH", [currentAppPath UTF8String], 1);
system("/bin/bash -c '{ for (( i = 0; i < 3000 && $(echo $(/bin/ps -xp $PPID|/usr/bin/wc -l))-1; i++ )); do\n"
" /bin/sleep .2;\n"
" done\n"
" if [[ $(/bin/ps -xp $PPID|/usr/bin/wc -l) -ne 2 ]]; then\n"
" /bin/sleep 1.0;\n"
" /usr/bin/open \"${LAUNCH_PATH}\"\n"
" fi\n"
"} &>/dev/null &'");
[NSApp terminate:self];
}
}
}
@end