-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
base: dev
Are you sure you want to change the base?
Conversation
set_theme
to set theme dynamically
Package Changes Through f6a9717There 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 VersionsThe following package releases are the planned based on the context of changes in this pull request.
Add another change file through the GitHub UI by following this link. Read about change files or the docs at github.com/jbolda/covector |
There was a problem hiding this 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()
crates/tauri/src/window/mod.rs
Outdated
|
||
/// Set the window theme. | ||
pub fn set_theme(&self, theme: Option<Theme>) -> crate::Result<()> { | ||
self.window.dispatcher.set_theme(theme).map_err(Into::into) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
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>) { |
There was a problem hiding this comment.
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
tauri/crates/tauri/src/manager/mod.rs
Line 462 in f6a9717
pub fn extend_api(&self, plugin: &str, invoke: Invoke<R>) -> bool { |
Line 2157 in f6a9717
manager |
Closes #5279
Waiting for tauri-apps/tao#937