Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
now using prefix in pb.
Browse files Browse the repository at this point in the history
  • Loading branch information
TOwInOK committed May 2, 2024
1 parent f3282cb commit 89e61a0
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 35 deletions.
3 changes: 2 additions & 1 deletion settings.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[core]
Provider = "paper"
Version = "1.20.6"
ForceUpdate = true

[plugins.simple-voice-chat]
force_update = false
force_update = true
[plugins.chunky]
force_update = false
2 changes: 1 addition & 1 deletion src/lock/core.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};

use crate::settings::core::{Core, Provider};
use crate::settings::core::Provider;

#[derive(Deserialize, Serialize, Debug, Default, PartialEq, Clone)]
pub struct CoreMeta {
Expand Down
2 changes: 1 addition & 1 deletion src/models/cores/paper.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use indicatif::{MultiProgress, ProgressBar, ProgressState, ProgressStyle};
use indicatif::ProgressBar;
use serde::{Deserialize, Serialize};

use crate::{
Expand Down
4 changes: 2 additions & 2 deletions src/models/cores/purpur.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use indicatif::{MultiProgress, ProgressBar};
use indicatif::ProgressBar;
use serde::{Deserialize, Serialize};

use crate::{
Expand Down Expand Up @@ -43,7 +43,7 @@ impl ModelCore for Purpur {
type Version = String;

//find build and push link
async fn get_link(core: &Core, pb: &ProgressBar) -> Result<(String, ChooseHash, String)> {
async fn get_link(core: &Core, _pb: &ProgressBar) -> Result<(String, ChooseHash, String)> {
let build = core.build();
let version = core.version();
let version = find_version(version).await?;
Expand Down
7 changes: 5 additions & 2 deletions src/models/cores/vanilla.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
settings::core::Core,
tr::{hash::ChooseHash, model::core::ModelCore},
};
use indicatif::{MultiProgress, ProgressBar};
use indicatif::ProgressBar;
use serde::Deserialize;
use serde::Serialize;

Expand Down Expand Up @@ -69,7 +69,10 @@ impl ModelCore for Vanilla {
type Link = OuterLink;
type Version = VersionID;
/// Making request to mojang api and find the link to download minecraft.jar
async fn get_link(core: &Core, pb: &ProgressBar) -> Result<(OuterLink, ChooseHash, VersionID)> {
async fn get_link(
core: &Core,
_pb: &ProgressBar,
) -> Result<(OuterLink, ChooseHash, VersionID)> {
let version = core.version();
// debug!("Start find fn with version: {:#?}", version);
let link = find_version(version).await?;
Expand Down
26 changes: 12 additions & 14 deletions src/settings/core.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::sync::Arc;

use console::Term;
use indicatif::{MultiProgress, ProgressBar, ProgressState, ProgressStyle};
use log::{debug, info};
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
use log::debug;
use serde::{Deserialize, Serialize};
use tokio::sync::Mutex;

Expand Down Expand Up @@ -97,17 +96,15 @@ impl Core {
) -> Result<()> {
let mpb = mpb.lock().await;

let name = self.provider.as_str().to_string();
// PB style, init
let name_closure = move |_: &ProgressState, f: &mut dyn std::fmt::Write| {
f.write_str(&name).unwrap();
};
let pb = mpb.add(ProgressBar::new_spinner());
pb.set_style(
ProgressStyle::with_template("Package:: {name:.blue} >>> {msg:.blue}")
.unwrap()
.with_key("name", name_closure),
ProgressStyle::with_template(
"Package:: {prefix:.blue} >>>{spinner:.green} {msg:.blue} > eta: {eta:.blue}",
)
.unwrap(),
);
pb.set_prefix(self.provider.as_str());
// Check meta

let (link, hash, build) = self.get_link(&pb).await?;
let mut lock = lock.lock().await;
Expand All @@ -119,12 +116,13 @@ impl Core {
return Ok(());
}
}
pb.set_message("Downloading...");
let file = Core::get_file(link, hash, &pb).await?;
pb.set_message("Start download");
pb.set_message("Saving file");
Core::save_bytes(file, self.provider().as_str()).await?;
*lock.core_mut() = self.clone().to_meta(build);
lock.save().await
let res = lock.save().await;
pb.finish_with_message("Done");
res
}
async fn get_link(&self, pb: &ProgressBar) -> Result<(String, ChooseHash, String)> {
match self.provider {
Expand Down
22 changes: 9 additions & 13 deletions src/settings/extensions/plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::HashMap;
use std::sync::Arc;

use futures_util::future::join_all;
use indicatif::{MultiProgress, ProgressBar, ProgressState, ProgressStyle};
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
use serde::{Deserialize, Serialize};
use tokio::sync::Mutex;

Expand All @@ -13,7 +13,7 @@ use crate::tr::{download::Download, save::Save};

use super::plugin::Plugin;

const PATH: &'static str = "./plugins/";
const PATH: &str = "./plugins/";

#[derive(Deserialize, Serialize, Debug, Default, PartialEq)]
pub struct Plugins(HashMap<String, Plugin>);
Expand Down Expand Up @@ -42,20 +42,16 @@ impl Plugins {
for (name, plugin) in self.0.clone() {
// Get link
let (link, hash, build) = plugin.get_link(&name, game_version).await?;

// Init name for PB
let cloned_name = name.clone();
let name_closure = move |_: &ProgressState, f: &mut dyn std::fmt::Write| {
f.write_str(&cloned_name.clone()).unwrap();
};
// PB init
let pb = mpb.lock().await.add(ProgressBar::new_spinner());
// PB style
pb.set_style(
ProgressStyle::with_template("Package:: {name:.blue} >>> {msg:.blue}")
.unwrap()
.with_key("name", name_closure),
ProgressStyle::with_template(
"Package:: {prefix:.blue} >>>{spinner:.green} {msg:.blue} > eta: {eta:.blue}",
)
.unwrap(),
);
pb.set_prefix(name.clone());
// Check meta
if let Some(plugin_meta) = lock.lock().await.plugins().get(&name) {
let local_build = plugin_meta.build();
Expand Down Expand Up @@ -87,9 +83,9 @@ impl Plugins {
lock.plugins_mut().insert(name.to_string(), {
ExtensionMeta::new(build, format!("{}{}.jar", PATH, name))
});
let res = lock.save().await?;
lock.save().await?;
pb.finish_with_message("Done");
Ok(res)
Ok(())
}));
}
join_all(handler_list).await;
Expand Down
2 changes: 1 addition & 1 deletion src/tr/download.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::errors::error::Result;
use bytes::{Bytes, BytesMut};
use futures_util::StreamExt;
use indicatif::ProgressBar;
use indicatif::{ProgressBar, ProgressStyle};

use super::hash::ChooseHash;
pub trait Download {
Expand Down

0 comments on commit 89e61a0

Please sign in to comment.