-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathUpdateWindowController.m
121 lines (97 loc) · 2.81 KB
/
UpdateWindowController.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
120
121
//
// file: UpdateWindowController.m
// project: KnockKnock
// description: window handler for update window/popup
//
// created by Patrick Wardle
// copyright (c) 2017 Objective-See. All rights reserved.
//
#import "Consts.h"
#import "Utilities.h"
#import "AppDelegate.h"
#import "UpdateWindowController.h"
@implementation UpdateWindowController
@synthesize infoLabel;
@synthesize overlayView;
@synthesize firstButton;
@synthesize actionButton;
@synthesize infoLabelString;
@synthesize actionButtonTitle;
@synthesize progressIndicator;
//automatically called when nib is loaded
// ->center window
-(void)awakeFromNib
{
//center
[self.window center];
return;
}
//automatically invoked when window is loaded
// ->set to white
-(void)windowDidLoad
{
//super
[super windowDidLoad];
//not in dark mode?
// make window white
if(YES != isDarkMode())
{
//make white
self.window.backgroundColor = NSColor.whiteColor;
}
//indicated title bar is tranparent (too)
self.window.titlebarAppearsTransparent = YES;
//set main label
[self.infoLabel setStringValue:self.infoLabelString];
//set button text
self.actionButton.title = self.actionButtonTitle;
//hide first button when action is 'update'
// ->don't need update check button ;)
if(YES == [self.actionButton.title isEqualToString:@"Update"])
{
//hide
self.firstButton.hidden = YES;
//then make action button first responder
[self.window makeFirstResponder:self.actionButton];
}
//make it key window
[self.window makeKeyAndOrderFront:self];
//make window front
[NSApp activateIgnoringOtherApps:YES];
return;
}
//automatically invoked when window is closing
// ->make ourselves unmodal
-(void)windowWillClose:(NSNotification *)notification
{
//make un-modal
[[NSApplication sharedApplication] stopModal];
return;
}
//save the main label's & button title's text
// ->invoked before window is loaded (and thus buttons, etc are nil)
-(void)configure:(NSString*)label buttonTitle:(NSString*)buttonTitle
{
//save label's string
self.infoLabelString = label;
//save button's title
self.actionButtonTitle = buttonTitle;
return;
}
//invoked when user clicks button
// trigger action such as opening product website, updating, etc
-(IBAction)buttonHandler:(id)sender
{
//handle 'update' / 'more info', etc
// ->open LuLu's webpage, if they *didn't* click 'Close'
if(YES != [((NSButton*)sender).title isEqualToString:@"Close"])
{
//open URL
// ->invokes user's default browser
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:PRODUCT_URL]];
}
//always close window
[[self window] close];
return;
}
@end