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 APIs to support mojave dark modes #14755
Conversation
79e0ba4
to
78a3ed2
Compare
docs/api/system-preferences.md
Outdated
|
||
Returns `String` | `null` - Can be `dark`, `light` or `unknown`. | ||
|
||
Gets the macOS appearance setting that is you have declared you want for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/is //
docs/api/system-preferences.md
Outdated
|
||
### `systemPreferences.startAppLevelAppearanceTrackingOS()` _macOS_ | ||
|
||
This is a helper method to make your applications "appearance" setting track the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
application's
docs/api/system-preferences.md
Outdated
|
||
This is a helper method to make your applications "appearance" setting track the | ||
users OS level appearance setting. I.e. Your app will have dark mode enabled if | ||
the users system has dark mode enabled. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
user's
lib/browser/api/browser-window.js
Outdated
@@ -141,7 +141,7 @@ BrowserWindow.fromId = (id) => { | |||
} | |||
|
|||
BrowserWindow.getAllWindows = () => { | |||
return TopLevelWindow.getAllWindows().filter(isBrowserWindow) | |||
return TopLevelWindow.getAllWindows() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems significant.
semver/minor
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh this is a mis-commit, will remove
: 'light' | ||
|
||
systemPreferences.emit('appearance-changed', newAppearance) | ||
systemPreferences.setAppLevelAppearance(newAppearance) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should appearance-changed
emit after the appearance has been changed?
docs/api/system-preferences.md
Outdated
### `systemPreferences.startAppLevelAppearanceTrackingOS()` _macOS_ | ||
|
||
This is a helper method to make your applications "appearance" setting track the | ||
users OS level appearance setting. I.e. Your app will have dark mode enabled if |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
s/users/user's/
-
s/Your/your/
|
||
if (val.name == NSAppearanceNameAqua) { | ||
return mate::ConvertToV8(isolate, "light"); | ||
} else if (val.name == NSAppearanceNameDarkAqua) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent_ use of else if
after a return clause.
This is a style thing that I would let slide but there's a conditional return just above this paragraph and another return immediately following, making the inconsistency more jarring.
This would be good:
if (val == nil) {
return v8::Null(isolate);
}
if (val.name == NSAppearanceNameAqua) {
return mate::ConvertToV8(isolate, "light");
}
if (val.name == NSAppearanceNameDarkAqua) {
return mate::ConvertToV8(isolate, "dark");
}
return mate::ConvertToV8(isolate, "unknown")
This would also be OK:
if (val == nil) {
return v8::Null(isolate);
} else if (val.name == NSAppearanceNameAqua) {
return mate::ConvertToV8(isolate, "light");
} else if (val.name == NSAppearanceNameDarkAqua) {
return mate::ConvertToV8(isolate, "dark");
} else {
return mate::ConvertToV8(isolate, "unknown")
}
docs/api/system-preferences.md
Outdated
Gets the macOS appearance setting that is currently applied to your application, | ||
maps to [NSApplication.effectiverAppearance](https://developer.apple.com/documentation/appkit/nsapplication/2967171-effectiveappearance?language=objc) | ||
|
||
Please note that because Electron is not built targetting the 10.14 SDK your applications |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- s/not built/not yet built/
- targeting
- s/SDK/SDK,/
- application's
docs/api/system-preferences.md
Outdated
maps to [NSApplication.effectiverAppearance](https://developer.apple.com/documentation/appkit/nsapplication/2967171-effectiveappearance?language=objc) | ||
|
||
Please note that because Electron is not built targetting the 10.14 SDK your applications | ||
`effectiveAppearance` will always default to "light" and never automatically inherit the OS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confusing use of 'never' here since we're implying that it will work correctly once Electron is built targeting the 10.14 SDK.
Possibly better:
Please note that until Electron is built targeting the 10.14 SDK, your application's
effectiveAppearance
will default to 'light' and won't inherit the OS preference. In the interim we have provided a helper methodstartAppLevelAppearanceTrackingOS()
which emulates this behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually -- rather than make this a public API that people will have to opt-in on and which we'll have to deprecate after moving to 10.14 SDK -- why not make this run automatically so that the color scheme will Just Work both before and after the SDK switch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not make this run automatically so that the color scheme will Just Work both before and after the SDK switch?
This is a good question, I personally wouldn't want this to be forced upon apps because enabling dark mode in your app is more complex than just the native macOS UI looking dark mode. For instance if we forced this on all app's context menus would become dark themed, which may not look too good with a light themed app.
In my mind, this would be opt-in for apps that have a dark theme, and once we move to 10.14's SDK the auto-move can be opt-out through a field in the Info.plist
which we can document once we make that move. (There is a built-in field macOS respects to not auto-switch that Chrome uses at the moment)
I'll add a note to this API though that it is exempt from the standard deprecation cycle, it will be removed in a single major bump at some point in the future because as soon as we reach 10.14 this API will be pointless and probably not work correctly.
78a3ed2
to
965b7c8
Compare
@ckerr Updated 👍 |
docs/api/system-preferences.md
Outdated
Returns `String` - Can be `dark`, `light` or `unknown`. | ||
|
||
Gets the macOS appearance setting that is currently applied to your application, | ||
maps to [NSApplication.effectiverAppearance](https://developer.apple.com/documentation/appkit/nsapplication/2967171-effectiveappearance?language=objc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[NSApplication.effectiveAppearance]?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't objective c, it's intended to indicate a property style value to JS devs that they can click on to learn more
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding an r into "effectiveAppearance" so it's "effectiverAppearance" does that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's more effective that way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*more effectiver
7716c60
to
40ecd21
Compare
Release Notes Persisted
|
* feat: add APIs to support mojave dark mode Closes #13387 * docs: fix system-prefs typo
@MarshallOfSound Perhaps this is going to be a dumb question.. I've added the code below in the main process in order to dynamically set a theme status state in my app.
But I'm getting What did I do wrong here? :( |
@MarshallOfSound Don't mind me... Fixed own problem by doing this instead,
Got the idea from here. - sindresorhus/caprine#510 |
@MarshallOfSound In what version is this change available? ^-^ |
@mapeso I believe this is in 4.0.0-beta.1 |
Are there plans to backport this to 3.x or 2.x release lines? |
Closes #13387
This PR implements the following APIs:
Please note the lack of tests is currently delibrate due to our tests not running on mojave machines (so these APIs are all noops)
Notes: Added
systemPreferences
APIs to help apps respect mojave dark mode settings