5
// Created by Andy Matuschak on 3/12/06.
6
// Copyright 2006 Andy Matuschak. All rights reserved.
9
#import "SUUpdateAlert.h"
10
#import "SUAppcastItem.h"
11
#import "SUUtilities.h"
12
#import <WebKit/WebKit.h>
14
@implementation SUUpdateAlert
16
- initWithAppcastItem:(SUAppcastItem *)item
18
NSString *path = [[NSBundle bundleForClass:[self class]] pathForResource:@"SUUpdateAlert" ofType:@"nib"];
19
if (!path) // slight hack to resolve issues with running with in configurations
21
NSBundle *current = [NSBundle bundleForClass:[self class]];
22
NSString *frameworkPath = [[[NSBundle mainBundle] sharedFrameworksPath] stringByAppendingFormat:@"/Sparkle.framework", [current bundleIdentifier]];
23
NSBundle *framework = [NSBundle bundleWithPath:frameworkPath];
24
path = [framework pathForResource:@"SUUpdateAlert" ofType:@"nib"];
27
[super initWithWindowNibPath:path owner:self];
29
updateItem = [item retain];
30
[self setShouldCascadeWindows:NO];
41
- (void)endWithSelection:(SUUpdateAlertChoice)choice
43
[releaseNotesView stopLoading:self];
44
[releaseNotesView setFrameLoadDelegate:nil];
45
[releaseNotesView setPolicyDelegate:nil];
47
if ([delegate respondsToSelector:@selector(updateAlert:finishedWithChoice:)])
48
[delegate updateAlert:self finishedWithChoice:choice];
51
- (IBAction)installUpdate:sender
53
[self endWithSelection:SUInstallUpdateChoice];
56
- (IBAction)skipThisVersion:sender
58
[self endWithSelection:SUSkipThisVersionChoice];
61
- (IBAction)remindMeLater:sender
63
[self endWithSelection:SURemindMeLaterChoice];
66
- (void)displayReleaseNotes
68
[releaseNotesView setFrameLoadDelegate:self];
69
[releaseNotesView setPolicyDelegate:self];
71
// Stick a nice big spinner in the middle of the web view until the page is loaded.
72
NSRect frame = [[releaseNotesView superview] frame];
73
releaseNotesSpinner = [[[NSProgressIndicator alloc] initWithFrame:NSMakeRect(NSMidX(frame)-16, NSMidY(frame)-16, 32, 32)] autorelease];
74
[releaseNotesSpinner setStyle:NSProgressIndicatorSpinningStyle];
75
[releaseNotesSpinner startAnimation:self];
76
webViewFinishedLoading = NO;
77
[[releaseNotesView superview] addSubview:releaseNotesSpinner];
79
// If there's a release notes URL, load it; otherwise, just stick the contents of the description into the web view.
80
if ([updateItem releaseNotesURL])
82
[[releaseNotesView mainFrame] loadRequest:[NSURLRequest requestWithURL:[updateItem releaseNotesURL] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30]];
86
[[releaseNotesView mainFrame] loadHTMLString:[updateItem description] baseURL:nil];
90
- (BOOL)showsReleaseNotes
92
if (!SUInfoValueForKey(SUShowReleaseNotesKey)) { return YES; } // defaults to YES
93
return [SUInfoValueForKey(SUShowReleaseNotesKey) boolValue];
96
- (BOOL)allowsAutomaticUpdates
98
if (!SUInfoValueForKey(SUExpectsDSASignatureKey)) { return NO; } // automatic updating requires DSA-signed updates
99
if (!SUInfoValueForKey(SUAllowsAutomaticUpdatesKey)) { return YES; } // defaults to YES
100
return [SUInfoValueForKey(SUAllowsAutomaticUpdatesKey) boolValue];
105
[[self window] setLevel:NSFloatingWindowLevel];
106
[[self window] setFrameAutosaveName:@"SUUpdateAlertFrame"];
108
// We're gonna do some frame magic to match the window's size to the description field and the presence of the release notes view.
109
NSRect frame = [[self window] frame];
111
if (![self showsReleaseNotes])
113
// Resize the window to be appropriate for not having a huge release notes view.
114
frame.size.height -= [releaseNotesView frame].size.height;
116
[[self window] setShowsResizeIndicator:NO];
117
[[self window] setMinSize:frame.size];
118
[[self window] setMaxSize:frame.size];
121
if (![self allowsAutomaticUpdates])
123
NSRect boxFrame = [[[releaseNotesView superview] superview] frame];
124
boxFrame.origin.y -= 20;
125
boxFrame.size.height += 20;
126
[[[releaseNotesView superview] superview] setFrame:boxFrame];
129
[[self window] setFrame:frame display:NO];
130
[[self window] center];
132
if ([self showsReleaseNotes])
134
[self displayReleaseNotes];
138
- (BOOL)windowShouldClose:note
140
[self endWithSelection:SURemindMeLaterChoice];
144
- (NSImage *)applicationIcon
146
return [NSImage imageNamed:@"NSApplicationIcon"];
149
- (NSString *)titleText
151
return [NSString stringWithFormat:SULocalizedString(@"A new version of %@ is available!", nil), SUHostAppDisplayName()];
154
- (NSString *)descriptionText
156
return [NSString stringWithFormat:SULocalizedString(@"%@ %@ is now available (you have %@). Would you like to download it now?", nil), SUHostAppDisplayName(), [updateItem versionString], SUHostAppVersionString()];
159
- (void)webView:(WebView *)sender didFinishLoadForFrame:frame
161
if ([frame parentFrame] == nil) {
162
webViewFinishedLoading = YES;
163
[releaseNotesSpinner setHidden:YES];
164
[sender display]; // necessary to prevent weird scroll bar artifacting
168
- (void)webView:sender decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request frame:frame decisionListener:listener
170
if (webViewFinishedLoading == YES) {
171
[[NSWorkspace sharedWorkspace] openURL:[request URL]];
180
- (void)setDelegate:del