mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2025-11-14 00:31:33 +10:00
feat(download ui): debug queue interface
This commit is contained in:
31
composables/game.ts
Normal file
31
composables/game.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { listen } from "@tauri-apps/api/event";
|
||||
import type { Game, GameStatus } from "~/types";
|
||||
|
||||
const gameRegistry: { [key: string]: Game } = {};
|
||||
|
||||
const gameStatusRegistry: { [key: string]: Ref<GameStatus> } = {};
|
||||
|
||||
export const useGame = async (id: string) => {
|
||||
if (!gameRegistry[id]) {
|
||||
const data: { game: Game; status: GameStatus } = await invoke(
|
||||
"fetch_game",
|
||||
{
|
||||
id,
|
||||
}
|
||||
);
|
||||
gameRegistry[id] = data.game;
|
||||
if (!gameStatusRegistry[id]) {
|
||||
gameStatusRegistry[id] = ref(data.status);
|
||||
|
||||
listen(`update_game/${id}`, (event) => {
|
||||
const payload: { status: GameStatus } = event.payload as any;
|
||||
gameStatusRegistry[id].value = payload.status;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const game = gameRegistry[id];
|
||||
const status = gameStatusRegistry[id];
|
||||
return { game, status };
|
||||
};
|
||||
Reference in New Issue
Block a user