Skip to content

Commit 7fa442f

Browse files
Reapply "refactor(app): reduce tech debt by eliminating wry fork" (#4555)
* Reapply "refactor(app): reduce tech debt by eliminating `wry` fork (#4500)" This reverts commit 2535156. * test: temporarily replace ad link by something with sound * Revert "test: temporarily replace ad link by something with sound" This reverts commit 74bb7ee. * Reapply "test: temporarily replace ad link by something with sound" This reverts commit f1b0e9f. * test: also disable ads init muting script for good measure * Revert "test: also disable ads init muting script for good measure" This reverts commit 4ac7a81. * Revert "Reapply "test: temporarily replace ad link by something with sound"" This reverts commit c5f1b9f.
1 parent 2535156 commit 7fa442f

4 files changed

Lines changed: 30 additions & 16 deletions

File tree

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: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,6 @@ wildcard_dependencies = "warn"
240240
[profile.dev.package.sqlx-macros]
241241
opt-level = 3
242242

243-
[patch.crates-io]
244-
wry = { git = "https://github.com/modrinth/wry", rev = "f2ce0b0" }
245-
246243
# Optimize for speed and reduce size on release builds
247244
[profile.release]
248245
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
@@ -49,6 +49,10 @@ tauri-build = { workspace = true, features = ["codegen"] }
4949
[target.'cfg(target_os = "linux")'.dependencies]
5050
tauri-plugin-updater = { workspace = true, optional = true }
5151

52+
[target.'cfg(windows)'.dependencies]
53+
webview2-com.workspace = true
54+
windows-core.workspace = true
55+
5256
[features]
5357
# by default Tauri runs in production mode
5458
# 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)