From b55767b276710dca467807681ceed99c70915b4d Mon Sep 17 00:00:00 2001 From: SpikeHD Date: Mon, 16 May 2022 22:19:19 -0700 Subject: [PATCH] allow setting IP --- src-tauri/src/main.rs | 1 + src-tauri/src/proxy.rs | 20 ++++++++++++++++++-- src/ui/components/ServerLaunchSection.tsx | 3 +++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 7c04dea..2a47fe5 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -19,6 +19,7 @@ fn main() { .invoke_handler(tauri::generate_handler![ connect, disconnect, + proxy::set_proxy_addr, run_program, run_jar, unzip::unzip, diff --git a/src-tauri/src/proxy.rs b/src-tauri/src/proxy.rs index e290e91..de2f0fe 100644 --- a/src-tauri/src/proxy.rs +++ b/src-tauri/src/proxy.rs @@ -3,6 +3,9 @@ * https://github.com/omjadas/hudsucker/blob/main/examples/log.rs */ +use lazy_static::lazy_static; +use std::sync::Mutex; + use hudsucker::{ async_trait::async_trait, certificate_authority::RcgenAuthority, @@ -21,9 +24,22 @@ async unsafe fn shutdown_signal() { .expect("Failed to install CTRL+C signal handler"); } +// Global ver for getting server address +lazy_static!{ + static ref SERVER: Mutex = { + let m = "localhost:443".to_string(); + Mutex::new(m) + }; +} + #[derive(Clone)] struct ProxyHandler; +#[tauri::command] +pub fn set_proxy_addr(addr: String){ + *SERVER.lock().unwrap() = addr; +} + #[async_trait] impl HttpHandler for ProxyHandler { async fn handle_request(&mut self, @@ -39,8 +55,8 @@ impl HttpHandler for ProxyHandler { // Check URI against constraints. if path.contains("hoyoverse.com") || path.contains("mihoyo.com") || path.contains("yuanshen.com") { - println!("uri path: {}", uri.path()); - uri = format!("https://127.0.0.1:443{}", uri.path()).parse::().unwrap(); + println!("uri path: {}{}", *SERVER.lock().unwrap(), uri.path()); + uri = format!("https://{}{}", *SERVER.lock().unwrap(), uri.path()).parse::().unwrap(); } let builder = Request::builder() diff --git a/src/ui/components/ServerLaunchSection.tsx b/src/ui/components/ServerLaunchSection.tsx index eb740a5..101c719 100644 --- a/src/ui/components/ServerLaunchSection.tsx +++ b/src/ui/components/ServerLaunchSection.tsx @@ -82,6 +82,9 @@ export default class ServerLaunchSection extends React.Component await setConfigOption('last_ip', this.state.ip) await setConfigOption('last_port', this.state.port) + // Set IP + await invoke('set_proxy_addr', { addr: this.state.ip + ':' + this.state.port }) + // Connect to proxy await invoke('connect', { port: 8365 }) }