-
Notifications
You must be signed in to change notification settings - Fork 1
/
AppDelegate.m
119 lines (96 loc) · 3.41 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
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
//
// AppDelegate.m
// Flowrate
//
// Created by Nathan Vander Wilt on 10/27/09.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//
#import "AppDelegate.h"
#import "AlbumInfo.h"
#import "HostView.h"
#import "RootController.h"
#import "AlbumController.h"
#import "HIDRemote.h"
@interface AppDelegate ()
@property (readwrite, getter=isTerminating) BOOL terminating;
@end
static NSString* const LaunchFullScreen = @"LaunchFullScreen";
@implementation AppDelegate
@synthesize layerHost;
@synthesize terminating;
- (void)awakeFromNib {
rootController = [RootController new];
[self.layerHost pushController:rootController];
if ([HIDRemote isCandelairInstallationRequiredForRemoteMode:kHIDRemoteModeExclusiveAuto]) {
NSLog(@"Candelair needs to be installed!");
rootController.status = RootRemoteError;
return;
}
self.layerHost.remoteActive = YES;
}
- (void)applicationDidHide:(NSNotification*)notification {
(void)notification;
/* NOTE: this works around an issue (#806) where app can be hidden using Cmd-H
while in full screen. A better solution might be to disable the shortcut,
or figure out how to exit full screen properly when hidden. */
if ([self.layerHost isInFullScreenMode]) {
[NSApp performSelector:@selector(unhide:) withObject:self afterDelay:0];
// NOTE: toggling results in first responder issue when unhidden by user.
//[self toggleFullScreen];
}
}
- (void)toggleFullScreen {
if ([self.layerHost isInFullScreenMode]) {
[NSCursor unhide];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:LaunchFullScreen];
[self.layerHost exitFullScreenModeWithOptions:nil];
// not exactly sure why this is necessary
[[self.layerHost window] makeFirstResponder:layerHost];
}
else {
[NSCursor hide];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:LaunchFullScreen];
[self.layerHost enterFullScreenMode:[NSScreen mainScreen] withOptions:nil];
}
if ([[NSApp keyWindow] firstResponder] != layerHost) NSLog(@"Not first responder!");
}
- (void)preventFullScreen {
if (![self.layerHost isInFullScreenMode]) return;
[NSCursor unhide];
[self.layerHost exitFullScreenModeWithOptions:nil];
// not exactly sure why this is necessary
[[self.layerHost window] makeFirstResponder:layerHost];
}
- (void)allowFullScreen {
if ([self.layerHost isInFullScreenMode]) return;
if ([[NSUserDefaults standardUserDefaults] boolForKey:LaunchFullScreen]) {
[self toggleFullScreen];
}
}
- (void)finishQueueAndTerminate {
[[AlbumInfo sharedAlbumInfo] finish];
if ([[AlbumInfo sharedAlbumInfo] didRateItems]) {
[NSTask launchedTaskWithLaunchPath:@"/usr/bin/osascript" arguments:
[NSArray arrayWithObjects:@"-e", @"delay 0.05\ntell application \"iPhoto\" to activate", nil]];
}
[NSApp replyToApplicationShouldTerminate:YES];
}
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)sender {
(void)sender;
self.terminating = YES;
self.layerHost.remoteActive = NO;
[self.layerHost popToController:rootController];
rootController.status = RootQuitting;
[self performSelectorInBackground:@selector(finishQueueAndTerminate) withObject:nil];
return NSTerminateLater;
}
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication*)sender {
(void)sender;
return YES;
}
- (IBAction)showHelp:(id)sender {
(void)sender;
NSURL* helpURL = [NSURL URLWithString:@"http://calftrail.com/support/photon_star_instructions.html"];
[[NSWorkspace sharedWorkspace] openURL:helpURL];
}
@end