Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
feat: app version update notification (#36)
Kyle Mendella72240144fdd
diff --git a/src/app.css b/src/app.cssindex 818dbed5b..17626fcb6 100644--- a/src/app.css+++ b/src/app.css@@ -126,3 +126,10 @@.dashboard-table-wrapper > :global(div.space-y-4) > :global(div:last-child) {display: none !important;}++.version-collapsed {+ writing-mode: vertical-rl;+ text-orientation: mixed;+ transform: rotate(180deg);+ opacity: 0.7;+}diff --git a/src/lib/components/navbar.svelte b/src/lib/components/navbar.svelteindex 06a17b2b3..2758f862f 100644--- a/src/lib/components/navbar.svelte+++ b/src/lib/components/navbar.svelte@@ -11,6 +11,7 @@ChevronRight,ChevronLeft,FileStack,+ ExternalLink, // Add this for the update link icontype Icon as IconType,} from "@lucide/svelte";import { page } from "$app/stores";@@ -20,6 +21,24 @@import { Separator } from "$lib/components/ui/separator/index.js";import { cn } from "$lib/utils";import { browser } from "$app/environment";+ import type { AppVersionInformation } from "$lib/types/application-configuration";++ // Menu items and version information with proper typing+ let {+ items = [+ { href: "/", label: "Dashboard", icon: Home },+ { href: "/containers", label: "Containers", icon: Box },+ { href: "/stacks", label: "Stacks", icon: FileStack },+ { href: "/images", label: "Images", icon: Image },+ { href: "/networks", label: "Networks", icon: Network },+ { href: "/volumes", label: "Volumes", icon: HardDrive },+ { href: "/settings", label: "Settings", icon: Settings },+ ] as MenuItem[],+ versionInformation,+ } = $props<{+ items?: MenuItem[];+ versionInformation?: AppVersionInformation;+ }>();// Define MenuItem type with proper IconTypetype MenuItem = {@@ -49,18 +68,8 @@}}- // Menu items with proper typing- let {- items = [- { href: "/", label: "Dashboard", icon: Home },- { href: "/containers", label: "Containers", icon: Box },- { href: "/stacks", label: "Stacks", icon: FileStack },- { href: "/images", label: "Images", icon: Image },- { href: "/networks", label: "Networks", icon: Network },- { href: "/volumes", label: "Volumes", icon: HardDrive },- { href: "/settings", label: "Settings", icon: Settings },- ] as MenuItem[],- } = $props();+ // Determine if update is available+ const updateAvailable = $derived(versionInformation?.updateAvailable);</script><!-- Mobile menu button -->@@ -98,7 +107,7 @@<div class="flex-shrink-0"><imgsrc="/img/nautix_logo_new.png"- alt="Nautix"+ alt="Arcane"class="h-15 w-15"width="30"height="30"@@ -108,7 +117,9 @@<div class="flex flex-col justify-center"><span class="text-lg font-bold tracking-tight leading-none">Arcane</span>- <span class="text-xs text-muted-foreground">v0.1.0</span>+ <span class="text-xs text-muted-foreground"+ >v{versionInformation.currentVersion}</span+ ></div>{/if}</div>@@ -201,6 +212,41 @@{/each}</nav>+ <!-- Only show update section if an update is available -->+ {#if updateAvailable}+ <Separator />++ <!-- Update available notification -->+ <div+ class={cn("transition-all px-3 py-2", isCollapsed ? "text-center" : "")}+ >+ {#if !isCollapsed}+ <a+ href={versionInformation.releaseUrl}+ target="_blank"+ rel="noopener noreferrer"+ class="flex items-center justify-between text-blue-500 hover:underline text-sm"+ >+ <span>Update available</span>+ <span class="flex items-center">+ v{versionInformation.newestVersion}+ <ExternalLink class="ml-1 h-3 w-3" />+ </span>+ </a>+ {:else}+ <a+ href={versionInformation.releaseUrl}+ target="_blank"+ rel="noopener noreferrer"+ title="Update available: v{versionInformation.newestVersion}"+ class="flex justify-center text-blue-500"+ >+ <ExternalLink class="h-4 w-4" />+ </a>+ {/if}+ </div>+ {/if}+<Separator /><!-- Footer section - simplified -->diff --git a/src/lib/services/app-config-service.ts b/src/lib/services/app-config-service.tsnew file mode 100644index 000000000..67b1a3119--- /dev/null+++ b/src/lib/services/app-config-service.ts@@ -0,0 +1,63 @@+import { version as currentVersion } from "$app/environment";+import type { AppVersionInformation } from "$lib/types/application-configuration";++export default class AppConfigService {+ /**+ * Fetches version information from GitHub or a configured API+ */+ async getVersionInformation(): Promise<AppVersionInformation> {+ try {+ // GitHub API URL for releases - adjust with your repository details+ const apiUrl =+ "https://api.github.com/repos/yourusername/arcane/releases/latest";++ const response = await fetch(apiUrl);+ if (!response.ok) {+ throw new Error(`Failed to fetch version info: ${response.status}`);+ }++ const data = await response.json();++ // GitHub release tag usually starts with 'v' (e.g., 'v1.0.0')+ // Remove the 'v' prefix if present to compare versions properly+ const newestVersion = data.tag_name.replace(/^v/, "");+ const currentVersionClean = currentVersion.replace(/^v/, "");++ // Simple version comparison (you might want a more robust solution)+ const updateAvailable = this.isNewerVersion(+ newestVersion,+ currentVersionClean+ );++ return {+ currentVersion: currentVersion,+ newestVersion: newestVersion,+ updateAvailable: updateAvailable,+ releaseUrl: data.html_url,+ releaseNotes: data.body,+ };+ } catch (error) {+ console.error("Error fetching version information:", error);+ // Return only current version if fetch fails+ return { currentVersion };+ }+ }++ /**+ * Compare versions to determine if an update is available+ * Simple version comparison, assumes semantic versioning (x.y.z)+ */+ private isNewerVersion(latest: string, current: string): boolean {+ if (!latest || !current) return false;++ const latestParts = latest.split(".").map(Number);+ const currentParts = current.split(".").map(Number);++ for (let i = 0; i < 3; i++) {+ if ((latestParts[i] || 0) > (currentParts[i] || 0)) return true;+ if ((latestParts[i] || 0) < (currentParts[i] || 0)) return false;+ }++ return false; // Versions are equal+ }+}diff --git a/src/lib/types/application-configuration.ts b/src/lib/types/application-configuration.tsnew file mode 100644index 000000000..ba3f7dc5b--- /dev/null+++ b/src/lib/types/application-configuration.ts@@ -0,0 +1,7 @@+export interface AppVersionInformation {+ currentVersion: string;+ newestVersion?: string;+ updateAvailable?: boolean;+ releaseUrl?: string;+ releaseNotes?: string;+}diff --git a/src/routes/+layout.server.ts b/src/routes/+layout.server.tsnew file mode 100644index 000000000..aaccfd8f2--- /dev/null+++ b/src/routes/+layout.server.ts@@ -0,0 +1,43 @@+import { version as currentVersion } from "$app/environment";+import { env } from "$env/dynamic/private";+import AppConfigService from "$lib/services/app-config-service";+import type { AppVersionInformation } from "$lib/types/application-configuration";+import type { LayoutServerLoad } from "./$types";++// Cache the version information+let versionInformation: AppVersionInformation;+let versionInformationLastUpdated: number;++export const load = (async () => {+ // If update checks are disabled via env var, return only current version+ const updateCheckDisabled = env.UPDATE_CHECK_DISABLED === "true";++ if (updateCheckDisabled) {+ return {+ versionInformation: {+ currentVersion,+ } as AppVersionInformation,+ };+ }++ const appConfigService = new AppConfigService();++ // Cache the version information for 3 hours+ const cacheExpired =+ versionInformationLastUpdated &&+ Date.now() - versionInformationLastUpdated > 1000 * 60 * 60 * 3;++ if (!versionInformation || cacheExpired) {+ try {+ versionInformation = await appConfigService.getVersionInformation();+ versionInformationLastUpdated = Date.now();+ } catch (error) {+ console.error("Error fetching version information:", error);+ versionInformation = { currentVersion } as AppVersionInformation;+ }+ }++ return {+ versionInformation,+ };+}) satisfies LayoutServerLoad;diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelteindex 05e191a48..47d24341e 100644--- a/src/routes/+layout.svelte+++ b/src/routes/+layout.svelte@@ -3,7 +3,11 @@import { ModeWatcher } from "mode-watcher";import Nav from "$lib/components/navbar.svelte";import { Toaster } from "$lib/components/ui/sonner/index.js";- let { children } = $props();++ let { children, data } = $props();++ // We'll pass this directly to the navbar component+ const versionInformation = data.versionInformation;</script><svelte:head><title>Arcane</title></svelte:head>@@ -12,7 +16,7 @@<Toaster /><div class="flex min-h-screen bg-background">- <Nav />+ <Nav {versionInformation} /><main class="flex-1"><section class="p-6">diff --git a/svelte.config.js b/svelte.config.jsindex 760c6b1c0..45e7ddec8 100644--- a/svelte.config.js+++ b/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' with { type: "json" };const config = {preprocess: vitePreprocess(),@@ -12,6 +13,9 @@ const config = {csrf: {checkOrigin: process.env.NODE_ENV === "production",},+ version: {+ name: packageJson.version+ }},};