From 68645eca56ba792008d37525996471e6facb6e76 Mon Sep 17 00:00:00 2001 From: TOwInOK <60252419+TOwInOK@users.noreply.github.com> Date: Thu, 25 Apr 2024 07:02:38 +0700 Subject: [PATCH] fix problem with dns (tokio spawn) --- config.lock | 14 +++++++++++--- src/config/mod.rs | 5 ++++- src/config/models/extensions/modrinth.rs | 1 + src/controller/mod.rs | 11 ++++++----- src/main.rs | 1 - 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/config.lock b/config.lock index 53b6501..1f5211f 100644 --- a/config.lock +++ b/config.lock @@ -1,5 +1,13 @@ [core] -name = "vanilla" -path = "" +name = "purpur" +version = "1.20.4" +build = "2176" +path = "core/purpur.jar" -[plugins] +[plugins.chunky] +version = "iwsbfPGg" +path = "plugins/chunky.jar" + +[plugins.simple-voice-chat] +version = "B23zGLmw" +path = "plugins/simple-voice-chat.jar" diff --git a/src/config/mod.rs b/src/config/mod.rs index 73550ba..ac94f01 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -3,7 +3,7 @@ pub mod core; mod models; pub mod plugins; -use crate::errors::error::Result; +use crate::{downloader::hash::ChooseHash, errors::error::Result}; use additions::Additions; use core::Core; use log::info; @@ -39,4 +39,7 @@ impl Config { Ok(config) } + pub async fn get_core_link(self) -> Result<(String, ChooseHash, String)> { + self.core.get_link().await + } } diff --git a/src/config/models/extensions/modrinth.rs b/src/config/models/extensions/modrinth.rs index 894c42f..a165d2d 100644 --- a/src/config/models/extensions/modrinth.rs +++ b/src/config/models/extensions/modrinth.rs @@ -47,6 +47,7 @@ impl ModelExtensions for ModrinthData { ) -> Result<(String, crate::downloader::hash::ChooseHash, String)> { let loader = "fabric"; let link: String = { + // TODO: Make normal params! match game_version { Some(game_version) => { let channel = plugin.channel.get_str().await; diff --git a/src/controller/mod.rs b/src/controller/mod.rs index 0a470fb..6ce1831 100644 --- a/src/controller/mod.rs +++ b/src/controller/mod.rs @@ -1,6 +1,6 @@ use std::{sync::Arc, time::Duration}; -use log::{error, info, trace}; +use log::{debug, error, info, trace}; use tokio::{sync::Mutex, time::sleep}; use tokio_util::sync::CancellationToken; @@ -21,11 +21,12 @@ impl Controller { let config = Arc::clone(&controller.config); let lock = Arc::clone(&controller.lock); - tokio::spawn(async move { + let c = tokio::spawn(async move { run(config, lock, &token).await; }); + let _ = tokio::try_join!(c).unwrap(); - watch_config_changes(&token_clone).await + // watch_config_changes(&token_clone).await } async fn new() -> Result { @@ -91,14 +92,14 @@ async fn start(config: &Arc>, lock: &Arc>) { async fn run(config: Arc>, lock: Arc>, token: &CancellationToken) { // let sleep_cooldown = self.config.lock().await.additions.time_to_await; - let cooldown = 100; + let cooldown = 600f32; loop { info!("Start checking and download"); start(&config, &lock).await; // Sleep for 5 minutes tokio::select! { - _ = sleep(Duration::from_millis(cooldown)) => {}, + _ = sleep(Duration::from_secs_f32(cooldown)) => {}, _ = token.cancelled() => break, }; } diff --git a/src/main.rs b/src/main.rs index e5ce525..e819786 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,6 +9,5 @@ async fn main() { pretty_env_logger::formatted_builder() .filter_level(log::LevelFilter::Trace) .init(); - controller::Controller::init().await }