mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2026-11-15 07:07:07 +00:00
clean builds and add auto-updater
This commit is contained in:
1 parent
c0afd1fea9
commit
a67b982b1c
12 files changed
+842
-135
No files matched your search
Generated
+22
@@ -32,6 +32,8 @@
|
||||
"@sveltejs/vite-plugin-svelte": "^6.2.4",
|
||||
"@tailwindcss/vite": "^4.1.8",
|
||||
"@tauri-apps/api": "^2.12.3",
|
||||
"@tauri-apps/plugin-process": "^2.4.0",
|
||||
"@tauri-apps/plugin-updater": "^2.14.1",
|
||||
"@types/eslint": "^9.6.1",
|
||||
"@types/events": "^3.0.3",
|
||||
"@types/file-saver": "^2.0.7",
|
||||
@@ -2667,6 +2669,26 @@
|
||||
"url": "https://opencollective.com/tauri"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/plugin-process": {
|
||||
"version": "2.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/plugin-process/-/plugin-process-2.4.0.tgz",
|
||||
"integrity": "sha512-GddrmsSLAYrLa/yTXlXK/YRDzUgYeeOnUXTbiyvJWkmI424RmDPD3FVLeqcon7rv6O6ZfhBilcrHWnSo7o6hIQ==",
|
||||
"dev": true,
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"dependencies": {
|
||||
"@tauri-apps/api": "^2.12.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/plugin-updater": {
|
||||
"version": "2.14.1",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/plugin-updater/-/plugin-updater-2.14.1.tgz",
|
||||
"integrity": "sha512-Hr7nlBm1wT6xbwzjZ/S36YULazu8MNlj5vvOwMl47fXI7HTa5Bjl1PbDEwVHaZTAKzE1VZsUy35UqnbrQxmYQw==",
|
||||
"dev": true,
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"dependencies": {
|
||||
"@tauri-apps/api": "^2.12.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/cookie": {
|
||||
"version": "0.6.0",
|
||||
"dev": true,
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
"@sveltejs/vite-plugin-svelte": "^6.2.4",
|
||||
"@tailwindcss/vite": "^4.1.8",
|
||||
"@tauri-apps/api": "^2.12.3",
|
||||
"@tauri-apps/plugin-process": "^2.4.0",
|
||||
"@tauri-apps/plugin-updater": "^2.14.1",
|
||||
"@types/eslint": "^9.6.1",
|
||||
"@types/events": "^3.0.3",
|
||||
"@types/file-saver": "^2.0.7",
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
import { BundleType, getBundleType, getVersion } from '@tauri-apps/api/app';
|
||||
import { relaunch } from '@tauri-apps/plugin-process';
|
||||
import { check, type Update } from '@tauri-apps/plugin-updater';
|
||||
import { toast } from 'svelte-sonner';
|
||||
import { engine } from '$lib/engine';
|
||||
import { i18n } from '$lib/i18n/i18n.svelte';
|
||||
|
||||
/** Where the `.deb` and `.rpm` packages can be downloaded, as they do not update themselves. */
|
||||
const releases = 'https://github.com/gpxstudio/gpx.studio/releases/latest';
|
||||
|
||||
/**
|
||||
* Offers the update, if there is one. The app does not restart by itself, as it would interrupt
|
||||
* the user. The beta versions are not updated, as they would be replaced by the stable release.
|
||||
*/
|
||||
export async function checkForUpdates() {
|
||||
if (import.meta.env.DEV || (await getVersion()).includes('-')) {
|
||||
return;
|
||||
}
|
||||
const update = await check().catch((error) => {
|
||||
// most likely offline: it will be checked again the next time the app starts
|
||||
console.warn('Could not check for updates', error);
|
||||
return null;
|
||||
});
|
||||
if (update === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
const message = i18n._('desktop.update_available').replace('{version}', update.version);
|
||||
const bundle = await getBundleType();
|
||||
if (bundle === BundleType.Deb || bundle === BundleType.Rpm) {
|
||||
toast.info(message, {
|
||||
duration: Number.POSITIVE_INFINITY,
|
||||
action: {
|
||||
label: i18n._('desktop.update_download'),
|
||||
onClick: () => engine.openUrl(releases),
|
||||
},
|
||||
});
|
||||
} else {
|
||||
toast.info(message, {
|
||||
duration: Number.POSITIVE_INFINITY,
|
||||
action: {
|
||||
label: i18n._('desktop.update_restart'),
|
||||
onClick: () => install(update),
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function install(update: Update) {
|
||||
const installing = toast.loading(i18n._('desktop.update_installing'));
|
||||
try {
|
||||
await update.downloadAndInstall();
|
||||
await relaunch();
|
||||
} catch (error) {
|
||||
console.error('Could not install the update', error);
|
||||
toast.error(i18n._('desktop.update_failed'), { id: installing });
|
||||
}
|
||||
}
|
||||
@@ -598,5 +598,12 @@
|
||||
"title": "This page is out of date",
|
||||
"description": "Your files were saved by a newer version of gpx.studio, which this page cannot read. Reload the page to get the latest version.",
|
||||
"reload": "Reload"
|
||||
},
|
||||
"desktop": {
|
||||
"update_available": "gpx.studio {version} is available",
|
||||
"update_restart": "Update and restart",
|
||||
"update_download": "Download",
|
||||
"update_installing": "Installing the update...",
|
||||
"update_failed": "The update could not be installed"
|
||||
}
|
||||
}
|
||||
@@ -87,6 +87,8 @@
|
||||
);
|
||||
}
|
||||
languageRestored = true;
|
||||
// in its own chunk, as the website does not need it
|
||||
import('$lib/desktop/updates').then(({ checkForUpdates }) => checkForUpdates());
|
||||
}
|
||||
|
||||
let files: string[] = JSON.parse(page.url.searchParams.get('files') || '[]');
|
||||
|
||||
Reference in new issue
Block a user