Skip to content

Commit

Permalink
fix: os-specific ua
Browse files Browse the repository at this point in the history
  • Loading branch information
SpikeHD committed Dec 15, 2024
1 parent 743de35 commit 6c88fe9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
4 changes: 1 addition & 3 deletions src-tauri/src/gpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ pub fn disable_hardware_accel_linux(window: &tauri::WebviewWindow) {
let config = get_config();
let wv = webview.inner();
let settings = WebViewExt::settings(&wv).unwrap_or_default();

settings.set_user_agent(Some("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36"));


if config.disable_hardware_accel.unwrap_or(false) {
settings.set_hardware_acceleration_policy(HardwareAccelerationPolicy::Never);
}
Expand Down
17 changes: 13 additions & 4 deletions src-tauri/src/util/window_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@ use crate::log;

use super::paths::get_webdata_dir;

static USERAGENT: &str = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36";
#[cfg(target_os = "windows")]
static OS: &str = "(Windows NT 10.0; Win64; x64)";
#[cfg(target_os = "macos")]
static OS: &str = "(Macintosh; Intel Mac OS X 10_15_7)";
#[cfg(target_os = "linux")]
static OS: &str = "(X11; Linux x86_64)";

fn useragent() -> String {
format!("Mozilla/5.0 {OS} AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36")
}

pub fn clear_cache_check() {
let appdata = dirs::data_dir().unwrap_or_default().join("dorion");
Expand Down Expand Up @@ -111,7 +120,7 @@ pub fn set_user_agent(win: &tauri::WebviewWindow) {
.expect("Failed to cast settings!");

settings
.SetUserAgent(&HSTRING::from(USERAGENT))
.SetUserAgent(&HSTRING::from(useragent()))
.unwrap_or_default();
})
.unwrap_or_else(|e| log!("Failed to set user-agent: {:?}", e));
Expand All @@ -128,7 +137,7 @@ pub fn set_user_agent(win: &tauri::WebviewWindow) {
let webview = webview.inner();
let settings = webview.settings().unwrap();

settings.set_user_agent(Some(USERAGENT));
settings.set_user_agent(Some(useragent()));
})
.unwrap_or_else(|e| log!("Failed to set user-agent: {:?}", e));
}
Expand All @@ -141,7 +150,7 @@ pub fn set_user_agent(win: &tauri::WebviewWindow) {
win
.with_webview(|webview| unsafe {
let webview: &WKWebView = &*webview.inner().cast();
let useragent = NSString::from_str(USERAGENT);
let useragent = NSString::from_str(useragent());

webview.setCustomUserAgent(Some(&useragent));
})
Expand Down

0 comments on commit 6c88fe9

Please sign in to comment.