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