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

Sync theia dark/light theme with electron nativeTheme setting #15037

Conversation

mvtec-richter
Copy link
Contributor

@mvtec-richter mvtec-richter commented Feb 25, 2025

What it does

This will sync the theia dark/light theme setting with electron nativeTheme setting.
This is to have native tooltips matching to the dark/light setting of the current theme.

This only works on Windows and MacOS in the electron application. Changing nativeTheme on Linux is not implemented in electron yet. Changing themes in the browser is not possible. This would still require to migrate tooltips to the HoverService or something similar.

Relates to #14075

How to test

  • Start electron application
  • Hover any native tooltip:
    • editor tab title
    • filename in explorer
    • title of problem view

Previously, the tooltip background color followed the system default. With this PR, the background color will align with theme currently selected in theia.

Follow-ups

Breaking changes

  • This PR introduces breaking changes and requires careful review. If yes, the breaking changes section in the changelog has been updated.

Attribution

Contributed by MVTec Software GmbH

Review checklist

Reminder for reviewers

* Sync theia dark/light theme setting with electron nativeTheme setting
* This is to have native tooltips matching to the dark/light setting of the current theme

Fixes eclipse-theia#14075

Signed-off-by: Florian Richter <[email protected]>
@tsmaeder tsmaeder requested a review from sgraband February 26, 2025 08:22
Copy link
Contributor

@sgraband sgraband left a comment

Choose a reason for hiding this comment

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

Thanks for the changes!
Apart from the minor improvements in the comment the code looks good to me 👍

For me this however does not seem to work. If i change the Theme in the Theia example app i always get the dark os theme. However, i should note, that i also get the dark theme on current master, even when i change my local theme to light.

Do you have any idea, where this might come from? Are you aware of any special settings in this regard that you have active? Which OS did you use to test?

@@ -32,6 +32,10 @@ export function isHighContrast(scheme: ThemeType): boolean {
return scheme === 'hc' || scheme === 'hcLight';
}

export function isLightOrDark(type: ThemeType): 'light' | 'dark' {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we create a type for the 'light' | 'dark'? We use it quite a lot and it is originally a subtype of the ThemeType.
Additionally, the name isLightOrDark implies a boolean function imho. Can we either change this into:

  • isLightTheme (which returns true for hcLight and light) (or the other way around, but i believe this makes the method more readable).
  • getThemeMode(), if we choose this variant i believe we should wrap type === 'hc' || type === 'dark' in () to make it easier to understand.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your review. As suggested, I created a type ThemeMode and renamed the helper method to getThemeMode

Signed-off-by: Florian Richter <[email protected]>
@mvtec-richter
Copy link
Contributor Author

Thank you for your review. Originally, I only tested it on Windows 11 and there it works.
Now, I tried it on Ubuntu 24.04 and it doesn't work. The API should be the same. When googling for this issue, I found some old still open bugs in electron, but I'm not sure, if they are valid anymore.

@mvtec-richter
Copy link
Contributor Author

I investigated this further. I tried the dark mode electron fiddle example on Fedora and Ubuntu and the theming of native elements like tooltips and the titlebar didn't change. This only seems to be implemented on Windows and MacOS.
VSCode does set nativeTheme.themeSource, however theming of tooltips does not depend on it.
I still think, this change would be an improvement for Theia, even if it doesn't fix the tooltip theming on Linux.

@sgraband
Copy link
Contributor

Thank you for the code improvements and the investigation. I agree, this is still an improvement even though it does not work on Linux. I believe we should track this in the issue, that the Linux implementation for this is still missing. Could you update the ticket accordingly, once this PR is merged. Btw, the titlebar changes the color for me, when i use the electron native bar, so at least that seems to work 🤷

@cdamus would you have time to test this change on Mac? If you have any questions about what there is to test just let me know.

@cdamus
Copy link
Contributor

cdamus commented Feb 28, 2025

Seems to work on macOS @sgraband . 👍

CleanShot 2025-02-28 at 09 41 45

Copy link
Contributor

@sgraband sgraband left a comment

Choose a reason for hiding this comment

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

Thanks for checking @cdamus! This LGTM then 👍

@mvtec-richter Could you update the ticket to refelect that this is currently not working for Linux?

@mvtec-richter
Copy link
Contributor Author

Thanks for checking @cdamus! This LGTM then 👍

@mvtec-richter Could you update the ticket to refelect that this is currently not working for Linux?

Thank you very much for the review.
I updated the description of this pullrequest. Is this what you meant?

@sgraband
Copy link
Contributor

sgraband commented Mar 3, 2025

It would be good to also add this to #14075 linking to this PR and documenting there that a fix for linux is still required to close the issue. Thank you! I will merge this as soon as the tests succeed.

@sgraband sgraband merged commit 68fdaba into eclipse-theia:master Mar 4, 2025
10 of 11 checks passed
@github-actions github-actions bot added this to the 1.60.0 milestone Mar 4, 2025
@mvtec-richter mvtec-richter deleted the sync-electron-theme-with-theia-theme branch March 4, 2025 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants