docs: fix missing import, explicitly use nativeTheme api (#21937)
* docs: fix missing import, explicitly use nativeTheme api * Update docs/tutorial/mojave-dark-mode-guide.md Co-Authored-By: Charles Kerr <ckerr@github.com> * switch to nativeTheme event Co-authored-by: Charles Kerr <ckerr@github.com>
This commit is contained in:
parent
89eb309d0b
commit
95cfa1b0aa
1 changed files with 6 additions and 9 deletions
|
@ -2,10 +2,10 @@
|
||||||
|
|
||||||
In macOS 10.14 Mojave, Apple introduced a new [system-wide dark mode](https://developer.apple.com/design/human-interface-guidelines/macos/visual-design/dark-mode/)
|
In macOS 10.14 Mojave, Apple introduced a new [system-wide dark mode](https://developer.apple.com/design/human-interface-guidelines/macos/visual-design/dark-mode/)
|
||||||
for all macOS computers. If your app does have a dark mode, you can make your Electron app
|
for all macOS computers. If your app does have a dark mode, you can make your Electron app
|
||||||
follow the system-wide dark mode setting.
|
follow the system-wide dark mode setting using [the nativeTheme api](../api/native-theme.md).
|
||||||
|
|
||||||
In macOS 10.15 Catalina, Apple introduced a new "automatic" dark mode option for all macOS computers. In order
|
In macOS 10.15 Catalina, Apple introduced a new "automatic" dark mode option for all macOS computers. In order
|
||||||
for the `isDarkMode` and `Tray` APIs to work correctly in this mode on Catalina you need to either have `NSRequiresAquaSystemAppearance` set to `false` in your `Info.plist` file or be on Electron `>=7.0.0`.
|
for the `nativeTheme.shouldUseDarkColors` and `Tray` APIs to work correctly in this mode on Catalina you need to either have `NSRequiresAquaSystemAppearance` set to `false` in your `Info.plist` file or be on Electron `>=7.0.0`.
|
||||||
|
|
||||||
## Automatically updating the native interfaces
|
## Automatically updating the native interfaces
|
||||||
|
|
||||||
|
@ -18,15 +18,12 @@ out of this theming.
|
||||||
## Automatically updating your own interfaces
|
## Automatically updating your own interfaces
|
||||||
|
|
||||||
If your app has its own dark mode you should toggle it on and off in sync with the system's dark mode setting. You can do
|
If your app has its own dark mode you should toggle it on and off in sync with the system's dark mode setting. You can do
|
||||||
this by listening for the theme changed event on Electron's `systemPreferences` module. E.g.
|
this by listening for the theme updated event on Electron's `nativeTheme` module. E.g.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const { nativeTheme } = require('electron')
|
const { nativeTheme } = require('electron')
|
||||||
|
|
||||||
systemPreferences.subscribeNotification(
|
nativeTheme.on('updated', function theThemeHasChanged () {
|
||||||
'AppleInterfaceThemeChangedNotification',
|
updateMyAppTheme(nativeTheme.shouldUseDarkColors)
|
||||||
function theThemeHasChanged () {
|
})
|
||||||
updateMyAppTheme(nativeTheme.shouldUseDarkColors)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
```
|
```
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue