diff --git a/bun.lockb b/bun.lockb index 6d803ae..0762783 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/frontend/src/windows/main/components/Updater.svelte b/frontend/src/windows/main/components/Updater.svelte index da665af..b009920 100644 --- a/frontend/src/windows/main/components/Updater.svelte +++ b/frontend/src/windows/main/components/Updater.svelte @@ -6,16 +6,17 @@ import { toast } from 'svelte-sonner'; import { version } from '../../../../../package.json'; import { loadSettings, saveSettings } from './settings'; - import { compareVersions, curlGet } from '../ts/utils'; + import { curlGet } from '../ts/utils'; import Link from './Link.svelte'; import { shell } from '../ts/tools/shell'; + import compare from 'semver-compare'; let showUpdatePopup = false; let updateVersion = version; let body = ''; async function checkForUpdate() { - const checkWifi = await shell(`if [[ "$(networksetup -getairportnetwork en0 | grep -o 'Current Wi-Fi Network:')" != "" ]]; then echo "true"; else echo "false"; fi`,[],{completeCommand: true}); + const checkWifi = await shell(`if ping -c 1 -W 1 8.8.8.8 &> /dev/null; then echo "true"; else echo "false"; fi`,[],{completeCommand: true}); if (!checkWifi.stdOut.includes('true')) { toast.error('Could not connect to internet'); return; @@ -26,14 +27,13 @@ }); if (releases.message) return; for (const re of releases) { - if (compareVersions(re.tag_name, updateVersion) > 0) { + if (compare(re.tag_name, updateVersion) === 1) { updateVersion = re.tag_name; body = re.body; } } if (updateVersion === version) return; - const compare = compareVersions(updateVersion, version); - if (compare > 0) { + if (compare(updateVersion, version) === 1) { console.info(`[Updater] A new release is available: ${updateVersion}`); const settings = await loadSettings('updating'); if (settings) { diff --git a/frontend/src/windows/main/ts/utils.ts b/frontend/src/windows/main/ts/utils.ts index f908291..d157842 100644 --- a/frontend/src/windows/main/ts/utils.ts +++ b/frontend/src/windows/main/ts/utils.ts @@ -34,32 +34,6 @@ export async function curlGet(url: string): Promise { return res; } -/** - * Compare two semantic version strings. - * - * @param {string} v1 - The first version string. - * @param {string} v2 - The second version string. - * @returns {number} -1 if v1 < v2, 1 if v1 > v2, 0 if they are equal. - */ -export function compareVersions(v1: string, v2: string): number { - const v1Parts: number[] = v1.split('.').map(Number); - const v2Parts: number[] = v2.split('.').map(Number); - - for (let i = 0; i < Math.max(v1Parts.length, v2Parts.length); i++) { - const v1Part: number = v1Parts[i] || 0; - const v2Part: number = v2Parts[i] || 0; - - if (v1Part > v2Part) { - return 1; - } - if (v1Part < v2Part) { - return -1; - } - } - - return 0; -} - export function sleep(ms = 0) { return new Promise((resolve) => setTimeout(resolve, ms)); } diff --git a/package.json b/package.json index e1f2561..5efd447 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "@sveltejs/vite-plugin-svelte": "^3.0.2", "@tsconfig/svelte": "^5.0.2", "@types/path-browserify": "^1.0.2", + "@types/semver-compare": "^1.0.3", "@types/signale": "^1.4.7", "@types/tar": "^6.1.11", "autoprefixer": "^10.4.19", @@ -55,6 +56,7 @@ "lucide-svelte": "^0.446.0", "mode-watcher": "^0.3.1", "path-browserify": "^1.0.1", + "semver-compare": "^1.0.0", "svelte-markdown": "^0.4.1", "svelte-sonner": "^0.3.21", "tailwind-merge": "^2.5.2",