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

Add automatic switching between Dark Mode and Light #6051

Merged
merged 24 commits into from Jan 24, 2019

Conversation

say25
Copy link
Member

@say25 say25 commented Oct 31, 2018

Overview

Add automatic switching between Dark Mode and Light Mode or ability to change it programmatically.

Closes #5037

Description

  • Add automatic switching between Dark Mode and Light Mode (macOS Mojave Dark Mode).

ezgif-3-dabd0ed50fb3

Release notes

Notes: Add automatic switching between Dark Mode and Light Mode (macOS Mojave Dark Mode).

@say25
Copy link
Member Author

say25 commented Oct 31, 2018

@desktop/engineering not sure where the best place to put the currently commented code would be. We would basically need to subscribe to the electron event systemPreferences.subscribeNotification('AppleInterfaceThemeChangedNotification', updateThemeBasedOnSystem); on app start up (maybe DARWIN conditional). Opening an early PR for early feedback. I also think the electron.d.ts could be slightly broken :/

@shiftkey
Copy link
Member

@say25 thanks for opening this up!

not sure where the best place to put the currently commented code would be.

As this is a UI-specific feature, what about a module under app/src/ui/lib? systemPreferences is a main-process specific API, but you could use remote to access it - that's how we've done it for the title bar interaction:

const actionOnDoubleClick = remote.systemPreferences.getUserDefault(
'AppleActionOnDoubleClick',
'string'
)

And like UpdateStore you could define an event emitter interface to bubble up the event to the listeners.

Alternatively, you could have this live in app/src/main-process and it could just emit IPC calls into the renderer.

Inside AppWindow you can see the example of sending messages:

this.window.on('blur', () => this.window.webContents.send('blur'))

And app/src/ui/index.tsx has the example of the subscription:

ipcRenderer.on('blur', () => {
  dispatcher.setAccessKeyHighlightState(false)
  dispatcher.setAppFocusState(false)
})

on app start up (maybe DARWIN conditional).

The module could be conditionalized using __DARWIN__ to subscribe or no-op (for non-macOS platforms). You might even be able to read the OS build for macOS and not bother with the subscription for builds earlier than Mojave.

app/src/ui/lib/os-dark-mode.ts Outdated Show resolved Hide resolved
@say25 say25 changed the title WIP: Add automatic switching between Dark Mode and Light Add automatic switching between Dark Mode and Light Nov 2, 2018
@say25
Copy link
Member Author

say25 commented Nov 2, 2018

🎉

@say25
Copy link
Member Author

say25 commented Nov 15, 2018

Merge conflict from #6109 resolved. @desktop/engineering this should be Ready for Review.

@shiftkey shiftkey added macOS Issues specific to Desktop usage on macOS integrations Issues related to editor and shell integrations that ship in Desktop labels Nov 15, 2018
Copy link
Member

@shiftkey shiftkey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't updated to Mojave yet so I'm not the ideal person to be testing this, but I can help out from the "non-Mojave" and "non-macOS" testing side.

Legend for the emoji next to comments:

  • 🎨 suggestions for cleanup
  • 💭 things I'm still wrapping my head around

Other things are changes that I'd recommend making

app/src/ui/lib/dark-theme.ts Outdated Show resolved Hide resolved
app/src/ui/preferences/appearance.tsx Outdated Show resolved Hide resolved
app/src/ui/preferences/appearance.tsx Outdated Show resolved Hide resolved
@shiftkey
Copy link
Member

@say25 do you have any pointers for reviewers to help with testing this out on Mojave? It'd be nice to be able to quickly verify that the theme changes in macOS are propagated to Desktop, and that the preferences setting is respected...

@shiftkey shiftkey self-assigned this Nov 15, 2018
Copy link
Member

@shiftkey shiftkey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of minor things, but I've also tested out the current theme switching behaviour non-Mojave and Windows setups and those seem fine. I'm not going to upgrade to Mojave for a few weeks, so I'm going to ask someone running Mojave to also review and test this out.

