From 70ad0b4f39699fd81ffdfd5c8d6839f49348be78 Mon Sep 17 00:00:00 2001 From: Elias Schneider Date: Fri, 18 Oct 2024 20:48:59 +0200 Subject: [PATCH] feat: add version information to footer and update link if new update is available --- frontend/package.json | 2 +- .../src/lib/services/app-config-service.ts | 17 ++++++++++ frontend/src/routes/settings/+layout.svelte | 33 +++++++++++++++++-- frontend/src/routes/settings/+layout.ts | 11 +++++++ frontend/svelte.config.js | 4 +++ scripts/create-release.sh | 13 +++++--- 6 files changed, 71 insertions(+), 9 deletions(-) create mode 100644 frontend/src/routes/settings/+layout.ts diff --git a/frontend/package.json b/frontend/package.json index af0d5e1..b3a85c0 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,6 +1,6 @@ { "name": "pocket-id-frontend", - "version": "0.0.1", + "version": "0.9.0", "private": true, "scripts": { "dev": "vite dev --port 3000", diff --git a/frontend/src/lib/services/app-config-service.ts b/frontend/src/lib/services/app-config-service.ts index 3cad01a..9e3c27d 100644 --- a/frontend/src/lib/services/app-config-service.ts +++ b/frontend/src/lib/services/app-config-service.ts @@ -1,4 +1,6 @@ +import { version as currentVersion } from '$app/environment'; import type { AllAppConfig, AppConfigRawResponse } from '$lib/types/application-configuration'; +import axios from 'axios'; import APIService from './api-service'; export default class AppConfigService extends APIService { @@ -45,4 +47,19 @@ export default class AppConfigService extends APIService { await this.api.put(`/application-configuration/background-image`, formData); } + + async getVersionInformation() { + const response = ( + await axios.get('https://api.github.com/repos/stonith404/pocket-id/releases/latest') + ).data; + + const newestVersion = response.tag_name.replace('v', ''); + const isUpToDate = newestVersion === currentVersion; + + return { + isUpToDate, + newestVersion, + currentVersion + }; + } } diff --git a/frontend/src/routes/settings/+layout.svelte b/frontend/src/routes/settings/+layout.svelte index 3e94f46..9070505 100644 --- a/frontend/src/routes/settings/+layout.svelte +++ b/frontend/src/routes/settings/+layout.svelte @@ -1,14 +1,20 @@
-
-
+
+

Settings

@@ -41,6 +49,15 @@ {label} {/each} + {#if $userStore?.isAdmin && !versionInformation.isUpToDate} + + Update Pocket ID + + {/if}
@@ -48,5 +65,15 @@ {@render children()}
+
+

+ Powered by Pocket ID + ({versionInformation.currentVersion}) +

+
diff --git a/frontend/src/routes/settings/+layout.ts b/frontend/src/routes/settings/+layout.ts new file mode 100644 index 0000000..0cd6c6d --- /dev/null +++ b/frontend/src/routes/settings/+layout.ts @@ -0,0 +1,11 @@ +import AppConfigService from '$lib/services/app-config-service'; +import type { LayoutLoad } from './$types'; + +export const load: LayoutLoad = async () => { + const appConfigService = new AppConfigService(); + + const versionInformation = await appConfigService.getVersionInformation(); + return { + versionInformation + }; +}; diff --git a/frontend/svelte.config.js b/frontend/svelte.config.js index 468f57e..42d1a6c 100644 --- a/frontend/svelte.config.js +++ b/frontend/svelte.config.js @@ -1,5 +1,6 @@ import adapter from '@sveltejs/adapter-node'; import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'; +import packageJson from "./package.json" assert { type: "json" }; /** @type {import('@sveltejs/kit').Config} */ const config = { @@ -12,6 +13,9 @@ const config = { // If your environment is not supported, or you settled on a specific environment, switch out the adapter. // See https://kit.svelte.dev/docs/adapters for more information about adapters. adapter: adapter(), + version: { + name: packageJson.version, + } } }; diff --git a/scripts/create-release.sh b/scripts/create-release.sh index b432e34..1ed9a73 100644 --- a/scripts/create-release.sh +++ b/scripts/create-release.sh @@ -6,7 +6,7 @@ increment_version() { local version=$1 local part=$2 - IFS='.' read -r -a parts <<< "$version" + IFS='.' read -r -a parts <<<"$version" if [ "$part" == "minor" ]; then parts[1]=$((parts[1] + 1)) parts[2]=0 @@ -30,12 +30,15 @@ else fi # Update the .version file with the new version -echo $NEW_VERSION > .version +echo $NEW_VERSION >.version git add .version +# Update version in frontend/package.json +jq --arg new_version "$NEW_VERSION" '.version = $new_version' frontend/package.json >frontend/package.json && mv frontend/package_tmp.json frontend/package.json +git add frontend/package.json + # Check if conventional-changelog is installed, if not install it -if ! command -v conventional-changelog &> /dev/null -then +if ! command -v conventional-changelog &>/dev/null; then echo "conventional-changelog not found, installing..." npm install -g conventional-changelog-cli fi @@ -55,4 +58,4 @@ git tag "v$NEW_VERSION" git push git push --tags -echo "Release process complete. New version: $NEW_VERSION" \ No newline at end of file +echo "Release process complete. New version: $NEW_VERSION"