// The AppStream metainfo the AppImage carries, made from the shared one // before Tauri bundles (`beforeBundleCommand`). AppImage tools look for // `usr/share/metainfo/*.appdata.xml`, and the AppImage's desktop entry is // `Donut.desktop`, not the Flatpak's `com.donutbrowser.DonutBrowser.desktop`. // The URL types AppStream 0.15 does not know (Ubuntu 22.04, the oldest // system the AppImage runs on) are left out, so the file validates there. // The version being bundled becomes the newest release, as // packaging/linux/stamp-release.sh does for the Flatpak and the Snap. import { mkdirSync, readFileSync, writeFileSync } from "node:fs"; import { dirname, resolve } from "node:path"; import { fileURLToPath } from "node:url"; const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), ".."); export const SHARED_METAINFO = resolve( ROOT, "packaging/linux/com.donutbrowser.DonutBrowser.metainfo.xml", ); /** Where `bundle.linux.appimage.files` in tauri.conf.json takes it from. */ export const APPIMAGE_METAINFO = resolve( ROOT, "src-tauri/target/appimage/com.donutbrowser.DonutBrowser.appdata.xml", ); const SHARED_LAUNCHABLE = 'com.donutbrowser.DonutBrowser.desktop'; const APPIMAGE_LAUNCHABLE = 'Donut.desktop'; const NEWER_URL_TYPES = /^[ \t]*.*<\/url>\r?\n/gm; const RELEASES = /^([ \t]*)\r?\n/m; export function appimageMetainfo(shared, version, date) { if (!shared.includes(SHARED_LAUNCHABLE)) { throw new Error(`The shared metainfo has no ${SHARED_LAUNCHABLE}`); } if (!RELEASES.test(shared)) { throw new Error("The shared metainfo has no "); } const withoutNewerUrls = shared .replace(SHARED_LAUNCHABLE, APPIMAGE_LAUNCHABLE) .replace(NEWER_URL_TYPES, ""); if (withoutNewerUrls.includes(` `${line}${indent} \n`, ); } function main() { const { version } = JSON.parse( readFileSync(resolve(ROOT, "src-tauri/tauri.conf.json"), "utf8"), ); mkdirSync(dirname(APPIMAGE_METAINFO), { recursive: true }); writeFileSync( APPIMAGE_METAINFO, appimageMetainfo( readFileSync(SHARED_METAINFO, "utf8"), version, new Date().toISOString().slice(0, 10), ), ); } const isDirectRun = process.argv[1] && fileURLToPath(import.meta.url) === resolve(process.argv[1]); if (isDirectRun) main();