Skip to content

Commit

Permalink
fix: windows user agent setting
Browse files Browse the repository at this point in the history
  • Loading branch information
SpikeHD committed Jul 12, 2024
1 parent 5996619 commit 07326e1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 134 deletions.
128 changes: 15 additions & 113 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ embed_plist = "1.2.2"
tauri-plugin-window-state = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }

[target.'cfg(windows)'.dependencies]
webview2-com = "0.19.1"
webview2-com = "0.31.0"
windows-core = "0.58.0"
windows-implement = "0.39.0"

Expand Down
39 changes: 19 additions & 20 deletions src-tauri/src/util/window_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,26 +96,25 @@ pub fn remove_top_bar(_win: tauri::WebviewWindow) {}

#[cfg(target_os = "windows")]
pub fn set_user_agent(win: &tauri::WebviewWindow) {
// TODO fix
// use webview2_com::Microsoft::Web::WebView2::Win32::ICoreWebView2Settings2;
// use windows::core::{Interface, HSTRING};

// win
// .with_webview(|webview| unsafe {
// let settings = webview
// .controller()
// .CoreWebView2()
// .expect("Failed to get CoreWebView2!")
// .Settings()
// .expect("Failed to get Settings!");

// let settings = settings.cast::<ICoreWebView2Settings2>().expect("Failed to cast to ICoreWebView2Settings2!");

// settings
// .SetUserAgent(&HSTRING::from(USERAGENT))
// .unwrap_or_default();
// })
// .expect("Failed to set user agent!");
use webview2_com::Microsoft::Web::WebView2::Win32::ICoreWebView2Settings2;
use windows::core::{Interface, HSTRING};

win
.with_webview(|webview| unsafe {
let settings = webview
.controller()
.CoreWebView2()
.expect("Failed to get CoreWebView2!")
.Settings()
.expect("Failed to get Settings!")
.cast::<ICoreWebView2Settings2>()
.expect("Failed to cast settings!");

settings
.SetUserAgent(&HSTRING::from(USERAGENT))
.unwrap_or_default();
})
.expect("Failed to set user agent!");

log!("Set user agent!");
}
Expand Down

0 comments on commit 07326e1

Please sign in to comment.