Skip to content

Commit d57ed03

Browse files
feat: add enableDarwinDarkModeSupport option to support mojave dark mode for older electron versions
1 parent 76ca0e9 commit d57ed03

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

docs/api.md

+8
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,14 @@ valid versions. If omitted, it will use the version of the nearest local install
230230
`electron`, `electron-prebuilt-compile`, or `electron-prebuilt`, defined in `package.json` in either
231231
`dependencies` or `devDependencies`.
232232

233+
##### `darwinDarkModeSupport`
234+
235+
*Boolean*
236+
237+
Forces support for Mojave (macOS 10.14) dark mode in your packaged app, this sets the
238+
`NSRequiresAquaSystemAppearance` key to `false` in your app's `Info.plist`. For more
239+
information see the [Apple developer documentation](https://developer.apple.com/documentation/appkit/nsappearancecustomization/choosing_a_specific_appearance_for_your_app).
240+
233241
##### `extraResource`
234242

235243
*String* or *Array* of *String*s

mac.js

+8
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ class MacApp extends App {
3131
return this.opts.buildVersion
3232
}
3333

34+
get enableDarkMode () {
35+
return this.opts.darwinDarkModeSupport
36+
}
37+
3438
get protocols () {
3539
return this.opts.protocols.map((protocol) => {
3640
return {
@@ -212,6 +216,10 @@ class MacApp extends App {
212216
this.appPlist.NSHumanReadableCopyright = this.appCopyright
213217
}
214218

219+
if (this.enableDarkMode) {
220+
this.appPlist.NSRequiresAquaSystemAppearance = false
221+
}
222+
215223
return Promise.all(plists.map(plistArgs => {
216224
const filename = plistArgs[0]
217225
const varName = plistArgs[1]

test/darwin.js

+15
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,20 @@ function extendInfoTest (t, baseOpts, extraPathOrParams) {
128128
})
129129
}
130130

131+
function darkModeTest (t, baseOpts) {
132+
const opts = Object.assign({}, baseOpts, {
133+
appBundleId: 'com.electron.extratest',
134+
appCategoryType: 'public.app-category.music',
135+
buildVersion: '3.2.1',
136+
darwinDarkModeSupport: true
137+
})
138+
139+
return packageAndParseInfoPlist(t, opts)
140+
.then(obj => {
141+
return t.is(obj.NSRequiresAquaSystemAppearance, false, 'NSRequiresAquaSystemAppearance should be set to false')
142+
})
143+
}
144+
131145
function binaryNameTest (t, baseOpts, extraOpts, expectedExecutableName, expectedAppName) {
132146
const opts = Object.assign({}, baseOpts, extraOpts)
133147
const appName = expectedAppName || expectedExecutableName || opts.name
@@ -258,6 +272,7 @@ if (!(process.env.CI && process.platform === 'win32')) {
258272

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

262277
darwinTest('protocol/protocol-name argument test', (t, opts) => {
263278
opts.protocols = [

0 commit comments

Comments
 (0)