aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ui/src/stores/releases.svelte.ts
blob: c858abb87a8a16c8f8743663957f52daa8de9154 (plain) (blame)
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
import { invoke } from "@tauri-apps/api/core";

export interface GithubRelease {
  tag_name: string;
  name: string;
  published_at: string;
  body: string;
  html_url: string;
}

export class ReleasesState {
  releases = $state<GithubRelease[]>([]);
  isLoading = $state(false);
  isLoaded = $state(false);
  error = $state<string | null>(null);

  async loadReleases() {
    // If already loaded or currently loading, skip to prevent duplicate requests
    if (this.isLoaded || this.isLoading) return;

    this.isLoading = true;
    this.error = null;

    try {
      this.releases = await invoke<GithubRelease[]>("get_github_releases");
      this.isLoaded = true;
    } catch (e) {
      console.error("Failed to load releases:", e);
      this.error = String(e);
    } finally {
      this.isLoading = false;
    }
  }
}

export const releasesState = new ReleasesState();