From c1ebbc4b02c2e4fcb81661f2c0e87cd4f3f71147 Mon Sep 17 00:00:00 2001 From: JSON Derulo <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Tue, 21 Jan 2025 18:52:51 -0500 Subject: Initial commit --- src/index.tsx | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/types.d.ts | 14 +++++++ 2 files changed, 129 insertions(+) create mode 100755 src/index.tsx create mode 100644 src/types.d.ts (limited to 'src') diff --git a/src/index.tsx b/src/index.tsx new file mode 100755 index 0000000..16cd6cb --- /dev/null +++ b/src/index.tsx @@ -0,0 +1,115 @@ +import { + ButtonItem, + PanelSection, + PanelSectionRow, + Navigation, + staticClasses +} from "@decky/ui"; +import { + addEventListener, + removeEventListener, + callable, + definePlugin, + toaster, + // routerHook +} from "@decky/api" +import { useState } from "react"; +import { FaShip } from "react-icons/fa"; + +// import logo from "../assets/logo.png"; + +// This function calls the python function "add", which takes in two numbers and returns their sum (as a number) +// Note the type annotations: +// the first one: [first: number, second: number] is for the arguments +// the second one: number is for the return value +const add = callable<[first: number, second: number], number>("add"); + +// This function calls the python function "start_timer", which takes in no arguments and returns nothing. +// It starts a (python) timer which eventually emits the event 'timer_event' +const startTimer = callable<[], void>("start_timer"); + +function Content() { + const [result, setResult] = useState(); + + const onClick = async () => { + const result = await add(Math.random(), Math.random()); + setResult(result); + }; + + return ( + + + + {result ?? "Add two numbers via Python"} + + + + startTimer()} + > + {"Start Python timer"} + + + + {/* +
+ +
+
*/} + + {/* + { + Navigation.Navigate("/decky-plugin-test"); + Navigation.CloseSideMenus(); + }} + > + Router + + */} +
+ ); +}; + +export default definePlugin(() => { + console.log("Template plugin initializing, this is called once on frontend startup") + + // serverApi.routerHook.addRoute("/decky-plugin-test", DeckyPluginRouterTest, { + // exact: true, + // }); + + // Add an event listener to the "timer_event" event from the backend + const listener = addEventListener<[ + test1: string, + test2: boolean, + test3: number + ]>("timer_event", (test1, test2, test3) => { + console.log("Template got timer_event with:", test1, test2, test3) + toaster.toast({ + title: "template got timer_event", + body: `${test1}, ${test2}, ${test3}` + }); + }); + + return { + // The name shown in various decky menus + name: "Test Plugin", + // The element displayed at the top of your plugin's menu + titleView:
Decky Example Plugin
, + // The content of your plugin's menu + content: , + // The icon displayed in the plugin list + icon: , + // The function triggered when your plugin unloads + onDismount() { + console.log("Unloading") + removeEventListener("timer_event", listener); + // serverApi.routerHook.removeRoute("/decky-plugin-test"); + }, + }; +}); diff --git a/src/types.d.ts b/src/types.d.ts new file mode 100644 index 0000000..dfc0472 --- /dev/null +++ b/src/types.d.ts @@ -0,0 +1,14 @@ +declare module "*.svg" { + const content: string; + export default content; +} + +declare module "*.png" { + const content: string; + export default content; +} + +declare module "*.jpg" { + const content: string; + export default content; +} -- cgit v1.2.3