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 mode
Closes #13387
- Loading branch information
1 parent
32a9df2
commit 965b7c8
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,8 +1,45 @@ | ||
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 |