Skip to content

Commit

Permalink
display path with it
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackhr-arch committed Sep 14, 2024
1 parent 55752bc commit 04cbb69
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 43 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 5 additions & 10 deletions src/commands/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,8 @@ pub fn handle_cli(command: PackedArgs, backend: BackEnd) -> anyhow::Result<Strin
.collect();
if let Some(url) = al.get(0) {
println!("\nDownload start for {} {}", maybe_name, url);
backend.download_to_file(&maybe_name, url)?;
println!(
"\nDownloaded to {}",
std::env::current_dir()?.join(maybe_name).display()
);
let path = backend.download_to_file(&maybe_name, url)?;
println!("\nDownloaded to {}", path.display());
} else {
println!("Not select any, continue");
}
Expand All @@ -154,11 +151,9 @@ pub fn handle_cli(command: PackedArgs, backend: BackEnd) -> anyhow::Result<Strin
"\nDownload start for {} {}",
asset.name, asset.browser_download_url
);
backend.download_to_file(&asset.name, &asset.browser_download_url)?;
println!(
"\nDownloaded to {}",
std::env::current_dir()?.join(&asset.name).display()
);
let path =
backend.download_to_file(&asset.name, &asset.browser_download_url)?;
println!("\nDownloaded to {}", path.display());
}
}
}
Expand Down
53 changes: 27 additions & 26 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,29 +118,30 @@ async fn start_tui(backend: BackEnd) -> anyhow::Result<()> {
}

fn load_home_dir() -> std::path::PathBuf {
let config_dir = {
use std::{env, path::PathBuf};
let exe_dir = env::current_exe()
.expect("Err loading exe_file_path")
.parent()
.expect("Err finding exe_dir")
.to_path_buf();
let data_dir = exe_dir.join("data");
if data_dir.exists() && data_dir.is_dir() {
// portable mode
data_dir
use std::{env, path};
let data_dir = env::current_exe()
.expect("Err loading exe_file_path")
.parent()
.expect("Err finding exe_dir")
.join("data");
if data_dir.exists() && data_dir.is_dir() {
// portable mode
data_dir
} else {
if cfg!(target_os = "linux") {
env::var_os("XDG_CONFIG_HOME")
.map(|c| path::PathBuf::from(c))
.or(env::var_os("HOME").map(|h| path::PathBuf::from(h).join(".config")))
} else if cfg!(target_os = "windows") {
env::var_os("APPDATA").map(|c| path::PathBuf::from(c))
} else if cfg!(target_os = "macos") {
env::var_os("HOME").map(|h| path::PathBuf::from(h).join(".config"))
} else {
#[cfg(target_os = "linux")]
let config_dir_str = env::var("XDG_CONFIG_HOME")
.or_else(|_| env::var("HOME").map(|home| format!("{}/.config/clashtui", home)));
#[cfg(target_os = "windows")]
let config_dir_str = env::var("APPDATA").map(|appdata| format!("{}/clashtui", appdata));
#[cfg(target_os = "macos")]
let config_dir_str = env::var("HOME").map(|home| format!("{}/.config/clashtui", home));
PathBuf::from(&config_dir_str.expect("Err loading global config dir"))
unimplemented!("Not supported platform")
}
};
config_dir
.map(|c| c.join("clashtui"))
.unwrap()
}
}

fn setup_logging<P: AsRef<std::path::Path>>(log_file: P) {
Expand All @@ -158,11 +159,11 @@ fn setup_logging<P: AsRef<std::path::Path>>(log_file: P) {
} else {
false
};
// No need to change. This is set to auto switch to Info level when build release
#[allow(unused_variables)]
let log_level = log::LevelFilter::Info;
#[cfg(debug_assertions)]
let log_level = log::LevelFilter::Debug;
let log_level = if cfg!(debug_assertions) {
log::LevelFilter::Debug
} else {
log::LevelFilter::Info
};
let file_appender = FileAppender::builder()
.encoder(Box::new(PatternEncoder::new(
"{d(%H:%M:%S)} [{l}] {t} - {m}{n}",
Expand Down
7 changes: 4 additions & 3 deletions src/utils/backend/impl_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ impl BackEnd {
pub fn check_update(&self) -> anyhow::Result<Vec<crate::clash::webapi::github::Response>> {
Ok(self.api.check_update()?)
}
pub fn download_to_file(&self, name: &str, url: &str) -> anyhow::Result<()> {
pub fn download_to_file(&self, name: &str, url: &str) -> anyhow::Result<std::path::PathBuf> {
let path = std::env::current_dir()?.join(name);
let mut rp = self.api.get_file(url)?;
let mut fp = std::fs::File::create(std::env::current_dir()?.join(name))?;
let mut fp = std::fs::File::create(&path)?;
std::io::copy(&mut rp, &mut fp)?;
Ok(())
Ok(path)
}
pub fn update_mode(&self, mode: String) -> anyhow::Result<()> {
let load = format!(r#"{{"mode": "{mode}"}}"#);
Expand Down

0 comments on commit 04cbb69

Please sign in to comment.