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

feat(core): add a new function to set theme dynamically #10210

Open
wants to merge 23 commits into
base: dev
Choose a base branch
from

Conversation

Legend-Master
Copy link
Contributor

Closes #5279

Waiting for tauri-apps/tao#937

@Legend-Master Legend-Master changed the title feat(core): add a new function set_theme to set theme dynamically feat(core): add a new function to set theme dynamically Jul 6, 2024
Copy link
Contributor

github-actions bot commented Aug 8, 2024

Package Changes Through f6a9717

There are 6 changes which include tauri with prerelease, tauri-runtime-wry with prerelease, tauri-runtime with prerelease, tauri-utils with prerelease, tauri-cli with prerelease, @tauri-apps/cli with prerelease

Planned Package Versions

The following package releases are the planned based on the context of changes in this pull request.

package current next
tauri-utils 2.0.0-rc.12 2.0.0-rc.13
tauri-bundler 2.0.1-rc.13 2.0.1-rc.14
tauri-runtime 2.0.0-rc.12 2.0.0-rc.13
tauri-runtime-wry 2.0.0-rc.13 2.0.0-rc.14
tauri-codegen 2.0.0-rc.12 2.0.0-rc.13
tauri-macros 2.0.0-rc.11 2.0.0-rc.12
tauri-plugin 2.0.0-rc.12 2.0.0-rc.13
tauri-build 2.0.0-rc.12 2.0.0-rc.13
tauri 2.0.0-rc.15 2.0.0-rc.16
@tauri-apps/cli 2.0.0-rc.16 2.0.0-rc.17
tauri-cli 2.0.0-rc.16 2.0.0-rc.17

Add another change file through the GitHub UI by following this link.


Read about change files or the docs at github.com/jbolda/covector

@Legend-Master Legend-Master marked this pull request as ready for review September 19, 2024 15:41
@Legend-Master Legend-Master requested a review from a team as a code owner September 19, 2024 15:41
Copy link
Member

@amrbashir amrbashir left a comment

Choose a reason for hiding this comment

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

We should also add app.set_theme()

packages/api/src/window.ts Outdated Show resolved Hide resolved
crates/tauri-runtime-wry/src/lib.rs Show resolved Hide resolved

/// Set the window theme.
pub fn set_theme(&self, theme: Option<Theme>) -> crate::Result<()> {
self.window.dispatcher.set_theme(theme).map_err(Into::into)
Copy link
Member

Choose a reason for hiding this comment

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

On Windows, We should also update the theme for menu if there is any set

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you know how to make the entire menu dark? Using set_theme_for_hwnd only makes the root menu button dark

Copy link
Member

Choose a reason for hiding this comment

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

it should automatically be using dark theme if the window dark theme is configured correctly, maybe we did something wrong in the recent tao commit? could you try reverting that and see if it works?

Copy link
Contributor Author

@Legend-Master Legend-Master Sep 20, 2024

Choose a reason for hiding this comment

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

Tried tao 0.30, system on light mode, app on dark mode (using window_builder.theme(Some(Theme::Dark))), is this correct?

image

Copy link
Member

@amrbashir amrbashir Sep 20, 2024

Choose a reason for hiding this comment

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

Running the tao example in muda repository, I can see the menu is dark. This is using [email protected] btw. I am on Windows 11 though. I haven't tested the dark menus on Windows 10 ever.

Copy link
Contributor Author

@Legend-Master Legend-Master Sep 20, 2024

Choose a reason for hiding this comment

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

Maybe we need to do some work there then, if I switch system theme to dark, the sub menus are now dark, and some other apps like sublime text's sub menus do turn dark on light system theme with dark app theme

Do you mind trying out the example in this PR? I can't seem to change the menu from dark back to light

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh well, it's a muda bug, we sent the data through lparam but we're reading the data from wparam

Copy link
Contributor Author

@Legend-Master Legend-Master Sep 20, 2024

Choose a reason for hiding this comment

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

Made a PR tauri-apps/muda#224, also I think we also need to trigger a redraw here in muda, what do you think?

@Legend-Master
Copy link
Contributor Author

I need to get some sleep, will get back to this tomorrow

@@ -50,6 +52,11 @@ pub fn default_window_icon<R: Runtime>(
})
}

#[command(root = "crate")]
pub async fn set_app_theme<R: Runtime>(app: AppHandle<R>, theme: Option<Theme>) {
Copy link
Contributor Author

@Legend-Master Legend-Master Sep 20, 2024

Choose a reason for hiding this comment

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

This will cause a deadlock on plugins without async, lock happened on these two places, I'm not sure how should we handle this, seems like it's because this call triggers a ThemeChanged event while having a lock on the plugins when invoked

pub fn extend_api(&self, plugin: &str, invoke: Invoke<R>) -> bool {

manager

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.

[feat] Change Window theme dynamically at runtime
2 participants