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.
This commit is contained in:
Zorg committed 2017-01-07 22:55:13 -05:00
1 parent b645005689
commit 2bb5ce4318
13 files changed
+32 -19

No files matched your search

+2 -1
View File
@@ -14,6 +14,7 @@
#import "SUBundleIcon.h"
#import "SPULocalCacheDirectory.h"
#import "SPUInstallationType.h"
#import "SUHost.h"
#import <ServiceManagement/ServiceManagement.h>
#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) {
+2
View File
@@ -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 */,
+4 -2
View File
@@ -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];
}
});
}
+3 -1
View File
@@ -10,9 +10,11 @@
NS_ASSUME_NONNULL_BEGIN
@class SUHost;
@protocol InstallerProgressDelegate <NSObject>
- (void)installerProgressShouldDisplayWithBundle:(NSBundle *)bundle;
- (void)installerProgressShouldDisplayWithHost:(SUHost *)host;
- (void)installerProgressShouldStop;
@end
+1 -2
View File
@@ -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];
+1 -1
View File
@@ -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)]) {
+3 -1
View File
@@ -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
+4 -3
View File
@@ -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];
+3 -1
View File
@@ -10,9 +10,11 @@
NS_ASSUME_NONNULL_BEGIN
@class SUHost;
@interface SUBundleIcon : NSObject
+ (NSURL * _Nullable)iconURLForBundle:(NSBundle *)bundle;
+ (NSURL * _Nullable)iconURLForHost:(SUHost *)host;
@end
+6 -4
View File
@@ -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;
}
+1 -1
View File
@@ -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
+1 -1
View File
@@ -322,7 +322,7 @@
- (NSImage *)applicationIcon
{
return [SUApplicationInfo bestIconForBundle:self.host.bundle];
return [SUApplicationInfo bestIconForHost:self.host];
}
- (NSString *)titleText
+1 -1
View File
@@ -101,7 +101,7 @@
- (NSImage *)icon
{
return [SUApplicationInfo bestIconForBundle:self.host.bundle];
return [SUApplicationInfo bestIconForHost:self.host];
}
- (NSString *)promptDescription