Skip to content

Commit

Permalink
Add support for setting “Open at Login”-preference through the API (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
kasper committed Apr 13, 2016
1 parent 7c0198a commit aa7432d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
8 changes: 7 additions & 1 deletion API.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,17 @@ All of the following window events receive the corresponding `Window`-instance a
Phoenix supports the following (case sensitive) preferences:

- `daemon` (boolean): if set `true` Phoenix will run completely in the background, this also removes the status bar menu, defaults to `false`
- `openAtLogin` (boolean): if set `true` Phoenix will automatically open at login, defaults to `false`

Set the preferences using the `Phoenix`-object — for example:

```javascript
Phoenix.set({ 'daemon': true });
Phoenix.set({

'daemon': true,
'openAtLogin': true

});
```

## 4. Require
Expand Down
1 change: 1 addition & 0 deletions Phoenix/PHAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ - (void) menuNeedsUpdate:(NSMenu *)menu {
- (void) preferencesDidChange:(NSNotification *)__unused notification {

[self toggleStatusItem];
[PHOpenAtLoginHelper setOpensAtLogin:[[PHPreferences sharedPreferences] openAtLogin]];
}

#pragma mark - IBAction
Expand Down
5 changes: 5 additions & 0 deletions Phoenix/PHOpenAtLoginHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ + (BOOL) opensAtLogin {

+ (void) setOpensAtLogin:(BOOL)opensAtLogin {

// Item already set
if ([self opensAtLogin] == opensAtLogin) {
return;
}

NSURL *appUrl = [NSBundle mainBundle].bundleURL;

/* Add item */
Expand Down
1 change: 1 addition & 0 deletions Phoenix/PHPreferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ static NSString * const PHPreferencesDidChangeNotification = @"PHPreferencesDidC
- (void) reset;

- (BOOL) isDaemon;
- (BOOL) openAtLogin;

@end
6 changes: 6 additions & 0 deletions Phoenix/PHPreferences.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ @implementation PHPreferences

// Preference keys
static NSString * const PHDaemonKey = @"daemon";
static NSString * const PHOpenAtLogin = @"openAtLogin";

#pragma mark - Initialise

Expand Down Expand Up @@ -65,4 +66,9 @@ - (BOOL) isDaemon {
return [self.preferences[PHDaemonKey] boolValue];
}

- (BOOL) openAtLogin {

return [self.preferences[PHOpenAtLogin] boolValue];
}

@end

0 comments on commit aa7432d

Please sign in to comment.