mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-24 04:38:16 +00:00
Made Sparkle.h no longer a massive multi-headed abomination: now only SUAppcastItem, SUAppcast and SUUpdater (and SUVersionComparisonProtocol because it's part of the delegate protocol) are public. COMPATIBILITY ISSUE: This means there's no longer a public SUProbingUpdateDriver or a checkForUpdatesWithDriver: method. Now use checkForUpdateInformation. I may change that API before release, though. I'm thinking it might be better to give the delegate the opportunity to reject a potential update instead: then you'd just call checkForUpdatesInBackground and override that delegate method to always return NO. We'll see.
133 lines
4.0 KiB
Objective-C
133 lines
4.0 KiB
Objective-C
//
|
|
// SUUpdatePermissionPrompt.m
|
|
// Sparkle
|
|
//
|
|
// Created by Andy Matuschak on 1/24/08.
|
|
// Copyright 2008 Andy Matuschak. All rights reserved.
|
|
//
|
|
|
|
#import "SUUpdatePermissionPrompt.h"
|
|
|
|
#import "SUHost.h"
|
|
|
|
@implementation SUUpdatePermissionPrompt
|
|
|
|
- (BOOL)shouldAskAboutProfile
|
|
{
|
|
return [[host objectForInfoDictionaryKey:SUEnableSystemProfilingKey] boolValue];
|
|
}
|
|
|
|
- (id)initWithHost:(SUHost *)aHost delegate:(id)d
|
|
{
|
|
self = [super initWithHost:aHost windowNibName:@"SUUpdatePermissionPrompt"];
|
|
if (self)
|
|
{
|
|
host = [aHost retain];
|
|
delegate = [d retain];
|
|
isShowingMoreInfo = NO;
|
|
shouldSendProfile = [self shouldAskAboutProfile];
|
|
[self setShouldCascadeWindows:NO];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
+ (void)promptWithHost:(SUHost *)host delegate:(id)d
|
|
{
|
|
// If this is a background application we need to focus it in order to bring the prompt
|
|
// to the user's attention. Otherwise the prompt would be hidden behind other applications and
|
|
// the user would not know why the application was paused.
|
|
if ([host isBackgroundApplication]) { [NSApp activateIgnoringOtherApps:YES]; }
|
|
|
|
id prompt = [[[self class] alloc] initWithHost:host delegate:d];
|
|
[NSApp runModalForWindow:[prompt window]];
|
|
}
|
|
|
|
- (void)awakeFromNib
|
|
{
|
|
if (![self shouldAskAboutProfile])
|
|
{
|
|
NSRect frame = [[self window] frame];
|
|
frame.size.height -= [moreInfoButton frame].size.height;
|
|
[[self window] setFrame:frame display:YES];
|
|
}
|
|
}
|
|
|
|
- (void)dealloc
|
|
{
|
|
[host release];
|
|
[super dealloc];
|
|
}
|
|
|
|
- (NSImage *)icon
|
|
{
|
|
return [host icon];
|
|
}
|
|
|
|
- (NSString *)promptDescription
|
|
{
|
|
return [NSString stringWithFormat:SULocalizedString(@"Should %1$@ automatically check for updates? You can always check for updates manually from the %1$@ menu.", nil), [host name]];
|
|
}
|
|
|
|
- (NSArray *)systemProfileInformationArray
|
|
{
|
|
return [host systemProfile];
|
|
}
|
|
|
|
- (IBAction)toggleMoreInfo:(id)sender
|
|
{
|
|
[self willChangeValueForKey:@"isShowingMoreInfo"];
|
|
isShowingMoreInfo = !isShowingMoreInfo;
|
|
[self didChangeValueForKey:@"isShowingMoreInfo"];
|
|
|
|
NSView *contentView = [[self window] contentView];
|
|
NSRect contentViewFrame = [contentView frame];
|
|
NSRect windowFrame = [[self window] frame];
|
|
|
|
NSRect profileMoreInfoViewFrame = [moreInfoView frame];
|
|
NSRect profileMoreInfoButtonFrame = [moreInfoButton frame];
|
|
NSRect descriptionFrame = [descriptionTextField frame];
|
|
|
|
if (isShowingMoreInfo)
|
|
{
|
|
// Add the subview
|
|
contentViewFrame.size.height += profileMoreInfoViewFrame.size.height;
|
|
profileMoreInfoViewFrame.origin.y = profileMoreInfoButtonFrame.origin.y - profileMoreInfoViewFrame.size.height;
|
|
profileMoreInfoViewFrame.origin.x = descriptionFrame.origin.x;
|
|
profileMoreInfoViewFrame.size.width = descriptionFrame.size.width;
|
|
|
|
windowFrame.size.height += profileMoreInfoViewFrame.size.height;
|
|
windowFrame.origin.y -= profileMoreInfoViewFrame.size.height;
|
|
|
|
[moreInfoView setFrame:profileMoreInfoViewFrame];
|
|
[moreInfoView setHidden:YES];
|
|
[contentView addSubview:moreInfoView
|
|
positioned:NSWindowBelow
|
|
relativeTo:moreInfoButton];
|
|
} else {
|
|
// Remove the subview
|
|
[moreInfoView setHidden:NO];
|
|
[moreInfoView removeFromSuperview];
|
|
contentViewFrame.size.height -= profileMoreInfoViewFrame.size.height;
|
|
|
|
windowFrame.size.height -= profileMoreInfoViewFrame.size.height;
|
|
windowFrame.origin.y += profileMoreInfoViewFrame.size.height;
|
|
}
|
|
[[self window] setFrame:windowFrame display:YES animate:YES];
|
|
[contentView setFrame:contentViewFrame];
|
|
[contentView setNeedsDisplay:YES];
|
|
[moreInfoView setHidden:(!isShowingMoreInfo)];
|
|
}
|
|
|
|
- (IBAction)finishPrompt:(id)sender
|
|
{
|
|
if (![delegate respondsToSelector:@selector(updatePermissionPromptFinishedWithResult:)])
|
|
[NSException raise:@"SUInvalidDelegate" format:@"SUUpdatePermissionPrompt's delegate (%@) doesn't respond to updatePermissionPromptFinishedWithResult:!", delegate];
|
|
[host setBool:shouldSendProfile forUserDefaultsKey:SUSendProfileInfoKey];
|
|
[delegate updatePermissionPromptFinishedWithResult:([sender tag] == 1 ? SUAutomaticallyCheck : SUDoNotAutomaticallyCheck)];
|
|
[[self window] close];
|
|
[NSApp stopModal];
|
|
[self autorelease];
|
|
}
|
|
|
|
@end
|