Skip to content

Commit dbc64af

Browse files
refactor(app): reduce tech debt by eliminating wry fork (#4500)
1 parent 7e682c2 commit dbc64af

File tree

4 files changed

+31
-16
lines changed

4 files changed

+31
-16
lines changed

Cargo.lock

Lines changed: 2 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ webp = { version = "0.3.0", default-features = false }
182182
whoami = "1.6.0"
183183
windows = "0.61.3"
184184
windows-core = "0.61.2"
185+
webview2-com = "0.38.0" # Should be updated in lockstep with wry
185186
winreg = "0.55.0"
186187
woothee = "0.13.0"
187188
yaserde = "0.12.0"
@@ -228,9 +229,6 @@ todo = "warn"
228229
unnested_or_patterns = "warn"
229230
wildcard_dependencies = "warn"
230231

231-
[patch.crates-io]
232-
wry = { git = "https://github.com/modrinth/wry", rev = "f2ce0b0" }
233-
234232
# Optimize for speed and reduce size on release builds
235233
[profile.release]
236234
opt-level = "s" # Optimize for binary size

apps/app/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ native-dialog.workspace = true
5151
[target.'cfg(target_os = "linux")'.dependencies]
5252
tauri-plugin-updater = { workspace = true, optional = true }
5353

54+
[target.'cfg(windows)'.dependencies]
55+
webview2-com.workspace = true
56+
windows-core.workspace = true
57+
5458
[features]
5559
# by default Tauri runs in production mode
5660
# when `tauri dev` runs it is executed with `cargo run --no-default-features` if `devPath` is an URL

apps/app/src/api/ads.rs

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ pub async fn init_ads_window<R: Runtime>(
7979
override_shown: bool,
8080
) -> crate::api::Result<()> {
8181
use tauri::WebviewUrl;
82-
const LINK_SCRIPT: &str = include_str!("ads-init.js");
8382

8483
let state = app.state::<RwLock<AdsState>>();
8584
let mut state = state.write().await;
@@ -102,25 +101,42 @@ pub async fn init_ads_window<R: Runtime>(
102101
webview.set_position(PhysicalPosition::new(-1000, -1000));
103102
}
104103
} else if let Some(window) = app.get_window("main") {
105-
let _ = window.add_child(
104+
let webview = window.add_child(
106105
tauri::webview::WebviewBuilder::new(
107106
"ads-window",
108107
WebviewUrl::External(
109108
AD_LINK.parse().unwrap(),
110109
),
111110
)
112-
.initialization_script(LINK_SCRIPT)
113-
// .initialization_script_for_main_only(LINK_SCRIPT, false)
114-
.user_agent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36")
115-
.zoom_hotkeys_enabled(false)
116-
.transparent(true),
111+
.initialization_script_for_all_frames(include_str!("ads-init.js"))
112+
.user_agent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36")
113+
.zoom_hotkeys_enabled(false)
114+
.transparent(true)
115+
.on_new_window(|_, _| tauri::webview::NewWindowResponse::Deny),
117116
if state.shown {
118117
position
119118
} else {
120119
PhysicalPosition::new(-1000.0, -1000.0)
121120
},
122121
size,
123-
);
122+
)?;
123+
124+
webview.with_webview(#[allow(unused_variables)] |webview2| {
125+
#[cfg(windows)]
126+
{
127+
use webview2_com::Microsoft::Web::WebView2::Win32::ICoreWebView2_8;
128+
use windows_core::Interface;
129+
130+
let webview2_controller = webview2.controller();
131+
let Ok(webview2_8) = unsafe { webview2_controller.CoreWebView2() }
132+
.and_then(|core_webview2| core_webview2.cast::<ICoreWebView2_8>())
133+
else {
134+
return;
135+
};
136+
137+
unsafe { webview2_8.SetIsMuted(true) }.ok();
138+
}
139+
})?;
124140
}
125141
}
126142

0 commit comments

Comments
 (0)