mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2026-02-06 02:06:29 +01:00
allow setting IP
This commit is contained in:
@@ -19,6 +19,7 @@ fn main() {
|
|||||||
.invoke_handler(tauri::generate_handler![
|
.invoke_handler(tauri::generate_handler![
|
||||||
connect,
|
connect,
|
||||||
disconnect,
|
disconnect,
|
||||||
|
proxy::set_proxy_addr,
|
||||||
run_program,
|
run_program,
|
||||||
run_jar,
|
run_jar,
|
||||||
unzip::unzip,
|
unzip::unzip,
|
||||||
|
|||||||
@@ -3,6 +3,9 @@
|
|||||||
* https://github.com/omjadas/hudsucker/blob/main/examples/log.rs
|
* https://github.com/omjadas/hudsucker/blob/main/examples/log.rs
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use lazy_static::lazy_static;
|
||||||
|
use std::sync::Mutex;
|
||||||
|
|
||||||
use hudsucker::{
|
use hudsucker::{
|
||||||
async_trait::async_trait,
|
async_trait::async_trait,
|
||||||
certificate_authority::RcgenAuthority,
|
certificate_authority::RcgenAuthority,
|
||||||
@@ -21,9 +24,22 @@ async unsafe fn shutdown_signal() {
|
|||||||
.expect("Failed to install CTRL+C signal handler");
|
.expect("Failed to install CTRL+C signal handler");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Global ver for getting server address
|
||||||
|
lazy_static!{
|
||||||
|
static ref SERVER: Mutex<String> = {
|
||||||
|
let m = "localhost:443".to_string();
|
||||||
|
Mutex::new(m)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct ProxyHandler;
|
struct ProxyHandler;
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn set_proxy_addr(addr: String){
|
||||||
|
*SERVER.lock().unwrap() = addr;
|
||||||
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl HttpHandler for ProxyHandler {
|
impl HttpHandler for ProxyHandler {
|
||||||
async fn handle_request(&mut self,
|
async fn handle_request(&mut self,
|
||||||
@@ -39,8 +55,8 @@ impl HttpHandler for ProxyHandler {
|
|||||||
|
|
||||||
// Check URI against constraints.
|
// Check URI against constraints.
|
||||||
if path.contains("hoyoverse.com") || path.contains("mihoyo.com") || path.contains("yuanshen.com") {
|
if path.contains("hoyoverse.com") || path.contains("mihoyo.com") || path.contains("yuanshen.com") {
|
||||||
println!("uri path: {}", uri.path());
|
println!("uri path: {}{}", *SERVER.lock().unwrap(), uri.path());
|
||||||
uri = format!("https://127.0.0.1:443{}", uri.path()).parse::<Uri>().unwrap();
|
uri = format!("https://{}{}", *SERVER.lock().unwrap(), uri.path()).parse::<Uri>().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
let builder = Request::builder()
|
let builder = Request::builder()
|
||||||
|
|||||||
@@ -82,6 +82,9 @@ export default class ServerLaunchSection extends React.Component<IProps, IState>
|
|||||||
await setConfigOption('last_ip', this.state.ip)
|
await setConfigOption('last_ip', this.state.ip)
|
||||||
await setConfigOption('last_port', this.state.port)
|
await setConfigOption('last_port', this.state.port)
|
||||||
|
|
||||||
|
// Set IP
|
||||||
|
await invoke('set_proxy_addr', { addr: this.state.ip + ':' + this.state.port })
|
||||||
|
|
||||||
// Connect to proxy
|
// Connect to proxy
|
||||||
await invoke('connect', { port: 8365 })
|
await invoke('connect', { port: 8365 })
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user