diff --git a/docs/README.md b/docs/README.md index 45baaff9721..3347607bd78 100644 --- a/docs/README.md +++ b/docs/README.md @@ -51,7 +51,7 @@ an issue: * [Represented File for macOS BrowserWindows](tutorial/represented-file.md) * [Native File Drag & Drop](tutorial/native-file-drag-drop.md) * [Offscreen Rendering](tutorial/offscreen-rendering.md) - * [Supporting macOS Dark Mode](tutorial/mojave-dark-mode-guide.md) + * [Dark Mode](tutorial/dark-mode.md) * [Web embeds in Electron](tutorial/web-embeds.md) * [Accessibility](tutorial/accessibility.md) * [Spectron](tutorial/accessibility.md#spectron) @@ -134,6 +134,7 @@ These individual tutorials expand on topics discussed in the guide above. * [MenuItem](api/menu-item.md) * [net](api/net.md) * [netLog](api/net-log.md) +* [nativeTheme](api/native-theme.md) * [Notification](api/notification.md) * [powerMonitor](api/power-monitor.md) * [powerSaveBlocker](api/power-save-blocker.md) diff --git a/docs/api/system-preferences.md b/docs/api/system-preferences.md index 5ba7e7a52e3..3936cd7c2f8 100644 --- a/docs/api/system-preferences.md +++ b/docs/api/system-preferences.md @@ -51,8 +51,6 @@ Returns: Returns `Boolean` - Whether the system is in Dark Mode. -**Note:** On macOS 10.15 Catalina in order for this API to return the correct value when in the "automatic" dark mode setting you must either have `NSRequiresAquaSystemAppearance=false` in your `Info.plist` or be on Electron `>=7.0.0`. See the [dark mode guide](../tutorial/mojave-dark-mode-guide.md) for more information. - **Deprecated:** Should use the new [`nativeTheme.shouldUseDarkColors`](native-theme.md#nativethemeshouldusedarkcolors-readonly) API. ### `systemPreferences.isSwipeTrackingFromScrollEventsEnabled()` _macOS_ diff --git a/docs/images/dark_mode.gif b/docs/images/dark_mode.gif new file mode 100644 index 00000000000..d011564c90c Binary files /dev/null and b/docs/images/dark_mode.gif differ diff --git a/docs/tutorial/dark-mode.md b/docs/tutorial/dark-mode.md new file mode 100644 index 00000000000..d75680e02ba --- /dev/null +++ b/docs/tutorial/dark-mode.md @@ -0,0 +1,201 @@ +# Dark Mode + +## Overview + +### Automatically update the native interfaces + +"Native interfaces" include the file picker, window border, dialogs, context +menus, and more - anything where the UI comes from your operating system and +not from your app. The default behavior is to opt into this automatic theming +from the OS. + +### Automatically update 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 this by using the +[prefer-color-scheme] CSS media query. + +### Manually update your own interfaces + +If you want to manually switch between light/dark modes, you can do this by +setting the desired mode in the +[themeSource](https://www.electronjs.org/docs/api/native-theme#nativethemethemesource) +property of the `nativeTheme` module. This property's value will be propagated +to your Renderer process. Any CSS rules related to `prefers-color-scheme` will +be updated accordingly. + +## macOS settings + +In macOS 10.14 Mojave, Apple introduced a new [system-wide dark mode][system-wide-dark-mode] +for all macOS computers. If your Electron app has a dark mode, you can make it +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 for the `nativeTheme.shouldUseDarkColors` and +`Tray` APIs to work correctly in this mode on Catalina, you need to use Electron +`>=7.0.0`, or set `NSRequiresAquaSystemAppearance` to `false` in your +`Info.plist` file for older versions. Both [Electron Packager][electron-packager] +and [Electron Forge][electron-forge] have a +[`darwinDarkModeSupport` option][packager-darwindarkmode-api] +to automate the `Info.plist` changes during app build time. + +If you wish to opt-out while using Electron > 8.0.0, you must +set the `NSRequiresAquaSystemAppearance` key in the `Info.plist` file to +`true`. Please note that Electron 8.0.0 and above will not let you opt-out +of this theming, due to the use of the macOS 10.14 SDK. + +## Example + +We'll start with a working application from the +[Quick Start Guide](quick-start.md) and add functionality gradually. + +First, let's edit our interface so users can toggle between light and dark +modes. This basic UI contains buttons to change the `nativeTheme.themeSource` +setting and a text element indicating which `themeSource` value is selected. +By default, Electron follows the system's dark mode preference, so we +will hardcode the theme source as "System". + +Add the following lines to the `index.html` file: + +```html + + +
+ +Current theme source: System
+ + + + + + + +