From b417eb4ae97804070277eb19cc596bdb6bb9d281 Mon Sep 17 00:00:00 2001 From: Joe Wreschnig Date: Wed, 13 Mar 2013 21:10:54 +0100 Subject: [PATCH] Second try at login items. If the user hides Enjoyable in the status bar, explain and ask what to do. Try to have least-annoying interactions with Sparkle updater's additional prompt. --- Classes/EnjoyableApplicationDelegate.h | 3 +- Classes/EnjoyableApplicationDelegate.m | 49 +++++++++++++++++++- Info.plist | 4 +- Resources/English.lproj/Localizable.strings | Bin 6424 -> 7520 bytes Resources/English.lproj/MainMenu.xib | 10 +++- 5 files changed, 61 insertions(+), 5 deletions(-) diff --git a/Classes/EnjoyableApplicationDelegate.h b/Classes/EnjoyableApplicationDelegate.h index f61578b..acea8a9 100644 --- a/Classes/EnjoyableApplicationDelegate.h +++ b/Classes/EnjoyableApplicationDelegate.h @@ -11,7 +11,8 @@ #import "NJMappingMenuController.h" @interface EnjoyableApplicationDelegate : NSObject { + NJMappingMenuDelegate, + NSWindowDelegate> { IBOutlet NSMenu *dockMenu; IBOutlet NSMenu *statusItemMenu; IBOutlet NSWindow *window; diff --git a/Classes/EnjoyableApplicationDelegate.m b/Classes/EnjoyableApplicationDelegate.m index 411067e..b1d9907 100644 --- a/Classes/EnjoyableApplicationDelegate.m +++ b/Classes/EnjoyableApplicationDelegate.m @@ -5,6 +5,8 @@ // Created by Sam McCall on 4/05/09. // +#import + #import "EnjoyableApplicationDelegate.h" #import "NJMapping.h" @@ -48,7 +50,11 @@ } - (void)applicationDidFinishLaunching:(NSNotification *)notification { - [window makeKeyAndOrderFront:nil]; + if ([NSUserDefaults.standardUserDefaults boolForKey:@"hidden in status item"] + && NSRunningApplication.currentApplication.wasLaunchedAsLoginItemOrResume) + [self transformIntoElement:nil]; + else + [window makeKeyAndOrderFront:nil]; } - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication @@ -143,5 +149,46 @@ [self.mappingsController mappingPressed:self]; } +- (void)loginItemPromptDidEnd:(NSWindow *)sheet + returnCode:(int)returnCode + contextInfo:(void *)contextInfo { + if (returnCode == NSAlertDefaultReturn) { + [NSRunningApplication.currentApplication addToLoginItems]; + // If we're going to automatically start, don't bug the user + // about automatic updates next boot - they probably want it, + // and if they don't they probably want a prompt for it less. + SUUpdater.sharedUpdater.automaticallyChecksForUpdates = YES; + } +} + +- (void)loginItemPromptDidDismiss:(NSWindow *)sheet + returnCode:(int)returnCode + contextInfo:(void *)contextInfo { + [NSUserDefaults.standardUserDefaults setBool:YES forKey:@"explained login items"]; + [window performClose:sheet]; +} + +- (BOOL)windowShouldClose:(NSWindow *)sender { + if (sender != window + || NSRunningApplication.currentApplication.isLoginItem + || [NSUserDefaults.standardUserDefaults boolForKey:@"explained login items"]) + return YES; + NSBeginAlertSheet( + NSLocalizedString(@"login items prompt", @"alert prompt for adding to login items"), + NSLocalizedString(@"login items add button", @"button to add to login items"), + NSLocalizedString(@"login items don't add button", @"button to not add to login items"), + nil, window, self, + @selector(loginItemPromptDidEnd:returnCode:contextInfo:), + @selector(loginItemPromptDidDismiss:returnCode:contextInfo:), + NULL, + NSLocalizedString(@"login items explanation", @"a brief explanation of login items") + ); + for (int i = 0; i < 10; ++i) + [self performSelector:@selector(flashStatusItem) + withObject:self + afterDelay:0.5 * i]; + return NO; +} + @end diff --git a/Info.plist b/Info.plist index 2b34274..285b858 100644 --- a/Info.plist +++ b/Info.plist @@ -42,11 +42,11 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.0 + 1.1 CFBundleSignature ???? CFBundleVersion - 259 + 294 LSApplicationCategoryType public.app-category.utilities NSHumanReadableCopyright diff --git a/Resources/English.lproj/Localizable.strings b/Resources/English.lproj/Localizable.strings index 564ef88d1ae705702f756a03d3bddd1b4785727c..8b9a71782f2bf1dcc87e4fa301c7df7b43d4a61f 100644 GIT binary patch delta 953 zcmbu8ze)o^5XJ|q7(0uAg}B5*2ok|kku+LqAy|kY!sYIw(PR_uE@-MegIuAnU?=zn zR(8IEkK%9kviXAnK{@tzcXsESZ)U!I-u>Epy{g;=(vesa$;3#XxhGv_-L+UJ%z;FF zZLxCAF2ic@>9JFr;h%xfm6UZ&cBCxT#pn5Fd988A?O+`52>)A(-lXp zBC3$kQB$Hy&?70`h*Q;Wiv8Fh%y9Z~IYodf=#ZQYq7KNsk443w67-T4BY#@nczj>A h`g%Gj)pIP~(V_swTgjZd{q6aTe$~FbomM`Uz5z(5uK54} delta 16 YcmaE0HN$8_oY>@DEFznCNiAan06ho>od5s; diff --git a/Resources/English.lproj/MainMenu.xib b/Resources/English.lproj/MainMenu.xib index 98b5cef..2a95667 100644 --- a/Resources/English.lproj/MainMenu.xib +++ b/Resources/English.lproj/MainMenu.xib @@ -1629,6 +1629,14 @@ aW5nLg 941 + + + delegate + + + + 977 + delegate @@ -3259,7 +3267,7 @@ aW5nLg - 976 + 977 -- 2.20.1