diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 6bfacc36..d12f6e2d 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -541,14 +541,18 @@ name = "diffuse" version = "3.2.0" dependencies = [ "cocoa", + "objc", + "objc-foundation", "serde", "serde_json", "tauri", "tauri-build", "tauri-plugin-localhost", "tauri-plugin-window-state", - "window-shadows", - "window-vibrancy", + "webkit2gtk", + "webview2-com", + "windows 0.37.0", + "windows-implement", ] [[package]] @@ -2110,15 +2114,6 @@ dependencies = [ "cty", ] -[[package]] -name = "raw-window-handle" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed7e3d950b66e19e0c372f3fa3fbbcf85b1746b571f74e0c2af6042a5c93420a" -dependencies = [ - "cty", -] - [[package]] name = "redox_syscall" version = "0.2.16" @@ -2192,7 +2187,7 @@ dependencies = [ "objc", "objc-foundation", "objc_id", - "raw-window-handle 0.4.3", + "raw-window-handle", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", @@ -2633,7 +2628,7 @@ dependencies = [ "parking_lot", "paste", "png 0.17.5", - "raw-window-handle 0.4.3", + "raw-window-handle", "scopeguard", "serde", "unicode-segmentation", @@ -2679,7 +2674,7 @@ dependencies = [ "open", "percent-encoding", "rand 0.8.5", - "raw-window-handle 0.4.3", + "raw-window-handle", "regex", "rfd", "semver 1.0.13", @@ -2792,7 +2787,7 @@ dependencies = [ "http", "http-range", "infer", - "raw-window-handle 0.4.3", + "raw-window-handle", "serde", "serde_json", "tauri-utils", @@ -2812,7 +2807,7 @@ dependencies = [ "gtk", "percent-encoding", "rand 0.8.5", - "raw-window-handle 0.4.3", + "raw-window-handle", "tauri-runtime", "tauri-utils", "uuid 1.1.2", @@ -3399,30 +3394,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "window-shadows" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c69eb48aac2da0199ea148c6f2c2610db8a0572b32a3dc857dec40ca22f1cec" -dependencies = [ - "cocoa", - "objc", - "raw-window-handle 0.5.0", - "windows-sys", -] - -[[package]] -name = "window-vibrancy" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b66a7f578d164c3f53425ecb73241246ed56a7c3383a15e741684c949a88c86" -dependencies = [ - "cocoa", - "objc", - "raw-window-handle 0.4.3", - "windows-sys", -] - [[package]] name = "windows" version = "0.32.0" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 8c9dbdec..15d9aad1 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -20,11 +20,28 @@ serde = { version = "^1.0", features = ["derive"] } tauri = { version = "^1.0.5", features = ["dialog-all", "fs-all", "http-all", "path-all", "shell-open", "shell-open-api", "window-all"] } tauri-plugin-localhost = { version = "^0.1.0" } tauri-plugin-window-state = { version = "^0.1.0" } -window-shadows = { version = "^0.2.0" } -window-vibrancy = { version = "^0.1.3" } + +[target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\"))".dependencies] +webkit2gtk = "0.18.0" [target.'cfg(target_os = "macos")'.dependencies] -cocoa = "^0.24.0" +objc = "0.2" +objc-foundation = "0.1" +cocoa = "0.24" + +[target.'cfg(windows)'.dependencies] +webview2-com = "0.16.0" +windows-implement = "0.37.0" + +[target.'cfg(windows)'.dependencies.windows] +version = "0.37.0" +features = [ + "Data_Xml_Dom", + "Win32_Foundation", + "Win32_Security", + "Win32_System_Threading", + "Win32_UI_WindowsAndMessaging", +] [features] default = [ "custom-protocol" ] diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 94011e4d..7bdc49b4 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -28,6 +28,7 @@ fn main() { .build()?; win.set_transparent_titlebar(ToolbarThickness::Thin); + set_user_agent(win); // Fin Ok(()) @@ -89,4 +90,51 @@ unsafe fn make_toolbar(id: cocoa::base::id) { let new_toolbar = NSToolbar::alloc(id); new_toolbar.init_(); id.setToolbar_(new_toolbar); +} + + + +// USER AGENT + + +fn set_user_agent(window: Window) { + let user_agent = "Chrome"; + + window.with_webview(move |webview| { + #[cfg(windows)] + unsafe { + use webview2_com::Microsoft::Web::WebView2::Win32::ICoreWebView2Settings2; + use windows::core::Interface; + + let settings: ICoreWebView2Settings2 = webview + .controller() + .CoreWebView2() + .unwrap() + .Settings() + .unwrap() + .cast() + .unwrap(); + + settings + .SetUserAgent(user_agent) + .unwrap(); + } + + #[cfg(target_os = "linux")] + { + use webkit2gtk::{WebViewExt, SettingsExt}; + let webview = webview.inner(); + let settings = webview.settings().unwrap(); + settings.set_user_agent(Some(user_agent)); + } + + // untested + #[cfg(target_os = "macos")] + unsafe { + use objc::{msg_send, sel, sel_impl}; + use objc_foundation::{NSString, INSString}; + let agent = NSString::from_str(user_agent); + let () = msg_send![webview.inner(), setCustomUserAgent: agent]; + } + }); } \ No newline at end of file