A music player that connects to your cloud/distributed storage.
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

Set custom user agent for Tauri app (#352)

authored by

Steven Vandevelde and committed by
GitHub
d73c03fb fd4d12de

+79 -43
+11 -40
src-tauri/Cargo.lock
··· 541 541 version = "3.2.0" 542 542 dependencies = [ 543 543 "cocoa", 544 + "objc", 545 + "objc-foundation", 544 546 "serde", 545 547 "serde_json", 546 548 "tauri", 547 549 "tauri-build", 548 550 "tauri-plugin-localhost", 549 551 "tauri-plugin-window-state", 550 - "window-shadows", 551 - "window-vibrancy", 552 + "webkit2gtk", 553 + "webview2-com", 554 + "windows 0.37.0", 555 + "windows-implement", 552 556 ] 553 557 554 558 [[package]] ··· 2111 2115 ] 2112 2116 2113 2117 [[package]] 2114 - name = "raw-window-handle" 2115 - version = "0.5.0" 2116 - source = "registry+https://github.com/rust-lang/crates.io-index" 2117 - checksum = "ed7e3d950b66e19e0c372f3fa3fbbcf85b1746b571f74e0c2af6042a5c93420a" 2118 - dependencies = [ 2119 - "cty", 2120 - ] 2121 - 2122 - [[package]] 2123 2118 name = "redox_syscall" 2124 2119 version = "0.2.16" 2125 2120 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 2192 2187 "objc", 2193 2188 "objc-foundation", 2194 2189 "objc_id", 2195 - "raw-window-handle 0.4.3", 2190 + "raw-window-handle", 2196 2191 "wasm-bindgen", 2197 2192 "wasm-bindgen-futures", 2198 2193 "web-sys", ··· 2633 2628 "parking_lot", 2634 2629 "paste", 2635 2630 "png 0.17.5", 2636 - "raw-window-handle 0.4.3", 2631 + "raw-window-handle", 2637 2632 "scopeguard", 2638 2633 "serde", 2639 2634 "unicode-segmentation", ··· 2679 2674 "open", 2680 2675 "percent-encoding", 2681 2676 "rand 0.8.5", 2682 - "raw-window-handle 0.4.3", 2677 + "raw-window-handle", 2683 2678 "regex", 2684 2679 "rfd", 2685 2680 "semver 1.0.13", ··· 2792 2787 "http", 2793 2788 "http-range", 2794 2789 "infer", 2795 - "raw-window-handle 0.4.3", 2790 + "raw-window-handle", 2796 2791 "serde", 2797 2792 "serde_json", 2798 2793 "tauri-utils", ··· 2812 2807 "gtk", 2813 2808 "percent-encoding", 2814 2809 "rand 0.8.5", 2815 - "raw-window-handle 0.4.3", 2810 + "raw-window-handle", 2816 2811 "tauri-runtime", 2817 2812 "tauri-utils", 2818 2813 "uuid 1.1.2", ··· 3398 3393 version = "0.4.0" 3399 3394 source = "registry+https://github.com/rust-lang/crates.io-index" 3400 3395 checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 3401 - 3402 - [[package]] 3403 - name = "window-shadows" 3404 - version = "0.2.0" 3405 - source = "registry+https://github.com/rust-lang/crates.io-index" 3406 - checksum = "6c69eb48aac2da0199ea148c6f2c2610db8a0572b32a3dc857dec40ca22f1cec" 3407 - dependencies = [ 3408 - "cocoa", 3409 - "objc", 3410 - "raw-window-handle 0.5.0", 3411 - "windows-sys", 3412 - ] 3413 - 3414 - [[package]] 3415 - name = "window-vibrancy" 3416 - version = "0.1.3" 3417 - source = "registry+https://github.com/rust-lang/crates.io-index" 3418 - checksum = "0b66a7f578d164c3f53425ecb73241246ed56a7c3383a15e741684c949a88c86" 3419 - dependencies = [ 3420 - "cocoa", 3421 - "objc", 3422 - "raw-window-handle 0.4.3", 3423 - "windows-sys", 3424 - ] 3425 3396 3426 3397 [[package]] 3427 3398 name = "windows"
+20 -3
src-tauri/Cargo.toml
··· 20 20 tauri = { version = "^1.0.5", features = ["dialog-all", "fs-all", "http-all", "path-all", "shell-open", "shell-open-api", "window-all"] } 21 21 tauri-plugin-localhost = { version = "^0.1.0" } 22 22 tauri-plugin-window-state = { version = "^0.1.0" } 23 - window-shadows = { version = "^0.2.0" } 24 - window-vibrancy = { version = "^0.1.3" } 23 + 24 + [target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\"))".dependencies] 25 + webkit2gtk = "0.18.0" 25 26 26 27 [target.'cfg(target_os = "macos")'.dependencies] 27 - cocoa = "^0.24.0" 28 + objc = "0.2" 29 + objc-foundation = "0.1" 30 + cocoa = "0.24" 31 + 32 + [target.'cfg(windows)'.dependencies] 33 + webview2-com = "0.16.0" 34 + windows-implement = "0.37.0" 35 + 36 + [target.'cfg(windows)'.dependencies.windows] 37 + version = "0.37.0" 38 + features = [ 39 + "Data_Xml_Dom", 40 + "Win32_Foundation", 41 + "Win32_Security", 42 + "Win32_System_Threading", 43 + "Win32_UI_WindowsAndMessaging", 44 + ] 28 45 29 46 [features] 30 47 default = [ "custom-protocol" ]
+48
src-tauri/src/main.rs
··· 28 28 .build()?; 29 29 30 30 win.set_transparent_titlebar(ToolbarThickness::Thin); 31 + set_user_agent(win); 31 32 32 33 // Fin 33 34 Ok(()) ··· 89 90 let new_toolbar = NSToolbar::alloc(id); 90 91 new_toolbar.init_(); 91 92 id.setToolbar_(new_toolbar); 93 + } 94 + 95 + 96 + 97 + // USER AGENT 98 + 99 + 100 + fn set_user_agent(window: Window) { 101 + let user_agent = "Chrome"; 102 + 103 + window.with_webview(move |webview| { 104 + #[cfg(windows)] 105 + unsafe { 106 + use webview2_com::Microsoft::Web::WebView2::Win32::ICoreWebView2Settings2; 107 + use windows::core::Interface; 108 + 109 + let settings: ICoreWebView2Settings2 = webview 110 + .controller() 111 + .CoreWebView2() 112 + .unwrap() 113 + .Settings() 114 + .unwrap() 115 + .cast() 116 + .unwrap(); 117 + 118 + settings 119 + .SetUserAgent(user_agent) 120 + .unwrap(); 121 + } 122 + 123 + #[cfg(target_os = "linux")] 124 + { 125 + use webkit2gtk::{WebViewExt, SettingsExt}; 126 + let webview = webview.inner(); 127 + let settings = webview.settings().unwrap(); 128 + settings.set_user_agent(Some(user_agent)); 129 + } 130 + 131 + // untested 132 + #[cfg(target_os = "macos")] 133 + unsafe { 134 + use objc::{msg_send, sel, sel_impl}; 135 + use objc_foundation::{NSString, INSString}; 136 + let agent = NSString::from_str(user_agent); 137 + let () = msg_send![webview.inner(), setCustomUserAgent: agent]; 138 + } 139 + }); 92 140 }