/
TotalTerminal.mm
146 lines (110 loc) · 5.06 KB
/
TotalTerminal.mm
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#import "TotalTerminal.h"
@implementation TotalTerminal
-(void) awakeFromNib {
LOG(@"awakeFromNib");
[self storePreferencesPaneSize];
}
+(TotalTerminal*) sharedInstance {
static TotalTerminal* plugin = nil;
if (!plugin) {
plugin = [[TotalTerminal alloc] init];
}
return plugin;
}
+(void) launchCrashWatcher {
AUTO_LOGGER();
#ifndef _DEBUG_MODE
if (![[NSUserDefaults standardUserDefaults] boolForKey:@"TotalTerminalDoNotLaunchCrashWatcher"]) {
NSString* path = [[NSBundle bundleForClass:[self class]] pathForResource:@"TotalTerminalCrashWatcher" ofType:@"app"];
INFO(@"Launching TotalTerminalCrashWatcher from '%@'", path);
[[NSWorkspace sharedWorkspace] launchApplication:path];
}
#endif
}
+(void) install {
AUTO_LOGGER();
[self launchCrashWatcher];
[self initDebugSubsystems];
// under 10.7 when TotalTerminal is injected during Terminal launch some windows may be going through restoration process
// so the Terminal windows are not fully re-created
[self performSelector:@selector(delayedBoot) withObject:nil afterDelay:2.0];
}
+(void) delayedBoot {
AUTO_LOGGER();
NSUserDefaults* ud = [NSUserDefaults standardUserDefaults];
[self sanitizeDefaults:ud];
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"TotalTerminalCloseWindowsOnStart"]) {
[self closeExistingWindows];
}
SWIZZLE(TTAppPrefsController, windowDidLoad);
SWIZZLE(TTAppPrefsController, toolbar: itemForItemIdentifier: willBeInsertedIntoToolbar:);
SWIZZLE(TTAppPrefsController, windowWillReturnFieldEditor: toObject:);
SWIZZLE(TTAppPrefsController, tabView: didSelectTabViewItem:);
[self loadFeatures];
[[TotalTerminal sharedInstance] openVisor];
}
-(id) init {
AUTO_LOGGER();
self = [super init];
if (!self) return self;
preventShortcutUpdates_ = FALSE;
originalPreferencesSize.width = 0;
lastPosition_ = nil;
hotKey_ = nil;
escapeHotKey = nil;
fullScreenKey_ = nil;
background_ = nil;
statusItem_ = nil;
[self refreshFeedURLInUpdater];
statusMenu_ = [[NSMenu alloc] initWithTitle:@"Status Menu"];
[self setWindow:nil];
activeIcon_ = [[NSImage alloc] initWithContentsOfFile:[[NSBundle bundleForClass:[self classForCoder]] pathForImageResource:@"VisorActive"]];
inactiveIcon_ = [[NSImage alloc] initWithContentsOfFile:[[NSBundle bundleForClass:[self classForCoder]] pathForImageResource:@"VisorInactive"]];
previouslyActiveAppPID_ = 0;
isHidden_ = true;
isMain_ = false;
isKey_ = false;
[NSBundle loadNibNamed:@"TotalTerminal" owner:self];
isActiveAlternativeIcon_ = FALSE;
alternativeDockIcon = [[NSImage alloc] initWithContentsOfFile:[[NSBundle bundleForClass:[self class]] pathForImageResource:@"TotalTerminal"]];
originalDockIcon = [[NSImage alloc] initWithContentsOfFile:[[NSBundle bundleForClass:[self class]] pathForImageResource:@"Terminal"]];
modifiersOption_ = [[NSImage alloc] initWithContentsOfFile:[[NSBundle bundleForClass:[self class]] pathForImageResource:@"ModifiersOption"]];
modifiersCommand_ = [[NSImage alloc] initWithContentsOfFile:[[NSBundle bundleForClass:[self class]] pathForImageResource:@"ModifiersCommand"]];
modifiersControl_ = [[NSImage alloc] initWithContentsOfFile:[[NSBundle bundleForClass:[self class]] pathForImageResource:@"ModifiersControl"]];
modifiersShift_ = [[NSImage alloc] initWithContentsOfFile:[[NSBundle bundleForClass:[self class]] pathForImageResource:@"ModifiersShift"]];
[self setupDockIcon];
[self initializeBackground];
[self initStatusMenu];
[self updateCachedShortcuts];
[self updateStatusMenu];
[self updateHotKeyRegistration];
[self updateEscapeHotKeyRegistration];
[self updateFullScreenHotKeyRegistration];
[self startEventMonitoring];
NSUserDefaults* ud = [NSUserDefaults standardUserDefaults];
if ([ud boolForKey:@"TotalTerminalShowStatusItem"]) {
[self activateStatusMenu];
}
[self augumentMainMenu];
[self registerObservers];
[[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(inputSourceChanged) name:(NSString*)kTISNotifySelectedKeyboardInputSourceChanged object:nil];
universalTimer_ = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(universalTimerFired:) userInfo:nil repeats:YES];
return self;
}
-(void) universalTimerFired:(NSTimer*)timer {
// this polling code is used to track previous app when visor is shown
// see updatePreviouslyActiveApp for more info
if (![self isHidden]) {
[self updatePreviouslyActiveApp];
}
}
-(void) updateShouldShowTransparencyAlert {
[self willChangeValueForKey:@"shouldShowTransparencyAlert"];
[self didChangeValueForKey:@"shouldShowTransparencyAlert"];
}
-(NSNumber*) shouldShowTransparencyAlert {
return ([[NSUserDefaults standardUserDefaults] boolForKey:@"TotalTerminalVisorUseBackgroundAnimation"] &&
((float)[self getVisorProfileBackgroundAlpha] >= 1.0f))
? (NSNumber*)kCFBooleanTrue : (NSNumber*)kCFBooleanFalse;
}
@end