diff --git a/app.vue b/app.vue index b921045..9c11de6 100644 --- a/app.vue +++ b/app.vue @@ -6,7 +6,9 @@ diff --git a/composables/downloads.ts b/composables/downloads.ts new file mode 100644 index 0000000..860a8c3 --- /dev/null +++ b/composables/downloads.ts @@ -0,0 +1,27 @@ +import { listen } from "@tauri-apps/api/event"; + +export type QueueState = { + queue: Array<{ id: string; status: string; progress: number | null }>; + status: string; +}; + +export type StatsState = { + speed: number; // Bytes per second + time: number; // Seconds, +}; + +export const useQueueState = () => + useState("queue", () => ({ queue: [], status: "Unknown" })); + +export const useStatsState = () => + useState("stats", () => ({ speed: 0, time: 0 })); + +listen("update_queue", (event) => { + const queue = useQueueState(); + queue.value = event.payload as QueueState; +}); + +listen("update_stats", (event) => { + const stats = useStatsState(); + stats.value = event.payload as StatsState; +}); diff --git a/composables/queue.ts b/composables/queue.ts deleted file mode 100644 index 0487260..0000000 --- a/composables/queue.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { listen } from "@tauri-apps/api/event"; - -export type QueueState = { - queue: Array<{ id: string; status: string, progress: number | null }>; -}; - -export const useQueueState = () => - useState("queue", () => ({ queue: [] })); - -listen("update_queue", (event) => { - const queue = useQueueState(); - queue.value = event.payload as QueueState; -}); diff --git a/composables/state-navigation.ts b/composables/state-navigation.ts index 790d258..f7a9b4b 100644 --- a/composables/state-navigation.ts +++ b/composables/state-navigation.ts @@ -1,4 +1,5 @@ import { listen } from "@tauri-apps/api/event"; +import { data } from "autoprefixer"; import { AppStatus, type AppState } from "~/types"; export function setupHooks() { @@ -18,6 +19,20 @@ export function setupHooks() { router.push("/store"); }); + listen("download_error", (event) => { + createModal( + ModalType.Notification, + { + title: "Drop encountered an error while downloading", + description: `Drop encountered an error while downloading your game: "${( + event.payload as unknown as string + ).toString()}"`, + buttonText: "Close" + }, + (e, c) => c() + ); + }); + /* document.addEventListener("contextmenu", (event) => { diff --git a/gamepad.ts b/gamepad.ts new file mode 100644 index 0000000..5218db9 --- /dev/null +++ b/gamepad.ts @@ -0,0 +1,67 @@ +import gameControl, { XBoxButton, Button, type GCGamepad } from 'esm-gamecontroller.js'; + +let mainGamepad: Ref = ref(undefined); + +let buttonIndex = 0; +const buttons = computed((): any[] => { + let as = document.getElementsByTagName('a'); + let buttons = document.getElementsByTagName('button'); + return [].concat(Array.from(as)).concat(Array.from(buttons)); +}) + +const wrap = (num: number, min: number, max: number) => ((((num - min) % (max - min)) + (max - min)) % (max - min)) + min; + +setInterval(() => { + mainGamepad.value = navigator.getGamepads().filter(g => g !== null)[0]?.axes[1]; + console.log(navigator.getGamepads().filter(g => g !== null)[0]?.axes) + }, 100); + +watch(mainGamepad, (v) => { + console.log(v) + if (!v || v == 0) return; + buttonIndex = wrap(buttonIndex + v > 0 ? 1 : -1, 0, buttons.value.length); + + console.log(`Focusing ${buttonIndex}`) + console.log(buttons.value[buttonIndex]); + + buttons.value[buttonIndex].focus() +}) + + + +/* +setInterval(() => { + console.log(gamepads[0]); + console.log(gamepads[0].checkStatus()) +}, 1000); +*/ + +/* +window.ongamepadconnected = (e) => { + console.log("ongamepadconnected", e); +} + + +function selectButton(index: number) { + buttonIndex = (buttonIndex + index) % buttons.value.length; + console.log(`Selecting button ${buttonIndex}`); + buttons.value[buttonIndex].focus() +} + +function processGamepads() { + while (true) { + console.log("Processing gamepads"); + let gamepad = navigator.getGamepads()[0]; + if (!gamepad) continue; + let direction = gamepad.axes[1]; + if (direction > 0.1) { + selectButton(1) + console.log("Selecting button 1") + } + else if (direction < -0.1) { + selectButton(-1) + console.log("Selecting button -1") + } + } +} +*/ \ No newline at end of file diff --git a/package.json b/package.json index 7226f0f..fb6e428 100644 --- a/package.json +++ b/package.json @@ -14,15 +14,19 @@ "dependencies": { "@headlessui/vue": "^1.7.23", "@heroicons/vue": "^2.1.5", + "@maulingmonkey/gamepad": "^0.0.5", "@nuxtjs/tailwindcss": "^6.12.2", "@tauri-apps/api": ">=2.0.0", "@tauri-apps/plugin-deep-link": "~2", "@tauri-apps/plugin-dialog": "^2.0.1", + "@tauri-apps/plugin-os": "~2", "@tauri-apps/plugin-shell": ">=2.0.0", + "esm-gamecontroller.js": "^1.0.4", + "gamepad-events": "^0.7.0", "markdown-it": "^14.1.0", - "moment": "^2.30.1", "nuxt": "^3.13.0", "scss": "^0.2.4", + "tauri-plugin-gamepad-api": "^0.0.5", "vue": "latest", "vue-router": "latest", "vuedraggable": "^4.1.0" diff --git a/pages/library/[id]/index.vue b/pages/library/[id]/index.vue index a770ac8..4cc2e7e 100644 --- a/pages/library/[id]/index.vue +++ b/pages/library/[id]/index.vue @@ -20,8 +20,9 @@