summaryrefslogtreecommitdiff
path: root/frontend/src/store.tsx
blob: cc0e4cf04f50a3844ccac7605df69c0e3bd035f6 (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
50
51
52
53
54
55
56
57
58
import { Plugin } from './plugin';

export interface StorePluginVersion {
  name: string;
  hash: string;
}

export interface StorePlugin {
  id: number;
  name: string;
  versions: StorePluginVersion[];
  author: string;
  description: string;
  tags: string[];
  image_url: string;
}

// name: version
export type PluginUpdateMapping = Map<string, StorePluginVersion>;

export async function getPluginList(): Promise<StorePlugin[]> {
  let version = await window.DeckyPluginLoader.updateVersion();
  return fetch('https://plugins.deckbrew.xyz/plugins', {
    method: 'GET',
    headers: {
      'X-Decky-Version': version.current,
    },
  }).then((r) => r.json());
}

export async function installFromURL(url: string) {
  const splitURL = url.split('/');
  await window.DeckyPluginLoader.callServerMethod('install_plugin', {
    name: splitURL[splitURL.length - 1].replace('.zip', ''),
    artifact: url,
  });
}

export async function requestPluginInstall(plugin: string, selectedVer: StorePluginVersion) {
  await window.DeckyPluginLoader.callServerMethod('install_plugin', {
    name: plugin,
    artifact: `https://cdn.tzatzikiweeb.moe/file/steam-deck-homebrew/versions/${selectedVer.hash}.zip`,
    version: selectedVer.name,
    hash: selectedVer.hash,
  });
}

export async function checkForUpdates(plugins: Plugin[]): Promise<PluginUpdateMapping> {
  const serverData = await getPluginList();
  const updateMap = new Map<string, StorePluginVersion>();
  for (let plugin of plugins) {
    const remotePlugin = serverData?.find((x) => x.name == plugin.name);
    if (remotePlugin && remotePlugin.versions?.length > 0 && plugin.version != remotePlugin?.versions?.[0]?.name) {
      updateMap.set(plugin.name, remotePlugin.versions[0]);
    }
  }
  return updateMap;
}