From 3f229687f3c5dd927fb362cb8db99683870692df Mon Sep 17 00:00:00 2001 From: quexeky Date: Sat, 4 Jan 2025 15:47:14 +1100 Subject: [PATCH] feat(download manager): Added generic download manager Signed-off-by: quexeky --- desktop/composables/downloads.ts | 5 +- desktop/composables/game.ts | 24 +-- desktop/pages/queue.vue | 28 ++-- desktop/src-tauri/Cargo.lock | 9 +- desktop/src-tauri/Cargo.toml | 1 + desktop/src-tauri/src/db.rs | 28 ++-- .../src/download_manager/download_manager.rs | 2 +- .../download_manager_builder.rs | 65 +++++--- .../src/download_manager/downloadable.rs | 6 +- .../download_manager/downloadable_metadata.rs | 7 +- .../src-tauri/src/downloads/download_agent.rs | 109 +++++++++++-- .../src/downloads/download_commands.rs | 4 +- desktop/src-tauri/src/lib.rs | 18 +-- desktop/src-tauri/src/library.rs | 144 +++++++++--------- .../src-tauri/src/process/process_commands.rs | 16 +- .../src-tauri/src/process/process_manager.rs | 42 ++--- desktop/src-tauri/src/state.rs | 31 ++-- desktop/src-tauri/src/tools/tool.rs | 4 +- desktop/types.ts | 13 ++ desktop/utils/generateGameMeta.ts | 9 ++ 20 files changed, 363 insertions(+), 202 deletions(-) create mode 100644 desktop/utils/generateGameMeta.ts diff --git a/desktop/composables/downloads.ts b/desktop/composables/downloads.ts index 860a8c3c..55de7fb7 100644 --- a/desktop/composables/downloads.ts +++ b/desktop/composables/downloads.ts @@ -1,7 +1,8 @@ import { listen } from "@tauri-apps/api/event"; +import type { DownloadableMetadata } from "~/types"; export type QueueState = { - queue: Array<{ id: string; status: string; progress: number | null }>; + queue: Array<{ meta: DownloadableMetadata; status: string; progress: number | null }>; status: string; }; @@ -24,4 +25,4 @@ listen("update_queue", (event) => { listen("update_stats", (event) => { const stats = useStatsState(); stats.value = event.payload as StatsState; -}); +}); \ No newline at end of file diff --git a/desktop/composables/game.ts b/desktop/composables/game.ts index c2ffc0c4..0335a7a0 100644 --- a/desktop/composables/game.ts +++ b/desktop/composables/game.ts @@ -13,6 +13,7 @@ export type SerializedGameStatus = [ ]; export const parseStatus = (status: SerializedGameStatus): GameStatus => { + console.log(status); if (status[0]) { return { type: status[0].type, @@ -28,28 +29,29 @@ export const parseStatus = (status: SerializedGameStatus): GameStatus => { } }; -export const useGame = async (id: string) => { - if (!gameRegistry[id]) { +export const useGame = async (gameId: string) => { + if (!gameRegistry[gameId]) { const data: { game: Game; status: SerializedGameStatus } = await invoke( "fetch_game", { - id, + gameId, } ); - gameRegistry[id] = data.game; - if (!gameStatusRegistry[id]) { - gameStatusRegistry[id] = ref(parseStatus(data.status)); + gameRegistry[gameId] = data.game; + if (!gameStatusRegistry[gameId]) { + gameStatusRegistry[gameId] = ref(parseStatus(data.status)); - listen(`update_game/${id}`, (event) => { + listen(`update_game/${gameId}`, (event) => { const payload: { status: SerializedGameStatus; } = event.payload as any; - gameStatusRegistry[id].value = parseStatus(payload.status); + console.log(payload.status); + gameStatusRegistry[gameId].value = parseStatus(payload.status); }); } } - const game = gameRegistry[id]; - const status = gameStatusRegistry[id]; + const game = gameRegistry[gameId]; + const status = gameStatusRegistry[gameId]; return { game, status }; -}; +}; \ No newline at end of file diff --git a/desktop/pages/queue.vue b/desktop/pages/queue.vue index 52574dd1..d78967c1 100644 --- a/desktop/pages/queue.vue +++ b/desktop/pages/queue.vue @@ -14,19 +14,19 @@