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-08 15:36:30 -05:00
1 parent 0b6b6fe4ca
commit fc9b2b38fa
9 files changed
+21 -14

No files matched your search

+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];
+1 -1
View File
@@ -61,7 +61,7 @@
- (NSImage *__nonnull)applicationIcon
{
return [SUApplicationInfo bestIconForBundle:self.host.bundle];
return [SUApplicationInfo bestIconForHost:self.host];
}
- (NSString *__nonnull)titleText
+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,21 +7,23 @@
//
#import "SUBundleIcon.h"
#import "SUHost.h"
@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
@@ -314,7 +314,7 @@
// are focused to inform the user since there is no dock icon to notify them.
if ([SUApplicationInfo isBackgroundApplication:[NSApplication sharedApplication]]) { [NSApp activateIgnoringOtherApps:YES]; }
[alert setIcon:[SUApplicationInfo bestIconForBundle:self.host.bundle]];
[alert setIcon:[SUApplicationInfo bestIconForHost:self.host]];
[alert runModal];
if ([[updater delegate] respondsToSelector:@selector(updaterDidShowModalAlert:)])
+1 -1
View File
@@ -221,7 +221,7 @@
- (NSImage *)applicationIcon
{
return [SUApplicationInfo bestIconForBundle:self.host.bundle];
return [SUApplicationInfo bestIconForHost:self.host];
}
- (NSString *)titleText
+1 -1
View File
@@ -100,7 +100,7 @@
- (NSImage *)icon
{
return [SUApplicationInfo bestIconForBundle:self.host.bundle];
return [SUApplicationInfo bestIconForHost:self.host];
}
- (NSString *)promptDescription