From 229fd31de69ab2aa0dac659dbf696f1127066430 Mon Sep 17 00:00:00 2001 From: heixiansen Date: Thu, 27 Feb 2025 18:05:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=89=88=E6=9C=AC=E5=8F=B7?= =?UTF-8?q?=E6=9D=83=E9=87=8D=E6=A0=A1=E9=AA=8C=EF=BC=8C=E5=8F=91=E5=B8=83?= =?UTF-8?q?1.4.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composables/tray.ts | 58 +++++++++++++++++++-------------------- src-tauri/tauri.conf.json | 2 +- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/composables/tray.ts b/composables/tray.ts index 48d1c15..5e2ab16 100644 --- a/composables/tray.ts +++ b/composables/tray.ts @@ -31,13 +31,10 @@ export async function useTray(init: boolean = false, beforExit: Function, handle tooltip: `EasyTierGame\n${pkg.version}`, title: `EasyTierGame\n${pkg.version}`, id: DEFAULT_TRAY_NAME, - menu: await Menu.new({ - id: "main", - items: await generateMenuItem(beforExit, handleConnection), - }), - action: async (e) => { + menu: await Menu.new({ id: "main", items: await generateMenuItem(beforExit, handleConnection) }), + action: async e => { toggleVisibility(); - }, + } }); } } catch (error) { @@ -48,18 +45,13 @@ export async function useTray(init: boolean = false, beforExit: Function, handle if (init) { tray.setTooltip(`EasyTierGame\n${pkg.version}`); tray.setShowMenuOnLeftClick(false); - tray.setMenu( - await Menu.new({ - id: "main", - items: await generateMenuItem(beforExit, handleConnection), - }) - ); + tray.setMenu(await Menu.new({ id: "main", items: await generateMenuItem(beforExit, handleConnection) })); } return tray; } -export async function generateMenuItem(beforExit: Function, handleConnection:Function) { +export async function generateMenuItem(beforExit: Function, handleConnection: Function) { return [ await MenuItemShow("显示 / 隐藏"), await MenuItemExchangeConnection("联机 / 断开", handleConnection), @@ -67,7 +59,7 @@ export async function generateMenuItem(beforExit: Function, handleConnection:Fun await PredefinedMenuItem.new({ item: "Separator" }), await MenuItemPublicPeers(), await PredefinedMenuItem.new({ item: "Separator" }), - await MenuItemExit("退出", beforExit), + await MenuItemExit("退出", beforExit) ]; } @@ -80,18 +72,17 @@ export async function MenuItemExit(text: string, beforExit: Function) { await beforExit(); } await getCurrentWindow().close(); - }, + } }); } export async function MenuItemPublicPeers() { - return await MenuItem.new({ id: "publicPeers", text: "公共节点", action: async () => { - await open(import.meta.env.VITE_PUBLIC_PEERS_URL) - }, + await open(import.meta.env.VITE_PUBLIC_PEERS_URL); + } }); } @@ -101,17 +92,17 @@ export async function MenuItemShow(text: string) { text, action: async () => { await toggleVisibility(); - }, + } }); } -export async function MenuItemExchangeConnection(text: string, handleConnection:Function) { - const menutItem = await MenuItem.new({ +export async function MenuItemExchangeConnection(text: string, handleConnection: Function) { + const menutItem = await MenuItem.new({ id: "exchangeConnection", text, action: async () => { const isStart = await handleConnection(); - }, + } }); return menutItem; } @@ -122,12 +113,10 @@ export async function MenuItemTheme() { text: "主题切换", action: async () => { const mainStore = useMainStore(); - mainStore.$patch({ - theme: !mainStore.theme - }); + mainStore.$patch({ theme: !mainStore.theme }); // mainStore.$persist(); await setTheme(mainStore.theme); - }, + } }); } @@ -160,6 +149,17 @@ export async function setTrayTooltip(tray: TrayIcon | null, tooltip?: string | n } } +const versionWeight = (version: string) => { + version = version ? version.trim() : ""; + const [major = "0", minor = "0", patch = "0"] = version.split("."); + return parseInt(major) * 10000 + parseInt(minor) * 100 + parseInt(patch); +}; + +const versionDifference = (current: string, latest: string) => { + const currentVersion = versionWeight(current); + const latestVersion = versionWeight(latest); + return currentVersion - latestVersion; +}; export const checkNewVersion = async () => { const mainStore = useMainStore(); @@ -167,9 +167,9 @@ export const checkNewVersion = async () => { if (hasNewVersion.value) return; let [tagName, downloadUrl] = await invoke("fetch_game_releases"); mainStore.latestTagName = tagName; -} +}; export const hasNewVersion = computed(() => { const mainStore = useMainStore(); - return !!mainStore.latestTagName && mainStore.latestTagName != pkg.version; -}) \ No newline at end of file + return !!mainStore.latestTagName && versionDifference(pkg.version, mainStore.latestTagName) < 0 ; +}); diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index e975dae..2badc31 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -12,7 +12,7 @@ "app": { "windows": [ { - "title": "easytier-game 1.4.1", + "title": "easytier-game 1.4.2", "label": "main", "minWidth": 340, "width": 340,