Skip to content

Commit

Permalink
Merge pull request #893 from electron-userland/mojave-dark-mode
Browse files Browse the repository at this point in the history
feat: add darwinDarkModeSupport option to support mojave dark mode for older Electron versions
  • Loading branch information
malept committed Oct 2, 2018
2 parents 76ca0e9 + a837d84 commit 7495565
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
8 changes: 8 additions & 0 deletions docs/api.md
Expand Up @@ -230,6 +230,14 @@ valid versions. If omitted, it will use the version of the nearest local install
`electron`, `electron-prebuilt-compile`, or `electron-prebuilt`, defined in `package.json` in either
`dependencies` or `devDependencies`.

##### `darwinDarkModeSupport`

*Boolean* (default: `false`)

Forces support for Mojave (macOS 10.14) dark mode in your packaged app, this sets the
`NSRequiresAquaSystemAppearance` key to `false` in your app's `Info.plist`. For more
information see the [Apple developer documentation](https://developer.apple.com/documentation/appkit/nsappearancecustomization/choosing_a_specific_appearance_for_your_app).

##### `extraResource`

*String* or *Array* of *String*s
Expand Down
8 changes: 8 additions & 0 deletions mac.js
Expand Up @@ -31,6 +31,10 @@ class MacApp extends App {
return this.opts.buildVersion
}

get enableDarkMode () {
return this.opts.darwinDarkModeSupport
}

get protocols () {
return this.opts.protocols.map((protocol) => {
return {
Expand Down Expand Up @@ -212,6 +216,10 @@ class MacApp extends App {
this.appPlist.NSHumanReadableCopyright = this.appCopyright
}

if (this.enableDarkMode) {
this.appPlist.NSRequiresAquaSystemAppearance = false
}

return Promise.all(plists.map(plistArgs => {
const filename = plistArgs[0]
const varName = plistArgs[1]
Expand Down
15 changes: 15 additions & 0 deletions test/darwin.js
Expand Up @@ -128,6 +128,20 @@ function extendInfoTest (t, baseOpts, extraPathOrParams) {
})
}

function darkModeTest (t, baseOpts) {
const opts = Object.assign({}, baseOpts, {
appBundleId: 'com.electron.extratest',
appCategoryType: 'public.app-category.music',
buildVersion: '3.2.1',
darwinDarkModeSupport: true
})

return packageAndParseInfoPlist(t, opts)
.then(obj => {
return t.is(obj.NSRequiresAquaSystemAppearance, false, 'NSRequiresAquaSystemAppearance should be set to false')
})
}

function binaryNameTest (t, baseOpts, extraOpts, expectedExecutableName, expectedAppName) {
const opts = Object.assign({}, baseOpts, extraOpts)
const appName = expectedAppName || expectedExecutableName || opts.name
Expand Down Expand Up @@ -258,6 +272,7 @@ if (!(process.env.CI && process.platform === 'win32')) {

darwinTest('extendInfo by filename test', extendInfoTest, extraInfoPath)
darwinTest('extendInfo by params test', extendInfoTest, extraInfoParams)
darwinTest('mojave dark mode test: should enable dark mode', darkModeTest)

darwinTest('protocol/protocol-name argument test', (t, opts) => {
opts.protocols = [
Expand Down
2 changes: 2 additions & 0 deletions usage.txt
Expand Up @@ -69,6 +69,8 @@ app-bundle-id bundle identifier to use in the app plist
app-category-type the application category type
For example, `app-category-type=public.app-category.developer-tools` will set the
application category to 'Developer Tools'.
darwin-dark-mode-support
forces support for Mojave/10.14 dark mode in the packaged app
extend-info a plist file to merge into the app plist
helper-bundle-id bundle identifier to use in the app helper plist
osx-sign (OSX host platform only) Whether to sign the OSX app packages. You can either
Expand Down

0 comments on commit 7495565

Please sign in to comment.