Skip to content

Commit 40d0af8

Browse files
Remove the internet checker as it was just very slow and wastes requests
Replaced with a warning when the program errors out because of a possible lack of internet connectivity
1 parent 125d893 commit 40d0af8

File tree

2 files changed

+16
-48
lines changed

2 files changed

+16
-48
lines changed

src/main.rs

Lines changed: 16 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ use libium::config::{
3737
structs::{Config, ModIdentifier, Modpack, Profile},
3838
};
3939
use octocrab::OctocrabBuilder;
40-
use once_cell::sync::{Lazy, OnceCell};
41-
use reqwest::header::{AUTHORIZATION, USER_AGENT};
40+
use once_cell::sync::Lazy;
4241
use std::{
4342
env::{var, var_os},
4443
process::ExitCode,
@@ -49,7 +48,6 @@ const CROSS: &str = "×";
4948
pub static TICK: Lazy<ColoredString> = Lazy::new(|| "✓".green());
5049
pub static YELLOW_TICK: Lazy<ColoredString> = Lazy::new(|| "✓".yellow());
5150
pub static THEME: Lazy<ColorfulTheme> = Lazy::new(Default::default);
52-
pub static GITHUB_TOKEN: OnceCell<String> = OnceCell::new();
5351
#[allow(clippy::expect_used)]
5452
pub static STYLE_NO: Lazy<ProgressStyle> = Lazy::new(|| {
5553
ProgressStyle::default_bar()
@@ -84,6 +82,18 @@ fn main() -> ExitCode {
8482
let runtime = builder.build().expect("Could not initialise Tokio runtime");
8583
if let Err(err) = runtime.block_on(actual_main(cli)) {
8684
eprintln!("{}", err.to_string().red().bold());
85+
if err
86+
.to_string()
87+
.to_lowercase()
88+
.contains("error trying to connect")
89+
{
90+
eprintln!(
91+
"{}",
92+
"Verify that you are connnected to the internet"
93+
.yellow()
94+
.bold()
95+
);
96+
}
8797
ExitCode::FAILURE
8898
} else {
8999
ExitCode::SUCCESS
@@ -115,15 +125,11 @@ async fn actual_main(mut cli_app: Ferium) -> Result<()> {
115125
};
116126
}
117127

128+
let mut github = OctocrabBuilder::new();
118129
if let Some(token) = cli_app.github_token {
119-
GITHUB_TOKEN.get_or_init(|| token.to_string());
130+
github = github.personal_token(token);
120131
} else if let Ok(token) = var("GITHUB_TOKEN") {
121-
GITHUB_TOKEN.get_or_init(|| token.to_string());
122-
}
123-
124-
let mut github = OctocrabBuilder::new();
125-
if let Some(token) = GITHUB_TOKEN.get() {
126-
github = github.personal_token(token.clone());
132+
github = github.personal_token(token);
127133
}
128134

129135
let modrinth = Ferinth::new(
@@ -160,7 +166,6 @@ async fn actual_main(mut cli_app: Ferium) -> Result<()> {
160166
ignore_mod_loader,
161167
} => {
162168
let profile = get_active_profile(&mut config)?;
163-
check_internet().await?;
164169
eprint!("Adding mod... ");
165170
if let Ok(project_id) = identifier.parse::<i32>() {
166171
let name = libium::add::curseforge(
@@ -225,7 +230,6 @@ async fn actual_main(mut cli_app: Ferium) -> Result<()> {
225230
let profile = get_active_profile(&mut config)?;
226231
check_empty_profile(profile)?;
227232
if verbose {
228-
check_internet().await?;
229233
subcommands::list::verbose(modrinth, curseforge, profile, markdown).await?;
230234
} else {
231235
println!(
@@ -267,7 +271,6 @@ async fn actual_main(mut cli_app: Ferium) -> Result<()> {
267271
output_dir,
268272
install_overrides,
269273
} => {
270-
check_internet().await?;
271274
if let Ok(project_id) = identifier.parse::<i32>() {
272275
subcommands::modpack::add::curseforge(
273276
&curseforge,
@@ -323,7 +326,6 @@ async fn actual_main(mut cli_app: Ferium) -> Result<()> {
323326
subcommands::modpack::switch(&mut config, modpack_name)?;
324327
}
325328
ModpackSubCommands::Upgrade => {
326-
check_internet().await?;
327329
subcommands::modpack::upgrade(
328330
&modrinth,
329331
&curseforge,
@@ -353,7 +355,6 @@ async fn actual_main(mut cli_app: Ferium) -> Result<()> {
353355
name,
354356
output_dir,
355357
} => {
356-
check_internet().await?;
357358
subcommands::profile::configure(
358359
get_active_profile(&mut config)?,
359360
game_version,
@@ -370,9 +371,6 @@ async fn actual_main(mut cli_app: Ferium) -> Result<()> {
370371
name,
371372
output_dir,
372373
} => {
373-
if game_version.is_none() {
374-
check_internet().await?;
375-
}
376374
subcommands::profile::create(
377375
&mut config,
378376
import,
@@ -417,7 +415,6 @@ async fn actual_main(mut cli_app: Ferium) -> Result<()> {
417415
subcommands::remove(profile, mod_names)?;
418416
}
419417
SubCommands::Upgrade => {
420-
check_internet().await?;
421418
let profile = get_active_profile(&mut config)?;
422419
check_empty_profile(profile)?;
423420
subcommands::upgrade(modrinth, curseforge, github.build()?, profile).await?;
@@ -482,31 +479,3 @@ fn check_empty_profile(profile: &Profile) -> Result<()> {
482479
}
483480
Ok(())
484481
}
485-
486-
/// Check for an internet connection
487-
async fn check_internet() -> Result<()> {
488-
let client = reqwest::Client::default();
489-
490-
client
491-
.get(ferinth::BASE_URL.as_ref())
492-
.send()
493-
.await?
494-
.error_for_status()?;
495-
496-
client
497-
.get("https://api.curseforge.com/")
498-
.send()
499-
.await?
500-
.error_for_status()?;
501-
502-
let mut github = client.get("https://api.github.com/").header(
503-
USER_AGENT,
504-
concat!(env!("CARGO_PKG_NAME"), " ", env!("CARGO_PKG_VERSION")),
505-
);
506-
if let Some(token) = GITHUB_TOKEN.get() {
507-
github = github.header(AUTHORIZATION, format!("Bearer {token}"));
508-
}
509-
github.send().await?.error_for_status()?;
510-
511-
Ok(())
512-
}

src/subcommands/list.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![allow(clippy::unwrap_used)]
2-
#![allow(clippy::needless_pass_by_value)]
32

43
use crate::TICK;
54
use anyhow::{Context, Result};

0 commit comments

Comments
 (0)