📧✨ Beautiful email. For everyone.
fix: keep website and desktop versions current (#32)
Paul Koeckecd3a1426a3b
diff --git a/apps/desktop/package.json b/apps/desktop/package.jsonindex d7b99da..47e638f 100644--- a/apps/desktop/package.json+++ b/apps/desktop/package.json@@ -1,6 +1,6 @@{"name": "@inlark/desktop",- "version": "0.1.0",+ "version": "0.3.0","private": true,"license": "AGPL-3.0-only","description": "A considered home for your email.",diff --git a/apps/desktop/src/renderer/src/App.tsx b/apps/desktop/src/renderer/src/App.tsxindex 1e9f23f..19cad95 100644--- a/apps/desktop/src/renderer/src/App.tsx+++ b/apps/desktop/src/renderer/src/App.tsx@@ -102,6 +102,7 @@ import { SubmissionList } from './SendingStatus'import { IndexingMeter } from './IndexingMeter'import { UpdateNotice } from './UpdateNotice'import { offersAction } from './view-actions'+import { version as packagedVersion } from '../../../package.json'const Composer = lazy(() => import('./Composer').then((m) => ({ default: m.Composer })))const SettingsPanel = lazy(() => import('./Settings').then((m) => ({ default: m.SettingsPanel })))@@ -131,7 +132,7 @@ export function App() {settings: defaultSettings,secureStorage: false,demo: isDemo,- version: '0.1.0',+ version: packagedVersion,}const { accounts, settings } = bootstrapconst view = (diff --git a/apps/desktop/src/renderer/src/demo.ts b/apps/desktop/src/renderer/src/demo.tsindex c372e95..9f18518 100644--- a/apps/desktop/src/renderer/src/demo.ts+++ b/apps/desktop/src/renderer/src/demo.ts@@ -25,6 +25,7 @@ import {type SubmissionSummary,} from '@inlark/core'import { longDate } from './mail-date'+import { version as packagedVersion } from '../../../package.json'const names = ['Personal', 'Studio', 'Projects', 'Community', 'Archive']const emails = [@@ -639,7 +640,10 @@ export const demoAPI: DesktopMailAPI = {settings,secureStorage: false,demo: true,- version: '0.1.0',+ version:+ typeof window !== 'undefined' && window.mail+ ? (await window.mail.bootstrap()).version+ : packagedVersion,}),discover: async (email) => {await pause(700)diff --git a/apps/marketing/src/components/Hero.astro b/apps/marketing/src/components/Hero.astroindex 47ef502..4457ba1 100644--- a/apps/marketing/src/components/Hero.astro+++ b/apps/marketing/src/components/Hero.astro@@ -3,7 +3,13 @@ import { ArrowUpRight, Download } from '@inlark/ui/icons'import InboxWindow from './InboxWindow.astro'import Stars from './Stars.astro'import { GitHubIcon } from './GitHubIcon'-import { links, version } from '../data/links'+import { links } from '../data/links'+import { fetchLatestRelease, unconfirmedRelease } from '../data/release'++const release = import.meta.env.PROD+ ? ((await fetchLatestRelease(import.meta.env.GITHUB_TOKEN).catch(() => null)) ??+ unconfirmedRelease)+ : unconfirmedRelease---<section id="top" class="relative isolate overflow-x-clip pt-32 sm:pt-44">@@ -14,8 +20,11 @@ import { links, version } from '../data/links'href={links.releases}class="rise group inline-flex items-center gap-2.5 rounded-full border border-line-strong bg-ink/[0.03] py-1.5 pr-3 pl-2 text-[0.8rem] text-ink-2 transition-colors hover:border-ink/20 hover:text-ink">- <span class="rounded-full bg-dawn/15 px-2 py-0.5 font-mono text-[0.68rem] text-dawn">- v{version}+ <span+ data-release-version+ class="rounded-full bg-dawn/15 px-2 py-0.5 font-mono text-[0.68rem] text-dawn"+ >+ v{release.version}</span>Early preview for desktop<ArrowUpRight@@ -64,6 +73,17 @@ import { links, version } from '../data/links'</div></section>+<script>+ import { fetchCurrentRelease } from '../data/release'++ const badge = document.querySelector('[data-release-version]')+ if (badge) {+ void fetchCurrentRelease().then((release) => {+ if (release) badge.textContent = `v${release.version}`+ })+ }+</script>+<style>.stage {--window-height: clamp(420px, 52vw, 640px);diff --git a/apps/marketing/src/components/download/Download.tsx b/apps/marketing/src/components/download/Download.tsxindex fa1bcb4..006cce4 100644--- a/apps/marketing/src/components/download/Download.tsx+++ b/apps/marketing/src/components/download/Download.tsx@@ -9,6 +9,7 @@ import {import {buildById,downloadFor,+ fetchCurrentRelease,osNames,type Build,type BuildId,@@ -69,9 +70,7 @@ export function DownloadPage({ initial }: { initial: Release }) {useEffect(() => {let cancelled = false- const live = fetch('/api/release')- .then((response) => (response.ok ? (response.json() as Promise<Release>) : null))- .catch(() => null)+ const live = fetchCurrentRelease()live.then((latest) => !cancelled && latest && setRelease(latest))if (isMobile()) returndiff --git a/apps/marketing/src/data/links.ts b/apps/marketing/src/data/links.tsindex b8c36a6..ad6de69 100644--- a/apps/marketing/src/data/links.ts+++ b/apps/marketing/src/data/links.ts@@ -12,4 +12,4 @@ export const links = {imprint: '/imprint',}-export const version = '0.1.0'+export { version } from '../../../desktop/package.json'diff --git a/apps/marketing/src/data/release.ts b/apps/marketing/src/data/release.tsindex 15b74d1..2fba18d 100644--- a/apps/marketing/src/data/release.ts+++ b/apps/marketing/src/data/release.ts@@ -145,3 +145,13 @@ export async function fetchLatestRelease(token?: string): Promise<Release | null})),}}++/** Refreshes static pages through the Worker's cached release endpoint. */+export async function fetchCurrentRelease(): Promise<Release | null> {+ try {+ const response = await fetch('/api/release', { signal: AbortSignal.timeout(6000) })+ return response.ok ? ((await response.json()) as Release) : null+ } catch {+ return null+ }+}diff --git a/tests/marketing-release.test.ts b/tests/marketing-release.test.tsnew file mode 100644index 0000000..7b84fc6--- /dev/null+++ b/tests/marketing-release.test.ts@@ -0,0 +1,125 @@+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'+import {+ buildById,+ downloadFor,+ fetchCurrentRelease,+ fetchLatestRelease,+} from '../apps/marketing/src/data/release'++const githubRelease = (version: string) => ({+ tag_name: `v${version}`,+ html_url: `https://github.com/inlark/inlark/releases/tag/v${version}`,+ published_at: '2026-10-07T12:00:00Z',+ assets: [+ {+ name: `Inlark-${version}-amd64.deb`,+ size: 12345,+ browser_download_url: `https://github.com/inlark/inlark/releases/download/v${version}/Inlark-${version}-amd64.deb`,+ digest: 'sha256:abc123',+ },+ ],+})++afterEach(() => {+ vi.unstubAllGlobals()+ vi.useRealTimers()+})++describe('website release version', () => {+ it('uses the published tag and its assets rather than the source version', async () => {+ vi.stubGlobal(+ 'fetch',+ vi.fn(async () => Response.json(githubRelease('1.2.3'))),+ )+ const release = await fetchLatestRelease()++ expect(release?.version).toBe('1.2.3')+ const download = downloadFor(release!, buildById('deb'))+ expect(download.confirmed).toBe(true)+ expect(download.url).toContain('/v1.2.3/Inlark-1.2.3-amd64.deb')+ expect(download.digest).toBe('abc123')+ })++ it('refreshes the homepage and download page through the same cached endpoint', async () => {+ const release = {+ version: '1.3.0',+ url: 'https://github.com/inlark/inlark/releases/tag/v1.3.0',+ publishedAt: '2026-10-07T12:00:00Z',+ assets: [],+ }+ const fetch = vi.fn(async () => Response.json(release))+ vi.stubGlobal('fetch', fetch)++ expect(await fetchCurrentRelease()).toEqual(release)+ expect(fetch).toHaveBeenCalledWith('/api/release', { signal: expect.any(AbortSignal) })+ })++ it.each([404, 502])(+ 'keeps the initial version when the release endpoint returns %s',+ async (status) => {+ vi.stubGlobal(+ 'fetch',+ vi.fn(async () => new Response('', { status })),+ )+ expect(await fetchCurrentRelease()).toBeNull()+ },+ )++ it('keeps the initial version when the release request fails', async () => {+ vi.stubGlobal('fetch', vi.fn().mockRejectedValue(new TypeError('Network failure')))+ expect(await fetchCurrentRelease()).toBeNull()+ })++ it('keeps the initial version when the release response cannot be decoded', async () => {+ vi.stubGlobal(+ 'fetch',+ vi.fn(async () => new Response('<html>Unavailable</html>')),+ )+ expect(await fetchCurrentRelease()).toBeNull()+ })+})++describe('cached release endpoint', () => {+ beforeEach(() => {+ vi.resetModules()+ vi.useFakeTimers()+ vi.setSystemTime(new Date('2026-10-07T12:00:00Z'))+ })++ it('picks up a new release after the cache expires without a website deploy', async () => {+ const fetch = vi+ .fn()+ .mockResolvedValueOnce(Response.json(githubRelease('1.2.3')))+ .mockResolvedValueOnce(Response.json(githubRelease('1.3.0')))+ vi.stubGlobal('fetch', fetch)+ const { handle } = await import('../apps/marketing/worker/routes')+ const request = new Request('https://inlark.com/api/release')+ const current = await handle(request)+ expect(await current!.json()).toMatchObject({ version: '1.2.3' })++ const cached = await handle(request)+ expect(await cached!.json()).toMatchObject({ version: '1.2.3' })+ expect(fetch).toHaveBeenCalledTimes(1)++ vi.setSystemTime(new Date('2026-10-07T12:06:00Z'))+ const updated = await handle(request)+ expect(await updated!.json()).toMatchObject({ version: '1.3.0' })+ expect(fetch).toHaveBeenCalledTimes(2)+ })++ it('retains the last confirmed version during a GitHub outage', async () => {+ const fetch = vi+ .fn()+ .mockResolvedValueOnce(Response.json(githubRelease('1.2.3')))+ .mockRejectedValueOnce(new TypeError('Network failure'))+ vi.stubGlobal('fetch', fetch)+ const { handle } = await import('../apps/marketing/worker/routes')+ const request = new Request('https://inlark.com/api/release')+ await handle(request)++ vi.setSystemTime(new Date('2026-10-07T12:06:00Z'))+ const stale = await handle(request)+ expect(stale?.status).toBe(200)+ expect(await stale!.json()).toMatchObject({ version: '1.2.3' })+ })+})diff --git a/tests/version.test.ts b/tests/version.test.tsnew file mode 100644index 0000000..26df5fd--- /dev/null+++ b/tests/version.test.ts@@ -0,0 +1,25 @@+import { afterEach, describe, expect, it, vi } from 'vitest'+import { version } from '../apps/desktop/package.json'+import { demoAPI } from '../apps/desktop/src/renderer/src/demo'+import { unconfirmedRelease } from '../apps/marketing/src/data/release'++afterEach(() => vi.unstubAllGlobals())++describe('application version', () => {+ it('uses the desktop manifest in the browser demo and website fallback', async () => {+ vi.stubGlobal('window', {})+ expect((await demoAPI.bootstrap()).version).toBe(version)+ expect(unconfirmedRelease.version).toBe(version)+ })++ it('uses the running application version in the native demo', async () => {+ const bootstrap = vi.fn(async () => ({ version: '1.2.3-beta.1' }))+ vi.stubGlobal('window', { mail: { bootstrap } })++ const result = await demoAPI.bootstrap()+ expect(result.version).toBe('1.2.3-beta.1')+ expect(result.demo).toBe(true)+ expect(result.accounts.length).toBeGreaterThan(0)+ expect(bootstrap).toHaveBeenCalledOnce()+ })+})