summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAAGaming <aagaming@riseup.net>2024-06-13 18:11:44 -0400
committerAAGaming <aagaming@riseup.net>2024-06-13 18:31:08 -0400
commitb939274d157257d0a57b339193d961b39ded6207 (patch)
tree8d8fa1ac4ca672b7ced3042fb5f9ce1da7e99dee /src
parentcbd489150fc2f721fe788ef6d58b8b792843e7d0 (diff)
downloaddecky-bazzite-buddy-b939274d157257d0a57b339193d961b39ded6207.tar.gz
decky-bazzite-buddy-b939274d157257d0a57b339193d961b39ded6207.zip
support new APIs fully
Diffstat (limited to 'src')
-rwxr-xr-xsrc/index.tsx110
1 files changed, 54 insertions, 56 deletions
diff --git a/src/index.tsx b/src/index.tsx
index b43e86a..9bd8951 100755
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -1,67 +1,63 @@
import {
ButtonItem,
- definePlugin,
- DialogButton,
- Menu,
- MenuItem,
- Navigation,
PanelSection,
PanelSectionRow,
- ServerAPI,
- showContextMenu,
+ Router,
+ // ServerAPI,
staticClasses,
-} from "decky-frontend-lib";
-import { VFC } from "react";
+} from "@decky/ui";
+import {
+ addEventListener,
+ removeEventListener,
+ callable,
+ definePlugin,
+ toaster,
+ // routerHook
+} from "@decky/api"
+// import { call, callable } from "@decky/backend";
+import { useState } from "react";
import { FaShip } from "react-icons/fa";
-import logo from "../assets/logo.png";
+// import logo from "../assets/logo.png";
// interface AddMethodArgs {
// left: number;
// right: number;
// }
+const add = callable<[first: number, second: number], number>("add");
+const startTimer = callable<[], void>("start_timer");
+function Content() {
+ const [result, setResult] = useState<number | undefined>();
-const Content: VFC<{ serverAPI: ServerAPI }> = ({serverAPI}) => {
- // const [result, setResult] = useState<number | undefined>();
-
- // const onClick = async () => {
- // const result = await serverAPI.callPluginMethod<AddMethodArgs, number>(
- // "add",
- // {
- // left: 2,
- // right: 2,
- // }
- // );
- // if (result.success) {
- // setResult(result.result);
- // }
- // };
+ const onClick = async () => {
+ const result = await add(Math.random(), Math.random());
+ setResult(result);
+ };
return (
<PanelSection title="Panel Section">
<PanelSectionRow>
<ButtonItem
layout="below"
- onClick={(e) =>
- showContextMenu(
- <Menu label="Menu" cancelText="CAAAANCEL" onCancel={() => {}}>
- <MenuItem onSelected={() => {}}>Item #1</MenuItem>
- <MenuItem onSelected={() => {}}>Item #2</MenuItem>
- <MenuItem onSelected={() => {}}>Item #3</MenuItem>
- </Menu>,
- e.currentTarget ?? window
- )
- }
+ onClick={onClick}
>
- Server says yolo
+ {result || "Add two numbers via Python"}
</ButtonItem>
</PanelSectionRow>
-
<PanelSectionRow>
+ <ButtonItem
+ layout="below"
+ onClick={() => startTimer()}
+ >
+ {"Start Python timer"}
+ </ButtonItem>
+ </PanelSectionRow>
+
+ {/* <PanelSectionRow>
<div style={{ display: "flex", justifyContent: "center" }}>
<img src={logo} />
</div>
- </PanelSectionRow>
+ </PanelSectionRow> */}
<PanelSectionRow>
<ButtonItem
@@ -78,28 +74,30 @@ const Content: VFC<{ serverAPI: ServerAPI }> = ({serverAPI}) => {
);
};
-const DeckyPluginRouterTest: VFC = () => {
- return (
- <div style={{ marginTop: "50px", color: "white" }}>
- Hello World!
- <DialogButton onClick={() => Navigation.NavigateToLibraryTab()}>
- Go to Library
- </DialogButton>
- </div>
- );
-};
-
-export default definePlugin((serverApi: ServerAPI) => {
- serverApi.routerHook.addRoute("/decky-plugin-test", DeckyPluginRouterTest, {
- exact: true,
+export default definePlugin(() => {
+ // serverApi.routerHook.addRoute("/decky-plugin-test", DeckyPluginRouterTest, {
+ // exact: true,
+ // });
+ // console.log("init plugin", call, callable)
+ const listener = addEventListener<[
+ test1: string,
+ test2: boolean,
+ test3: number
+ ]>("test_event", (test1, test2, test3) => {
+ console.log("Template got event", test1, test2, test3)
+ toaster.toast({
+ title: "template got event",
+ body: `${test1}, ${test2}, ${test3}`
+ });
});
-
return {
- title: <div className={staticClasses.Title}>Example Plugin</div>,
- content: <Content serverAPI={serverApi} />,
+ title: <div className={staticClasses.Title}>API v2 Example Plugin</div>,
+ content: <Content />,
icon: <FaShip />,
onDismount() {
- serverApi.routerHook.removeRoute("/decky-plugin-test");
+ console.log("Unloading")
+ removeEventListener("test_event", listener);
+ // serverApi.routerHook.removeRoute("/decky-plugin-test");
},
};
});