Skip to content

Commit

Permalink
Cleanup for #212
Browse files Browse the repository at this point in the history
  • Loading branch information
kasper committed May 20, 2018
1 parent f70f0e0 commit 08752cf
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ Release: dd.mm.yyyy
- Upgrade Lodash to 4.17.5 (from 4.17.4).
- Upgrade Sparkle to 1.19.0.

### API

#### App

- Change: Function `launch(...)` now supports a focus option to focus the app automatically on launch ([#211](https://github.com/kasper/phoenix/issues/211), [#212](https://github.com/kasper/phoenix/pull/212)).

2.6.1
-----

Expand Down
2 changes: 1 addition & 1 deletion Phoenix/PHApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#pragma mark - Apps

+ (instancetype) get:(NSString *)appName;
+ (instancetype) launch:(NSString *)appName :(NSDictionary<NSString *, id> *)optionals;
JSExportAs(launch, + (instancetype) launch:(NSString *)appName withOptionals:(NSDictionary<NSString *, id> *)optionals);
+ (instancetype) focused;
+ (NSArray<PHApp *> *) all;

Expand Down
13 changes: 7 additions & 6 deletions Phoenix/PHApp.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ @interface PHApp ()

@implementation PHApp

static NSString * const PHAppFocusOptionKey = @"focus";
static NSString * const PHAppForceOptionKey = @"force";
static NSString * const PHAppLaunchFocusOptionKey = @"focus";

#pragma mark - Initialising

Expand All @@ -42,26 +42,27 @@ + (instancetype) get:(NSString *)appName {
return nil;
}

+ (instancetype) launch:(NSString *)appName :(NSDictionary<NSString *, id> *)optionals {
+ (instancetype) launch:(NSString *)appName withOptionals:(NSDictionary<NSString *, id> *)optionals {

NSWorkspace *sharedWorkspace = [NSWorkspace sharedWorkspace];
NSString *appPath = [sharedWorkspace fullPathForApplication:appName];
NSWorkspaceLaunchOptions launchOptions = NSWorkspaceLaunchWithoutActivation;

if (!appPath) {
NSLog(@"Error: Could not find an app with the name “%@”.", appName);
return nil;
}

NSNumber *focusOption = optionals[PHAppLaunchFocusOptionKey];
NSNumber *focusOption = optionals[PHAppFocusOptionKey];

NSWorkspaceLaunchOptions launchOption = NSWorkspaceLaunchWithoutActivation;
// Focus on launch
if (focusOption && focusOption.boolValue) {
launchOption = NSWorkspaceLaunchDefault;
launchOptions = NSWorkspaceLaunchDefault;
}

NSError *error;
NSRunningApplication *app = [sharedWorkspace launchApplicationAtURL:[NSURL fileURLWithPath:appPath]
options:launchOption
options:launchOptions
configuration:@{}
error:&error];
if (error) {
Expand Down
8 changes: 4 additions & 4 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,10 @@ end
- `hide()` hides the app, returns `true` if successful
- `terminate(Map<String, AnyObject> optionals)` terminates the app, returns `true` if successful

### Launch Optionals

- `focus` (boolean): if set `true` the app will automatically be focused on launch, by default the app launches to the background

### Window Optionals

- `visible` (boolean): if set `true` returns all visible windows for the app, if set `false` returns all hidden windows for the app
Expand All @@ -613,10 +617,6 @@ end

- `force` (boolean): if set `true` force terminates the app

### Launch Optionals

- `focus` (boolean): if set `true`, the launched app will be automatically focused. You don't need to call app.focus() to bring it forward.

## 21. Window

Use the `Window`-object to control windows. Every screen (i.e. display) combines to form a large rectangle. Every window lives within this rectangle and their position can be altered by giving coordinates inside this rectangle. To position a window to a specific display, you need to calculate its position within the large rectangle. To figure out the coordinates for a given screen, use the functions in `Screen`. Beware that a window can get stale if you keep a reference to it and it is for instance closed while you do so.
Expand Down

0 comments on commit 08752cf

Please sign in to comment.