Skip to content

Commit

Permalink
Switching to code less use of LLManager.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Weiß committed Feb 25, 2014
1 parent 5260c41 commit 74ef984
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
2 changes: 2 additions & 0 deletions LaunchAtLoginSample/LLAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
@property (assign) IBOutlet NSWindow *window;
@property (assign) IBOutlet NSButton *checkBox;

#if 0
- (IBAction)checkBoxAction:(id)sender;
#endif

@end
37 changes: 37 additions & 0 deletions LaunchAtLoginSample/LLAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,49 @@

@implementation LLAppDelegate

- (void)awakeFromNib{
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
[notificationCenter addObserver:self
selector:@selector(settingLaunchAtLoginFailed:)
name:LLManagerSetLaunchAtLoginFailedNotification
object:nil];
}

#if 0
// Using LLManager in code.
// This is disabled, because this sample uses an LLManager
// instantiated in the nib/xib file and bound to there.
// notifyIfSetLaunchAtLoginFailed is set there via “User Defined Runtime Attributes”.
// We could instantiate an instance here and do that all in code,
// but we don’t, because we are lazy. ;)
- (void)applicationDidFinishLaunching:(NSNotification *)notification{
[self.checkBox setState:[LLManager launchAtLogin]];
}

- (IBAction)checkBoxAction:(id)sender{
[LLManager setLaunchAtLogin:[sender state]];
}
#endif

- (void)settingLaunchAtLoginFailed:(NSNotification *)notification{
NSAlert *alert = nil;

NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
NSDictionary *localizedInfoDictionary = [[NSBundle mainBundle] localizedInfoDictionary];

NSString *displayName = [localizedInfoDictionary objectForKey:(NSString *)kCFBundleNameKey];
if (displayName == nil) displayName = infoDictionary[(NSString *)kCFBundleNameKey];

NSString *message = [NSString stringWithFormat:NSLocalizedString(@"Could not change the setting for opening “%@” at Login.", @"Notify of launch at login setting change failure."), displayName];
NSString *details = NSLocalizedString(@"Your version of OS X may not be supported, yet. \n"
"Alternatively, you may not have the required permissions to change the setting or the app may be damaged.", @"Notify of launch at login setting change failure (details).");
alert = [NSAlert alertWithMessageText:message
defaultButton:nil // Default: OK
alternateButton:nil
otherButton:nil
informativeTextWithFormat:details, nil];

[alert runModal];
}

@end
8 changes: 7 additions & 1 deletion LaunchAtLoginSample/MainMenu.xib
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="checkBoxAction:" target="494" id="541"/>
<binding destination="jyP-1a-sO5" name="value" keyPath="launchAtLogin" id="6hf-vf-vL7"/>
</connections>
</button>
</subviews>
Expand All @@ -681,5 +681,11 @@
</connections>
</customObject>
<customObject id="420" customClass="NSFontManager"/>
<customObject id="jyP-1a-sO5" userLabel="Launch Manager" customClass="LLManager">
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="boolean" keyPath="notifyIfSetLaunchAtLoginFailed" value="YES"/>
</userDefinedRuntimeAttributes>
</customObject>
<userDefaultsController representsSharedInstance="YES" id="njg-MX-xAS"/>
</objects>
</document>

0 comments on commit 74ef984

Please sign in to comment.