mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2026-02-04 09:25:16 +01:00
Remove warnings
This commit is contained in:
@@ -37,29 +37,29 @@ pub async fn download_file(window: tauri::Window, url: &str, path: &str) -> Resu
|
|||||||
let new = min(downloaded + (chunk.len() as u64), total_size);
|
let new = min(downloaded + (chunk.len() as u64), total_size);
|
||||||
downloaded = new;
|
downloaded = new;
|
||||||
|
|
||||||
let mut resHash = std::collections::HashMap::new();
|
let mut res_hash = std::collections::HashMap::new();
|
||||||
|
|
||||||
resHash.insert(
|
res_hash.insert(
|
||||||
"downloaded".to_string(),
|
"downloaded".to_string(),
|
||||||
downloaded.to_string()
|
downloaded.to_string()
|
||||||
);
|
);
|
||||||
|
|
||||||
resHash.insert(
|
res_hash.insert(
|
||||||
"total".to_string(),
|
"total".to_string(),
|
||||||
total_size.to_string()
|
total_size.to_string()
|
||||||
);
|
);
|
||||||
|
|
||||||
resHash.insert(
|
res_hash.insert(
|
||||||
"path".to_string(),
|
"path".to_string(),
|
||||||
path.to_string()
|
path.to_string()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create event to send to frontend
|
// Create event to send to frontend
|
||||||
window.emit("download_progress", &resHash);
|
window.emit("download_progress", &res_hash).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
// One more "finish" event
|
// One more "finish" event
|
||||||
window.emit("download_finished", &path);
|
window.emit("download_finished", &path).unwrap();
|
||||||
|
|
||||||
// We are done
|
// We are done
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
|||||||
@@ -10,14 +10,18 @@ mod proxy;
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
tauri::Builder::default()
|
tauri::Builder::default()
|
||||||
.invoke_handler(tauri::generate_handler![run_program])
|
|
||||||
.invoke_handler(tauri::generate_handler![downloader::download_file])
|
.invoke_handler(tauri::generate_handler![downloader::download_file])
|
||||||
|
.invoke_handler(tauri::generate_handler![run_program])
|
||||||
|
.invoke_handler(tauri::generate_handler![connect, disconnect])
|
||||||
.run(tauri::generate_context!())
|
.run(tauri::generate_context!())
|
||||||
.expect("error while running tauri application");
|
.expect("error while running tauri application");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn connect() {
|
async fn connect() {
|
||||||
|
// Log message to console.
|
||||||
|
println!("Connecting to proxy...");
|
||||||
|
|
||||||
// Create and start a proxy.
|
// Create and start a proxy.
|
||||||
proxy::create_proxy().await;
|
proxy::create_proxy().await;
|
||||||
|
|
||||||
@@ -31,13 +35,8 @@ fn disconnect() {
|
|||||||
proxy::disconnect_from_proxy();
|
proxy::disconnect_from_proxy();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
|
||||||
fn test() {
|
|
||||||
println!("test");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[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());
|
opener::open(path.clone()).expect("Failed to open program");
|
||||||
}
|
}
|
||||||
@@ -12,7 +12,6 @@ use hudsucker::{
|
|||||||
|
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use registry::{Hive, Data, Security};
|
use registry::{Hive, Data, Security};
|
||||||
use tracing::*;
|
|
||||||
|
|
||||||
use rustls_pemfile as pemfile;
|
use rustls_pemfile as pemfile;
|
||||||
|
|
||||||
@@ -20,7 +19,7 @@ use rustls_pemfile as pemfile;
|
|||||||
* Application shutdown handler.
|
* Application shutdown handler.
|
||||||
*/
|
*/
|
||||||
async fn shutdown_signal() {
|
async fn shutdown_signal() {
|
||||||
|
disconnect_from_proxy();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@@ -29,16 +28,16 @@ struct ProxyHandler;
|
|||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl HttpHandler for ProxyHandler {
|
impl HttpHandler for ProxyHandler {
|
||||||
async fn handle_request(&mut self,
|
async fn handle_request(&mut self,
|
||||||
context: &HttpContext,
|
_context: &HttpContext,
|
||||||
request: Request<Body>
|
request: Request<Body>
|
||||||
) -> RequestOrResponse {
|
) -> RequestOrResponse {
|
||||||
println!("{:?}", request.uri().path());
|
println!("{:?}", request.uri().path());
|
||||||
RequestOrResponse::Request(request)
|
RequestOrResponse::Request(request)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_response(&mut self,
|
async fn handle_response(&mut self,
|
||||||
context: &HttpContext,
|
_context: &HttpContext,
|
||||||
response: Response<Body>
|
response: Response<Body>
|
||||||
) -> Response<Body> { response }
|
) -> Response<Body> { response }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,16 +68,15 @@ 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], 8080)))
|
.with_addr(SocketAddr::from(([127, 0, 0, 1], 8537)))
|
||||||
.with_rustls_client()
|
.with_rustls_client()
|
||||||
.with_ca(authority)
|
.with_ca(authority)
|
||||||
.with_http_handler(ProxyHandler)
|
.with_http_handler(ProxyHandler)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Create the proxy & listen for errors.
|
// Create the proxy & listen for errors.
|
||||||
if let Err(e) = proxy.start(shutdown_signal()).await {
|
proxy.start(shutdown_signal()).await
|
||||||
error!("{}", e);
|
.expect("Failed to start proxy");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -90,8 +88,8 @@ pub(crate) fn connect_to_proxy() {
|
|||||||
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:8080;https=127.0.0.1:8080;ftp=127.0.0.1:8080".parse().unwrap()));
|
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("ProxyEnable", &Data::U32(1));
|
settings.set_value("ProxyEnable", &Data::U32(1)).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,6 +102,6 @@ pub(crate) fn disconnect_from_proxy() {
|
|||||||
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("ProxyEnable", &Data::U32(0));
|
settings.set_value("ProxyEnable", &Data::U32(0)).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user