feat: promisify systemPreferences notification methods (#18631)

* feat: promisify systemPreferences notification methods

* correct userInfo typedef
This commit is contained in:
Shelley Vohr 2019-06-06 07:47:18 -07:00 committed by GitHub
parent 4b9da4dd0e
commit eec12b399a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 117 additions and 49 deletions

View file

@ -45,6 +45,9 @@ When a majority of affected functions are migrated, this flag will be enabled by
- [ses.clearCache(callback)](https://github.com/electron/electron/blob/master/docs/api/session.md#clearCache)
- [ses.getBlobData(identifier, callback)](https://github.com/electron/electron/blob/master/docs/api/session.md#getBlobData)
- [shell.openExternal(url[, options, callback])](https://github.com/electron/electron/blob/master/docs/api/shell.md#openExternal)
- [systemPreferences.subscribeNotification(event, callback)](https://github.com/electron/electron/blob/master/docs/api/system-preferences.md#subscribeNotification)
- [systemPreferences.subscribeLocalNotification(event, callback)](https://github.com/electron/electron/blob/master/docs/api/system-preferences.md#subscribeLocalNotification)
- [systemPreferences.subscribeWorkspaceNotification(event, callback)](https://github.com/electron/electron/blob/master/docs/api/system-preferences.md#subscribeWorkspaceNotification)
- [webFrame.executeJavaScript(code[, userGesture, callback])](https://github.com/electron/electron/blob/master/docs/api/web-frame.md#executeJavaScript)
- [webFrame.executeJavaScriptInIsolatedWorld(worldId, scripts[, userGesture, callback])](https://github.com/electron/electron/blob/master/docs/api/web-frame.md#executeJavaScriptInIsolatedWorld)
- [webviewTag.capturePage([rect, ]callback)](https://github.com/electron/electron/blob/master/docs/api/webview-tag.md#capturePage)

View file

@ -62,7 +62,7 @@ Returns `Boolean` - Whether the Swipe between pages setting is on.
### `systemPreferences.postNotification(event, userInfo[, deliverImmediately])` _macOS_
* `event` String
* `userInfo` Object
* `userInfo` Record<string, unknown>
* `deliverImmediately` Boolean (optional) - `true` to post notifications immediately even when the subscribing app is inactive.
Posts `event` as native notifications of macOS. The `userInfo` is an Object
@ -71,7 +71,7 @@ that contains the user information dictionary sent along with the notification.
### `systemPreferences.postLocalNotification(event, userInfo)` _macOS_
* `event` String
* `userInfo` Object
* `userInfo` Record<string, unknown>
Posts `event` as native notifications of macOS. The `userInfo` is an Object
that contains the user information dictionary sent along with the notification.
@ -79,7 +79,7 @@ that contains the user information dictionary sent along with the notification.
### `systemPreferences.postWorkspaceNotification(event, userInfo)` _macOS_
* `event` String
* `userInfo` Object
* `userInfo` Record<string, unknown>
Posts `event` as native notifications of macOS. The `userInfo` is an Object
that contains the user information dictionary sent along with the notification.
@ -89,7 +89,7 @@ that contains the user information dictionary sent along with the notification.
* `event` String
* `callback` Function
* `event` String
* `userInfo` Object
* `userInfo` Record<string, unknown>
Returns `Number` - The ID of this subscription
@ -109,43 +109,93 @@ example values of `event` are:
* `AppleColorPreferencesChangedNotification`
* `AppleShowScrollBarsSettingChanged`
**[Deprecated](modernization/promisification.md)**
### `systemPreferences.subscribeNotification(event)` _macOS_
* `event` String
Returns `Promise<Object>` - Resolves with an object containing the following items:
* `id` Number - The ID of this subscription, which can be used to unsubscribe the
`event`.
* `event` String
* `userInfo` Record<string, unknown>
Subscribes to native notifications of macOS.
Under the hood this API subscribes to `NSDistributedNotificationCenter`,
example values of `event` are:
* `AppleInterfaceThemeChangedNotification`
* `AppleAquaColorVariantChanged`
* `AppleColorPreferencesChangedNotification`
* `AppleShowScrollBarsSettingChanged`
### `systemPreferences.subscribeLocalNotification(event, callback)` _macOS_
* `event` String
* `callback` Function
* `event` String
* `userInfo` Object
* `userInfo` Record<string, unknown>
Returns `Number` - The ID of this subscription
Same as `subscribeNotification`, but uses `NSNotificationCenter` for local defaults.
This is necessary for events such as `NSUserDefaultsDidChangeNotification`.
**[Deprecated](modernization/promisification.md)**
### `systemPreferences.subscribeLocalNotification(event)` _macOS_
* `event` String
Returns `Promise<Object>` - Resolves with an object containing the following items:
* `id` Number - The ID of this subscription
* `event` String
* `userInfo` Record<string, unknown>
Same as `subscribeNotification`, but uses `NSNotificationCenter` for local defaults.
This is necessary for events such as `NSUserDefaultsDidChangeNotification`.
### `systemPreferences.subscribeWorkspaceNotification(event, callback)` _macOS_
* `event` String
* `callback` Function
* `event` String
* `userInfo` Object
* `userInfo` Record<string, unknown>
Same as `subscribeNotification`, but uses `NSWorkspace.sharedWorkspace.notificationCenter`.
This is necessary for events such as `NSWorkspaceDidActivateApplicationNotification`.
**[Deprecated](modernization/promisification.md)**
### `systemPreferences.subscribeWorkspaceNotification(event)` _macOS_
* `event` String
Returns `Promise<Object>` - Resolves with an object containing the following items:
* `id` Number - The ID of this subscription
* `event` String
* `userInfo` Record<string, unknown>
Same as `subscribeNotification`, but uses `NSWorkspace.sharedWorkspace.notificationCenter`.
This is necessary for events such as `NSWorkspaceDidActivateApplicationNotification`.
### `systemPreferences.unsubscribeNotification(id)` _macOS_
* `id` Integer
* `id` Number
Removes the subscriber with `id`.
### `systemPreferences.unsubscribeLocalNotification(id)` _macOS_
* `id` Integer
* `id` Number
Same as `unsubscribeNotification`, but removes the subscriber from `NSNotificationCenter`.
### `systemPreferences.unsubscribeWorkspaceNotification(id)` _macOS_
* `id` Integer
* `id` Number
Same as `unsubscribeNotification`, but removes the subscriber from `NSWorkspace.sharedWorkspace.notificationCenter`.