From 15eb9424d45f6aba063696055ee9f229846531d9 Mon Sep 17 00:00:00 2001 From: HorizonCode Date: Mon, 7 Jul 2025 09:41:42 +0200 Subject: [PATCH] chore: add update dialog --- bun.lock | 4 ++ package.json | 2 + src-tauri/Cargo.lock | 2 +- src-tauri/Cargo.toml | 6 +-- src-tauri/src/commands.rs | 10 ++++ src-tauri/src/lib.rs | 13 +++-- src/lib/api/git.ts | 33 ++++++++++++ .../components/ui/titlebar/titlebar.svelte | 5 +- src/lib/global.ts | 4 ++ src/lib/osuUtil.ts | 3 ++ src/lib/types.ts | 51 ++++++++++++++++++ src/pages/Loading.svelte | 9 ++++ src/routes/+layout.svelte | 54 ++++++++++++++++++- 13 files changed, 185 insertions(+), 11 deletions(-) create mode 100644 src/lib/api/git.ts diff --git a/bun.lock b/bun.lock index 12cfa8b..87bbb7a 100644 --- a/bun.lock +++ b/bun.lock @@ -24,6 +24,7 @@ "osu-parsers": "4.1.7", "prettier-plugin-rust": "^0.1.9", "radix-icons-svelte": "1.2.1", + "semver": "^7.7.2", "svelte-confetti": "^2.0.0", }, "devDependencies": { @@ -35,6 +36,7 @@ "@sveltejs/vite-plugin-svelte": "5.1.0", "@tauri-apps/cli": "2.6.1", "@types/crypto-js": "^4.2.2", + "@types/semver": "^7.7.0", "autoprefixer": "10.4.21", "bits-ui": "^1.4.7", "clsx": "2.1.1", @@ -286,6 +288,8 @@ "@types/node": ["@types/node@20.19.1", "", { "dependencies": { "undici-types": "~6.21.0" } }, "sha512-jJD50LtlD2dodAEO653i3YF04NWak6jN3ky+Ri3Em3mGR39/glWiboM/IePaRbgwSfqM1TpGXfAg8ohn/4dTgA=="], + "@types/semver": ["@types/semver@7.7.0", "", {}, "sha512-k107IF4+Xr7UHjwDc7Cfd6PRQfbdkiRabXGRjo07b4WyPahFBZCZ1sE+BNxYIJPPg73UkfOsVOLwqVc/6ETrIA=="], + "@typescript-eslint/eslint-plugin": ["@typescript-eslint/eslint-plugin@8.35.1", "", { "dependencies": { "@eslint-community/regexpp": "^4.10.0", "@typescript-eslint/scope-manager": "8.35.1", "@typescript-eslint/type-utils": "8.35.1", "@typescript-eslint/utils": "8.35.1", "@typescript-eslint/visitor-keys": "8.35.1", "graphemer": "^1.4.0", "ignore": "^7.0.0", "natural-compare": "^1.4.0", "ts-api-utils": "^2.1.0" }, "peerDependencies": { "@typescript-eslint/parser": "^8.35.1", "eslint": "^8.57.0 || ^9.0.0", "typescript": ">=4.8.4 <5.9.0" } }, "sha512-9XNTlo7P7RJxbVeICaIIIEipqxLKguyh+3UbXuT2XQuFp6d8VOeDEGuz5IiX0dgZo8CiI6aOFLg4e8cF71SFVg=="], "@typescript-eslint/parser": ["@typescript-eslint/parser@8.35.1", "", { "dependencies": { "@typescript-eslint/scope-manager": "8.35.1", "@typescript-eslint/types": "8.35.1", "@typescript-eslint/typescript-estree": "8.35.1", "@typescript-eslint/visitor-keys": "8.35.1", "debug": "^4.3.4" }, "peerDependencies": { "eslint": "^8.57.0 || ^9.0.0", "typescript": ">=4.8.4 <5.9.0" } }, "sha512-3MyiDfrfLeK06bi/g9DqJxP5pV74LNv4rFTyvGDmT3x2p1yp1lOd+qYZfiRPIOf/oON+WRZR5wxxuF85qOar+w=="], diff --git a/package.json b/package.json index 9522b88..08d2d72 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "osu-parsers": "4.1.7", "prettier-plugin-rust": "^0.1.9", "radix-icons-svelte": "1.2.1", + "semver": "^7.7.2", "svelte-confetti": "^2.0.0" }, "devDependencies": { @@ -49,6 +50,7 @@ "@sveltejs/vite-plugin-svelte": "5.1.0", "@tauri-apps/cli": "2.6.1", "@types/crypto-js": "^4.2.2", + "@types/semver": "^7.7.0", "autoprefixer": "10.4.21", "bits-ui": "^1.4.7", "clsx": "2.1.1", diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 5a6add8..3ddf673 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -1081,7 +1081,7 @@ dependencies = [ [[package]] name = "ezpplauncher" -version = "0.1.0" +version = "3.0.0-beta.1" dependencies = [ "hardware-id", "md5", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 373b30b..7fa69b9 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "ezpplauncher" -version = "0.1.0" -description = "A Tauri App" -authors = ["you"] +version = "3.0.0-beta.1" +description = "EZPPLauncher redefined." +authors = ["HorizonCode"] edition = "2024" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index fec7d0e..82433b3 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -16,6 +16,11 @@ use crate::utils::{ set_osu_config_vals, set_osu_user_config_vals, }; +#[tauri::command] +pub fn get_launcher_version() -> String { + env!("CARGO_PKG_VERSION").to_string() +} + #[tauri::command] pub fn get_hwid() -> String { let hwid = get_id().unwrap(); @@ -624,3 +629,8 @@ pub fn is_osu_running() -> bool { pub fn open_url_in_browser(url: String) -> Result<(), String> { open::that(&url).map_err(|e| format!("Failed to open URL: {}", e)) } + +#[tauri::command] +pub fn exit(app: AppHandle) { + app.exit(0x0100); +} diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index c274b64..6e13043 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -4,10 +4,11 @@ use tauri::Manager; pub mod commands; pub mod utils; use crate::commands::{ - download_ezpp_launcher_update_files, find_osu_installation, get_beatmapsets_count, - get_ezpp_launcher_update_files, get_hwid, get_osu_release_stream, get_osu_skin, - get_osu_version, get_skins_count, is_osu_running, open_url_in_browser, replace_ui_files, - run_osu, run_osu_updater, set_osu_config_values, set_osu_user_config_values, valid_osu_folder, + download_ezpp_launcher_update_files, exit, find_osu_installation, get_beatmapsets_count, + get_ezpp_launcher_update_files, get_hwid, get_launcher_version, get_osu_release_stream, + get_osu_skin, get_osu_version, get_skins_count, is_osu_running, open_url_in_browser, + replace_ui_files, run_osu, run_osu_updater, set_osu_config_values, set_osu_user_config_values, + valid_osu_folder, }; #[cfg_attr(mobile, tauri::mobile_entry_point)] @@ -42,7 +43,9 @@ pub fn run() { download_ezpp_launcher_update_files, replace_ui_files, is_osu_running, - open_url_in_browser + open_url_in_browser, + get_launcher_version, + exit ]) .plugin(tauri_plugin_fs::init()) .plugin(tauri_plugin_dialog::init()) diff --git a/src/lib/api/git.ts b/src/lib/api/git.ts new file mode 100644 index 0000000..b90bbd3 --- /dev/null +++ b/src/lib/api/git.ts @@ -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 => { + try { + const request = await betterFetch( + `${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; + } + }, +}; diff --git a/src/lib/components/ui/titlebar/titlebar.svelte b/src/lib/components/ui/titlebar/titlebar.svelte index 095c4ee..d08e917 100644 --- a/src/lib/components/ui/titlebar/titlebar.svelte +++ b/src/lib/components/ui/titlebar/titlebar.svelte @@ -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 @@
-
+
EZPP Launcher Logo EZPPLauncher + {$launcherVersion}
diff --git a/src/lib/global.ts b/src/lib/global.ts index 2969333..bdff563 100644 --- a/src/lib/global.ts +++ b/src/lib/global.ts @@ -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(Loading); +export const launcherVersion = writable(''); +export const newVersion = writable(undefined); + export const currentLoadingInfo = writable('Initializing...'); export const firstStartup = writable(false); diff --git a/src/lib/osuUtil.ts b/src/lib/osuUtil.ts index 110ed94..620e420 100644 --- a/src/lib/osuUtil.ts +++ b/src/lib/osuUtil.ts @@ -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('get_launcher_version'); +export const exit = async () => await invoke('exit'); diff --git a/src/lib/types.ts b/src/lib/types.ts index 98c4825..a0d97d0 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -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; + }[]; +}; diff --git a/src/pages/Loading.svelte b/src/pages/Loading.svelte index 886539a..336de0b 100644 --- a/src/pages/Loading.svelte +++ b/src/pages/Loading.svelte @@ -7,6 +7,8 @@ currentSkin, currentView, firstStartup, + launcherVersion, + newVersion, osuBuild, osuStream, skins, @@ -34,6 +36,7 @@ getVersion, isValidOsuFolder, } from '@/osuUtil'; + import { git } from '@/api/git'; let ezppLogo: HTMLImageElement; let spinnerCircle: SVGCircleElement; @@ -139,6 +142,12 @@ } } + currentLoadingInfo.set('Checking for EZPPLauncher updates...'); + const launcherUpdate = await git.hasUpdate($launcherVersion); + if (launcherUpdate) { + newVersion.set(launcherUpdate); + } + animate(ezppLogo, { opacity: [1, 0], scale: [1, 1.05], diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 16e141d..6083340 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -1,7 +1,15 @@