feat(library): Added option to change root directory

Signed-off-by: quexeky <git@quexeky.dev>
This commit is contained in:
quexeky
2024-11-10 13:18:28 +11:00
parent 00b7179743
commit 1aa52c0a21
3 changed files with 30 additions and 6 deletions

View File

@ -8,6 +8,7 @@
<input placeholder="GAME ID" v-model="gameId" />
<input placeholder="VERSION NAME" v-model="versionName" />
<input placeholder="STATUS" v-model="status" />
<input placeholder="NEW ROOT DIR" v-model="newRootDir" />
<button
class="w-full rounded-md p-4 bg-blue-600 text-white"
@ -36,6 +37,12 @@
>
Set game download progress
</button>
<button
class="w-full rounded-md p-4 bg-blue-600 text-white"
@click="changeRootDirectoryWrapper"
>
Change root download location
</button>
</template>
<script setup lang="ts">
@ -44,6 +51,8 @@ import { invoke } from "@tauri-apps/api/core";
const gameId = ref("");
const versionName = ref("");
const status = ref("");
const newRootDir = ref("");
async function queueGame() {
await invoke("queue_game_download", {
@ -63,7 +72,7 @@ function queueGameWrapper() {
}
async function startGameDownloads() {
console.log("Downloading Games");
await invoke("start_game_downloads", { maxThreads: 4 })
await invoke("start_game_downloads", { maxThreads: 4 });
console.log("Finished downloading games");
}
function startGameDownloadsWrapper() {
@ -83,7 +92,7 @@ function cancelGameDownloadWrapper() {
}
async function getGameDownloadProgress() {
console.log("Getting game download status");
await invoke("get_game_download_progress", { gameId: gameId.value })
await invoke("get_game_download_progress", { gameId: gameId.value });
}
function getGameDownloadProgressWrapper() {
getGameDownloadProgress()
@ -106,7 +115,7 @@ function getGameDownloadProgressWrapper() {
async function setGameDownloadStatus(status: string) {
console.log("Setting game download status");
await invoke("set_download_state", { gameId: gameId.value, status: status })
await invoke("set_download_state", { gameId: gameId.value, status: status });
}
function setGameDownloadStatusWrapper() {
console.log("Called setGameDownloadWrapper");
@ -116,4 +125,15 @@ function setGameDownloadStatusWrapper() {
console.log(e)
})
}
async function changeRootDirectory() {
console.log("Changing root directory");
await invoke("change_root_directory", { newDir: newRootDir.value });
}
function changeRootDirectoryWrapper() {
changeRootDirectory()
.then(() => {})
.catch((e) => {
console.log(e)
})
}
</script>

View File

@ -6,11 +6,12 @@ use std::{
};
use directories::BaseDirs;
use log::info;
use rustbreak::{deser::Bincode, PathDatabase};
use serde::{Deserialize, Serialize};
use url::Url;
use crate::DB;
use crate::{AppState, DB};
#[derive(serde::Serialize, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
@ -91,7 +92,9 @@ impl DatabaseImpls for DatabaseInterface {
}
}
fn change_root_directory<T: Into<PathBuf>>(new_dir: T) {
#[tauri::command]
pub fn change_root_directory(new_dir: String) {
info!("Changed root directory to {}", new_dir);
let mut lock = DATA_ROOT_DIR.lock().unwrap();
*lock = new_dir.into();
}

View File

@ -10,7 +10,7 @@ mod tests;
use crate::db::DatabaseImpls;
use crate::downloads::download_agent::GameDownloadAgent;
use auth::{auth_initiate, generate_authorization_header, recieve_handshake};
use db::{DatabaseInterface, DATA_ROOT_DIR};
use db::{change_root_directory, DatabaseInterface, DATA_ROOT_DIR};
use downloads::download_commands::*;
use env_logger::Env;
use http::{header::*, response::Builder as ResponseBuilder};
@ -119,6 +119,7 @@ pub fn run() {
// Library
fetch_library,
fetch_game,
change_root_directory,
// Downloads
queue_game_download,
start_game_downloads,