Skip to content

Commit 5664735

Browse files
committed
fix(desktop): skip background color init script for transparent windows
1 parent 6c11552 commit 5664735

1 file changed

Lines changed: 16 additions & 14 deletions

File tree

apps/desktop/src-tauri/src/windows.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1709,25 +1709,27 @@ impl ShowCapWindow {
17091709
})
17101710
.unwrap_or(None);
17111711

1712-
let is_dark = match theme {
1713-
Some(tauri::Theme::Dark) => true,
1714-
Some(tauri::Theme::Light) => false,
1715-
None | Some(_) => is_system_dark_mode(),
1716-
};
1717-
1718-
let bg_color = if is_dark { "#141414" } else { "#ffffff" };
1719-
let init_script = format!(
1720-
r#"(function(){{var s=document.createElement('style');s.textContent='html:not([data-transparent-window]),html:not([data-transparent-window]) body{{background-color:{bg}}}';document.documentElement.appendChild(s);}})();"#,
1721-
bg = bg_color
1722-
);
1723-
17241712
let mut builder = WebviewWindow::builder(app, id.label(), WebviewUrl::App(url.into()))
17251713
.title(id.title())
17261714
.visible(false)
17271715
.accept_first_mouse(true)
17281716
.shadow(true)
1729-
.theme(theme)
1730-
.initialization_script(&init_script);
1717+
.theme(theme);
1718+
1719+
if !id.is_transparent() {
1720+
let is_dark = match theme {
1721+
Some(tauri::Theme::Dark) => true,
1722+
Some(tauri::Theme::Light) => false,
1723+
None | Some(_) => is_system_dark_mode(),
1724+
};
1725+
1726+
let bg_color = if is_dark { "#141414" } else { "#ffffff" };
1727+
let init_script = format!(
1728+
r#"(function(){{var s=document.createElement('style');s.textContent='html,body{{background-color:{bg}}}';document.documentElement.appendChild(s);}})();"#,
1729+
bg = bg_color
1730+
);
1731+
builder = builder.initialization_script(&init_script);
1732+
}
17311733

17321734
if let Some(min) = id.min_size() {
17331735
builder = builder

0 commit comments

Comments
 (0)