From e97406815c36cd35a02f485bb2407cad4e3e2f3a Mon Sep 17 00:00:00 2001 From: SpikeHD <25207995+SpikeHD@users.noreply.github.com> Date: Mon, 11 Nov 2024 12:51:35 -0800 Subject: [PATCH] fix: use native fetch when extension is running --- README.md | 4 +- src-tauri/Cargo.lock | 114 +++++++++++------------ src-tauri/Cargo.toml | 2 +- src-tauri/injection/shared/recreate.ts | 10 +- src-tauri/src/functionality/extension.rs | 20 +++- src-tauri/src/main.rs | 1 + 6 files changed, 87 insertions(+), 64 deletions(-) diff --git a/README.md b/README.md index c97b74c..d5b5397 100644 --- a/README.md +++ b/README.md @@ -220,9 +220,7 @@ Dorion supports all themes, BetterDiscord and others, with a [couple caveats](#k pnpm tauri build # ...or to debug/open in dev mode - # (JS needs to be built manually when building in dev mode) - pnpm build:js - pnpm tauri dev + pnpm dev ``` All built files will be in `src-tauri/target/(release|debug)/`. Installation files (eg. `.msi`, `.deb`) are located in `bundle/`. diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index cdeb0ea..ac201ea 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -104,9 +104,9 @@ dependencies = [ [[package]] name = "allocator-api2" -version = "0.2.19" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "611cc2ae7d2e242c457e4be7f97036b8ad9ca152b499f53faf99b1ed8fc2553f" +checksum = "45862d1c77f2228b9e10bc609d5bc203d86ebc9b87ad8d5d5167a6c9abf739d9" [[package]] name = "android-tzdata" @@ -323,7 +323,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f012b8cc0c850f34117ec8252a44418f2e34a2cf501de89e29b241ae5f79471" dependencies = [ "dirs 4.0.0", - "thiserror 1.0.68", + "thiserror 1.0.69", "winreg 0.10.1", ] @@ -498,7 +498,7 @@ dependencies = [ "glib", "libc", "once_cell", - "thiserror 1.0.68", + "thiserror 1.0.69", ] [[package]] @@ -541,7 +541,7 @@ dependencies = [ "semver", "serde", "serde_json", - "thiserror 1.0.68", + "thiserror 1.0.69", ] [[package]] @@ -820,9 +820,9 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" +checksum = "0ca741a962e1b0bff6d724a1a0958b686406e853bb14061f218562e1896f95e6" dependencies = [ "libc", ] @@ -1645,7 +1645,7 @@ dependencies = [ "once_cell", "pin-project-lite", "smallvec", - "thiserror 1.0.68", + "thiserror 1.0.69", ] [[package]] @@ -1692,7 +1692,7 @@ dependencies = [ "memchr", "once_cell", "smallvec", - "thiserror 1.0.68", + "thiserror 1.0.69", ] [[package]] @@ -1784,7 +1784,7 @@ checksum = "fdd4240fc91d3433d5e5b0fc5b67672d771850dc19bbee03c1381e19322803d7" dependencies = [ "log", "presser", - "thiserror 1.0.68", + "thiserror 1.0.69", "winapi", "windows 0.52.0", ] @@ -1912,7 +1912,7 @@ dependencies = [ "com", "libc", "libloading 0.8.5", - "thiserror 1.0.68", + "thiserror 1.0.69", "widestring", "winapi", ] @@ -2432,7 +2432,7 @@ dependencies = [ "combine", "jni-sys", "log", - "thiserror 1.0.68", + "thiserror 1.0.69", "walkdir", "windows-sys 0.45.0", ] @@ -2461,7 +2461,7 @@ dependencies = [ "jsonptr", "serde", "serde_json", - "thiserror 1.0.68", + "thiserror 1.0.69", ] [[package]] @@ -2771,7 +2771,7 @@ dependencies = [ "once_cell", "png", "serde", - "thiserror 1.0.68", + "thiserror 1.0.69", "windows-sys 0.59.0", ] @@ -2815,7 +2815,7 @@ dependencies = [ "rustc-hash 1.1.0", "spirv", "termcolor", - "thiserror 1.0.68", + "thiserror 1.0.69", ] [[package]] @@ -2856,7 +2856,7 @@ dependencies = [ "ndk-sys 0.6.0+11769913", "num_enum", "raw-window-handle", - "thiserror 1.0.68", + "thiserror 1.0.69", ] [[package]] @@ -3761,7 +3761,7 @@ dependencies = [ "rustc-hash 2.0.0", "rustls", "socket2", - "thiserror 1.0.68", + "thiserror 1.0.69", "tokio", "tracing", ] @@ -3778,7 +3778,7 @@ dependencies = [ "rustc-hash 2.0.0", "rustls", "slab", - "thiserror 1.0.68", + "thiserror 1.0.69", "tinyvec", "tracing", ] @@ -3948,7 +3948,7 @@ checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" dependencies = [ "getrandom 0.2.15", "libredox", - "thiserror 1.0.68", + "thiserror 1.0.69", ] [[package]] @@ -3965,9 +3965,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" dependencies = [ "aho-corasick", "memchr", @@ -4104,9 +4104,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.39" +version = "0.38.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "375116bee2be9ed569afe2154ea6a99dfdffd257f533f187498c2a8f5feaf4ee" +checksum = "99e4ea3e1cdc4b559b8e5650f9c8e5998e3e5c1343b4eaf034565f32318d63c0" dependencies = [ "bitflags 2.6.0", "errno", @@ -4751,9 +4751,9 @@ dependencies = [ [[package]] name = "tao" -version = "0.30.6" +version = "0.30.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "833b4d43383d76d5078d72f3acd977f47eb5b6751eb40baa665d13828e7b79df" +checksum = "6682a07cf5bab0b8a2bd20d0a542917ab928b5edb75ebd4eda6b05cbaab872da" dependencies = [ "bitflags 2.6.0", "cocoa", @@ -4807,9 +4807,9 @@ checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" [[package]] name = "tauri" -version = "2.1.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c24f1ab82d336e09f5f1094a4d9227c99ac26cce263bfdf8136897cc6db6f1d0" +checksum = "e545de0a2dfe296fa67db208266cd397c5a55ae782da77973ef4c4fac90e9f2c" dependencies = [ "anyhow", "bytes", @@ -4845,7 +4845,7 @@ dependencies = [ "tauri-runtime", "tauri-runtime-wry", "tauri-utils", - "thiserror 2.0.1", + "thiserror 2.0.3", "tokio", "tray-icon", "url", @@ -4898,7 +4898,7 @@ dependencies = [ "sha2", "syn 2.0.87", "tauri-utils", - "thiserror 2.0.1", + "thiserror 2.0.3", "time", "url", "uuid", @@ -4948,7 +4948,7 @@ dependencies = [ "serde_json", "tauri", "tauri-plugin", - "thiserror 1.0.68", + "thiserror 1.0.69", ] [[package]] @@ -4967,7 +4967,7 @@ dependencies = [ "serde_repr", "tauri", "tauri-plugin", - "thiserror 1.0.68", + "thiserror 1.0.69", "url", "uuid", ] @@ -4988,7 +4988,7 @@ dependencies = [ "tauri", "tauri-plugin", "tauri-plugin-fs", - "thiserror 1.0.68", + "thiserror 1.0.69", "tokio", "url", "urlpattern", @@ -5008,7 +5008,7 @@ dependencies = [ "serde_repr", "tauri", "tauri-plugin", - "thiserror 1.0.68", + "thiserror 1.0.69", "time", "url", ] @@ -5038,7 +5038,7 @@ dependencies = [ "shared_child", "tauri", "tauri-plugin", - "thiserror 1.0.68", + "thiserror 1.0.69", "tokio", ] @@ -5052,7 +5052,7 @@ dependencies = [ "serde", "serde_json", "tauri", - "thiserror 1.0.68", + "thiserror 1.0.69", "windows-sys 0.59.0", "zbus 4.4.0", ] @@ -5069,7 +5069,7 @@ dependencies = [ "serde_json", "tauri", "tauri-plugin", - "thiserror 1.0.68", + "thiserror 1.0.69", ] [[package]] @@ -5086,7 +5086,7 @@ dependencies = [ "serde", "serde_json", "tauri-utils", - "thiserror 2.0.1", + "thiserror 2.0.3", "url", "windows 0.58.0", ] @@ -5146,7 +5146,7 @@ dependencies = [ "serde_json", "serde_with", "swift-rs", - "thiserror 2.0.1", + "thiserror 2.0.3", "toml 0.8.19", "url", "urlpattern", @@ -5182,7 +5182,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3ecbfeedbd4e41fd66dc3c01951f49af81a824c4f493c02d91b837cf01caf69" dependencies = [ "quick-xml 0.31.0", - "thiserror 1.0.68", + "thiserror 1.0.69", "windows 0.58.0", "windows-version", ] @@ -5228,27 +5228,27 @@ checksum = "8eaa81235c7058867fa8c0e7314f33dcce9c215f535d1913822a2b3f5e289f3c" [[package]] name = "thiserror" -version = "1.0.68" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02dd99dc800bbb97186339685293e1cc5d9df1f8fae2d0aecd9ff1c77efea892" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" dependencies = [ - "thiserror-impl 1.0.68", + "thiserror-impl 1.0.69", ] [[package]] name = "thiserror" -version = "2.0.1" +version = "2.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07c1e40dd48a282ae8edc36c732cbc219144b87fb6a4c7316d611c6b1f06ec0c" +checksum = "c006c85c7651b3cf2ada4584faa36773bd07bac24acfb39f3c431b36d7e667aa" dependencies = [ - "thiserror-impl 2.0.1", + "thiserror-impl 2.0.3", ] [[package]] name = "thiserror-impl" -version = "1.0.68" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7c61ec9a6f64d2793d8a45faba21efbe3ced62a886d44c36a009b2b519b4c7e" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", @@ -5257,9 +5257,9 @@ dependencies = [ [[package]] name = "thiserror-impl" -version = "2.0.1" +version = "2.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "874aa7e446f1da8d9c3a5c95b1c5eb41d800045252121dc7f8e0ba370cee55f5" +checksum = "f077553d607adc1caf65430528a576c757a71ed73944b66ebb58ef2bbd243568" dependencies = [ "proc-macro2", "quote", @@ -5521,7 +5521,7 @@ dependencies = [ "once_cell", "png", "serde", - "thiserror 1.0.68", + "thiserror 1.0.69", "windows-sys 0.59.0", ] @@ -5545,7 +5545,7 @@ dependencies = [ "log", "rand 0.8.5", "sha1", - "thiserror 1.0.68", + "thiserror 1.0.69", "url", "utf-8", ] @@ -5948,7 +5948,7 @@ version = "0.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3a3e2eeb58f82361c93f9777014668eb3d07e7d174ee4c819575a9208011886" dependencies = [ - "thiserror 1.0.68", + "thiserror 1.0.69", "windows 0.58.0", "windows-core 0.58.0", ] @@ -5997,7 +5997,7 @@ dependencies = [ "raw-window-handle", "rustc-hash 1.1.0", "smallvec", - "thiserror 1.0.68", + "thiserror 1.0.69", "wgpu-hal", "wgpu-types", ] @@ -6036,7 +6036,7 @@ dependencies = [ "renderdoc-sys", "rustc-hash 1.1.0", "smallvec", - "thiserror 1.0.68", + "thiserror 1.0.69", "wasm-bindgen", "web-sys", "wgpu-types", @@ -6574,7 +6574,7 @@ dependencies = [ "sha2", "soup3", "tao-macros", - "thiserror 1.0.68", + "thiserror 1.0.69", "url", "webkit2gtk", "webkit2gtk-sys", @@ -6608,9 +6608,9 @@ dependencies = [ [[package]] name = "xcb" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02e75181b5a62b6eeaa72f303d3cef7dbb841e22885bf6d3e66fe23e88c55dc6" +checksum = "f1e2f212bb1a92cd8caac8051b829a6582ede155ccb60b5d5908b81b100952be" dependencies = [ "bitflags 1.3.2", "libc", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 45869ed..98182e5 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -31,7 +31,7 @@ include-flate = "0.3" serde_json = "1" serde = { version = "1", features = ["derive"] } -tauri = { version = "2.0", features = ["macos-private-api", "macos-proxy", "devtools", "tray-icon", "image-png"] } +tauri = { version = "2.1", features = ["macos-private-api", "macos-proxy", "devtools", "tray-icon", "image-png"] } tauri-plugin-shell = "=2.0.1" tauri-plugin-single-instance = "2.0" tauri-plugin-process = "2.0" diff --git a/src-tauri/injection/shared/recreate.ts b/src-tauri/injection/shared/recreate.ts index c4ba822..53b5355 100644 --- a/src-tauri/injection/shared/recreate.ts +++ b/src-tauri/injection/shared/recreate.ts @@ -1,15 +1,21 @@ import { isJson } from './util' -export function proxyFetch() { +export async function proxyFetch() { window.nativeFetch = window.fetch + const extensionInjected = await window.__TAURI__.core.invoke('extension_injected') + + console.log('[Proxy Fetch] Extension injected: ', extensionInjected) + window.fetch = async (url, options) => { const { http } = window.__TAURI__ const discordReg = /https?:\/\/(?:[a-z]+\.)?(?:discord\.com|discordapp\.com)(?:\/.*)?/g const scienceReg = /\/api\/v.*\/(science|track)/g // If it matches, just let it go through native OR its a relative URL - if (url.toString().match(discordReg) || url.toString().startsWith('ipc://') || url.toString().startsWith('/')) { + if (extensionInjected || url.toString().match(discordReg) || url.toString().startsWith('ipc://') || url.toString().startsWith('/')) { + console.log('[Proxy Fetch] Using native fetch') + // Block science though! if (url.toString().match(scienceReg)) { console.log(`[Fetch Proxy] Blocked URL: ${url}`) diff --git a/src-tauri/src/functionality/extension.rs b/src-tauri/src/functionality/extension.rs index 7bdd02f..cf6aa23 100644 --- a/src-tauri/src/functionality/extension.rs +++ b/src-tauri/src/functionality/extension.rs @@ -1,7 +1,11 @@ +use std::sync::atomic::AtomicBool; + use tauri::WebviewWindow; use crate::log; +static EXTENSION_INJECTED: AtomicBool = AtomicBool::new(false); + #[cfg(target_os = "windows")] pub fn add_extension(win: &WebviewWindow, path: std::path::PathBuf) { use webview2_com::{ @@ -47,7 +51,16 @@ pub fn add_extension(win: &WebviewWindow, path: std::path::PathBuf) { log!("Attempting to add extension..."); let handler = ProfileAddBrowserExtensionCompletedHandler::create(Box::new(|result, _ext| { - log!("Extension added?: {:?}", result); + match result { + Ok(_) => { + log!("Extension added successfully!"); + EXTENSION_INJECTED.store(true, std::sync::atomic::Ordering::Relaxed); + } + Err(e) => { + log!("Failed to add extension: {:?}", e); + } + } + Ok(()) })); @@ -66,6 +79,11 @@ pub fn add_extension(win: &WebviewWindow, path: std::path::PathBuf) { .unwrap_or_default(); } +#[tauri::command] +pub fn extension_injected() -> bool { + EXTENSION_INJECTED.load(std::sync::atomic::Ordering::Relaxed) +} + #[cfg(target_os = "windows")] pub fn load_extensions(win: &WebviewWindow) { use crate::util::paths::get_extensions_dir; diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index ab63730..28f3912 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -143,6 +143,7 @@ fn main() { .invoke_handler(tauri::generate_handler![ should_disable_plugins, git_hash, + functionality::extension::extension_injected, functionality::window::minimize, functionality::window::toggle_maximize, #[cfg(not(target_os = "macos"))]