mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-24 04:38:16 +00:00
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:
1 parent
0b6b6fe4ca
commit
fc9b2b38fa
9 files changed
+21
-14
No files matched your search
Vendored
+3
-1
@@ -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
|
||||
|
||||
|
||||
Vendored
+4
-3
@@ -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];
|
||||
|
||||
Vendored
+1
-1
@@ -61,7 +61,7 @@
|
||||
|
||||
- (NSImage *__nonnull)applicationIcon
|
||||
{
|
||||
return [SUApplicationInfo bestIconForBundle:self.host.bundle];
|
||||
return [SUApplicationInfo bestIconForHost:self.host];
|
||||
}
|
||||
|
||||
- (NSString *__nonnull)titleText
|
||||
|
||||
Vendored
+3
-1
@@ -10,9 +10,11 @@
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class SUHost;
|
||||
|
||||
@interface SUBundleIcon : NSObject
|
||||
|
||||
+ (NSURL * _Nullable)iconURLForBundle:(NSBundle *)bundle;
|
||||
+ (NSURL * _Nullable)iconURLForHost:(SUHost *)host;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
Vendored
+6
-4
@@ -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;
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -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
|
||||
|
||||
Vendored
+1
-1
@@ -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:)])
|
||||
|
||||
Vendored
+1
-1
@@ -221,7 +221,7 @@
|
||||
|
||||
- (NSImage *)applicationIcon
|
||||
{
|
||||
return [SUApplicationInfo bestIconForBundle:self.host.bundle];
|
||||
return [SUApplicationInfo bestIconForHost:self.host];
|
||||
}
|
||||
|
||||
- (NSString *)titleText
|
||||
|
||||
Vendored
+1
-1
@@ -100,7 +100,7 @@
|
||||
|
||||
- (NSImage *)icon
|
||||
{
|
||||
return [SUApplicationInfo bestIconForBundle:self.host.bundle];
|
||||
return [SUApplicationInfo bestIconForHost:self.host];
|
||||
}
|
||||
|
||||
- (NSString *)promptDescription
|
||||
|
||||
Reference in new issue
Block a user