mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2025-11-13 16:22:43 +10:00
feat(settings): finish download dir CRUD interface
This commit is contained in:
@ -27,7 +27,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<ul role="list" class="divide-y divide-gray-800">
|
<ul role="list" class="divide-y divide-gray-800">
|
||||||
<li
|
<li
|
||||||
v-for="dir in dirs"
|
v-for="(dir, dirIdx) in dirs"
|
||||||
:key="dir"
|
:key="dir"
|
||||||
class="flex justify-between gap-x-6 py-5"
|
class="flex justify-between gap-x-6 py-5"
|
||||||
>
|
>
|
||||||
@ -43,7 +43,16 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex shrink-0 items-center gap-x-6">
|
<div class="flex shrink-0 items-center gap-x-6">
|
||||||
<button class="-m-2.5 block p-2.5 text-zinc-400 hover:text-zinc-100">
|
<button
|
||||||
|
@click="() => deleteDirectory(dirIdx)"
|
||||||
|
:disabled="dirs.length <= 1"
|
||||||
|
:class="[
|
||||||
|
dirs.length <= 1
|
||||||
|
? 'text-zinc-700'
|
||||||
|
: 'text-zinc-400 hover:text-zinc-100',
|
||||||
|
'-m-2.5 block p-2.5',
|
||||||
|
]"
|
||||||
|
>
|
||||||
<span class="sr-only">Open options</span>
|
<span class="sr-only">Open options</span>
|
||||||
<TrashIcon class="size-5" aria-hidden="true" />
|
<TrashIcon class="size-5" aria-hidden="true" />
|
||||||
</button>
|
</button>
|
||||||
@ -169,7 +178,14 @@ const currentDirectory = ref<string | undefined>(undefined);
|
|||||||
const error = ref<string | undefined>(undefined);
|
const error = ref<string | undefined>(undefined);
|
||||||
const createDirectoryLoading = ref(false);
|
const createDirectoryLoading = ref(false);
|
||||||
|
|
||||||
const dirs = ref(await invoke<Array<string>>("fetch_download_dir_stats"));
|
const dirs = ref<Array<string>>([]);
|
||||||
|
|
||||||
|
async function updateDirs() {
|
||||||
|
const newDirs = await invoke<Array<string>>("fetch_download_dir_stats");
|
||||||
|
dirs.value = newDirs;
|
||||||
|
}
|
||||||
|
|
||||||
|
await updateDirs();
|
||||||
|
|
||||||
async function selectDirectoryDialog(): Promise<string> {
|
async function selectDirectoryDialog(): Promise<string> {
|
||||||
const res = await invoke("plugin:dialog|open", {
|
const res = await invoke("plugin:dialog|open", {
|
||||||
@ -201,12 +217,12 @@ async function submitDirectory() {
|
|||||||
createDirectoryLoading.value = true;
|
createDirectoryLoading.value = true;
|
||||||
|
|
||||||
// Add directory
|
// Add directory
|
||||||
await invoke("add_new_download_dir", { newDir: currentDirectory.value });
|
await invoke("add_download_dir", { newDir: currentDirectory.value });
|
||||||
|
|
||||||
// Update list
|
// Update list
|
||||||
const newDirs = await invoke<Array<string>>("fetch_download_dir_stats");
|
await updateDirs();
|
||||||
dirs.value = newDirs;
|
|
||||||
|
|
||||||
|
currentDirectory.value = undefined;
|
||||||
createDirectoryLoading.value = false;
|
createDirectoryLoading.value = false;
|
||||||
open.value = false;
|
open.value = false;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -214,4 +230,9 @@ async function submitDirectory() {
|
|||||||
createDirectoryLoading.value = false;
|
createDirectoryLoading.value = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function deleteDirectory(index: number) {
|
||||||
|
await invoke("delete_download_dir", { index });
|
||||||
|
await updateDirs();
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -101,7 +101,7 @@ impl DatabaseImpls for DatabaseInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn add_new_download_dir(new_dir: String) -> Result<(), String> {
|
pub fn add_download_dir(new_dir: String) -> Result<(), String> {
|
||||||
// Check the new directory is all good
|
// Check the new directory is all good
|
||||||
let new_dir_path = Path::new(&new_dir);
|
let new_dir_path = Path::new(&new_dir);
|
||||||
if new_dir_path.exists() {
|
if new_dir_path.exists() {
|
||||||
@ -124,6 +124,9 @@ pub fn add_new_download_dir(new_dir: String) -> Result<(), String> {
|
|||||||
|
|
||||||
// Add it to the dictionary
|
// Add it to the dictionary
|
||||||
let mut lock = DB.borrow_data_mut().unwrap();
|
let mut lock = DB.borrow_data_mut().unwrap();
|
||||||
|
if lock.games.install_dirs.contains(&new_dir) {
|
||||||
|
return Err("Download directory already used".to_string());
|
||||||
|
}
|
||||||
lock.games.install_dirs.push(new_dir);
|
lock.games.install_dirs.push(new_dir);
|
||||||
drop(lock);
|
drop(lock);
|
||||||
DB.save().unwrap();
|
DB.save().unwrap();
|
||||||
@ -131,6 +134,16 @@ pub fn add_new_download_dir(new_dir: String) -> Result<(), String> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn delete_download_dir(index: usize) -> Result<(), String> {
|
||||||
|
let mut lock = DB.borrow_data_mut().unwrap();
|
||||||
|
lock.games.install_dirs.remove(index);
|
||||||
|
drop(lock);
|
||||||
|
DB.save().unwrap();
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
// Will, in future, return disk/remaining size
|
// Will, in future, return disk/remaining size
|
||||||
// Just returns the directories that have been set up
|
// Just returns the directories that have been set up
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
|
|||||||
@ -10,7 +10,7 @@ mod tests;
|
|||||||
|
|
||||||
use crate::db::DatabaseImpls;
|
use crate::db::DatabaseImpls;
|
||||||
use auth::{auth_initiate, generate_authorization_header, recieve_handshake};
|
use auth::{auth_initiate, generate_authorization_header, recieve_handshake};
|
||||||
use db::{add_new_download_dir, fetch_download_dir_stats, DatabaseInterface, DATA_ROOT_DIR};
|
use db::{add_download_dir, delete_download_dir, fetch_download_dir_stats, DatabaseInterface, DATA_ROOT_DIR};
|
||||||
use downloads::download_commands::*;
|
use downloads::download_commands::*;
|
||||||
use downloads::download_manager::DownloadManagerBuilder;
|
use downloads::download_manager::DownloadManagerBuilder;
|
||||||
use downloads::download_manager_interface::DownloadManager;
|
use downloads::download_manager_interface::DownloadManager;
|
||||||
@ -126,7 +126,8 @@ pub fn run() {
|
|||||||
// Library
|
// Library
|
||||||
fetch_library,
|
fetch_library,
|
||||||
fetch_game,
|
fetch_game,
|
||||||
add_new_download_dir,
|
add_download_dir,
|
||||||
|
delete_download_dir,
|
||||||
fetch_download_dir_stats,
|
fetch_download_dir_stats,
|
||||||
// Downloads
|
// Downloads
|
||||||
download_game,
|
download_game,
|
||||||
|
|||||||
Reference in New Issue
Block a user