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
Add automatic switching between Dark Mode and Light Mode or ability to change it programmatically. #5037
Comments
@nehayward thanks for the suggestion! It looks like there's already an explicit API for this in Electron const {systemPreferences} = require('electron')
console.log(systemPreferences.isDarkMode()) Alternatively, if there's a way to listen for changes to this value from native code there could be a way to wrap that up in a Node native module that can be used from in the app. |
@shiftkey oh that's awesome, so it's really just adding the ability to the CLI or in prefs options for the desktop app. I'm working on an app to be able to easily toggle app themes, and I'm hoping to open source it soon. This is why I'd like this feature. I linked to some swift code for doing this natively, I can work on wrapping it in a node module if that'd be helpful? |
@nehayward It would be awesome if you were to create a tool that would allow Node apps to read & write user defaults since this could be applied to uses other than just checking which theme is activated. |
@nehayward let's put the technical stuff aside for the moment and talk about how this would look to the user:
|
@j-f1 I'm not too familiar with node apps, however I've been doing a lot work with defaults and I'm sure we could collaborate or open source something if there is interest in the community. |
|
Q: What does "automatically switch" mean here? Q: What would "switching" look like to the user while they have the app open? Currently the app just flicks between themes, I gather there's a smoother way to do this but what other examples are out there that we can be inspired by? Q: Where is this setting found for the user? Under Preferences | Appearances? Q: What should this value default to? Do we make this opt-in? Or opt-out? |
We should now be able to use the Electron 2.0.2 API as Desktop now used Electron 2.0.5 https://github.com/desktop/desktop/pull/5136/files |
Thanks for the reminder @say25!
The preferences check is currently static, and there's been discussion about updating the app when the OS updates which I think requires something callback-based. This would be a neat addition to Electron core (or whatever API pattern they prefer):
If someone wanted to explore that it'd be greatly appreciated, but that requires some C++ skills, familiarity with Electron source, and getting something reviewed and merged and included in an update. Otherwise if there's a native Node module we can use to bring this into that'd be a good interim step. |
Perhaps |
I'd suggest discussing this hypothetical API over here electron/electron#13387 rather than in this issue. |
@shiftkey You can use existing Electron APIs to monitor for dark mode changes. Check out my implementation here The basics are: systemPreferences.subscribeNotification(
'AppleInterfaceThemeChangedNotification',
function theThemeHasChanged() {
updateMyAppTheme(systemPreferences.isDarkMode())
}
); Also worth noting there are a bunch of new dark mode APIs coming down the pipe in Electron Core --> electron/electron#14755 |
@MarshallOfSound excellent - I can see that available in 2.0.9 so we don't need to wait to upgrade to 3.0 to play around with this! |
@MarshallOfSound it would appear that this isn't working const subscriptionID = systemPreferences.subscribeNotification('AppleInterfaceThemeChangedNotification', updateThemeBasedOnSystem); I think it has do with a problem in |
@say25 Yeah looks like the |
@MarshallOfSound not sure how involved you are on Electron but would this be back ported to 2.0.X? |
@say25 we have the ability to polyfill things in ourselves while we catch up to upstream. Here's where you can add what the correct signature should be, using one of our previous examples: desktop/app/src/lib/globals.d.ts Lines 206 to 211 in 019b78d
EDIT: and I see the PR has been labelled |
@shiftkey is it worth waiting for official support or just polyfilling it until then? |
@say25 polyfill to unblock yourself, and at some point in the future we'll come back and clean up the polyfill if the official declarations have the update. |
Got ready to do work on it, an noticed Electron 2.0.13 was dropped today (thanks @MarshallOfSound). Opened #6068 as a potential avenue to avoid the need for polyfill. Not sure if:
|
For the moment I'd just polyfill your PR until we've had a chance to figure out when we want to land the Electron upgrade. We're in the middle of doing QA for the next big release, so we're further away from getting that Electron upgrade reviewed, tested and merged. Electron 3.0 migration is even further away - |
Request
I love the new the dark mode and I would love it if it automatically switched with the change between Light and Dark mode on macOS.
Describe the solution you'd like
We could add an observer to check which theme the the OS is in, maybe add an option on the prefs to match system mode? You can check the current theme from defaults, here's an example in swift.
Describe alternatives you've considered
Alternatively, we could add an option to change this from the CLI or adding a preference file and let the user be able to switch between modes.
@niik Thanks!
The text was updated successfully, but these errors were encountered: