diff --git a/SUConstants.h b/SUConstants.h index 973546a5..0f38d1cb 100644 --- a/SUConstants.h +++ b/SUConstants.h @@ -24,6 +24,7 @@ extern NSString *SUPublicDSAKeyKey; extern NSString *SUAutomaticallyUpdateKey; extern NSString *SUAllowsAutomaticUpdatesKey; extern NSString *SUEnableAutomaticChecksKey; +extern NSString *SUEnableSystemProfilingKey; extern NSString *SUSendProfileInfoKey; // NSInteger is a type that was added to Leopard. diff --git a/SUConstants.m b/SUConstants.m index 575817f0..c788e4a9 100644 --- a/SUConstants.m +++ b/SUConstants.m @@ -21,5 +21,6 @@ NSString *SUExpectsDSASignatureKey = @"SUExpectsDSASignature"; NSString *SUPublicDSAKeyKey = @"SUPublicDSAKey"; NSString *SUAutomaticallyUpdateKey = @"SUAutomaticallyUpdate"; NSString *SUAllowsAutomaticUpdatesKey = @"SUAllowsAutomaticUpdates"; +NSString *SUEnableSystemProfilingKey = @"SUEnableSystemProfiling"; NSString *SUEnableAutomaticChecksKey = @"SUEnableAutomaticChecks"; NSString *SUSendProfileInfoKey = @"SUSendProfileInfo"; diff --git a/SUUpdatePermissionPrompt.h b/SUUpdatePermissionPrompt.h index 7649ac46..66621c83 100644 --- a/SUUpdatePermissionPrompt.h +++ b/SUUpdatePermissionPrompt.h @@ -11,10 +11,26 @@ #import "Sparkle.h" +typedef enum { + SUAutomaticallyUpdate, + SUDoNotAutomaticallyUpdate +} SUPermissionPromptResult; + @interface SUUpdatePermissionPrompt : SUWindowController { - + NSBundle *hostBundle; + id delegate; + IBOutlet NSTextField *descriptionTextField; + IBOutlet NSView *moreInfoView; + IBOutlet NSButton *moreInfoButton; + BOOL isShowingMoreInfo, shouldSendProfile; } ++ (void)promptWithHostBundle:(NSBundle *)hb delegate:(id)d; +- (IBAction)toggleMoreInfo:(id)sender; +- (IBAction)finishPrompt:(id)sender; +@end +@interface NSObject (SUUpdatePermissionPromptDelegateInformalProtocol) +- (void)updatePermissionPromptFinishedWithResult:(SUPermissionPromptResult)result; @end #endif diff --git a/SUUpdatePermissionPrompt.m b/SUUpdatePermissionPrompt.m index 0b982994..30423388 100644 --- a/SUUpdatePermissionPrompt.m +++ b/SUUpdatePermissionPrompt.m @@ -11,4 +11,112 @@ @implementation SUUpdatePermissionPrompt +- (BOOL)shouldAskAboutProfile +{ + return [[hostBundle objectForInfoDictionaryKey:SUEnableSystemProfilingKey] boolValue]; +} + +- (id)initWithHostBundle:(NSBundle *)hb delegate:(id)d +{ + hostBundle = [hb retain]; + delegate = [d retain]; + isShowingMoreInfo = NO; + shouldSendProfile = [self shouldAskAboutProfile]; + [super initWithHostBundle:hb windowNibName:@"SUUpdatePermissionPrompt"]; + [self setShouldCascadeWindows:NO]; + return self; +} + ++ (void)promptWithHostBundle:(NSBundle *)hb delegate:(id)d +{ + id prompt = [[[self class] alloc] initWithHostBundle:hb delegate:d]; + [prompt showWindow:self]; +} + +- (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 +{ + [hostBundle release]; + [super dealloc]; +} + +- (NSImage *)icon +{ + return [hostBundle icon]; +} + +- (NSString *)description +{ + return [NSString stringWithFormat:SULocalizedString(@"Should %1$@ automatically check for updates? You can always check for updates manually from the %1$@ menu.", nil), [hostBundle name]]; +} + +- (NSArray *)systemProfileInformationArray +{ + return [[SUSystemProfiler sharedSystemProfiler] systemProfileArrayForHostBundle:hostBundle]; +} + +- (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]; + [[SUUserDefaults standardUserDefaults] setBool:shouldSendProfile forKey:SUSendProfileInfoKey]; + [delegate updatePermissionPromptFinishedWithResult:([sender tag] == 1 ? SUAutomaticallyUpdate : SUDoNotAutomaticallyUpdate)]; + [[self window] close]; + [self autorelease]; +} + @end diff --git a/SUUpdater.m b/SUUpdater.m index 0143dbab..43fa6fee 100644 --- a/SUUpdater.m +++ b/SUUpdater.m @@ -17,6 +17,7 @@ @interface SUUpdater (Private) - (void)beginUpdateCheck; +- (void)beginUpdateCycle; - (void)showUpdateAlert; - (void)beginDownload; - (void)extractUpdate; @@ -83,38 +84,46 @@ static SUUpdater *sharedUpdater = nil; return; } - // The user's never been asked, so let's see if they want automatic checking. - NSAlert *alert = [NSAlert alertWithMessageText:SULocalizedString(@"Allow automatic update checking?", nil) defaultButton:SULocalizedString(@"Allow", nil) alternateButton:SULocalizedString(@"Don't Allow", nil) otherButton:nil informativeTextWithFormat:SULocalizedString(@"Would you like %1$@ to automatically check for updates to itself? If not, you can check for updates manually from the %1$@ menu.", nil), [hostBundle name]]; - [alert setIcon:[hostBundle icon]]; - [[SUUserDefaults standardUserDefaults] setBool:([alert runModal] == NSAlertDefaultReturn) forKey:SUEnableAutomaticChecksKey]; + [SUUpdatePermissionPrompt promptWithHostBundle:hostBundle delegate:self]; } if ([[SUUserDefaults standardUserDefaults] boolForKey:SUEnableAutomaticChecksKey] == YES) - { - // Find the stored check interval. User defaults override Info.plist. - if ([[SUUserDefaults standardUserDefaults] objectForKey:SUScheduledCheckIntervalKey]) - checkInterval = [[[SUUserDefaults standardUserDefaults] objectForKey:SUScheduledCheckIntervalKey] longValue]; - else if ([hostBundle objectForInfoDictionaryKey:SUScheduledCheckIntervalKey]) - checkInterval = [[hostBundle objectForInfoDictionaryKey:SUScheduledCheckIntervalKey] longValue]; - - if (checkInterval < SU_MIN_CHECK_INTERVAL) // This can also mean one that isn't set. - checkInterval = SU_DEFAULT_CHECK_INTERVAL; - - // How long has it been since last we checked for an update? - NSDate *lastCheckDate = [[SUUserDefaults standardUserDefaults] objectForKey:SULastCheckTimeKey]; - if (!lastCheckDate) { lastCheckDate = [NSDate distantPast]; } - NSTimeInterval intervalSinceCheck = [[NSDate date] timeIntervalSinceDate:lastCheckDate]; - - // Now we want to figure out how long until we check again. - NSTimeInterval delayUntilCheck; - if (intervalSinceCheck < checkInterval) - delayUntilCheck = (checkInterval - intervalSinceCheck); // It hasn't been long enough. - else - delayUntilCheck = 0; // We're overdue! Run one now. - - [self performSelector:@selector(checkForUpdatesInBackground) withObject:nil afterDelay:delayUntilCheck]; - [self performSelector:@selector(scheduleCheckWithIntervalObject:) withObject:[NSNumber numberWithDouble:checkInterval] afterDelay:delayUntilCheck]; - } + [self beginUpdateCycle]; +} + +- (void)updatePermissionPromptFinishedWithResult:(SUPermissionPromptResult)result +{ + BOOL automaticallyUpdate = (result == SUAutomaticallyUpdate); + [[SUUserDefaults standardUserDefaults] setBool:(result == SUAutomaticallyUpdate) forKey:SUEnableAutomaticChecksKey]; + if (automaticallyUpdate) + [self beginUpdateCycle]; +} + +- (void)beginUpdateCycle +{ + // Find the stored check interval. User defaults override Info.plist. + if ([[SUUserDefaults standardUserDefaults] objectForKey:SUScheduledCheckIntervalKey]) + checkInterval = [[[SUUserDefaults standardUserDefaults] objectForKey:SUScheduledCheckIntervalKey] longValue]; + else if ([hostBundle objectForInfoDictionaryKey:SUScheduledCheckIntervalKey]) + checkInterval = [[hostBundle objectForInfoDictionaryKey:SUScheduledCheckIntervalKey] longValue]; + + if (checkInterval < SU_MIN_CHECK_INTERVAL) // This can also mean one that isn't set. + checkInterval = SU_DEFAULT_CHECK_INTERVAL; + + // How long has it been since last we checked for an update? + NSDate *lastCheckDate = [[SUUserDefaults standardUserDefaults] objectForKey:SULastCheckTimeKey]; + if (!lastCheckDate) { lastCheckDate = [NSDate distantPast]; } + NSTimeInterval intervalSinceCheck = [[NSDate date] timeIntervalSinceDate:lastCheckDate]; + + // Now we want to figure out how long until we check again. + NSTimeInterval delayUntilCheck; + if (intervalSinceCheck < checkInterval) + delayUntilCheck = (checkInterval - intervalSinceCheck); // It hasn't been long enough. + else + delayUntilCheck = 0; // We're overdue! Run one now. + + [self performSelector:@selector(checkForUpdatesInBackground) withObject:nil afterDelay:delayUntilCheck]; + [self performSelector:@selector(scheduleCheckWithIntervalObject:) withObject:[NSNumber numberWithDouble:checkInterval] afterDelay:delayUntilCheck]; } - (void)scheduleCheckWithInterval:(NSTimeInterval)interval diff --git a/SUWindowController.h b/SUWindowController.h index bb96c72f..8b50a64c 100644 --- a/SUWindowController.h +++ b/SUWindowController.h @@ -16,4 +16,4 @@ - (id)initWithHostBundle:(NSBundle *)hb windowNibName:(NSString *)nibName; @end -#endif \ No newline at end of file +#endif diff --git a/Sparkle.h b/Sparkle.h index 5d709867..655a4efb 100644 --- a/Sparkle.h +++ b/Sparkle.h @@ -46,6 +46,7 @@ #import "SUUnarchiver.h" #import "SUUpdateAlert.h" #import "SUUpdater.h" +#import "SUUpdatePermissionPrompt.h" #import "SUUserDefaults.h" #import "SUVersionComparisonProtocol.h" #import "SUWindowController.h" diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 30f74a10..253881ea 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -17,6 +17,7 @@ 61177A1F0D1112E900749C97 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6117796E0D1112E000749C97 /* IOKit.framework */; }; 61180BCA0D64138900B4E0D1 /* SUWindowController.h in Headers */ = {isa = PBXBuildFile; fileRef = 61180BC80D64138900B4E0D1 /* SUWindowController.h */; settings = {ATTRIBUTES = (Public, ); }; }; 61180BCB0D64138900B4E0D1 /* SUWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 61180BC90D64138900B4E0D1 /* SUWindowController.m */; }; + 61180C900D64262100B4E0D1 /* SUUpdatePermissionPrompt.nib in Resources */ = {isa = PBXBuildFile; fileRef = 61180C8E0D64262100B4E0D1 /* SUUpdatePermissionPrompt.nib */; }; 6120721209CC5C4B007FE0F6 /* SUAutomaticUpdateAlert.h in Headers */ = {isa = PBXBuildFile; fileRef = 6120721009CC5C4B007FE0F6 /* SUAutomaticUpdateAlert.h */; settings = {ATTRIBUTES = (Public, ); }; }; 6120721309CC5C4B007FE0F6 /* SUAutomaticUpdateAlert.m in Sources */ = {isa = PBXBuildFile; fileRef = 6120721109CC5C4B007FE0F6 /* SUAutomaticUpdateAlert.m */; }; 61299A2F09CA2DAB00B7442F /* NSFileManager+Verification.h in Headers */ = {isa = PBXBuildFile; fileRef = 61299A2D09CA2DAB00B7442F /* NSFileManager+Verification.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -126,6 +127,7 @@ 6117796E0D1112E000749C97 /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = /System/Library/Frameworks/IOKit.framework; sourceTree = ""; }; 61180BC80D64138900B4E0D1 /* SUWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUWindowController.h; sourceTree = ""; }; 61180BC90D64138900B4E0D1 /* SUWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUWindowController.m; sourceTree = ""; }; + 61180C8F0D64262100B4E0D1 /* en */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = en; path = en.lproj/SUUpdatePermissionPrompt.nib; sourceTree = ""; }; 6120721009CC5C4B007FE0F6 /* SUAutomaticUpdateAlert.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUAutomaticUpdateAlert.h; sourceTree = ""; }; 6120721109CC5C4B007FE0F6 /* SUAutomaticUpdateAlert.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUAutomaticUpdateAlert.m; sourceTree = ""; }; 6129984309C9E2DA00B7442F /* NSFileManager+Authentication.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSFileManager+Authentication.h"; sourceTree = ""; }; @@ -376,6 +378,7 @@ 61AAE8220A321A7F00D8810D /* Sparkle.strings */, 61AAE8240A321A7F00D8810D /* SUAutomaticUpdateAlert.nib */, 61AAE8260A321A7F00D8810D /* SUUpdateAlert.nib */, + 61180C8E0D64262100B4E0D1 /* SUUpdatePermissionPrompt.nib */, 61299B3509CB04E000B7442F /* Sparkle.h */, ); name = "Other Sources"; @@ -628,6 +631,7 @@ 61AAE8280A321A7F00D8810D /* Sparkle.strings in Resources */, 61AAE8290A321A8000D8810D /* SUAutomaticUpdateAlert.nib in Resources */, 61AAE82A0A321A8000D8810D /* SUUpdateAlert.nib in Resources */, + 61180C900D64262100B4E0D1 /* SUUpdatePermissionPrompt.nib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -718,6 +722,14 @@ /* End PBXTargetDependency section */ /* Begin PBXVariantGroup section */ + 61180C8E0D64262100B4E0D1 /* SUUpdatePermissionPrompt.nib */ = { + isa = PBXVariantGroup; + children = ( + 61180C8F0D64262100B4E0D1 /* en */, + ); + name = SUUpdatePermissionPrompt.nib; + sourceTree = ""; + }; 61AAE8220A321A7F00D8810D /* Sparkle.strings */ = { isa = PBXVariantGroup; children = ( diff --git a/Test Application/Test Application-Info.plist b/Test Application/Test Application-Info.plist index 63a5bc9c..01722c41 100644 --- a/Test Application/Test Application-Info.plist +++ b/Test Application/Test Application-Info.plist @@ -26,5 +26,7 @@ NSApplication SUFeedURL http://www.andymatuschak.org/files/sparkletestcast.xml + SUEnableSystemProfiling + diff --git a/en.lproj/SUPermissionPrompt.nib/keyedobjects.nib b/en.lproj/SUPermissionPrompt.nib/keyedobjects.nib deleted file mode 100644 index 6b635bd1..00000000 Binary files a/en.lproj/SUPermissionPrompt.nib/keyedobjects.nib and /dev/null differ diff --git a/en.lproj/SUPermissionPrompt.nib/classes.nib b/en.lproj/SUUpdatePermissionPrompt.nib/classes.nib similarity index 68% rename from en.lproj/SUPermissionPrompt.nib/classes.nib rename to en.lproj/SUUpdatePermissionPrompt.nib/classes.nib index 7a12a1fc..5220a221 100644 --- a/en.lproj/SUPermissionPrompt.nib/classes.nib +++ b/en.lproj/SUUpdatePermissionPrompt.nib/classes.nib @@ -6,37 +6,37 @@ CLASS - NSObject + SUWindowController LANGUAGE ObjC + SUPERCLASS + NSWindowController ACTIONS - checkForUpdates + finishPrompt id - closeProfileInfoSheet + toggleMoreInfo id CLASS - SUUpdater + SUUpdatePermissionPrompt LANGUAGE ObjC OUTLETS - checkForUpdatesText - NSTextField delegate id - profileMoreInfoButton + descriptionTextField + NSTextField + moreInfoButton NSButton - profileMoreInfoView + moreInfoView NSView - profileMoreInfoWindow - NSWindow SUPERCLASS - NSObject + SUWindowController CLASS @@ -46,6 +46,12 @@ SUPERCLASS NSObject + + CLASS + NSObject + LANGUAGE + ObjC + IBVersion 1 diff --git a/en.lproj/SUPermissionPrompt.nib/info.nib b/en.lproj/SUUpdatePermissionPrompt.nib/info.nib similarity index 81% rename from en.lproj/SUPermissionPrompt.nib/info.nib rename to en.lproj/SUUpdatePermissionPrompt.nib/info.nib index 70dd7529..76607778 100644 --- a/en.lproj/SUPermissionPrompt.nib/info.nib +++ b/en.lproj/SUUpdatePermissionPrompt.nib/info.nib @@ -4,10 +4,13 @@ IBFramework Version 629 + IBLastKnownRelativeProjectPath + ../../Sparkle.xcodeproj IBOldestOS 5 IBOpenObjects + 39 6 IBSystem Version diff --git a/en.lproj/SUUpdatePermissionPrompt.nib/keyedobjects.nib b/en.lproj/SUUpdatePermissionPrompt.nib/keyedobjects.nib new file mode 100644 index 00000000..e45317ec Binary files /dev/null and b/en.lproj/SUUpdatePermissionPrompt.nib/keyedobjects.nib differ