Skip to content

Commit

Permalink
Add support for device sleep events (#282)
Browse files Browse the repository at this point in the history
  • Loading branch information
kasper committed Feb 5, 2022
1 parent 23a3e9b commit 9b2f27b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Release: dd.mm.yyyy
### New

- Improved documentation! 👩🏼‍💻 The documentation is now powered by Docusaurus and hosted at https://kasper.github.io/phoenix/.
- Add support for device sleep events ([#282](https://github.com/kasper/phoenix/issues/282)).
- Add support for moving windows to spaces in macOS 12.0 with `Space#moveWindows(...)` ([#289](https://github.com/kasper/phoenix/issues/289)).

### Changes
Expand All @@ -30,6 +31,11 @@ Release: dd.mm.yyyy

### API

#### Events

- New: Event `deviceWillSleep` is triggered when the device will sleep ([#282](https://github.com/kasper/phoenix/issues/282)).
- New: Event `deviceDidWake` is triggered when the device did wake ([#282](https://github.com/kasper/phoenix/issues/282)).

#### Space

- New: Function `moveWindows(...)` moves the given windows to the space (macOS 10.13+) ([#289](https://github.com/kasper/phoenix/issues/289)).
Expand Down
12 changes: 11 additions & 1 deletion Phoenix/PHEventTranslator.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ + (NSNotificationCenter *) notificationCenterForNotification:(NSString *)notific

NSNotificationCenter *workspaceNotificationCenter = [NSWorkspace sharedWorkspace].notificationCenter;

notificationToNotificationCenter = @{ /* Space Notifications */
notificationToNotificationCenter = @{ /* Device Notifications */

NSWorkspaceWillSleepNotification: workspaceNotificationCenter,
NSWorkspaceDidWakeNotification: workspaceNotificationCenter,

/* Space Notifications */

NSWorkspaceActiveSpaceDidChangeNotification: workspaceNotificationCenter,

Expand Down Expand Up @@ -55,6 +60,11 @@ + (NSString *) notificationForEvent:(NSString *)event {
@"didLaunch": PHEventDidLaunchNotification,
@"willTerminate": PHEventWillTerminateNotification,

/* Device Notifications */

@"deviceWillSleep": NSWorkspaceWillSleepNotification,
@"deviceDidWake": NSWorkspaceDidWakeNotification,

/* Screen Notifications */

@"screensDidChange": NSApplicationDidChangeScreenParametersNotification,
Expand Down
7 changes: 7 additions & 0 deletions docs/docs/api/2-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ Phoenix supports the following (case sensitive) events. Use these to construct a
- `didLaunch` triggered once when Phoenix has launched and the context is ready
- `willTerminate` triggered when Phoenix will terminate, use this event to perform any tasks before the application terminates

## Device

### 2.7.0+

- `deviceWillSleep` triggered when the device will sleep
- `deviceDidWake` triggered when the device did wake

## Screen

- `screensDidChange` triggered when screens (i.e. displays) are added, removed, or dynamically reconfigured
Expand Down

0 comments on commit 9b2f27b

Please sign in to comment.