Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Switching to code less use of LLManager.

  • Loading branch information...
commit 74ef9843a3b234decebcb1b9e2088caffc78f955 1 parent 5260c41
Jan Weiß authored
View
2  LaunchAtLoginSample/LLAppDelegate.h
@@ -14,6 +14,8 @@
@property (assign) IBOutlet NSWindow *window;
@property (assign) IBOutlet NSButton *checkBox;
+#if 0
- (IBAction)checkBoxAction:(id)sender;
+#endif
@end
View
37 LaunchAtLoginSample/LLAppDelegate.m
@@ -12,6 +12,21 @@
@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]];
}
@@ -19,5 +34,27 @@ - (void)applicationDidFinishLaunching:(NSNotification *)notification{
- (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
View
8 LaunchAtLoginSample/MainMenu.xib
@@ -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>
@@ -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>
Please sign in to comment.
Something went wrong with that request. Please try again.