📧✨ Beautiful email. For everyone.
feat: publish standalone Flatpak bundles (#46)
Paul Koecka0ad7acd7be3
diff --git a/.github/workflows/flatpak.yml b/.github/workflows/flatpak.ymlnew file mode 100644index 0000000..d36fce0--- /dev/null+++ b/.github/workflows/flatpak.yml@@ -0,0 +1,113 @@+name: Build Flatpak++on:+ pull_request:+ paths:+ - '.github/workflows/flatpak.yml'+ - '.github/workflows/release.yml'+ - 'scripts/*flatpak*'+ - 'apps/desktop/**'+ - 'packages/**'+ - 'pnpm-lock.yaml'+ - 'pnpm-workspace.yaml'+ - 'package.json'+ - 'tests/flatpak.test.ts'+ - 'tests/updates.test.ts'+ - 'vitest.config.ts'+ workflow_dispatch:+ workflow_call:+ inputs:+ version:+ description: Release tag to package+ type: string+ required: true++permissions:+ contents: read++jobs:+ package:+ runs-on: ubuntu-24.04+ outputs:+ version: ${{ steps.version.outputs.version }}+ steps:+ - uses: actions/checkout@v7+ - uses: actions/setup-node@v7+ with:+ node-version: '24'+ - name: Set release version+ id: version+ env:+ RELEASE_VERSION: ${{ inputs.version }}+ run: |+ if [ -n "$RELEASE_VERSION" ]; then+ npm --prefix apps/desktop version "${RELEASE_VERSION#v}" --no-git-tag-version --allow-same-version --ignore-scripts --package-lock=false+ fi+ echo "version=$(node -p "require('./apps/desktop/package.json').version")" >> "$GITHUB_OUTPUT"+ - uses: pnpm/action-setup@v6+ with:+ run_install: false+ - run: pnpm install --frozen-lockfile+ - run: pnpm check+ - name: Package Linux directory+ run: pnpm --filter @inlark/desktop exec electron-builder --linux dir --x64 --publish never+ - name: Prepare archive and manifest+ run: bash scripts/flatpak-archive.sh+ - uses: actions/upload-artifact@v7+ with:+ name: flatpak-input+ path: apps/desktop/release/flatpak/+ if-no-files-found: error++ flatpak:+ needs: package+ runs-on: ubuntu-24.04+ container:+ image: ghcr.io/flathub-infra/flatpak-github-actions:freedesktop-25.08+ options: --privileged+ steps:+ - uses: actions/checkout@v7+ - uses: actions/download-artifact@v7+ with:+ name: flatpak-input+ path: apps/desktop/release/flatpak/+ - name: Validate desktop and AppStream metadata+ run: |+ desktop-file-validate apps/desktop/release/flatpak/manifest/com.inlark.Inlark.desktop+ appstreamcli validate --no-net apps/desktop/release/flatpak/manifest/com.inlark.Inlark.metainfo.xml+ - name: Build standalone bundle+ env:+ VERSION: ${{ needs.package.outputs.version }}+ run: |+ flatpak remote-add --user --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo+ flatpak-builder --user --force-clean --disable-rofiles-fuse --install-deps-from=flathub \+ --repo=apps/desktop/release/flatpak/repo --default-branch=stable \+ apps/desktop/release/flatpak/build apps/desktop/release/flatpak/manifest/com.inlark.Inlark.json+ flatpak build-bundle --runtime-repo=https://dl.flathub.org/repo/flathub.flatpakrepo \+ apps/desktop/release/flatpak/repo "apps/desktop/release/inlark-$VERSION-x64.flatpak" \+ com.inlark.Inlark stable+ - uses: actions/upload-artifact@v7+ with:+ name: desktop-linux-flatpak+ path: apps/desktop/release/inlark-*-x64.flatpak+ if-no-files-found: error++ smoke:+ needs: [package, flatpak]+ runs-on: ubuntu-24.04+ steps:+ - uses: actions/checkout@v7+ - uses: actions/download-artifact@v7+ with:+ name: desktop-linux-flatpak+ path: apps/desktop/release/+ - name: Install Flatpak test tools+ run: |+ sudo apt-get update+ sudo apt-get install -y flatpak xvfb xauth dbus-x11+ # Allow nested sandbox namespaces on this disposable test runner.+ sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0+ - name: Smoke-test installed Flatpak+ env:+ VERSION: ${{ needs.package.outputs.version }}+ run: bash scripts/test-flatpak.sh "apps/desktop/release/inlark-$VERSION-x64.flatpak"diff --git a/.github/workflows/release.yml b/.github/workflows/release.ymlindex 04a5f55..5848db8 100644--- a/.github/workflows/release.yml+++ b/.github/workflows/release.yml@@ -214,8 +214,14 @@ jobs:test -f "$RUNNER_TEMP/inlark-profile/share/applications/inlark.desktop"test -f "$RUNNER_TEMP/inlark-profile/share/icons/hicolor/512x512/apps/inlark.png"+ flatpak:+ needs: validate-tag+ uses: ./.github/workflows/flatpak.yml+ with:+ version: ${{ github.ref_name }}+release:- needs: [build, nix]+ needs: [build, nix, flatpak]runs-on: ubuntu-latestpermissions:contents: write@@ -237,6 +243,7 @@ jobs:echo "Expected 8 installers, found $count" >&2exit 1fi+ test -f "release-assets/inlark-${RELEASE_TAG#v}-x64.flatpak"channel="${RELEASE_TAG#v}"if [[ "$channel" == *-* ]]; thenchannel="${channel#*-}"diff --git a/.gitignore b/.gitignoreindex 6450e9c..aa057b2 100644--- a/.gitignore+++ b/.gitignore@@ -13,4 +13,5 @@ test-results/!.env.example*.log.test-data/+.flatpak-builder/resultdiff --git a/.prettierignore b/.prettierignoreindex 82b5010..18a013e 100644--- a/.prettierignore+++ b/.prettierignore@@ -3,6 +3,7 @@ node_modules.turbo.astro.wrangler+.flatpak-builder**/out**/releaseresultdiff --git a/README.md b/README.mdindex d3ce50d..d11ce88 100644--- a/README.md+++ b/README.md@@ -57,13 +57,28 @@ If you run your own mail server, or just have a few accounts at small providers,Grab the latest build from the [releases page](https://github.com/inlark/inlark/releases/latest):-Packaged builds check for updates in the background. When an update downloads successfully, inlark installs it after you quit, so it never interrupts your work. If the automatic update fails, inlark links to the [download page](https://inlark.com/download) for a manual install.+Native installers check for updates in the background. When an update downloads successfully, inlark installs it after you quit, so it never interrupts your work. If the automatic update fails, inlark links to the [download page](https://inlark.com/download) for a manual install. Flatpak and Nix installations use the update steps below.-| Platform | Download |-| -------- | ---------------------------------------------------------- |-| Windows | Installer (x64) |-| macOS | DMG or ZIP, for both Apple Silicon and Intel |-| Linux | AppImage, `.deb` or `.rpm` (x64), or [Nix](#nix-and-nixos) |+| Platform | Download |+| -------- | ------------------------------------------------------------------------------- |+| Windows | Installer (x64) |+| macOS | DMG or ZIP, for both Apple Silicon and Intel |+| Linux | AppImage, `.deb`, `.rpm` or [Flatpak](#flatpak) (x64), or [Nix](#nix-and-nixos) |++### Flatpak++Install Flatpak using your distribution's instructions, then download the `.flatpak` bundle from the [latest release](https://github.com/inlark/inlark/releases/latest). From the download directory, run the following, replacing `<version>` with the downloaded version:++```sh+flatpak install --user ./inlark-<version>-x64.flatpak+flatpak run com.inlark.Inlark+```++Confirm adding Flathub when asked: it supplies the shared runtime. inlark itself is distributed through GitHub Releases and does not require a Flathub listing.++**Updates are manual.** Download the new bundle, quit inlark, and install it with `flatpak install --user --reinstall ./inlark-<new-version>-x64.flatpak`. This keeps your Flatpak accounts, drafts and settings. `flatpak update` updates the shared runtime, but does not fetch new inlark bundles. The native installer updater is disabled in Flatpak.++Flatpak stores app data separately, under `~/.var/app/com.inlark.Inlark/config/Inlark`. Switching from an AppImage, `.deb`, `.rpm` or Nix installation does not import existing accounts or drafts. The internal Flatpak ID and `Inlark` data directory keep their original spelling for compatibility.### Nix and NixOS@@ -135,11 +150,15 @@ pnpm test:packaged-crypto # bundled worker encryption and locking smoke testpnpm test:crypto-interop # independent GnuPG verification of inlark outputnix build path:. # Nix package in ./result/bin/inlarkpnpm package:linux # AppImage, .deb and .rpm in apps/desktop/release+pnpm package:flatpak # standalone .flatpak bundle (x64 Linux)+pnpm test:flatpak # isolated Flatpak installation and native IPC/SQLite smoke testpnpm test:deb # Debian packaging smoke test (Podman)```The Nix build is pinned by `flake.lock`, `pnpm-lock.yaml` and the dependency hash in `nix/package.nix`. After changing dependencies, replace that hash with the one Nix reports.+Flatpak packaging also needs `flatpak` and `flatpak-builder`; its smoke test needs Xvfb and xauth. See the [Flatpak packaging guide](apps/desktop/packaging/flatpak/README.md) for release automation and desktop validation.+To smoke-test the Nix package without opening a window:```shdiff --git a/apps/desktop/packaging/flatpak/README.md b/apps/desktop/packaging/flatpak/README.mdnew file mode 100644index 0000000..f2f977c--- /dev/null+++ b/apps/desktop/packaging/flatpak/README.md@@ -0,0 +1,71 @@+# Flatpak packaging++inlark publishes standalone x86_64 `.flatpak` bundles on GitHub Releases. There is+no Flathub submission, publishing token or hosted inlark Flatpak repository.+Installation and updates are described in the [root README](../../../../README.md#flatpak).++The app ID is `com.inlark.Inlark`, preserving the identity of the original+packaging. Display names and release filenames use lowercase `inlark`.++## Build and test++Install Node 24, pnpm 12.3.4, Flatpak and flatpak-builder, then run:++```sh+pnpm install --frozen-lockfile+pnpm package:flatpak+```++The output is `apps/desktop/release/inlark-<version>-x64.flatpak`. The recipe+packages an unpacked Electron build, with a SHA-256-pinned archive. It uses+Freedesktop 25.08 and the matching Electron BaseApp, obtained from Flathub.+Keep the runtime and BaseApp versions current together. Zypak launches Electron+with Chromium's sandbox enabled; do not add `--no-sandbox`.++With Xvfb, xauth and a D-Bus session available, run:++```sh+pnpm test:flatpak+# Or test a specific downloaded release:+bash scripts/test-flatpak.sh /path/to/inlark-<version>-x64.flatpak+```++The smoke test uses a temporary user Flatpak installation and disposable app+data. It does not replace an existing inlark installation or read real accounts.+It checks the renderer/preload IPC bridge and SQLite worker, requires an explicit+success message, and removes the temporary installation afterward. Runtime+downloads require network access.++## Desktop integration++The manifest grants network access for mail servers, display and GPU access,+Secret Service/KWallet access for the OS keyring, and StatusNotifier access for the tray.+File selection, opening links and notifications use desktop portals. There is no+blanket home-directory access. Electron's desktop identity matches the Flatpak+desktop file; the existing credential identity remains unchanged.++Before publishing packaging changes, check on both GNOME and KDE, with Wayland+and X11 where available:++- Connect to a JMAP or IMAP/SMTP server, send mail, and reconnect after restarting.+- Save a login with the OS keyring unlocked, then confirm it is readable after a restart.+- Add, save and open attachments; import and export OpenPGP keys through file dialogs.+- Check notifications, tray behavior, external links, `mailto:` links and the system title bar preference.+- Reinstall a newer bundle and confirm that accounts, drafts and settings survive.++Flatpak app data lives under `~/.var/app/com.inlark.Inlark/config/Inlark`, separate+from native installations. The Electron installer updater is disabled under+Flatpak. Users must download and reinstall newer bundles; `flatpak update` only+updates dependencies from their configured repositories.++## Release automation++`.github/workflows/flatpak.yml` builds the directory archive and generated+manifest, validates desktop/AppStream metadata, builds the bundle and runs the+installed application smoke test. It runs for relevant PRs, supports manual+dispatch, and is called by the tag release workflow with the tag's version.++The release workflow waits for Flatpak validation and publishes the tested bundle+alongside native installers. Both stable and prerelease tags produce bundles.+There is no dependency on Flathub app review or repository access. A signed+inlark update repository can be added later using the same application ID.diff --git a/apps/desktop/packaging/flatpak/com.inlark.Inlark.desktop b/apps/desktop/packaging/flatpak/com.inlark.Inlark.desktopnew file mode 100644index 0000000..305aed4--- /dev/null+++ b/apps/desktop/packaging/flatpak/com.inlark.Inlark.desktop@@ -0,0 +1,12 @@+[Desktop Entry]+Type=Application+Name=inlark+Comment=A considered home for your email+Exec=inlark %U+Icon=com.inlark.Inlark+Terminal=false+Categories=Network;Email;+Keywords=mail;email;IMAP;JMAP;+MimeType=x-scheme-handler/mailto;+StartupWMClass=com.inlark.Inlark+StartupNotify=truediff --git a/apps/desktop/packaging/flatpak/com.inlark.Inlark.metainfo.xml b/apps/desktop/packaging/flatpak/com.inlark.Inlark.metainfo.xmlnew file mode 100644index 0000000..5b355f1--- /dev/null+++ b/apps/desktop/packaging/flatpak/com.inlark.Inlark.metainfo.xml@@ -0,0 +1,53 @@+<?xml version="1.0" encoding="UTF-8"?>+<!-- Copyright 2026 Paul Koeck -->+<component type="desktop-application">+ <id>com.inlark.Inlark</id>+ <name>inlark</name>+ <summary>A considered home for your email</summary>+ <metadata_license>CC0-1.0</metadata_license>+ <project_license>AGPL-3.0-only</project_license>+ <developer id="com.inlark">+ <name>Paul Koeck</name>+ </developer>+ <description>+ <p>+ inlark is a fast, keyboard-friendly email client for the accounts you already own.+ Connect directly to your JMAP or IMAP server, with no hosted service, subscription,+ or telemetry.+ </p>+ <ul>+ <li>Read conversations from several accounts in one unified inbox</li>+ <li>Search, archive, organise, and write email with your keyboard or mouse</li>+ <li>Keep drafts safe and undo everyday mailbox actions</li>+ <li>Enjoy carefully designed dark and light appearances</li>+ </ul>+ <p>inlark is an early preview. Gmail and Microsoft OAuth sign-in are not yet supported.</p>+ </description>+ <launchable type="desktop-id">com.inlark.Inlark.desktop</launchable>+ <url type="homepage">https://inlark.com</url>+ <url type="bugtracker">https://github.com/inlark/inlark/issues</url>+ <url type="vcs-browser">https://github.com/inlark/inlark</url>+ <screenshots>+ <screenshot type="default">+ <image>https://raw.githubusercontent.com/inlark/inlark/v@VERSION@/.github/assets/inbox-dark.png</image>+ <caption>A unified inbox with a clear identity for every account</caption>+ </screenshot>+ <screenshot>+ <image>https://raw.githubusercontent.com/inlark/inlark/v@VERSION@/.github/assets/reader-dark.png</image>+ <caption>A focused conversation reader</caption>+ </screenshot>+ <screenshot>+ <image>https://raw.githubusercontent.com/inlark/inlark/v@VERSION@/.github/assets/inbox-light.png</image>+ <caption>The same inbox in light appearance</caption>+ </screenshot>+ </screenshots>+ <content_rating type="oars-1.1">+ <content_attribute id="social-chat">intense</content_attribute>+ <content_attribute id="social-contacts">intense</content_attribute>+ </content_rating>+ <releases>+ <release version="@VERSION@" date="@DATE@">+ <url type="details">https://github.com/inlark/inlark/releases/tag/v@VERSION@</url>+ </release>+ </releases>+</component>diff --git a/apps/desktop/packaging/flatpak/com.inlark.Inlark.template.json b/apps/desktop/packaging/flatpak/com.inlark.Inlark.template.jsonnew file mode 100644index 0000000..b3ef9f0--- /dev/null+++ b/apps/desktop/packaging/flatpak/com.inlark.Inlark.template.json@@ -0,0 +1,41 @@+{+ "app-id": "com.inlark.Inlark",+ "runtime": "org.freedesktop.Platform",+ "runtime-version": "25.08",+ "sdk": "org.freedesktop.Sdk",+ "base": "org.electronjs.Electron2.BaseApp",+ "base-version": "25.08",+ "command": "inlark",+ "separate-locales": false,+ "finish-args": [+ "--share=network",+ "--share=ipc",+ "--socket=wayland",+ "--socket=fallback-x11",+ "--device=dri",+ "--talk-name=org.freedesktop.secrets",+ "--talk-name=org.kde.kwalletd5",+ "--talk-name=org.kde.kwalletd6",+ "--talk-name=org.kde.StatusNotifierWatcher"+ ],+ "modules": [+ {+ "name": "inlark",+ "buildsystem": "simple",+ "build-commands": [+ "mkdir -p /app/inlark",+ "cp -a inlark/. /app/inlark/",+ "install -Dm755 inlark.sh /app/bin/inlark",+ "install -Dm644 com.inlark.Inlark.desktop /app/share/applications/com.inlark.Inlark.desktop",+ "install -Dm644 com.inlark.Inlark.metainfo.xml /app/share/metainfo/com.inlark.Inlark.metainfo.xml",+ "install -Dm644 com.inlark.Inlark.png /app/share/icons/hicolor/512x512/apps/com.inlark.Inlark.png"+ ],+ "sources": [+ { "type": "file", "path": "inlark.sh" },+ { "type": "file", "path": "com.inlark.Inlark.desktop" },+ { "type": "file", "path": "com.inlark.Inlark.metainfo.xml" },+ { "type": "file", "path": "com.inlark.Inlark.png" }+ ]+ }+ ]+}diff --git a/apps/desktop/packaging/flatpak/inlark.sh b/apps/desktop/packaging/flatpak/inlark.shnew file mode 100755index 0000000..08092ad--- /dev/null+++ b/apps/desktop/packaging/flatpak/inlark.sh@@ -0,0 +1,3 @@+#!/bin/sh+unset ELECTRON_RUN_AS_NODE+exec zypak-wrapper /app/inlark/inlark "$@"diff --git a/apps/desktop/src/main/index.ts b/apps/desktop/src/main/index.tsindex 905ea05..f71b1f7 100644--- a/apps/desktop/src/main/index.ts+++ b/apps/desktop/src/main/index.ts@@ -37,6 +37,8 @@ protocol.registerSchemesAsPrivileged([},])configureAppIdentity(app)+if (process.platform === 'linux' && process.env.FLATPAK_ID)+ app.setDesktopName(process.env.FLATPAK_ID + '.desktop')let window: BrowserWindow | null = null,tray: Tray | null = null,quitting = falsediff --git a/apps/desktop/src/main/updates.ts b/apps/desktop/src/main/updates.tsindex bb5a79e..7ea70c6 100644--- a/apps/desktop/src/main/updates.ts+++ b/apps/desktop/src/main/updates.ts@@ -34,7 +34,8 @@ export class UpdateManager {}start() {- if (!app.isPackaged) return+ // Flatpak's /app is immutable. Bundle users install updates through Flatpak.+ if (!app.isPackaged || process.env.FLATPAK_ID) returnautoUpdater.autoDownload = trueautoUpdater.autoInstallOnAppQuit = trueautoUpdater.autoRunAppAfterInstall = falsediff --git a/apps/marketing/src/components/download/Download.tsx b/apps/marketing/src/components/download/Download.tsxindex a166fa6..e4c367e 100644--- a/apps/marketing/src/components/download/Download.tsx+++ b/apps/marketing/src/components/download/Download.tsx@@ -36,9 +36,10 @@ const alternatives: Record<BuildId, BuildId[]> = {'mac-arm64': ['mac-x64'],'mac-x64': ['mac-arm64'],windows: [],- appimage: ['deb', 'rpm', 'nix'],- deb: ['appimage', 'rpm', 'nix'],- rpm: ['appimage', 'deb', 'nix'],+ appimage: ['deb', 'rpm', 'flatpak', 'nix'],+ deb: ['appimage', 'rpm', 'flatpak', 'nix'],+ rpm: ['appimage', 'deb', 'flatpak', 'nix'],+ flatpak: ['appimage', 'deb', 'rpm'],nix: ['nixos', 'appimage'],nixos: ['nix', 'appimage'],}@@ -50,6 +51,7 @@ const alternativeLabel: Record<BuildId, string> = {appimage: 'AppImage',deb: '.deb',rpm: '.rpm',+ flatpak: 'Flatpak',nix: 'Nix',nixos: 'NixOS',}diff --git a/apps/marketing/src/components/download/Steps.tsx b/apps/marketing/src/components/download/Steps.tsxindex bcbae81..12729a0 100644--- a/apps/marketing/src/components/download/Steps.tsx+++ b/apps/marketing/src/components/download/Steps.tsx@@ -116,6 +116,33 @@ function steps({ build, file }: Download): Step[] {connect,]}+ case 'flatpak':+ return [+ {+ title: 'Install the bundle',+ body: 'Needs Flatpak installed on your system. Confirm adding Flathub for the shared runtime when asked.',+ visual: (+ <CodeBlock+ code={`cd ~/Downloads\nflatpak install --user ./${file}`}+ title="Terminal"+ className="h-full"+ />+ ),+ },+ {+ title: 'Open inlark',+ body: (+ <>+ Find it in your app menu. To update, download the new bundle and install it with{' '}+ <Path>flatpak install --user --reinstall</Path>. Your accounts and drafts stay saved.+ </>+ ),+ visual: (+ <CodeBlock code="flatpak run com.inlark.Inlark" title="Terminal" className="h-full" />+ ),+ },+ connect,+ ]case 'nix':return [{diff --git a/apps/marketing/src/data/release.ts b/apps/marketing/src/data/release.tsindex 4028402..d47fada 100644--- a/apps/marketing/src/data/release.ts+++ b/apps/marketing/src/data/release.ts@@ -2,7 +2,7 @@ import { links, version as packagedVersion } from './links'export type Os = 'mac' | 'windows' | 'linux'export type BuildId =- 'mac-arm64' | 'mac-x64' | 'windows' | 'appimage' | 'deb' | 'rpm' | 'nix' | 'nixos'+ 'mac-arm64' | 'mac-x64' | 'windows' | 'appimage' | 'deb' | 'rpm' | 'flatpak' | 'nix' | 'nixos'export interface Build {id: BuildId@@ -58,6 +58,13 @@ export const builds: Build[] = [detail: '.rpm package',file: (v) => `inlark-${v}-x86_64.rpm`,},+ {+ id: 'flatpak',+ os: 'linux',+ label: 'Flatpak',+ detail: '64-bit bundle · manual updates',+ file: (v) => `inlark-${v}-x64.flatpak`,+ },{ id: 'nix', os: 'linux', label: 'Nix', detail: 'Any Linux with Nix, x86-64 or ARM' },{ id: 'nixos', os: 'linux', label: 'NixOS', detail: 'Flake module' },]diff --git a/package.json b/package.jsonindex 4df1fdb..b076735 100644--- a/package.json+++ b/package.json@@ -12,6 +12,8 @@"test": "vitest run","check": "pnpm format:check && pnpm typecheck && pnpm test && pnpm build","package:linux": "bash scripts/package-linux.sh",+ "package:flatpak": "bash scripts/package-flatpak.sh",+ "test:flatpak": "bash scripts/test-flatpak.sh","test:integration": "vitest run --no-file-parallelism tests/stalwart.integration.test.ts tests/stalwart-imap.integration.test.ts","test:stalwart": "node scripts/stalwart-test.mjs","format": "prettier --write .",diff --git a/scripts/flatpak-archive.sh b/scripts/flatpak-archive.shnew file mode 100755index 0000000..736d3c2--- /dev/null+++ b/scripts/flatpak-archive.sh@@ -0,0 +1,12 @@+#!/usr/bin/env bash+set -euo pipefail+cd "$(dirname "$0")/.."+version=$(node -p "require('./apps/desktop/package.json').version")+directory=apps/desktop/release/linux-unpacked+test -x "$directory/inlark"+test -f "$directory/resources/app.asar"+install -m644 LICENSE "$directory/resources/LICENSE.inlark"+mkdir -p apps/desktop/release/flatpak+archive="apps/desktop/release/flatpak/inlark-$version-x64.tar.gz"+tar -czf "$archive" -C "$directory" .+node scripts/prepare-flatpak.mjs "$version" "$archive"diff --git a/scripts/package-flatpak.sh b/scripts/package-flatpak.shnew file mode 100755index 0000000..02bd83d--- /dev/null+++ b/scripts/package-flatpak.sh@@ -0,0 +1,20 @@+#!/usr/bin/env bash+set -euo pipefail+cd "$(dirname "$0")/.."+if [[ $(uname -m) != x86_64 ]]; then+ echo 'Flatpak packaging currently supports x86_64 Linux.' >&2+ exit 1+fi+command -v flatpak >/dev/null+command -v flatpak-builder >/dev/null+pnpm build+pnpm --filter @inlark/desktop exec electron-builder --linux dir --x64 --publish never+bash scripts/flatpak-archive.sh+flatpak remote-add --user --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo+flatpak-builder --user --force-clean --disable-rofiles-fuse --install-deps-from=flathub --repo=apps/desktop/release/flatpak/repo \+ --default-branch=stable apps/desktop/release/flatpak/build \+ apps/desktop/release/flatpak/manifest/com.inlark.Inlark.json+version=$(node -p "require('./apps/desktop/package.json').version")+flatpak build-bundle --runtime-repo=https://dl.flathub.org/repo/flathub.flatpakrepo \+ apps/desktop/release/flatpak/repo "apps/desktop/release/inlark-$version-x64.flatpak" \+ com.inlark.Inlark stablediff --git a/scripts/prepare-flatpak.mjs b/scripts/prepare-flatpak.mjsnew file mode 100755index 0000000..aee3593--- /dev/null+++ b/scripts/prepare-flatpak.mjs@@ -0,0 +1,57 @@+#!/usr/bin/env node+import { createHash } from 'node:crypto'+import { createReadStream } from 'node:fs'+import { copyFile, mkdir, readFile, writeFile } from 'node:fs/promises'+import { basename, join, relative, resolve } from 'node:path'+import { fileURLToPath } from 'node:url'++const root = fileURLToPath(new URL('../', import.meta.url))+const [version, archiveArgument, outputArgument = 'apps/desktop/release/flatpak/manifest'] =+ process.argv.slice(2)+const match =+ version &&+ /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/.exec(+ version,+ )+if (!match || match[4]?.split('.').some((part) => /^0\d+$/.test(part)))+ throw new Error('Supply a release version, for example 0.3.0.')+if (!archiveArgument) throw new Error('Supply the packaged Linux x64 archive.')+const archive = resolve(archiveArgument)+const filename = `inlark-${version}-x64.tar.gz`+if (basename(archive) !== filename) throw new Error(`Expected archive named ${filename}.`)+const date = process.env.RELEASE_DATE || new Date().toISOString().slice(0, 10)+if (+ !/^\d{4}-\d{2}-\d{2}$/.test(date) ||+ Number.isNaN(Date.parse(date)) ||+ new Date(date).toISOString().slice(0, 10) !== date+)+ throw new Error('RELEASE_DATE must be a valid ISO date.')+const hash = createHash('sha256')+for await (const chunk of createReadStream(archive)) hash.update(chunk)+const sha256 = hash.digest('hex')+const template = join(root, 'apps/desktop/packaging/flatpak')+const output = resolve(outputArgument)++// Package the checksum-pinned directory build before publishing the release.+await mkdir(output, { recursive: true })+const manifest = JSON.parse(+ await readFile(join(template, 'com.inlark.Inlark.template.json'), 'utf8'),+)+const source = {+ type: 'archive',+ 'strip-components': 0,+ path: relative(output, archive),+ sha256,+ dest: 'inlark',+ 'only-arches': ['x86_64'],+}+manifest.modules[0].sources.unshift(source)+await writeFile(join(output, 'com.inlark.Inlark.json'), JSON.stringify(manifest, null, 2) + '\n')+const metadata = (await readFile(join(template, 'com.inlark.Inlark.metainfo.xml'), 'utf8'))+ .replaceAll('@VERSION@', version)+ .replaceAll('@DATE@', date)+await writeFile(join(output, 'com.inlark.Inlark.metainfo.xml'), metadata)+for (const name of ['com.inlark.Inlark.desktop', 'inlark.sh'])+ await copyFile(join(template, name), join(output, name))+await copyFile(join(root, 'apps/desktop/resources/icon.png'), join(output, 'com.inlark.Inlark.png'))+console.log(`Prepared Flatpak manifest for ${version} (${sha256}).`)diff --git a/scripts/test-flatpak.sh b/scripts/test-flatpak.shnew file mode 100755index 0000000..f32826c--- /dev/null+++ b/scripts/test-flatpak.sh@@ -0,0 +1,30 @@+#!/usr/bin/env bash+set -euo pipefail+cd "$(dirname "$0")/.."+id=com.inlark.Inlark+if [[ $# -gt 0 ]]; then+ bundle=$1+else+ version=$(node -p "require('./apps/desktop/package.json').version")+ bundle="apps/desktop/release/inlark-$version-x64.flatpak"+fi+bundle=$(realpath "$bundle")+# Keep both the installation and test data separate from the user's real app.+smoke_root=$(mktemp -d)+trap 'rm -rf "$smoke_root"' EXIT+export XDG_DATA_HOME="$smoke_root/data"+export XDG_CONFIG_HOME="$smoke_root/config"+export XDG_CACHE_HOME="$smoke_root/cache"+export XDG_RUNTIME_DIR="$smoke_root/runtime"+mkdir -m700 "$XDG_RUNTIME_DIR"+flatpak install --user --noninteractive --assumeyes --reinstall "$bundle"+# Use a disposable directory inside the sandbox: never read real account data.+# Zypak provides Chromium's sandbox; the test keeps it enabled.+result=0+env -u WAYLAND_DISPLAY -u ELECTRON_RUN_AS_NODE xvfb-run -a timeout --kill-after=10s 90s dbus-run-session -- flatpak run --user --branch=stable \+ --unset-env=FONTCONFIG_FILE --unset-env=FONTCONFIG_PATH \+ --env=INLARK_DATA_DIR=/tmp/inlark-flatpak-smoke \+ "$id" --smoke-test --ozone-platform=x11 --disable-gpu > "$smoke_root/output.log" 2>&1 || result=$?+cat "$smoke_root/output.log"+if [[ "$result" -ne 0 ]]; then exit "$result"; fi+grep -F 'Native IPC smoke test passed:' "$smoke_root/output.log"diff --git a/tests/flatpak.test.ts b/tests/flatpak.test.tsnew file mode 100644index 0000000..39740e1--- /dev/null+++ b/tests/flatpak.test.ts@@ -0,0 +1,86 @@+import { createHash } from 'node:crypto'+import { execFileSync, spawnSync } from 'node:child_process'+import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'+import { tmpdir } from 'node:os'+import { join, resolve } from 'node:path'+import { afterEach, beforeEach, describe, expect, it } from 'vitest'++describe('standalone Flatpak release preparation', () => {+ let directory: string+ beforeEach(() => {+ directory = mkdtempSync(join(tmpdir(), 'inlark-flatpak-'))+ })+ afterEach(() => rmSync(directory, { recursive: true, force: true }))++ function prepare(version = '0.3.0') {+ const archive = join(directory, `inlark-${version}-x64.tar.gz`)+ writeFileSync(archive, 'the packaged release')+ const output = join(directory, 'manifest')+ execFileSync(process.execPath, ['scripts/prepare-flatpak.mjs', version, archive, output], {+ env: { ...process.env, RELEASE_DATE: '2026-10-11' },+ })+ return { archive, output }+ }++ it('packages the exact local archive and generates release-specific metadata', () => {+ const { archive, output } = prepare()+ const manifest = JSON.parse(readFileSync(join(output, 'com.inlark.Inlark.json'), 'utf8'))+ const source = manifest.modules[0].sources[0]+ expect(resolve(output, source.path)).toBe(archive)+ expect(source.sha256).toBe(createHash('sha256').update(readFileSync(archive)).digest('hex'))+ expect(source.url).toBeUndefined()+ expect(source['strip-components']).toBe(0)+ const metadata = readFileSync(join(output, 'com.inlark.Inlark.metainfo.xml'), 'utf8')+ expect(metadata).toContain('<release version="0.3.0" date="2026-10-11">')+ expect(metadata).toContain('/v0.3.0/.github/assets/inbox-dark.png')+ expect(metadata).not.toMatch(/@VERSION@|@DATE@/)+ expect(readFileSync(join(output, 'com.inlark.Inlark.png'))).toEqual(+ readFileSync('apps/desktop/resources/icon.png'),+ )+ })++ it.each(['0.3.0-beta.1', '0.3.0+build.1'])('can package release %s', (version) => {+ const { output } = prepare(version)+ expect(readFileSync(join(output, 'com.inlark.Inlark.metainfo.xml'), 'utf8')).toContain(+ `<release version="${version}"`,+ )+ })++ it('rejects mismatched archive versions before producing a manifest', () => {+ const archive = join(directory, 'inlark-0.2.0-x64.tar.gz')+ writeFileSync(archive, 'old release')+ const result = spawnSync(+ process.execPath,+ ['scripts/prepare-flatpak.mjs', '0.3.0', archive, join(directory, 'output')],+ { encoding: 'utf8' },+ )+ expect(result.status).toBe(1)+ expect(result.stderr).toContain('Expected archive named inlark-0.3.0-x64.tar.gz')+ })++ it.each(['0.3.0-beta..1', '0.3.0-01', '../0.3.0', '0.3.0"'])(+ 'rejects invalid version %s',+ (version) => {+ const result = spawnSync(+ process.execPath,+ ['scripts/prepare-flatpak.mjs', version, 'unused'],+ {+ encoding: 'utf8',+ },+ )+ expect(result.status).toBe(1)+ expect(result.stderr).toContain('Supply a release version')+ },+ )++ it.each(['2026-02-30', '2026-13-01'])('rejects invalid metadata date %s', (date) => {+ const archive = join(directory, 'inlark-0.3.0-x64.tar.gz')+ writeFileSync(archive, 'release')+ const result = spawnSync(process.execPath, ['scripts/prepare-flatpak.mjs', '0.3.0', archive], {+ env: { ...process.env, RELEASE_DATE: date },+ encoding: 'utf8',+ })+ expect(result.status).toBe(1)+ expect(result.stderr).toContain('RELEASE_DATE must be a valid ISO date')+ })+})diff --git a/tests/updates.test.ts b/tests/updates.test.tsnew file mode 100644index 0000000..4deaf79--- /dev/null+++ b/tests/updates.test.ts@@ -0,0 +1,63 @@+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'++const mocks = vi.hoisted(() => ({+ app: { isPackaged: true },+ updater: {+ autoDownload: false,+ autoInstallOnAppQuit: false,+ autoRunAppAfterInstall: true,+ on: vi.fn(),+ checkForUpdates: vi.fn().mockResolvedValue(null),+ },+ fetch: vi.fn(),+}))+vi.mock('electron', () => ({+ app: mocks.app,+ autoUpdater: { on: vi.fn() },+ net: { fetch: mocks.fetch },+}))+vi.mock('../apps/desktop/node_modules/electron-updater', () => ({+ default: { autoUpdater: mocks.updater },+}))++import { UpdateManager } from '../apps/desktop/src/main/updates'++describe('application updates', () => {+ beforeEach(() => {+ vi.useFakeTimers()+ vi.clearAllMocks()+ vi.stubEnv('FLATPAK_ID', '')+ mocks.app.isPackaged = true+ })+ afterEach(() => {+ vi.useRealTimers()+ vi.unstubAllEnvs()+ })++ it('leaves Flatpak updates to the package manager without querying GitHub', async () => {+ vi.stubEnv('FLATPAK_ID', 'com.inlark.Inlark')+ const publish = vi.fn()+ const manager = new UpdateManager(publish)+ manager.start()+ await vi.advanceTimersByTimeAsync(24 * 60 * 60 * 1000)+ expect(mocks.updater.on).not.toHaveBeenCalled()+ expect(mocks.updater.checkForUpdates).not.toHaveBeenCalled()+ expect(mocks.fetch).not.toHaveBeenCalled()+ expect(publish).not.toHaveBeenCalled()+ expect(manager.getStatus()).toEqual({ phase: 'idle' })+ })++ it('still checks for updates in other packaged installations', async () => {+ new UpdateManager(vi.fn()).start()+ await vi.advanceTimersByTimeAsync(15_000)+ expect(mocks.updater.on).toHaveBeenCalledWith('update-available', expect.any(Function))+ expect(mocks.updater.checkForUpdates).toHaveBeenCalledTimes(1)+ })++ it('does not check in development builds', async () => {+ mocks.app.isPackaged = false+ new UpdateManager(vi.fn()).start()+ await vi.advanceTimersByTimeAsync(15_000)+ expect(mocks.updater.checkForUpdates).not.toHaveBeenCalled()+ })+})