Permalink
Browse files

Automatically opens preference dialog when launched again

  • Loading branch information...
1 parent b06cb93 commit fe6836abb9a251c59908b561510b954627c052ff Filip Krikava committed Jan 14, 2011
Showing with 8 additions and 22 deletions.
  1. +1 −8 README.md
  2. +7 −14 ShiftIt/ShiftItAppDelegate.m
View
@@ -41,14 +41,7 @@ FAQ
**I disabled the `Show Icon in Menu Bar` in the preferences, how can I get it back?how can I get it back?**
-Right now there are three options:
-
-1. In Terminal run: `open -na /Applications/ShiftIt.app` (or wherever you have installed it). This will attempt to run a new instance. It will show a dialog giving you an option to go the preferences.
-
-1. Manually change the preference value: form Terminal run: `defaults write org.shiftitapp.ShiftIt shiftItshowMenu 1` and then restart the app.
-
-1. Quit the app and start it from Terminal with a `-shiftItShowMenu`
-like: `/Applications/ShiftIt.app/Contents/MacOS/ShiftIt -shiftItshowMenu 1`
+Launch the application again. It will open the preference dialog.
3rd Party Frameworks
--------------------
@@ -130,20 +130,6 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults synchronize];
- // check we are the only one
- if (FMTNumberOfRunningProcessesWithBundleId(kShiftItAppBundleId) > 1) {
- int ret = NSRunAlertPanel (@"ShiftIt is already running",
- @"There is point to have more than instance at the same time so this one will now quit.",
- @"Quit",
- @"Show preferences",
- nil);
- if (ret == NSAlertAlternateReturn) {
- [[NSDistributedNotificationCenter defaultCenter] postNotificationName:kShowPreferencesRequestNotification object:nil];
- }
-
- [NSApp terminate:self];
- }
-
// check preferences
BOOL hasStartedBefore = [defaults boolForKey:kHasStartedBeforePrefKey];
@@ -212,6 +198,13 @@ - (void) applicationWillTerminate:(NSNotification *)aNotification {
}
}
+- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows: (BOOL)flag{
+ if(flag==NO){
+ [self showPreferences:nil];
+ }
+ return YES;
+}
+
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
if([FMTStr(@"values.%@",kShowMenuPrefKey) isEqualToString:keyPath]) {
[self updateMenuBarIcon_];

0 comments on commit fe6836a

Please sign in to comment.