summaryrefslogtreecommitdiff
path: root/frontend/src/updater.ts
blob: dd37f0b4999fca72da8f44e98f74c3b6c415971c (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
import { sleep } from 'decky-frontend-lib';

export enum Branches {
  Release,
  Prerelease,
  Nightly,
}

export interface DeckyUpdater {
  updateProgress: (val: number) => void;
  finish: () => void;
}

export interface VerInfo {
  current: string;
  remote: {
    assets: {
      browser_download_url: string;
      created_at: string;
    }[];
    name: string;
    body: string;
    prerelease: boolean;
    published_at: string;
    tag_name: string;
  } | null;
  updatable: boolean;
}

export async function callUpdaterMethod(methodName: string, args = {}) {
  const response = await fetch(`http://127.0.0.1:1337/updater/${methodName}`, {
    method: 'POST',
    credentials: 'include',
    headers: {
      'Content-Type': 'application/json',
      Authentication: window.deckyAuthToken,
    },
    body: JSON.stringify(args),
  });

  return response.json();
}

export async function finishUpdate() {
  callUpdaterMethod('do_restart');
  await sleep(3000);
  location.reload();
}