Commit x2
This commit is contained in:
parent
a1dba40494
commit
4b715e2eae
@ -1,7 +1,7 @@
|
|||||||
use core::str;
|
use core::str;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::sync::{mpsc, Mutex};
|
use tokio::sync::{mpsc, Mutex};
|
||||||
use tokio::sync::mpsc::UnboundedReceiver;
|
use tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender};
|
||||||
use crate::{config::LauncherConfig, minecraft::versions::VersionConfig, util};
|
use crate::{config::LauncherConfig, minecraft::versions::VersionConfig, util};
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
@ -37,7 +37,7 @@ impl Launcher {
|
|||||||
self.save_config();
|
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 root = self.config.launcher_dir();
|
||||||
let mut instances = root.clone();
|
let mut instances = root.clone();
|
||||||
instances.push("instances");
|
instances.push("instances");
|
||||||
@ -47,18 +47,14 @@ impl Launcher {
|
|||||||
|
|
||||||
instances.push("client.jar");
|
instances.push("client.jar");
|
||||||
|
|
||||||
let (sx, rx) = mpsc::unbounded_channel();
|
|
||||||
|
|
||||||
let client_jar_url = config.downloads.client.url;
|
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() {
|
/*for i in 0..config.libraries.len() {
|
||||||
let library = &config.libraries[i];
|
let library = &config.libraries[i];
|
||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
rx
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init_dirs(&self) {
|
pub fn init_dirs(&self) {
|
||||||
|
@ -76,7 +76,7 @@ async fn main() {
|
|||||||
|
|
||||||
let mut launcher = Launcher::default();
|
let mut launcher = Launcher::default();
|
||||||
|
|
||||||
let mut dl_rec = None;
|
let (sx, mut dl_rec) = mpsc::unbounded_channel();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
if let Some((ui_action, params, responder)) = receiver.recv().await {
|
if let Some((ui_action, params, responder)) = receiver.recv().await {
|
||||||
@ -131,7 +131,7 @@ async fn main() {
|
|||||||
Ok(config ) => {
|
Ok(config ) => {
|
||||||
println!("Config: {}", config.id);
|
println!("Config: {}", config.id);
|
||||||
responder.respond(Response::new(serde_json::to_vec(&UIMessage { params: vec!["show_loading".to_string()] }).unwrap()));
|
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) => {
|
Err(e) => {
|
||||||
println!("Error: {}", e);
|
println!("Error: {}", e);
|
||||||
@ -141,8 +141,10 @@ async fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
"check_download_status" => {
|
"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()));
|
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![]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
@ -379,6 +379,7 @@
|
|||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
|
||||||
function processParams(r) {
|
function processParams(r) {
|
||||||
|
console.log("got", r);
|
||||||
let params = JSON.parse(r).params;
|
let params = JSON.parse(r).params;
|
||||||
for( let i = 0; i < params.length; i++ ) {
|
for( let i = 0; i < params.length; i++ ) {
|
||||||
if( params[i].startsWith("show_") ) {
|
if( params[i].startsWith("show_") ) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user