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

fix(linux): Fix Window::theme may return incorrect theme #800

Merged
merged 3 commits into from
Oct 16, 2023

Conversation

rhysd
Copy link
Contributor

@rhysd rhysd commented Oct 13, 2023

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Docs
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change?

  • Yes
  • No

Checklist

Other information

On Ubuntu 22.04, the default theme name is "Yaru" in both dark mode and light mode. So it is not possible to check the theme mode by suffix like "-dark". The only way I could come up with was remembering what theme was set on building the window and returning the value at Window::theme. This PR adopts the idea.

@rhysd rhysd requested a review from a team as a code owner October 13, 2023 16:34
if let Some(settings) = Settings::default() {
let theme_name = settings.gtk_theme_name().map(|s| s.as_str().to_owned());
if let Some(theme) = theme_name {
if GTK_THEME_SUFFIX_LIST.iter().any(|t| theme.ends_with(t)) {
Copy link
Member

Choose a reason for hiding this comment

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

If we choose to keep a theme state, we probably don't need this constant.
Can you remove GTK_THEME_SUFFIX_LIST's definition as well?

Copy link
Member

Choose a reason for hiding this comment

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

We still need to check using GTK_THEME_SUFFIX_LIST because a developer may not specify an explicit theme to be set so it could be either light or dark but this PR implementation assumes that it will always be light theme.

@@ -185,10 +186,14 @@ impl Window {

let settings = Settings::default();

let mut theme = Theme::Light;
Copy link
Member

Choose a reason for hiding this comment

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

Instead of assuming that it is always light we should:

  1. change the newly added window.theme to be explicit_theme: Option<Theme>
  2. in the Window.theme() getter we check if self.explicit_theme.unwrap_or_else(|| /* old logic here */)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, that also works in my use case. Since the configuration name is preferred_theme, I think it represents the field well. I'll update this branch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I applied the change at 1236933.

@rhysd
Copy link
Contributor Author

rhysd commented Oct 16, 2023

I removed two redundant clones (to_owned) at 94bf325.

@amrbashir amrbashir merged commit 081ba16 into tauri-apps:dev Oct 16, 2023
9 checks passed
@github-actions github-actions bot mentioned this pull request Oct 16, 2023
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.

Window::theme may return incorrect theme on Linux
3 participants