mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2025-11-14 16:51:18 +10:00
feat(downloads): Added function to take and set any game state
Signed-off-by: quexeky <git@quexeky.dev>
This commit is contained in:
@ -7,41 +7,34 @@
|
||||
</button>
|
||||
<input placeholder="GAME ID" v-model="gameId" />
|
||||
<input placeholder="VERSION NAME" v-model="versionName" />
|
||||
<input placeholder="STATUS" v-model="status" />
|
||||
|
||||
<button
|
||||
class="w-full rounded-md p-4 bg-blue-600 text-white"
|
||||
@click="startGameDownloadsWrapper"
|
||||
>
|
||||
Start Game Downloads
|
||||
</button>
|
||||
|
||||
<button
|
||||
class="w-full rounded-md p-4 bg-blue-600 text-white"
|
||||
@click="cancelGameDownloadWrapper"
|
||||
>
|
||||
Cancel game download
|
||||
</button>
|
||||
|
||||
<button
|
||||
class="w-full rounded-md p-4 bg-blue-600 text-white"
|
||||
@click="getGameDownloadProgressWrapper"
|
||||
>
|
||||
Get game download progress
|
||||
</button>
|
||||
|
||||
<button
|
||||
class="w-full rounded-md p-4 bg-blue-600 text-white"
|
||||
@click="pauseGameDownloadWrapper"
|
||||
@click="setGameDownloadStatusWrapper"
|
||||
>
|
||||
Pause game download
|
||||
</button>
|
||||
<button
|
||||
class="w-full rounded-md p-4 bg-blue-600 text-white"
|
||||
@click="resumeGameDownloadWrapper"
|
||||
>
|
||||
Resume game download
|
||||
</button>
|
||||
<button
|
||||
class="w-full rounded-md p-4 bg-blue-600 text-white"
|
||||
@click="setGameDownloadWrapper"
|
||||
>
|
||||
Set game download
|
||||
Set game download progress
|
||||
</button>
|
||||
|
||||
</template>
|
||||
@ -50,6 +43,7 @@ import { invoke } from "@tauri-apps/api/core";
|
||||
|
||||
const gameId = ref("");
|
||||
const versionName = ref("");
|
||||
const status = ref("");
|
||||
|
||||
async function queueGame() {
|
||||
await invoke("queue_game_download", {
|
||||
@ -79,13 +73,9 @@ function startGameDownloadsWrapper() {
|
||||
console.log(e)
|
||||
})
|
||||
}
|
||||
async function cancelGameDownload() {
|
||||
console.log("Cancelling game download");
|
||||
await invoke("cancel_specific_game_download", { gameId: gameId.value })
|
||||
}
|
||||
function cancelGameDownloadWrapper() {
|
||||
console.log("Triggered game cancel wrapper");
|
||||
cancelGameDownload()
|
||||
setGameDownloadStatus("Cancelled")
|
||||
.then(() => {})
|
||||
.catch((e) => {
|
||||
console.log(e)
|
||||
@ -101,37 +91,26 @@ function getGameDownloadProgressWrapper() {
|
||||
.catch((e) => {
|
||||
console.log(e)
|
||||
})
|
||||
}
|
||||
/* status can be any of the following values:
|
||||
Uninitialised,
|
||||
Queued,
|
||||
Paused,
|
||||
Manifest,
|
||||
Downloading,
|
||||
Finished,
|
||||
Stalled,
|
||||
Failed,
|
||||
Cancelled,
|
||||
*/
|
||||
|
||||
}
|
||||
async function pauseGameDownload() {
|
||||
console.log("Getting game download status");
|
||||
await invoke("pause_game_download", { gameId: gameId.value })
|
||||
}
|
||||
function pauseGameDownloadWrapper() {
|
||||
pauseGameDownload()
|
||||
.then(() => {})
|
||||
.catch((e) => {
|
||||
console.log(e)
|
||||
})
|
||||
|
||||
}
|
||||
async function resumeGameDownload() {
|
||||
console.log("Getting game download status");
|
||||
await invoke("resume_game_download", { gameId: gameId.value })
|
||||
}
|
||||
function resumeGameDownloadWrapper() {
|
||||
resumeGameDownload()
|
||||
.then(() => {})
|
||||
.catch((e) => {
|
||||
console.log(e)
|
||||
})
|
||||
}
|
||||
async function setGameDownload() {
|
||||
async function setGameDownloadStatus(status: string) {
|
||||
console.log("Setting game download status");
|
||||
await invoke("set_download_state", { gameId: gameId.value, status: "Paused" })
|
||||
await invoke("set_download_state", { gameId: gameId.value, status: status })
|
||||
}
|
||||
function setGameDownloadWrapper() {
|
||||
setGameDownload()
|
||||
function setGameDownloadStatusWrapper() {
|
||||
console.log("Called setGameDownloadWrapper");
|
||||
setGameDownloadStatus(status.value)
|
||||
.then(() => {})
|
||||
.catch((e) => {
|
||||
console.log(e)
|
||||
|
||||
@ -116,33 +116,14 @@ pub async fn get_game_download_progress(
|
||||
Ok(progress)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn pause_game_download(
|
||||
state: tauri::State<'_, Mutex<AppState>>,
|
||||
game_id: String,
|
||||
) -> Result<(), String> {
|
||||
get_game_download(state, game_id).change_state(GameDownloadState::Paused);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn resume_game_download(
|
||||
state: tauri::State<'_, Mutex<AppState>>,
|
||||
game_id: String,
|
||||
) -> Result<(), String> {
|
||||
get_game_download(state, game_id).change_state(GameDownloadState::Downloading);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
#[tauri::command]
|
||||
pub async fn set_download_state(
|
||||
state: tauri::State<'_, Mutex<AppState>>,
|
||||
game_id: String,
|
||||
status: GameDownloadState
|
||||
) -> Result<(), String> {
|
||||
info!("Setting game state");
|
||||
get_game_download(state, game_id).change_state(status);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@ -124,8 +124,6 @@ pub fn run() {
|
||||
start_game_downloads,
|
||||
cancel_specific_game_download,
|
||||
get_game_download_progress,
|
||||
resume_game_download,
|
||||
pause_game_download,
|
||||
set_download_state
|
||||
])
|
||||
.plugin(tauri_plugin_shell::init())
|
||||
|
||||
Reference in New Issue
Block a user