app/src/lib/get-os.ts Outdated Show resolved Hide resolved
app/src/ui/preferences/appearance.tsx Outdated Show resolved Hide resolved
@shiftkey shiftkey removed their assignment Nov 20, 2018
Sorry, I can't test this till later
@say25
Copy link
Member Author

say25 commented Nov 20, 2018

Given that #6069 just got approved (and hopefully shall merge soon) I'll remove the electron 2.0.9 pollyfill at that time

@say25
Copy link
Member Author

say25 commented Nov 21, 2018

@shiftkey installed macOS Mojave on her machine, can confirm this works without state. Changed the check you sugguested to parts.length < 2 as macOS is generally 10.X.Y format though we only care about the middle digit I relaxed the constraint to < 2

@shiftkey shiftkey dismissed their stale review November 21, 2018 18:32

Changes are fine, and I've tested non-Mojave scenarios, but I don't have Mojave installed to do the real testing

@say25
Copy link
Member Author

say25 commented Nov 21, 2018

With #6069 merged down to master, I have merged master into this branch and removed the pollyfill shim.

@tierninho
Copy link
Contributor

tierninho commented Nov 30, 2018

The UI was tested for this change, and overall it functions well.

  • toggling Auto-theme checkbox is functional
  • switching OS theme is reflected in Desktop checkbox/theme
  • Switch theme in Desktop toggles off auto checkbox if it doesn't match OS
  • theme key:value is updated in local storage

Notes: cannot test if the setting in Desktop is saved until this feature hits beta.

Build/OS: 1.5.1-beta0, mac

@say25
Copy link
Member Author

say25 commented Dec 17, 2018

@shiftkey welcome back :D, noticed a merge conflict on this a couple days ago, resolved so it isn't currently blocked by me.

@shiftkey
Copy link
Member

@say25 I don't plan to upgrade to Mojave this year (lol) so someone else who does have it is going to have to jump in here to help out with reviewing...

@outofambit outofambit changed the base branch from master to development December 27, 2018 21:52
@iAmWillShepherd iAmWillShepherd self-assigned this Jan 17, 2019
app/src/lib/get-os.ts Outdated Show resolved Hide resolved
app/src/lib/get-os.ts Outdated Show resolved Hide resolved
app/src/lib/get-os.ts Outdated Show resolved Hide resolved
app/src/lib/get-os.ts Outdated Show resolved Hide resolved
app/src/ui/lib/theme-change-monitor.ts Show resolved Hide resolved
app/src/ui/lib/theme-change-monitor.ts Show resolved Hide resolved
app/src/ui/lib/theme-change-monitor.ts Show resolved Hide resolved
app/src/ui/preferences/appearance.tsx Outdated Show resolved Hide resolved
app/src/ui/preferences/appearance.tsx Outdated Show resolved Hide resolved
@say25
Copy link
Member Author

say25 commented Jan 18, 2019

🎉
light-gif

@billygriffin
Copy link
Contributor

🎉 This is super cool, thanks @say25! May I suggest we hold off on merging this in until #6660 gets into prod in 1.6.1 next week. I'd like to let this have at least a week in beta prior to shipping to prod in case there's any unexpected goofiness. Does that seem reasonable?

@say25
Copy link
Member Author

say25 commented Jan 18, 2019

Seems legit to me.

@shiftkey
Copy link
Member

@billygriffin @say25 because we've already merged in a bit of new work since the release I suspect we'll just cherry-pick the specific changes we want to go out and have a short beta cycle for 1.6.1, and shuffle this and the other work into 1.6.2.

@shiftkey shiftkey added this to the 1.6.1 milestone Jan 18, 2019
@iAmWillShepherd iAmWillShepherd merged commit 253a27b into desktop:development Jan 24, 2019
@say25 say25 deleted the Auto-Switch-Theme branch January 24, 2019 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integrations Issues related to editor and shell integrations that ship in Desktop macOS Issues specific to Desktop usage on macOS ready-for-review Pull Requests that are ready to be reviewed by the maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add automatic switching between Dark Mode and Light Mode or ability to change it programmatically.
5 participants