Auto increase bundle version, handling url scheme, image generation

This commit is contained in:
relikd
2019-02-14 18:31:28 +01:00
parent abf6312908
commit 7e68c1752c
9 changed files with 124 additions and 101 deletions

View File

@@ -55,15 +55,18 @@
- (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent {
NSString *url = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];
if ([url hasPrefix:@"feed:"]) {
// TODO: handle other app schemes like configuration export / import
url = [url substringFromIndex:5];
if ([url hasPrefix:@"//"])
url = [url substringFromIndex:2];
NSString *scheme = [[[NSURL URLWithString:url] scheme] lowercaseString];
url = [url substringFromIndex:scheme.length + 1]; // + ':'
if (url.length >= 2 && [[url substringToIndex:2] isEqualToString:@"//"]) {
url = [url substringFromIndex:2];
}
if ([scheme isEqualToString:@"feed"]) {
[FeedDownload autoDownloadAndParseURL:url successBlock:^{
[self reopenPreferencesIfOpen];
}];
}
// TODO: handle other app schemes like configuration export / import
// NSURLComponents *comp = [NSURLComponents componentsWithString:url];
}

View File

@@ -26,6 +26,8 @@
@class RSParsedFeed;
@interface Feed (Ext)
@property (nonnull, readonly) NSImage* iconImage16;
// Generator methods / Feed update
+ (instancetype)newFeedAndMetaInContext:(NSManagedObjectContext*)context;
+ (instancetype)appendToRootWithDefaultIntervalInContext:(NSManagedObjectContext*)moc;
@@ -35,6 +37,5 @@
// Article properties
- (NSArray<FeedArticle*>*)sortedArticles;
// Icon
- (NSImage*)iconImage16;
- (BOOL)setIconImage:(NSImage*)img;
@end

View File

@@ -62,7 +62,7 @@
item.title = self.group.nameOrError;
item.toolTip = self.subtitle;
item.enabled = (self.articles.count > 0);
item.image = [self iconImage16];
item.image = self.iconImage16;
item.representedObject = self.indexPath;
item.target = [self class];
item.action = @selector(didClickOnMenuItem:);
@@ -200,30 +200,17 @@
/**
@return Return @c 16x16px image. Either from core data storage or generated default RSS icon.
*/
- (NSImage*)iconImage16 {
NSData *imgData = self.icon.icon;
if (imgData)
{
NSImage *img = [[NSImage alloc] initWithData:imgData];
[img setSize:NSMakeSize(16, 16)];
return img;
}
else if (self.articles.count == 0)
{
static NSImage *warningIcon;
if (!warningIcon) {
warningIcon = [NSImage imageNamed:NSImageNameCaution];
[warningIcon setSize:NSMakeSize(16, 16)];
}
return warningIcon;
}
else
{
static NSImage *defaultRSSIcon; // TODO: setup imageNamed: for default rss icon
if (!defaultRSSIcon)
defaultRSSIcon = [RSSIcon iconWithSize:16];
return defaultRSSIcon;
- (nonnull NSImage*)iconImage16 {
NSImage *img = nil;
if (self.articles.count == 0) {
img = [NSImage imageNamed:NSImageNameCaution];
} else if (self.icon.icon) {
img = [[NSImage alloc] initWithData:self.icon.icon];
} else {
return [RSSIcon iconWithSize:16]; // TODO: setup imageNamed: for default rss icon?
}
[img setSize:NSMakeSize(16, 16)];
return img;
}
/**

View File

@@ -34,11 +34,12 @@ typedef NS_ENUM(int16_t, FeedGroupType) {
/// Overwrites @c type attribute with enum. Use one of: @c GROUP, @c FEED, @c SEPARATOR.
@property (nonatomic) FeedGroupType type;
@property (nonnull, readonly) NSString *nameOrError;
@property (nonnull, readonly) NSImage* groupIconImage16;
@property (nonnull, readonly) NSImage* iconImage16;
+ (instancetype)newGroup:(FeedGroupType)type inContext:(NSManagedObjectContext*)context;
- (void)setParent:(FeedGroup *)parent andSortIndex:(int32_t)sortIndex;
- (void)setNameIfChanged:(NSString*)name;
- (NSImage*)groupIconImage16;
- (NSMenuItem*)newMenuItem;
// Handle children and parents
- (NSString*)indexPathString;

View File

@@ -27,6 +27,33 @@
@implementation FeedGroup (Ext)
#pragma mark - Properties
/// @return Returns "(error)" if @c self.name is @c nil.
- (nonnull NSString*)nameOrError {
return (self.name ? self.name : NSLocalizedString(@"(error)", nil));
}
/// @return Return @c 16x16px NSImageNameFolder image.
- (nonnull NSImage*)groupIconImage16 {
NSImage *groupIcon = [NSImage imageNamed:NSImageNameFolder];
groupIcon.size = NSMakeSize(16, 16);
return groupIcon;
}
/**
@return Return @c 16x16px image.
Either feed icon ( @c type @c == @c FEED ) or @c NSImageNameFolder ( @c type @c == @c GROUP ).
*/
- (nonnull NSImage*)iconImage16 {
if (self.type == FEED)
return self.feed.iconImage16;
return self.groupIconImage16;
}
#pragma mark - Generator
/// Create new instance and set @c Feed and @c FeedMeta if group type is @c FEED
+ (instancetype)newGroup:(FeedGroupType)type inContext:(NSManagedObjectContext*)moc {
FeedGroup *fg = [[FeedGroup alloc] initWithEntity: FeedGroup.entity insertIntoManagedObjectContext:moc];
@@ -49,27 +76,12 @@
self.name = name;
}
/// @return Return static @c 16x16px NSImageNameFolder image.
- (NSImage*)groupIconImage16 {
static NSImage *groupIcon;
if (!groupIcon) {
groupIcon = [NSImage imageNamed:NSImageNameFolder];
groupIcon.size = NSMakeSize(16, 16);
}
return groupIcon;
}
/// @return Returns "(error)" if @c self.name is @c nil.
- (nonnull NSString*)nameOrError {
return (self.name ? self.name : NSLocalizedString(@"(error)", nil));
}
/// @return Fully initialized @c NSMenuItem with @c title and @c image.
- (NSMenuItem*)newMenuItem {
NSMenuItem *item = [NSMenuItem new];
item.title = self.nameOrError;
item.enabled = (self.children.count > 0);
item.image = [self groupIconImage16];
item.image = self.groupIconImage16;
item.representedObject = self.objectID;
return item;
}

View File

@@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.9</string>
<string>0.9.1</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
@@ -32,7 +32,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>1</string>
<string>1032</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>LSUIElement</key>
@@ -43,7 +43,7 @@
<true/>
</dict>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2018 relikd. Public Domain.</string>
<string>Copyright © 2019 relikd. Public Domain.</string>
<key>NSPrincipalClass</key>
<string>AppHook</string>
</dict>

View File

@@ -419,7 +419,7 @@ static NSString *dragNodeType = @"baRSS-feed-drag";
return cellView; // refresh cell already skipped with the above if condition
} else {
cellView.textField.objectValue = fg.name;
cellView.imageView.image = (fg.type == GROUP ? [NSImage imageNamed:NSImageNameFolder] : [fg.feed iconImage16]);
cellView.imageView.image = fg.iconImage16;
}
return cellView;
}