chore: add update dialog

This commit is contained in:
2025-07-07 09:41:42 +02:00
parent 43160800ce
commit 15eb9424d4
13 changed files with 185 additions and 11 deletions

33
src/lib/api/git.ts Normal file
View File

@@ -0,0 +1,33 @@
import type { Release } from '@/types';
import { betterFetch } from '@better-fetch/fetch';
import semver from 'semver';
const ENDPOINT = 'https://git.ez-pp.farm/';
const timeout = 5000; // 5 seconds;
export const git = {
hasUpdate: async (version: string): Promise<Release | undefined> => {
try {
const request = await betterFetch<Release[]>(
`${ENDPOINT}api/v1/repos/EZPPFarm/EZPPLauncher/releases?limit=1`,
{
timeout,
headers: {
'User-Agent': 'EZPPLauncher',
},
}
);
if (request.error) return undefined;
const latestRelease = request.data[0];
if (!latestRelease) return undefined;
const hasUpdate = semver.lt(version, latestRelease.tag_name);
return hasUpdate ? latestRelease : undefined;
} catch {
return undefined;
}
},
};

View File

@@ -6,6 +6,8 @@
import { getCurrentWindow } from '@tauri-apps/api/window';
import { onMount } from 'svelte';
import { launcherVersion } from '@/global';
import Badge from '../badge/badge.svelte';
onMount(() => {
const appWindow = getCurrentWindow();
@@ -18,9 +20,10 @@
</script>
<div data-tauri-drag-region class="titlebar z-[60] border-b border-theme-800/90">
<div class="mr-auto ms-2 flex flex-row gap-2 items-center text-[1.05rem] font-semibold">
<div class="mr-auto ms-2 flex flex-row gap-2 items-center text-[1.05rem] font-semibold pointer-events-none">
<img src={Logo} alt="EZPP Launcher Logo" class="h-11 w-11 inline-block" />
<span>EZPPLauncher</span>
<Badge class="!text-[0.6rem] py-[0.5px] bg-primary-500 hover:bg-primary-500">{$launcherVersion}</Badge>
</div>
<div class="titlebar-button rounded-lg transition-colors duration-75" id="titlebar-minimize">
<Minimize size={18} />

View File

@@ -2,9 +2,13 @@ import { writable } from 'svelte/store';
import { ezppfarm } from './api/ezpp';
import type { Component } from 'svelte';
import Loading from '../pages/Loading.svelte';
import type { Release } from './types';
export const currentView = writable<Component>(Loading);
export const launcherVersion = writable<string>('');
export const newVersion = writable<Release | undefined>(undefined);
export const currentLoadingInfo = writable<string>('Initializing...');
export const firstStartup = writable<boolean>(false);

View File

@@ -110,3 +110,6 @@ export const isOsuRunning = async () => {
const result = await invoke('is_osu_running');
return typeof result === 'boolean' ? result : false;
};
export const getLauncherVersion = async () => await invoke<string>('get_launcher_version');
export const exit = async () => await invoke('exit');

View File

@@ -134,3 +134,54 @@ export type UpdateStatus = {
size: number;
progress: number;
};
export type Release = {
id: number;
tag_name: string;
target_commitish: string;
name: string;
body: string;
url: string;
html_url: string;
tarball_url: string;
zipball_url: string;
upload_url: string;
draft: boolean;
prerelease: boolean;
created_at: Date;
published_at: Date;
author: {
id: number;
login: string;
login_name: string;
source_id: number;
full_name: string;
email: string;
avatar_url: string;
html_url: string;
language: string;
is_admin: boolean;
last_login: Date;
created: Date;
restricted: boolean;
active: boolean;
prohibit_login: boolean;
location: string;
website: string;
description: string;
visibility: string;
followers_count: number;
following_count: number;
starred_repos_count: number;
username: string;
};
assets: {
id: number;
name: string;
size: number;
download_count: number;
created_at: Date;
uuid: string;
browser_download_url: string;
}[];
};