From 2bb5ce4318844ea21efc008951c3b23b4756b16e Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 7 Jan 2017 22:55:13 -0500 Subject: [PATCH] Make SUBundleIcon & SUApplicationInfo take SUHost, not NSBundle When we retrieve the "CFBundleIconFile" key from the Info dictionary, we should rely on SUHost's method of obtaining that value now. --- InstallerLauncher/SUInstallerLauncher.m | 3 ++- Sparkle.xcodeproj/project.pbxproj | 2 ++ .../InstallerProgress/InstallerProgressAppController.m | 6 ++++-- Sparkle/InstallerProgress/InstallerProgressDelegate.h | 4 +++- Sparkle/InstallerProgress/ShowInstallerProgress.m | 3 +-- Sparkle/SPUStandardUserDriver.m | 2 +- Sparkle/SUApplicationInfo.h | 4 +++- Sparkle/SUApplicationInfo.m | 7 ++++--- Sparkle/SUBundleIcon.h | 4 +++- Sparkle/SUBundleIcon.m | 10 ++++++---- Sparkle/SUStatusController.m | 2 +- Sparkle/SUUpdateAlert.m | 2 +- Sparkle/SUUpdatePermissionPrompt.m | 2 +- 13 files changed, 32 insertions(+), 19 deletions(-) diff --git a/InstallerLauncher/SUInstallerLauncher.m b/InstallerLauncher/SUInstallerLauncher.m index 896c88be..923855e9 100644 --- a/InstallerLauncher/SUInstallerLauncher.m +++ b/InstallerLauncher/SUInstallerLauncher.m @@ -14,6 +14,7 @@ #import "SUBundleIcon.h" #import "SPULocalCacheDirectory.h" #import "SPUInstallationType.h" +#import "SUHost.h" #import #ifdef _APPKITDEFINES_H @@ -145,7 +146,7 @@ // Then use the icon (if one is available) for the authorization prompt // NSImage is not used because it relies on AppKit NSURL *tempIconDestinationURL = nil; - NSURL *iconURL = [SUBundleIcon iconURLForBundle:hostBundle]; + NSURL *iconURL = [SUBundleIcon iconURLForHost:[[SUHost alloc] initWithBundle:hostBundle]]; if (iconURL != nil) { CGImageSourceRef imageSource = CGImageSourceCreateWithURL((CFURLRef)iconURL, (CFDictionaryRef)@{}); if (imageSource != NULL) { diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index f517d02b..19fec199 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -163,6 +163,7 @@ 72464F711E1F326A00FB341C /* SUOperatingSystem.m in Sources */ = {isa = PBXBuildFile; fileRef = 726F2CE41BC9C33D001971A4 /* SUOperatingSystem.m */; }; 72464F721E1F327C00FB341C /* SUOperatingSystem.m in Sources */ = {isa = PBXBuildFile; fileRef = 726F2CE41BC9C33D001971A4 /* SUOperatingSystem.m */; }; 72464F7C1E2097F600FB341C /* SUOperatingSystem.m in Sources */ = {isa = PBXBuildFile; fileRef = 726F2CE41BC9C33D001971A4 /* SUOperatingSystem.m */; }; + 72464F7E1E21ED8C00FB341C /* SUHost.m in Sources */ = {isa = PBXBuildFile; fileRef = 61EF67550E25B58D00F754E0 /* SUHost.m */; }; 7246E0A31C83B685003B4E75 /* SPUStandardUpdaterController.h in Headers */ = {isa = PBXBuildFile; fileRef = 7246E0A11C83B685003B4E75 /* SPUStandardUpdaterController.h */; settings = {ATTRIBUTES = (Public, ); }; }; 7246E0A41C83B685003B4E75 /* SPUStandardUpdaterController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7246E0A21C83B685003B4E75 /* SPUStandardUpdaterController.m */; }; 724BB3711D31D0B7005D534A /* SUInstallerConnection.m in Sources */ = {isa = PBXBuildFile; fileRef = 724BB3701D31D0B7005D534A /* SUInstallerConnection.m */; }; @@ -3047,6 +3048,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 72464F7E1E21ED8C00FB341C /* SUHost.m in Sources */, 72464F711E1F326A00FB341C /* SUOperatingSystem.m in Sources */, 726E07B41CAF08D6001A286B /* main.m in Sources */, 721D8A7B1D4963190032E472 /* SPULocalCacheDirectory.m in Sources */, diff --git a/Sparkle/InstallerProgress/InstallerProgressAppController.m b/Sparkle/InstallerProgress/InstallerProgressAppController.m index da8a58de..9c5a8c95 100644 --- a/Sparkle/InstallerProgress/InstallerProgressAppController.m +++ b/Sparkle/InstallerProgress/InstallerProgressAppController.m @@ -14,6 +14,7 @@ #import "SPUInstallerAgentProtocol.h" #import "SUInstallerAgentInitiationProtocol.h" #import "StatusInfo.h" +#import "SUHost.h" /*! * Terminate the application after a delay from launching the new update to avoid OS activation issues @@ -290,12 +291,13 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3; TransformProcessType(&psn, kProcessTransformToForegroundApplication); // Note: the application icon needs to be set after showing the icon in the dock - self.application.applicationIconImage = [SUApplicationInfo bestIconForBundle:self.hostBundle]; + SUHost *host = [[SUHost alloc] initWithBundle:self.hostBundle]; + self.application.applicationIconImage = [SUApplicationInfo bestIconForHost:host]; // Activate ourselves otherwise we will probably be in the background [self.application activateIgnoringOtherApps:YES]; - [self.delegate installerProgressShouldDisplayWithBundle:self.hostBundle]; + [self.delegate installerProgressShouldDisplayWithHost:host]; } }); } diff --git a/Sparkle/InstallerProgress/InstallerProgressDelegate.h b/Sparkle/InstallerProgress/InstallerProgressDelegate.h index 9bf1d314..887b1bb8 100644 --- a/Sparkle/InstallerProgress/InstallerProgressDelegate.h +++ b/Sparkle/InstallerProgress/InstallerProgressDelegate.h @@ -10,9 +10,11 @@ NS_ASSUME_NONNULL_BEGIN +@class SUHost; + @protocol InstallerProgressDelegate -- (void)installerProgressShouldDisplayWithBundle:(NSBundle *)bundle; +- (void)installerProgressShouldDisplayWithHost:(SUHost *)host; - (void)installerProgressShouldStop; @end diff --git a/Sparkle/InstallerProgress/ShowInstallerProgress.m b/Sparkle/InstallerProgress/ShowInstallerProgress.m index 8e4602b8..3f9272b6 100644 --- a/Sparkle/InstallerProgress/ShowInstallerProgress.m +++ b/Sparkle/InstallerProgress/ShowInstallerProgress.m @@ -22,9 +22,8 @@ @synthesize statusController = _statusController; -- (void)installerProgressShouldDisplayWithBundle:(NSBundle *)bundle +- (void)installerProgressShouldDisplayWithHost:(SUHost *)host { - SUHost *host = [[SUHost alloc] initWithBundle:bundle]; self.statusController = [[SUStatusController alloc] initWithHost:host]; [self.statusController setButtonTitle:SULocalizedString(@"Cancel Update", @"") target:nil action:nil isDefault:NO]; diff --git a/Sparkle/SPUStandardUserDriver.m b/Sparkle/SPUStandardUserDriver.m index 9668cc12..6f551baf 100644 --- a/Sparkle/SPUStandardUserDriver.m +++ b/Sparkle/SPUStandardUserDriver.m @@ -295,7 +295,7 @@ // are focused to inform the user since there is no dock icon to notify them. if ([SUApplicationInfo isBackgroundApplication:[NSApplication sharedApplication]]) { [[NSApplication sharedApplication] activateIgnoringOtherApps:YES]; } - [alert setIcon:[SUApplicationInfo bestIconForBundle:self.host.bundle]]; + [alert setIcon:[SUApplicationInfo bestIconForHost:self.host]]; [alert runModal]; if ([delegate respondsToSelector:@selector(standardUserDriverDidShowModalAlert)]) { diff --git a/Sparkle/SUApplicationInfo.h b/Sparkle/SUApplicationInfo.h index db4dd1ca..9aeeca68 100644 --- a/Sparkle/SUApplicationInfo.h +++ b/Sparkle/SUApplicationInfo.h @@ -10,11 +10,13 @@ NS_ASSUME_NONNULL_BEGIN +@class SUHost; + @interface SUApplicationInfo : NSObject + (BOOL)isBackgroundApplication:(NSApplication *)application; -+ (NSImage *)bestIconForBundle:(NSBundle *)bundle; ++ (NSImage *)bestIconForHost:(SUHost *)host; @end diff --git a/Sparkle/SUApplicationInfo.m b/Sparkle/SUApplicationInfo.m index c8fec0be..eb349af3 100644 --- a/Sparkle/SUApplicationInfo.m +++ b/Sparkle/SUApplicationInfo.m @@ -8,6 +8,7 @@ #import "SUApplicationInfo.h" #import "SUBundleIcon.h" +#import "SUHost.h" @implementation SUApplicationInfo @@ -16,16 +17,16 @@ return (application.activationPolicy == NSApplicationActivationPolicyAccessory); } -+ (NSImage *)bestIconForBundle:(NSBundle *)bundle ++ (NSImage *)bestIconForHost:(SUHost *)host { - NSURL *iconURL = [SUBundleIcon iconURLForBundle:bundle]; + NSURL *iconURL = [SUBundleIcon iconURLForHost:host]; NSImage *icon = (iconURL == nil) ? nil : [[NSImage alloc] initWithContentsOfURL:iconURL]; // Use a default icon if none is defined. if (!icon) { // this asumption may not be correct (eg. even though we're not the main bundle, it could be still be a regular app) // but still better than nothing if no icon was included - BOOL isMainBundle = (bundle == [NSBundle mainBundle]); + BOOL isMainBundle = [host.bundle isEqualTo:[NSBundle mainBundle]]; NSString *fileType = isMainBundle ? (__bridge NSString *)kUTTypeApplication : (__bridge NSString *)kUTTypeBundle; icon = [[NSWorkspace sharedWorkspace] iconForFileType:fileType]; diff --git a/Sparkle/SUBundleIcon.h b/Sparkle/SUBundleIcon.h index f42be2fd..3e709b5d 100644 --- a/Sparkle/SUBundleIcon.h +++ b/Sparkle/SUBundleIcon.h @@ -10,9 +10,11 @@ NS_ASSUME_NONNULL_BEGIN +@class SUHost; + @interface SUBundleIcon : NSObject -+ (NSURL * _Nullable)iconURLForBundle:(NSBundle *)bundle; ++ (NSURL * _Nullable)iconURLForHost:(SUHost *)host; @end diff --git a/Sparkle/SUBundleIcon.m b/Sparkle/SUBundleIcon.m index 30a831a8..b1f5444f 100644 --- a/Sparkle/SUBundleIcon.m +++ b/Sparkle/SUBundleIcon.m @@ -7,6 +7,7 @@ // #import "SUBundleIcon.h" +#import "SUHost.h" #ifdef _APPKITDEFINES_H #error This is a "core" class and should NOT import AppKit @@ -14,18 +15,19 @@ @implementation SUBundleIcon -+ (NSURL *)iconURLForBundle:(NSBundle *)bundle +// Note: To obtain the most current bundle icon file from the Info dictionary, this should take a SUHost, not a NSBundle ++ (NSURL *)iconURLForHost:(SUHost *)host { - NSString *resource = [bundle objectForInfoDictionaryKey:@"CFBundleIconFile"]; + NSString *resource = [host objectForInfoDictionaryKey:@"CFBundleIconFile"]; if (resource == nil || ![resource isKindOfClass:[NSString class]]) { return nil; } - NSURL *iconURL = [bundle URLForResource:resource withExtension:@"icns"]; + NSURL *iconURL = [host.bundle URLForResource:resource withExtension:@"icns"]; // The resource could already be containing the path extension, so try again without the extra extension if (iconURL == nil) { - iconURL = [bundle URLForResource:resource withExtension:nil]; + iconURL = [host.bundle URLForResource:resource withExtension:nil]; } return iconURL; } diff --git a/Sparkle/SUStatusController.m b/Sparkle/SUStatusController.m index 580f0048..1198427c 100644 --- a/Sparkle/SUStatusController.m +++ b/Sparkle/SUStatusController.m @@ -66,7 +66,7 @@ - (NSImage *)applicationIcon { - return [SUApplicationInfo bestIconForBundle:self.host.bundle]; + return [SUApplicationInfo bestIconForHost:self.host]; } - (void)beginActionWithTitle:(NSString *)aTitle maxProgressValue:(double)aMaxProgressValue statusText:(NSString *)aStatusText diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index fde89736..2230bb9c 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -322,7 +322,7 @@ - (NSImage *)applicationIcon { - return [SUApplicationInfo bestIconForBundle:self.host.bundle]; + return [SUApplicationInfo bestIconForHost:self.host]; } - (NSString *)titleText diff --git a/Sparkle/SUUpdatePermissionPrompt.m b/Sparkle/SUUpdatePermissionPrompt.m index d99852f0..66e96ef2 100644 --- a/Sparkle/SUUpdatePermissionPrompt.m +++ b/Sparkle/SUUpdatePermissionPrompt.m @@ -101,7 +101,7 @@ - (NSImage *)icon { - return [SUApplicationInfo bestIconForBundle:self.host.bundle]; + return [SUApplicationInfo bestIconForHost:self.host]; } - (NSString *)promptDescription