Commit x2

This commit is contained in:
Michael Wain 2025-03-13 23:49:38 +03:00
parent a1dba40494
commit 4b715e2eae
3 changed files with 9 additions and 10 deletions

View File

@ -1,7 +1,7 @@
use core::str;
use std::sync::Arc;
use tokio::sync::{mpsc, Mutex};
use tokio::sync::mpsc::UnboundedReceiver;
use tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender};
use crate::{config::LauncherConfig, minecraft::versions::VersionConfig, util};
#[derive(Default)]
@ -37,7 +37,7 @@ impl Launcher {
self.save_config();
}
pub async fn new_vanilla_instance(&mut self, config: VersionConfig) -> UnboundedReceiver<(u8, String)> {
pub async fn new_vanilla_instance(&mut self, config: VersionConfig, sender: UnboundedSender<(u8, String)>) {
let root = self.config.launcher_dir();
let mut instances = root.clone();
instances.push("instances");
@ -47,18 +47,14 @@ impl Launcher {
instances.push("client.jar");
let (sx, rx) = mpsc::unbounded_channel();
let client_jar_url = config.downloads.client.url;
util::download_file(&client_jar_url, instances.to_str().unwrap(), config.downloads.client.size, sx);
util::download_file(&client_jar_url, instances.to_str().unwrap(), config.downloads.client.size, sender);
/*for i in 0..config.libraries.len() {
let library = &config.libraries[i];
}*/
rx
}
pub fn init_dirs(&self) {

View File

@ -76,7 +76,7 @@ async fn main() {
let mut launcher = Launcher::default();
let mut dl_rec = None;
let (sx, mut dl_rec) = mpsc::unbounded_channel();
loop {
if let Some((ui_action, params, responder)) = receiver.recv().await {
@ -131,7 +131,7 @@ async fn main() {
Ok(config ) => {
println!("Config: {}", config.id);
responder.respond(Response::new(serde_json::to_vec(&UIMessage { params: vec!["show_loading".to_string()] }).unwrap()));
dl_rec = Some(launcher.new_vanilla_instance(config).await);
launcher.new_vanilla_instance(config, sx.clone()).await;
}
Err(e) => {
println!("Error: {}", e);
@ -141,8 +141,10 @@ async fn main() {
}
}
"check_download_status" => {
if let Some((percent, text)) = dl_rec.unwrap().recv().await {
if let Some((percent, text)) = dl_rec.recv().await {
responder.respond(Response::new(serde_json::to_vec(&UIMessage { params: vec!["update_downloads".to_string(), text, percent.to_string()] }).unwrap()));
} else {
responder.respond(Response::new(vec![]));
}
}
_ => {}

View File

@ -379,6 +379,7 @@
<script type="text/javascript">
function processParams(r) {
console.log("got", r);
let params = JSON.parse(r).params;
for( let i = 0; i < params.length; i++ ) {
if( params[i].startsWith("show_") ) {