forked from electron/electron
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add APIs to support mojave dark modes (electron#14755)
* feat: add APIs to support mojave dark mode Closes electron#13387 * docs: fix system-prefs typo
- Loading branch information
1 parent
8963529
commit 0d2a0c7
Showing
8 changed files
with
204 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,47 @@ | ||
'use strict' | ||
|
||
const { app } = require('electron') | ||
const { EventEmitter } = require('events') | ||
const { systemPreferences, SystemPreferences } = process.atomBinding('system_preferences') | ||
|
||
// SystemPreferences is an EventEmitter. | ||
Object.setPrototypeOf(SystemPreferences.prototype, EventEmitter.prototype) | ||
EventEmitter.call(systemPreferences) | ||
|
||
if (process.platform === 'darwin') { | ||
let appearanceTrackingSubscriptionID = null | ||
|
||
systemPreferences.startAppLevelAppearanceTrackingOS = () => { | ||
if (appearanceTrackingSubscriptionID !== null) return | ||
|
||
const updateAppearanceBasedOnOS = () => { | ||
const newAppearance = systemPreferences.isDarkMode() | ||
? 'dark' | ||
: 'light' | ||
|
||
if (systemPreferences.getAppLevelAppearance() !== newAppearance) { | ||
systemPreferences.setAppLevelAppearance(newAppearance) | ||
// TODO(MarshallOfSound): Once we remove this logic and build against 10.14 | ||
// SDK we should re-implement this event as a monitor of `effectiveAppearance` | ||
systemPreferences.emit('appearance-changed', newAppearance) | ||
} | ||
} | ||
|
||
appearanceTrackingSubscriptionID = systemPreferences.subscribeNotification( | ||
'AppleInterfaceThemeChangedNotification', | ||
updateAppearanceBasedOnOS | ||
) | ||
|
||
updateAppearanceBasedOnOS() | ||
} | ||
|
||
systemPreferences.stopAppLevelAppearanceTrackingOS = () => { | ||
if (appearanceTrackingSubscriptionID === null) return | ||
|
||
systemPreferences.unsubscribeNotification(appearanceTrackingSubscriptionID) | ||
} | ||
|
||
app.on('quit', systemPreferences.stopAppLevelAppearanceTrackingOS) | ||
} | ||
|
||
module.exports = systemPreferences |