mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-16 09:04:45 +01:00
Allow for dynamic usage of the proxy port
This commit is contained in:
@@ -18,15 +18,15 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn connect() {
|
async fn connect(port: u16) {
|
||||||
// Log message to console.
|
// Log message to console.
|
||||||
println!("Connecting to proxy...");
|
println!("Connecting to proxy...");
|
||||||
|
|
||||||
// Create and start a proxy.
|
// Create and start a proxy.
|
||||||
proxy::create_proxy().await;
|
proxy::create_proxy(port).await;
|
||||||
|
|
||||||
// Change proxy settings.
|
// Change proxy settings.
|
||||||
proxy::connect_to_proxy();
|
proxy::connect_to_proxy(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
@@ -38,5 +38,6 @@ fn disconnect() {
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn run_program(path: String) {
|
fn run_program(path: String) {
|
||||||
// Open the program from the specified path.
|
// Open the program from the specified path.
|
||||||
opener::open(path.clone()).expect("Failed to open program");
|
opener::open(path.clone())
|
||||||
|
.expect("Failed to open program");
|
||||||
}
|
}
|
||||||
@@ -44,7 +44,7 @@ impl HttpHandler for ProxyHandler {
|
|||||||
/**
|
/**
|
||||||
* Starts an HTTP(S) proxy server.
|
* Starts an HTTP(S) proxy server.
|
||||||
*/
|
*/
|
||||||
pub(crate) async fn create_proxy() {
|
pub(crate) async fn create_proxy(proxy_port: u16) {
|
||||||
// Get the certificate and private key.
|
// Get the certificate and private key.
|
||||||
let mut private_key_bytes: &[u8] = include_bytes!("../resources/private-key.pem");
|
let mut private_key_bytes: &[u8] = include_bytes!("../resources/private-key.pem");
|
||||||
let mut ca_cert_bytes: &[u8] = include_bytes!("../resources/ca-certificate.pem");
|
let mut ca_cert_bytes: &[u8] = include_bytes!("../resources/ca-certificate.pem");
|
||||||
@@ -68,7 +68,7 @@ pub(crate) async fn create_proxy() {
|
|||||||
|
|
||||||
// Create an instance of the proxy.
|
// Create an instance of the proxy.
|
||||||
let proxy = ProxyBuilder::new()
|
let proxy = ProxyBuilder::new()
|
||||||
.with_addr(SocketAddr::from(([127, 0, 0, 1], 8537)))
|
.with_addr(SocketAddr::from(([0, 0, 0, 0], proxy_port)))
|
||||||
.with_rustls_client()
|
.with_rustls_client()
|
||||||
.with_ca(authority)
|
.with_ca(authority)
|
||||||
.with_http_handler(ProxyHandler)
|
.with_http_handler(ProxyHandler)
|
||||||
@@ -82,15 +82,20 @@ pub(crate) async fn create_proxy() {
|
|||||||
/**
|
/**
|
||||||
* Connects to the local HTTP(S) proxy server.
|
* Connects to the local HTTP(S) proxy server.
|
||||||
*/
|
*/
|
||||||
pub(crate) fn connect_to_proxy() {
|
pub(crate) fn connect_to_proxy(proxy_port: u16) {
|
||||||
if cfg!(target_os = "windows") {
|
if cfg!(target_os = "windows") {
|
||||||
|
// Create 'ProxyServer' string.
|
||||||
|
let server_string: String = format!("http=127.0.0.1:{};https=127.0.0.1:{};ftp=127.0.0.1:{}", proxy_port, proxy_port, proxy_port);
|
||||||
|
|
||||||
// Fetch the 'Internet Settings' registry key.
|
// Fetch the 'Internet Settings' registry key.
|
||||||
let settings = Hive::CurrentUser.open(r"Software\Microsoft\Windows\CurrentVersion\Internet Settings", Security::Write).unwrap();
|
let settings = Hive::CurrentUser.open(r"Software\Microsoft\Windows\CurrentVersion\Internet Settings", Security::Write).unwrap();
|
||||||
|
|
||||||
// Set registry values.
|
// Set registry values.
|
||||||
settings.set_value("ProxyServer", &Data::String("http=127.0.0.1:8537;https=127.0.0.1:8537;ftp=127.0.0.1:8537".parse().unwrap())).unwrap();
|
settings.set_value("ProxyServer", &Data::String(server_string.parse().unwrap())).unwrap();
|
||||||
settings.set_value("ProxyEnable", &Data::U32(1)).unwrap();
|
settings.set_value("ProxyEnable", &Data::U32(1)).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
println!("Connected to the proxy.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user