Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add darwinDarkModeSupport option to support mojave dark mode for older Electron versions #893

Merged
merged 3 commits into from Oct 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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