From 3cbfae072cb364513a7fce6216a0483c19af7a0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=91=E5=85=88=E6=A3=AE?= Date: Tue, 17 Dec 2024 17:48:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0easytierGame=E5=8F=91?= =?UTF-8?q?=E5=B8=83=E6=96=B0=E7=89=88=E7=9A=84=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composables/tray.ts | 19 ++++++++++++++++++ package.json | 3 +-- pages/index.vue | 23 ++++++++++++--------- pnpm-lock.yaml | 10 ---------- src-tauri/Cargo.lock | 2 +- src-tauri/Cargo.toml | 2 +- src-tauri/src/lib.rs | 42 +++++++++++++++++++++++++++++++++++++++ src-tauri/tauri.conf.json | 4 ++-- 8 files changed, 80 insertions(+), 25 deletions(-) diff --git a/composables/tray.ts b/composables/tray.ts index eae2669..750d856 100644 --- a/composables/tray.ts +++ b/composables/tray.ts @@ -5,6 +5,9 @@ import pkg from "@/package.json"; import { setTheme } from "~/composables/theme"; import useMainStore from "@/stores/index"; import { resourceDir as getResourceDir, join } from "@tauri-apps/api/path"; +import { invoke } from "@tauri-apps/api/core"; +// import { ElConfirmPrimary } from "~/utils/element"; +// import { open } from "@tauri-apps/plugin-shell"; const DEFAULT_TRAY_NAME = "main"; @@ -141,3 +144,19 @@ export async function setTrayTooltip(tray: TrayIcon | null, tooltip?: string | n await tray.setTooltip(`EasyTierGame\n${pkg.version}`); } } + + +export const checkNewVersion = async () => { + let [tagName, downloadUrl] = await invoke("fetch_game_releases"); + if(tagName && pkg.version !== tagName) { + return true; //有新版 + // const [err] = await ElConfirmPrimary("有新版本是否下载?", "发现新版本", { + // confirmButtonText: "下载", + // cancelButtonText: "取消", + // }) + // if(!err) { + // open(downloadUrl); + // } + } + return false; //没有新版 +} \ No newline at end of file diff --git a/package.json b/package.json index abad253..5b0884d 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "private": true, "author": "leizi97", "description": "A simple network initiator based on Easytier", - "version": "1.3.0", + "version": "1.3.1", "scripts": { "dev": "nuxt dev --dotenv env/.env.dev --host 0.0.0.0", "build": "nuxt generate --dotenv env/.env.prod", @@ -19,7 +19,6 @@ "@tauri-apps/plugin-cli": "^2.0.0", "@tauri-apps/plugin-clipboard-manager": "^2.0.0", "@tauri-apps/plugin-fs": "~2", - "@tauri-apps/plugin-http": "^2.0.1", "@tauri-apps/plugin-log": "^2.0.0", "@tauri-apps/plugin-shell": "~2", "@tauri-apps/plugin-window-state": "~2", diff --git a/pages/index.vue b/pages/index.vue index bd25171..2deaeb0 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -310,14 +310,17 @@ 增强工具 - - EasytierGame主页 - + + + + EasytierGame主页 + + @@ -510,7 +513,7 @@ Folder } from "@element-plus/icons-vue"; import { reactive, onBeforeUnmount, onMounted, ref } from "vue"; - import { useTray, setTrayRunState, setTrayTooltip } from "~/composables/tray"; + import { useTray, setTrayRunState, setTrayTooltip, checkNewVersion } from "~/composables/tray"; import { getMatches } from "@tauri-apps/plugin-cli"; import { initStartWinIpBroadcast } from "~/composables/netcard"; import useMainStore from "@/stores/index"; @@ -548,6 +551,7 @@ // console.error(config); const protocols = supportProtocols(); const data = reactive<{ [key: string]: any; releaseList: Array> }>({ + hasNewVersion: false, //easytierGame有没有新版 logVisible: false, cidrVisible: false, advanceVisible: false, @@ -988,6 +992,7 @@ initPreventSleep(); mountedShow(); // 不需要await closePrevent(); + data.hasNewVersion = await checkNewVersion(); }); onBeforeUnmount(() => { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6babcc1..23866b9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -35,9 +35,6 @@ importers: '@tauri-apps/plugin-fs': specifier: ~2 version: 2.0.2 - '@tauri-apps/plugin-http': - specifier: ^2.0.1 - version: 2.0.1 '@tauri-apps/plugin-log': specifier: ^2.0.0 version: 2.0.0 @@ -1159,9 +1156,6 @@ packages: '@tauri-apps/plugin-fs@2.0.2': resolution: {integrity: sha512-4YZaX2j7ta81M5/DL8aN10kTnpUkEpkPo1FTYPT8Dd0ImHe3azM8i8MrtjrDGoyBYLPO3zFv7df/mSCYF8oA0Q==} - '@tauri-apps/plugin-http@2.0.1': - resolution: {integrity: sha512-j6IA3pVBybSCwPpsihpX4z8bs6PluuGtr06ahL/xy4D8HunNBTmRmadJrFOQi0gOAbaig4MkQ15nzNLBLy8R1A==} - '@tauri-apps/plugin-log@2.0.0': resolution: {integrity: sha512-C+NII9vzswqnOQE8k7oRtnaw0z5TZsMmnirRhXkCKDEhQQH9841Us/PC1WHtGiAaJ8za1A1JB2xXndEq/47X/w==} @@ -5063,10 +5057,6 @@ snapshots: dependencies: '@tauri-apps/api': 2.1.1 - '@tauri-apps/plugin-http@2.0.1': - dependencies: - '@tauri-apps/api': 2.1.1 - '@tauri-apps/plugin-log@2.0.0': dependencies: '@tauri-apps/api': 2.1.1 diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index c5c9c0c..23feaec 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -1227,7 +1227,7 @@ checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" [[package]] name = "easytier-game" -version = "1.3.0" +version = "1.3.1" dependencies = [ "log", "planif", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 2e741f4..079548d 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "easytier-game" -version = "1.3.0" +version = "1.3.1" homepage = "https://github.com/EasyTier/EasyTier" repository = "https://github.com/EasyTier/EasytierGame" description = "A simple network initiator based on Easytier" diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 0ddccee..04f656e 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -78,6 +78,47 @@ pub async fn fetch_releases() -> Result, Error> { response.json::>().await } +#[tauri::command(rename_all = "snake_case")] +async fn fetch_game_releases() -> [String; 2] { + // 创建HTTP客户端 + let client = Client::new(); + // 构建请求的URL + let url = format!("https://api.github.com/repos/Easytier/EasytierGame/releases",); + + // 发送HTTP GET请求 + if let Ok(response) = client + .get(&url) + .header("User-Agent", "Tauri-fetch") + .send() + .await + { + // 反序列化响应体为Release列表 + match response.json::>().await { + Ok(releases) => { + if releases.len() <= 0 { + return [String::from(""), String::from("")]; + } + let release = releases.first().unwrap(); + let tag_name = release.tag_name.as_str(); + let browser_download_url = release + .assets + .first() + .unwrap() + .browser_download_url + .as_str(); + [String::from(tag_name), String::from(browser_download_url)] + } + Err(_e) => { + log::error!("game release {}", _e.to_string()); + [String::from(""), String::from("")] + } + } + } else { + log::error!("failed to get game release"); + [String::from(""), String::from("")] + } +} + #[tauri::command(rename_all = "snake_case")] fn get_core_version() -> String { let core_path = get_tool_exe_path("\\easytier\\easytier-core.exe"); @@ -641,6 +682,7 @@ pub fn run() { stop_command, get_core_version, fetch_easytier_list, + fetch_game_releases, download_easytier_zip, get_members_by_cli, search_pid_by_pname, diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 37e8992..f9c7a1c 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -1,7 +1,7 @@ { "$schema": "../node_modules/@tauri-apps/cli/config.schema.json", "productName": "easytier-game", - "version": "1.3.0", + "version": "1.3.1", "identifier": "com.tauri.easytier-game", "build": { @@ -13,7 +13,7 @@ "app": { "windows": [ { - "title": "easytier-game 1.3.0", + "title": "easytier-game 1.3.1", "label": "main", "minWidth": 340, "width": 340,