Skip to content

Notification Center #2104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Quicksilver/Code-App/QSController.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@class QSObject;
@class QSInterfaceController;
@class QSNotificationCenterHandler;

@protocol QSDropletHandling
- (void)handlePasteboardDrop:(NSPasteboard *)pb commandPath:(NSString *)path;
Expand All @@ -18,6 +19,7 @@
}

@property (strong) NSString* crashReportPath;
@property (strong) QSNotificationCenterHandler *notificationHandler;

+ (id)sharedInstance;
- (IBAction)runSetupAssistant:(id)sender;
Expand Down Expand Up @@ -66,6 +68,7 @@

- (NSString *)crashReportPath;
- (void)showDockIcon;
- (void)requestRelaunch:(id)sender;

@end

Expand Down
45 changes: 34 additions & 11 deletions Quicksilver/Code-App/QSController.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#import "QSTaskViewer.h"
#import "QSCrashReporterWindowController.h"
#import "QSDownloads.h"
#import "QSNotificationCenterHandler.h"


#import "QSIntValueTransformer.h"
Expand Down Expand Up @@ -48,9 +49,9 @@ + (void)initialize {
QSIntValueTransformer *intValueIsTwo = [[QSIntValueTransformer alloc] initWithInteger:2];
[NSValueTransformer setValueTransformer:intValueIsTwo forName:@"IntegerValueIsTwo"];

if (![NSApplication isMountainLion]) {
if (![NSApplication isMavericks]) {
NSBundle *appBundle = [NSBundle mainBundle];
NSRunAlertPanel([NSString stringWithFormat:@"%@ %@ Mac OS X 10.8+",[appBundle objectForInfoDictionaryKey:@"CFBundleName"],NSLocalizedString(@"requires",nil)] ,[NSString stringWithFormat:NSLocalizedString(@"Recent versions of Quicksilver require Mac OS %@. Older %@ compatible versions are available from the http://qsapp.com/download.php", nil),@"10.8 Lion",@"10.3–10.7"], NSLocalizedString(@"OK",nil), nil, nil, [appBundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"]);
NSRunAlertPanel([NSString stringWithFormat:@"%@ %@ Mac OS X 10.9+",[appBundle objectForInfoDictionaryKey:@"CFBundleName"],NSLocalizedString(@"requires",nil)] ,[NSString stringWithFormat:NSLocalizedString(@"Recent versions of Quicksilver require Mac OS %@. Older %@ compatible versions are available from the http://qsapp.com/download.php", nil),@"10.9 Lion",@"10.3–10.8"], NSLocalizedString(@"OK",nil), nil, nil, [appBundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"]);
// Quit - we don't want to be running :)
[NSApp terminate:nil];
}
Expand Down Expand Up @@ -119,6 +120,8 @@ - (id)init {

if (![QSApplicationSupportPath length])
QSApplicationSupportPath = [self applicationSupportFolder];
self.notificationHandler = [[QSNotificationCenterHandler alloc] init];
[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self.notificationHandler];
}
return self;
}
Expand Down Expand Up @@ -645,16 +648,24 @@ - (void)checkForFirstRun {
NSString *lastLocation = [defaults objectForKey:kLastUsedLocation];
if (lastLocation && ![bundlePath isEqualToString:[lastLocation stringByStandardizingPath]]) {
//New version in new location.
[NSApp activateIgnoringOtherApps:YES];
NSInteger selection = NSRunAlertPanel(NSLocalizedString(@"Running from a new location",nil), NSLocalizedString(@"The previous version of Quicksilver was located in \"%@\". Would you like to move this new version to that location?",nil), NSLocalizedString(@"Move and Relaunch",nil), NSLocalizedString(@"Don't Move",nil), nil, [[lastLocation stringByDeletingLastPathComponent] lastPathComponent]);
if (selection)
[NSApp relaunchAtPath:lastLocation movedFromPath:bundlePath];
NSUserNotification *locationAlert = [[NSUserNotification alloc] init];
[locationAlert setIdentifier:QSLocationChangedUserNotification];
[locationAlert setTitle:NSLocalizedString(@"Running from a new location", nil)];
[locationAlert setInformativeText:NSLocalizedString(@"The previous version of Quicksilver was located in \"%@\". Would you like to move this new version to that location?", nil)];
[locationAlert setActionButtonTitle:NSLocalizedString(@"Move and Relaunch", nil)];
[locationAlert setUserInfo:@{@"source": bundlePath, @"destination": lastLocation}];
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:locationAlert];
}
if ([defaults boolForKey:kShowReleaseNotesOnUpgrade]) {
[NSApp activateIgnoringOtherApps:YES];
NSInteger selection = NSRunInformationalAlertPanel([NSString stringWithFormat:NSLocalizedString(@"Quicksilver has been updated",nil), nil] , NSLocalizedString(@"You are using a new version of Quicksilver. Would you like to see the Release Notes?",nil), NSLocalizedString(@"Show Release Notes",nil), NSLocalizedString(@"Ignore",nil), nil);
if (selection == 1)
[self showReleaseNotes:self];
NSUserNotification *releaseAlert = [[NSUserNotification alloc] init];
[releaseAlert setIdentifier:QSReleaseNotesUserNotification];
NSString *title = NSLocalizedString(@"Quicksilver has been updated", nil);
NSString *details = NSLocalizedString(@"You are using a new version of Quicksilver. Would you like to see the Release Notes?", nil);
NSString *button = NSLocalizedString(@"Show Release Notes", nil);
[releaseAlert setTitle:title];
[releaseAlert setInformativeText:details];
[releaseAlert setActionButtonTitle:button];
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:releaseAlert];
}
if (lastVersion < [@"3929" hexIntValue] && [[NSRunningApplication currentApplication] executableArchitecture] == NSBundleExecutableArchitectureX86_64) {
// first time-running a 64-bit version
Expand Down Expand Up @@ -682,7 +693,6 @@ - (void)checkForFirstRun {
NSString *containerPath = [[bundlePath stringByDeletingLastPathComponent] stringByStandardizingPath];
BOOL shouldInstall = [containerPath isEqualToString:@"/Volumes/Quicksilver"] || [containerPath isEqualToString:[[QSDownloads downloadsLocation] path]];
if (shouldInstall) {
//New version in new location.
[NSApp activateIgnoringOtherApps:YES];
NSInteger selection = NSRunAlertPanel(NSLocalizedString(@"Would you like to install Quicksilver?",nil), NSLocalizedString(@"Quicksilver was launched from a download location.\rWould you like to copy Quicksilver to your applications folder?",nil), NSLocalizedString(@"Install in \"Applications\"",nil), NSLocalizedString(@"Quit",nil), NSLocalizedString(@"Choose Location...",nil));
NSString *installPath = nil;
Expand Down Expand Up @@ -793,6 +803,19 @@ - (void)setInterfaceController:(QSInterfaceController *)newInterfaceController {
[nc postNotificationName:QSInterfaceChangedNotification object:self];
}

- (void)requestRelaunch:(id)sender
{
NSUserNotification *relaunchAlert = [[NSUserNotification alloc] init];
[relaunchAlert setIdentifier:QSRelaunchRequestedUserNotification];
NSString *title = NSLocalizedString(@"Relaunch Necessary", nil);
NSString *details = NSLocalizedString(@"Quicksilver needs to be relaunched for some changes to take effect", nil);
NSString *button = NSLocalizedString(@"Relaunch", nil);
[relaunchAlert setTitle:title];
[relaunchAlert setInformativeText:details];
[relaunchAlert setActionButtonTitle:button];
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:relaunchAlert];
}

/* Deprecated. It's defined in Core Plugin */
- (id) finderProxy { return [QSReg performSelector:@selector(FSBrowserMediator)]; }

Expand Down
5 changes: 4 additions & 1 deletion Quicksilver/Code-App/QSHelpersPrefPane.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#import "QSResourceManager.h"
#import "QSRegistry.h"
#import "QSMacros.h"
#import "QSController.h"

#import "NSBundle_BLTRExtensions.h"

Expand Down Expand Up @@ -135,7 +136,9 @@ - (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject forTable
if (![anObject isEqual:[defaults objectForKey:mediatorType]]) {
[defaults setObject:anObject forKey:mediatorType];
[QSReg removePreferredInstanceOfTable:mediatorType];
if ([settings objectForKey:@"requiresRelaunch"]) [NSApp requestRelaunch:self];
if ([settings objectForKey:@"requiresRelaunch"]) {
[[QSController sharedInstance] requestRelaunch:nil];
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Quicksilver/Code-App/QSMainPreferencePanes.m
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ - (void)setShowChildrenInSplitView:(BOOL)flag {
[defaults setBool:flag forKey:@"QSResultsShowChildren"];

[defaults synchronize];
[NSApp requestRelaunch:nil];
[[QSController sharedInstance] requestRelaunch:nil];
}

- (void)updateKeyboardPopUp {
Expand Down Expand Up @@ -278,7 +278,7 @@ - (void)setDockIconIsHidden:(BOOL)flag {
if (![defaults objectForKey:@"QSShowMenuIcon"])
[defaults setInteger:1 forKey:@"QSShowMenuIcon"];
[defaults synchronize];
[NSApp requestRelaunch:nil];
[[QSController sharedInstance] requestRelaunch:nil];
}

- (IBAction)checkNow:(id)sender {
Expand Down
15 changes: 15 additions & 0 deletions Quicksilver/Code-App/QSNotificationCenterHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// QSNotificationCenterHandler.h
// Quicksilver
//
// Created by Rob McBroom on 2015/08/17.
//
//

#define QSReleaseNotesUserNotification @"QSReleaseNotesUserNotification"
#define QSLocationChangedUserNotification @"QSLocationChangedUserNotification"
#define QSRelaunchRequestedUserNotification @"QSRelaunchRequestedUserNotification"

@interface QSNotificationCenterHandler : NSObject <NSUserNotificationCenterDelegate>

@end
40 changes: 40 additions & 0 deletions Quicksilver/Code-App/QSNotificationCenterHandler.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// QSNotificationCenterHandler.m
// Quicksilver
//
// Created by Rob McBroom on 2015/08/17.
//
//

#import "QSNotificationCenterHandler.h"
#import "QSController.h"

@implementation QSNotificationCenterHandler

#pragma mark NSUserNotificationCenter delegate methods

- (void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification
{
if ([[notification identifier] isEqualToString:QSReleaseNotesUserNotification]) {
[[QSController sharedInstance] showReleaseNotes:self];
return;
}
if ([[notification identifier] isEqualToString:QSLocationChangedUserNotification]) {
NSString *lastLocation = notification.userInfo[@"destination"];
NSString *bundlePath = notification.userInfo[@"source"];
[NSApp relaunchAtPath:lastLocation movedFromPath:bundlePath];
return;
}
if ([[notification identifier] isEqualToString:QSRelaunchRequestedUserNotification]) {
[NSApp relaunch:nil];
return;
}
}

- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification
{
// there's no in-app equivalent for these notifications, so always show them
return YES;
}

@end
2 changes: 1 addition & 1 deletion Quicksilver/Code-App/QSNotificationCenterNotifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
// Display notifications using Notification Center introduced with 10.8
//

@interface QSNotificationCenterNotifier : NSObject <QSNotifier>
@interface QSNotificationCenterNotifier : NSObject <QSNotifier, NSUserNotificationCenterDelegate>

@end
13 changes: 11 additions & 2 deletions Quicksilver/Code-App/QSNotificationCenterNotifier.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,27 @@ @implementation QSNotificationCenterNotifier

- (void)displayNotificationWithAttributes:(NSDictionary *)attributes
{
#ifdef MAC_OS_X_VERSION_10_8
NSString *title = [attributes objectForKey:QSNotifierTitle];
NSString *subtitle = [attributes objectForKey:QSNotifierText];
NSString *details = [[attributes objectForKey:QSNotifierDetails] string];
NSImage *icon = [attributes objectForKey:QSNotifierIcon];

NSUserNotification *message = [[NSUserNotification alloc] init];
[message setTitle:title];
[message setSubtitle:subtitle];
[message setInformativeText:details];
[message setContentImage:icon];
[message setHasActionButton:NO];

[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:message];
#endif
}

#pragma mark NSUserNotificationCenter delegate methods

- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification
{
// there's no in-app equivalent for these notifications, so always show them
return YES;
}

@end
7 changes: 6 additions & 1 deletion Quicksilver/Code-App/QSUpdateController.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,21 @@

#import <Cocoa/Cocoa.h>

#define QSUpdateAvailableUserNotification @"QSUpdateAvailableUserNotification"
#define QSUpdateDownloadedUserNotification @"QSUpdateDownloadedUserNotification"
#define QSUpdateInstalledUserNotification @"QSUpdateInstalledUserNotification"

@class QSTask, QSURLDownload;

@interface QSUpdateController : NSObject {
@interface QSUpdateController : NSObject <NSUserNotificationCenterDelegate> {
NSTimer *updateTimer;
BOOL doStartupCheck;
QSURLDownload *appDownload;
NSString *newVersion;
NSString *tempPath;
QSTask *updateTask;
BOOL shouldCancel;
NSUserNotificationCenter *userNotificationCenter;
}

+ (id)sharedInstance;
Expand Down
Loading