Refactoring Status Menu

This commit is contained in:
relikd
2019-02-10 19:39:51 +01:00
parent cd0a1a3fd7
commit f2cca57fbb
39 changed files with 1491 additions and 1254 deletions

View File

@@ -21,8 +21,13 @@
// SOFTWARE.
#import "AppHook.h"
#import "BarMenu.h"
#import "BarStatusItem.h"
#import "FeedDownload.h"
#import "Preferences.h"
@interface AppHook()
@property (strong) Preferences *prefWindow;
@end
@implementation AppHook
@@ -33,7 +38,7 @@
}
- (void)applicationWillFinishLaunching:(NSNotification *)notification {
_barMenu = [BarMenu new];
_statusItem = [BarStatusItem new];
NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager];
[appleEventManager setEventHandler:self andSelector:@selector(handleGetURLEvent:withReplyEvent:)
forEventClass:kInternetEventClass andEventID:kAEGetURL];
@@ -60,6 +65,29 @@
}
#pragma mark - Handle Menu Interaction
/// Called whenever the user activates the preferences (either through menu click or hotkey).
- (void)openPreferences {
if (!self.prefWindow) {
self.prefWindow = [[Preferences alloc] initWithWindowNibName:@"Preferences"];
self.prefWindow.window.title = [NSString stringWithFormat:@"%@ %@", NSProcessInfo.processInfo.processName,
NSLocalizedString(@"Preferences", nil)];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(preferencesClosed:) name:NSWindowWillCloseNotification object:self.prefWindow.window];
}
[NSApp activateIgnoringOtherApps:YES];
[self.prefWindow showWindow:nil];
}
/// Callback method after user closes the preferences window.
- (void)preferencesClosed:(id)sender {
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSWindowWillCloseNotification object:self.prefWindow.window];
self.prefWindow = nil;
[FeedDownload scheduleUpdateForUpcomingFeeds];
}
#pragma mark - Core Data stack