Second try at login items. If the user hides Enjoyable in the status bar, explain...
authorJoe Wreschnig <joe.wreschnig@gmail.com>
Wed, 13 Mar 2013 20:10:54 +0000 (21:10 +0100)
committerJoe Wreschnig <joe.wreschnig@gmail.com>
Wed, 13 Mar 2013 20:10:54 +0000 (21:10 +0100)
Classes/EnjoyableApplicationDelegate.h
Classes/EnjoyableApplicationDelegate.m
Info.plist
Resources/English.lproj/Localizable.strings
Resources/English.lproj/MainMenu.xib

index f61578b225048c1683f45ebc3376312f5b89200f..acea8a92e142f96885afd795eb1d1ac487f3e553 100644 (file)
@@ -11,7 +11,8 @@
 #import "NJMappingMenuController.h"
 
 @interface EnjoyableApplicationDelegate : NSObject <NSApplicationDelegate,
-                                                    NJMappingMenuDelegate> {
+                                                    NJMappingMenuDelegate,
+                                                    NSWindowDelegate> {
     IBOutlet NSMenu *dockMenu;
     IBOutlet NSMenu *statusItemMenu;
     IBOutlet NSWindow *window;
index 411067e74d351bb3d55ec96a5bd5161a375174b2..b1d9907fb850cd85f7f05679c5acdbb8d6ce3224 100644 (file)
@@ -5,6 +5,8 @@
 //  Created by Sam McCall on 4/05/09.
 //
 
+#import <Sparkle/Sparkle.h>
+
 #import "EnjoyableApplicationDelegate.h"
 
 #import "NJMapping.h"
 }
 
 - (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
     [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
index 2b34274a79d46aa15212c3fbc7845c30f4c51c57..285b858ad8ecd57a3ea1825dd5e19e66cafff26a 100644 (file)
        <key>CFBundlePackageType</key>
        <string>APPL</string>
        <key>CFBundleShortVersionString</key>
-       <string>1.0</string>
+       <string>1.1</string>
        <key>CFBundleSignature</key>
        <string>????</string>
        <key>CFBundleVersion</key>
-       <string>259</string>
+       <string>294</string>
        <key>LSApplicationCategoryType</key>
        <string>public.app-category.utilities</string>
        <key>NSHumanReadableCopyright</key>
index 564ef88d1ae705702f756a03d3bddd1b4785727c..8b9a71782f2bf1dcc87e4fa301c7df7b43d4a61f 100644 (file)
Binary files a/Resources/English.lproj/Localizable.strings and b/Resources/English.lproj/Localizable.strings differ
index 98b5cef7620130d0295dbc5f6bc36566b2f3317d..2a956676397341cea2d562e0e938be80ab124d39 100644 (file)
@@ -1629,6 +1629,14 @@ aW5nLg</string>
                                        </object>
                                        <int key="connectionID">941</int>
                                </object>
+                               <object class="IBConnectionRecord">
+                                       <object class="IBOutletConnection" key="connection">
+                                               <string key="label">delegate</string>
+                                               <reference key="source" ref="808667431"/>
+                                               <reference key="destination" ref="207406104"/>
+                                       </object>
+                                       <int key="connectionID">977</int>
+                               </object>
                                <object class="IBConnectionRecord">
                                        <object class="IBOutletConnection" key="connection">
                                                <string key="label">delegate</string>
@@ -3259,7 +3267,7 @@ aW5nLg</string>
                        <nil key="activeLocalization"/>
                        <dictionary class="NSMutableDictionary" key="localizations"/>
                        <nil key="sourceID"/>
-                       <int key="maxID">976</int>
+                       <int key="maxID">977</int>
                </object>
                <object class="IBClassDescriber" key="IBDocument.Classes">
                        <array class="NSMutableArray" key="referencedPartialClassDescriptions">