feat(tui): added option for storing downloaded files in username directories
This commit is contained in:
@@ -221,6 +221,7 @@ impl MainTui {
|
||||
let sender = self.downloads_sender();
|
||||
let client = self.client.clone();
|
||||
let download_dir = self.download_dir.clone();
|
||||
let use_username_dirs = self.use_username_dirs;
|
||||
thread::spawn(move || {
|
||||
for (path, size) in files {
|
||||
match client.download(
|
||||
@@ -228,6 +229,7 @@ impl MainTui {
|
||||
username.clone(),
|
||||
size,
|
||||
download_dir.clone(),
|
||||
use_username_dirs,
|
||||
) {
|
||||
Ok((download, rx)) => {
|
||||
let _ = sender.send((download, rx));
|
||||
|
||||
@@ -48,9 +48,16 @@ impl MainTui {
|
||||
self.state.downloads.remove(index);
|
||||
self.select_download_after_removal(index);
|
||||
let _ = self.client.remove_download(&username, &filename);
|
||||
let use_username_dirs = self.use_username_dirs;
|
||||
|
||||
thread::spawn(move || {
|
||||
match client.download(filename.clone(), username, size, directory) {
|
||||
match client.download(
|
||||
filename.clone(),
|
||||
username,
|
||||
size,
|
||||
directory,
|
||||
use_username_dirs,
|
||||
) {
|
||||
Ok((download, rx)) => {
|
||||
let _ = sender.send((download, rx));
|
||||
}
|
||||
@@ -197,6 +204,7 @@ impl MainTui {
|
||||
let sender = self.downloads_sender();
|
||||
let client = self.client.clone();
|
||||
let download_dir = self.download_dir.clone();
|
||||
let use_username_dirs = self.use_username_dirs;
|
||||
|
||||
thread::spawn(move || {
|
||||
for file in selected_files {
|
||||
@@ -211,6 +219,7 @@ impl MainTui {
|
||||
file.username.clone(),
|
||||
file.size,
|
||||
download_dir.clone(),
|
||||
use_username_dirs,
|
||||
metadata,
|
||||
) {
|
||||
Ok((download, rx)) => {
|
||||
|
||||
@@ -23,6 +23,7 @@ pub struct MainTui {
|
||||
client: Arc<dyn SessionApi>,
|
||||
state: AppState,
|
||||
download_dir: String,
|
||||
use_username_dirs: bool,
|
||||
search_timeout: Duration,
|
||||
spinner_state: usize,
|
||||
store: Option<StateStore>,
|
||||
@@ -40,6 +41,7 @@ impl MainTui {
|
||||
pub fn new(
|
||||
client: Arc<dyn SessionApi>,
|
||||
download_dir: String,
|
||||
use_username_dirs: bool,
|
||||
search_timeout: Duration,
|
||||
store: Option<StateStore>,
|
||||
config_path: Option<std::path::PathBuf>,
|
||||
@@ -49,6 +51,7 @@ impl MainTui {
|
||||
state: AppState::new(),
|
||||
download_dir,
|
||||
search_timeout,
|
||||
use_username_dirs,
|
||||
spinner_state: 0,
|
||||
store,
|
||||
config_path,
|
||||
@@ -118,6 +121,7 @@ impl MainTui {
|
||||
token: 0,
|
||||
size: entry.size,
|
||||
download_directory: entry.download_directory,
|
||||
use_username_dirs: entry.use_username_dirs,
|
||||
status: soulseek_rs::DownloadStatus::Completed,
|
||||
sender: std::sync::mpsc::channel().0,
|
||||
queue_position: None,
|
||||
@@ -135,6 +139,7 @@ impl MainTui {
|
||||
entry.username,
|
||||
entry.size,
|
||||
entry.download_directory,
|
||||
entry.use_username_dirs,
|
||||
) {
|
||||
Ok((download, rx)) => {
|
||||
let _ = sender.send((download, rx));
|
||||
@@ -256,13 +261,20 @@ pub fn launch_main_tui(
|
||||
terminal: DefaultTerminal,
|
||||
client: Arc<dyn SessionApi>,
|
||||
download_dir: String,
|
||||
use_username_dirs: bool,
|
||||
search_timeout: Duration,
|
||||
store: Option<StateStore>,
|
||||
config_path: Option<std::path::PathBuf>,
|
||||
listener_fallback: Option<(u16, u16)>,
|
||||
) -> Result<TuiExit> {
|
||||
let mut tui =
|
||||
MainTui::new(client, download_dir, search_timeout, store, config_path);
|
||||
let mut tui = MainTui::new(
|
||||
client,
|
||||
download_dir,
|
||||
use_username_dirs,
|
||||
search_timeout,
|
||||
store,
|
||||
config_path,
|
||||
);
|
||||
tui.listener_fallback = listener_fallback;
|
||||
tui.run(terminal)
|
||||
}
|
||||
|
||||
@@ -369,6 +369,16 @@ impl MainTui {
|
||||
lines.push(Line::from(""));
|
||||
|
||||
lines.push(section("Folders"));
|
||||
lines.push(entry(
|
||||
selected == SettingsRow::UseUsernameDirs,
|
||||
"Use username directory ",
|
||||
if settings.use_username_dirs {
|
||||
"[x]"
|
||||
} else {
|
||||
"[ ]"
|
||||
}
|
||||
.to_string(),
|
||||
));
|
||||
lines.push(if settings.mode == SettingsMode::EditingDownloadDir {
|
||||
typing("Download folder: ", settings.input.clone())
|
||||
} else {
|
||||
|
||||
@@ -166,6 +166,7 @@ fn settings_shortcuts(
|
||||
SettingsRow::ChangePassword => ("Enter", "change password"),
|
||||
SettingsRow::Logout => ("Enter", "log out"),
|
||||
SettingsRow::DownloadDir => ("Enter", "edit folder"),
|
||||
SettingsRow::UseUsernameDirs => ("Enter", "toggle option"),
|
||||
SettingsRow::Share(_) => ("d", "remove share"),
|
||||
},
|
||||
("a", "add share"),
|
||||
|
||||
@@ -20,6 +20,7 @@ impl MainTui {
|
||||
account,
|
||||
self.download_dir.clone(),
|
||||
self.client.shared_directories(),
|
||||
self.use_username_dirs.clone(),
|
||||
));
|
||||
}
|
||||
|
||||
@@ -66,6 +67,7 @@ impl MainTui {
|
||||
};
|
||||
let download_dir = settings.download_dir.clone();
|
||||
let share_dirs = settings.share_dirs.clone();
|
||||
let use_username_dirs = settings.use_username_dirs;
|
||||
|
||||
let shares = if self.client.daemon_endpoint().is_some() {
|
||||
share_dirs.clone()
|
||||
@@ -121,6 +123,7 @@ impl MainTui {
|
||||
// load, so leaving it would resurrect a removed folder.
|
||||
config.shared_dir = None;
|
||||
config.shared_dirs = Some(share_dirs);
|
||||
config.use_username_dirs = Some(use_username_dirs);
|
||||
config.save(&path)
|
||||
});
|
||||
if let Err(e) = result {
|
||||
|
||||
@@ -84,6 +84,7 @@ fn at_status(
|
||||
token: 1,
|
||||
size: 4096,
|
||||
download_directory: "/tmp".to_string(),
|
||||
use_username_dirs: false,
|
||||
status,
|
||||
sender,
|
||||
queue_position: None,
|
||||
@@ -160,6 +161,7 @@ impl SessionApi for TalkativeSession {
|
||||
_username: String,
|
||||
_size: u64,
|
||||
_directory: String,
|
||||
_use_username_dirs: bool,
|
||||
) -> soulseek_rs::Result<(
|
||||
soulseek_rs::types::Download,
|
||||
std::sync::mpsc::Receiver<soulseek_rs::DownloadStatus>,
|
||||
@@ -172,6 +174,7 @@ impl SessionApi for TalkativeSession {
|
||||
_username: String,
|
||||
_size: u64,
|
||||
_directory: String,
|
||||
_use_username_dirs: bool,
|
||||
_metadata: soulseek_rs::types::DownloadMetadata,
|
||||
) -> soulseek_rs::Result<(
|
||||
soulseek_rs::types::Download,
|
||||
@@ -349,6 +352,7 @@ fn attach(session: Arc<TalkativeSession>) -> MainTui {
|
||||
MainTui::new(
|
||||
session,
|
||||
"/tmp".to_string(),
|
||||
false,
|
||||
Duration::from_secs(1),
|
||||
None,
|
||||
None,
|
||||
|
||||
@@ -17,6 +17,7 @@ fn applying_settings_attached_pushes_both_folders_to_the_daemon() {
|
||||
let mut tui = MainTui::new(
|
||||
session.clone(),
|
||||
"/daemon/old".to_string(),
|
||||
false,
|
||||
Duration::from_secs(1),
|
||||
None,
|
||||
Some(config_path.clone()),
|
||||
@@ -73,6 +74,7 @@ fn applying_settings_locally_stays_on_this_machine() {
|
||||
let mut tui = MainTui::new(
|
||||
session.clone(),
|
||||
"/tmp".to_string(),
|
||||
false,
|
||||
Duration::from_secs(1),
|
||||
None,
|
||||
Some(config_path),
|
||||
|
||||
Reference in New Issue
Block a user