From d57ed03c5dedb1104014b4d7cc31456bfb0f94e0 Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Tue, 2 Oct 2018 00:39:12 +1000 Subject: [PATCH 1/3] feat: add enableDarwinDarkModeSupport option to support mojave dark mode for older electron versions --- docs/api.md | 8 ++++++++ mac.js | 8 ++++++++ test/darwin.js | 15 +++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/docs/api.md b/docs/api.md index 9b1affd5..a2343771 100644 --- a/docs/api.md +++ b/docs/api.md @@ -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* + +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 diff --git a/mac.js b/mac.js index 16507592..19e0944b 100644 --- a/mac.js +++ b/mac.js @@ -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 { @@ -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] diff --git a/test/darwin.js b/test/darwin.js index 1b95b388..89fc7287 100644 --- a/test/darwin.js +++ b/test/darwin.js @@ -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 @@ -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 = [ From 76cd9120e51587d24fdf710272ab9b760e7686b0 Mon Sep 17 00:00:00 2001 From: Mark Lee Date: Mon, 1 Oct 2018 17:27:57 -0700 Subject: [PATCH 2/3] Add CLI usage --- usage.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/usage.txt b/usage.txt index 295ce796..fcbd5f00 100644 --- a/usage.txt +++ b/usage.txt @@ -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 From a837d84bdaee3adb035390bffd4038511298173a Mon Sep 17 00:00:00 2001 From: Mark Lee Date: Mon, 1 Oct 2018 17:28:12 -0700 Subject: [PATCH 3/3] Add default to API docs --- docs/api.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api.md b/docs/api.md index a2343771..09961562 100644 --- a/docs/api.md +++ b/docs/api.md @@ -232,7 +232,7 @@ valid versions. If omitted, it will use the version of the nearest local install ##### `darwinDarkModeSupport` -*Boolean* +*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