summaryrefslogtreecommitdiff
path: root/src/index.tsx
blob: e8db05779667db66a0a238d7d9c56d47d0b4d1e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { useState, useEffect } from "react";
import { PanelSection, PanelSectionRow, Dropdown, DropdownOption } from "@decky/ui";
import { callable, definePlugin } from "@decky/api";
import { FaShip } from "react-icons/fa";

const fetchInstalledGames = callable<[], string>("get_installed_games");

function Content() {
  const [games, setGames] = useState<DropdownOption[]>([]);
  const [selectedGame, setSelectedGame] = useState<DropdownOption | null>(null);

  useEffect(() => {
    const loadGames = async () => {
      const result = await fetchInstalledGames();
      const gameList = JSON.parse(result) as { appid: string; name: string }[];
      setGames(gameList.map(game => ({ data: game.appid, label: game.name })));
    };

    loadGames();
  }, []);

  return (
    <PanelSection title="Installed Games">
      <PanelSectionRow>
        <Dropdown
          rgOptions={games}
          selectedOption={selectedGame?.data || null}
          onChange={(option) => setSelectedGame(option)}
          strDefaultLabel="Select a game" // Placeholder equivalent
        />
      </PanelSectionRow>
      {selectedGame && (
        <PanelSectionRow>
          <div>You selected: {selectedGame.label}</div>
        </PanelSectionRow>
      )}
    </PanelSection>
  );
}

export default definePlugin(() => ({
  name: "Game Selector Plugin",
  titleView: <div>Game Selector Plugin</div>,
  content: <Content />,
  icon: <FaShip />,
  onDismount() {
    console.log("Plugin unmounted");
  },
}));