feat: remove needless mojave dark mode APIs and add instructions on how to use the macOS replacement (#14895)
This commit is contained in:
parent
13035612ab
commit
d628aad3bf
2 changed files with 6 additions and 60 deletions
|
@ -1,6 +1,5 @@
|
|||
'use strict'
|
||||
|
||||
const { app } = require('electron')
|
||||
const { EventEmitter } = require('events')
|
||||
const { systemPreferences, SystemPreferences } = process.atomBinding('system_preferences')
|
||||
|
||||
|
@ -8,40 +7,4 @@ const { systemPreferences, SystemPreferences } = process.atomBinding('system_pre
|
|||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue