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

Change Window Theme with Pulsar Theme #545

Merged
merged 4 commits into from
Apr 19, 2024
Merged

Conversation

confused-Techie
Copy link
Member

This PR adds a feature that's likely long overdue.

When a user changes the theme within Pulsar, the brightness of the background color will be computed, and if light or dark, will change the Pulsar Window theme to respect that. During initial boot the theme will still follow the system theme as it does, but otherwise once themes are loaded it will then be changed if needed.

How is this done

When the theme-manager enables a new theme, it will use the color.js class to get the RGB values of the HTML element's backgroundColor, with that it then uses the formula defined by ITU-R BT.709 to determine if that colour is brighter or darker.

Depending on that answer it will then call application-delegate.js (which is now provided to the Theme Manager) .setWindowTheme() which uses the IPC Bus to trigger the nativeTheme module from Electron to change the theme.

Issues

According to this as far as I can tell this module does not respect the theme for Windows on the title bar, but does so for the menu bar. So this may only half way fix the issue in Windows until we could either bump Electron versions, or someone that understands that discussion better can implement it. But I'm hoping this does work properly for users on other platforms.

Examples

Again remember, that an Electron issue prevents this working on the Title bar in Windows, which is where I took these pictures. So remembering that here's the results I was able to acheive.

When set to a light theme:

image

When set to a dark theme:

image


Resolves #422

@confused-Techie
Copy link
Member Author

Made the requested changes on this PR.

While it doesn't resolve all the issues related, do we think we should go ahead and close this one? Or still worth it to implement?

@Spiker985
Copy link
Member

Provided this PR still works in newer versions, and doesn't cause problems - we should probably implement this, no? It doesn't fix everything with the weird theming, but it does fix some, right?

@savetheclocktower
Copy link
Contributor

It might be worth putting behind a config setting, I suppose? I can see how it makes sense to infer a light-mode or dark-mode decision based on the UI theme the user has chosen… but I can also see how some people might just want all their window title bars to match each other.

@Spiker985
Copy link
Member

That's an easy agreement from me - especially since it would technically be a user facing change, and something that would be a divergence from their expected norm

@confused-Techie
Copy link
Member Author

Thanks for taking another look at this @Spiker985 & @savetheclocktower I'll go ahead and put the behavior behind a config file and get this updated as soon as I can

@confused-Techie
Copy link
Member Author

Alright, @Spiker985 & @savetheclocktower I've gone ahead and made sure this one is configurable. If anyone would like to review it, it'd be awesome to get this one merged

Copy link
Member

@DeeDeeG DeeDeeG left a comment

Choose a reason for hiding this comment

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

Seems legit. 👍

Maybe someday we can add something to auto-select a light or dark theme based on the OS theme. (Perhaps with a drop-down for system dark and another dropdown for system light, to designate the specific theme when OS theme is light vs when OS theme is dark.)

this.disposable.add(
ipcHelpers.on(ipcMain, 'setWindowTheme', (event, options) => {
if (options && typeof options === 'string') {
nativeTheme.themeSource = options;
Copy link
Member

Choose a reason for hiding this comment

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

Comment on lines +381 to +382
let luminosity = 0.2126 * bgColor.red + 0.7152 * bgColor.green + 0.0722 * bgColor.blue;
// ^^ Luminosity per ITU-R BT.709
Copy link
Member

Choose a reason for hiding this comment

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

@confused-Techie
Copy link
Member Author

Thanks for the review @DeeDeeG!
I'll go ahead and merge this one, and you're sources are basically correct for where I got my information.

As for syncing this setting with the OS theme, that should be the default behavior once we bump Electron versions (iirc) so hopefully that's a non-issue in the future.

@confused-Techie confused-Techie merged commit 5c19327 into master Apr 19, 2024
103 checks passed
@confused-Techie confused-Techie deleted the change-window-theme branch April 19, 2024 23:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inconsistent theme on the top bar
4 participants