Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

fix(desktop): check Flathub for Flathub install updates (#3638)

Hampus4af16443828e
diff --git a/fluxer_desktop/packaging/linux/app.fluxer.Fluxer.yml b/fluxer_desktop/packaging/linux/app.fluxer.Fluxer.yml
index b351b2627..7cd109bc8 100644
--- a/fluxer_desktop/packaging/linux/app.fluxer.Fluxer.yml
+++ b/fluxer_desktop/packaging/linux/app.fluxer.Fluxer.yml
@@ -35,6 +35,8 @@ modules:
buildsystem: simple
build-commands:
- install -Dm755 app.fluxer.Fluxer.sh ${FLATPAK_DEST}/bin/${FLATPAK_ID}
+ - install -d ${FLATPAK_DEST}/share/fluxer
+ - printf '%s\n' https://pkgs.fluxer.com/flatpak/ > ${FLATPAK_DEST}/share/fluxer/flatpak-repository
- mkdir -p ${FLATPAK_DEST}/fluxer
- cp -a app/. ${FLATPAK_DEST}/fluxer/
- patch-electron-desktop-filename ${FLATPAK_DEST}/fluxer/resources/app.asar
diff --git a/fluxer_desktop/packaging/linux/app.fluxer.FluxerCanary.yml b/fluxer_desktop/packaging/linux/app.fluxer.FluxerCanary.yml
index d9b083ccc..b791d731a 100644
--- a/fluxer_desktop/packaging/linux/app.fluxer.FluxerCanary.yml
+++ b/fluxer_desktop/packaging/linux/app.fluxer.FluxerCanary.yml
@@ -35,6 +35,8 @@ modules:
buildsystem: simple
build-commands:
- install -Dm755 app.fluxer.FluxerCanary.sh ${FLATPAK_DEST}/bin/${FLATPAK_ID}
+ - install -d ${FLATPAK_DEST}/share/fluxer
+ - printf '%s\n' https://pkgs.fluxer.com/flatpak/ > ${FLATPAK_DEST}/share/fluxer/flatpak-repository
- mkdir -p ${FLATPAK_DEST}/fluxer
- cp -a app/. ${FLATPAK_DEST}/fluxer/
- patch-electron-desktop-filename ${FLATPAK_DEST}/fluxer/resources/app.asar
diff --git a/fluxer_desktop/src/main/LinuxSandbox.ts b/fluxer_desktop/src/main/LinuxSandbox.ts
index daa99bf7a..a26533303 100644
--- a/fluxer_desktop/src/main/LinuxSandbox.ts
+++ b/fluxer_desktop/src/main/LinuxSandbox.ts
@@ -4,6 +4,7 @@ import fs from 'node:fs';
import {LINUX_DESKTOP_ENTRY_ID} from '@electron/common/DesktopIdentity';
const FLATPAK_INFO_PATH = '/.flatpak-info';
+const FLUXER_FLATPAK_REPOSITORY_MARKER_PATH = '/app/share/fluxer/flatpak-repository';
export function isFlatpakRuntime(): boolean {
if (process.platform !== 'linux') return false;
@@ -14,6 +15,15 @@ export function isFlatpakRuntime(): boolean {
}
}
+export function isFlatpakFromFluxerRepository(): boolean {
+ if (!isFlatpakRuntime()) return false;
+ try {
+ return fs.existsSync(FLUXER_FLATPAK_REPOSITORY_MARKER_PATH);
+ } catch {
+ return false;
+ }
+}
+
function parseFlatpakInfoAppId(contents: string): string | null {
let inApplication = false;
for (const rawLine of contents.split('\n')) {
diff --git a/fluxer_desktop/src/main/ShellUpdateCapability.ts b/fluxer_desktop/src/main/ShellUpdateCapability.ts
index 0158c8c01..14f999f6f 100644
--- a/fluxer_desktop/src/main/ShellUpdateCapability.ts
+++ b/fluxer_desktop/src/main/ShellUpdateCapability.ts
@@ -3,7 +3,7 @@
import {BUILD_CHANNEL, type BuildChannel} from '@electron/common/BuildChannel';
import {isPortableMode} from '@electron/common/UserDataPath';
import {type AppImageTarget, isRunningFromAppImage, resolveAppImageTarget} from '@electron/main/AppImageUpdate';
-import {isFlatpakRuntime} from '@electron/main/LinuxSandbox';
+import {isFlatpakFromFluxerRepository, isFlatpakRuntime} from '@electron/main/LinuxSandbox';
import {app} from 'electron';
export const ShellUpdateCapability = Object.freeze({
@@ -22,13 +22,14 @@ export type ShellUpdatePlan =
readonly target: AppImageTarget;
}
| {readonly capability: typeof ShellUpdateCapability.MANUAL_DOWNLOAD; readonly reason: 'platform' | 'unpackaged'}
- | {readonly capability: typeof ShellUpdateCapability.MANAGED_PACKAGE};
+ | {readonly capability: typeof ShellUpdateCapability.MANAGED_PACKAGE; readonly releaseFeed: 'fluxer' | 'flathub'};
interface ShellUpdateRuntime {
readonly channel: BuildChannel;
readonly packaged: boolean;
readonly portable: boolean;
readonly flatpak: boolean;
+ readonly flatpakFromFluxerRepository: boolean;
readonly appImage: AppImageTarget | null;
readonly platform: NodeJS.Platform;
}
@@ -38,13 +39,16 @@ function decideShellUpdatePlan(runtime: ShellUpdateRuntime): ShellUpdatePlan {
return {capability: ShellUpdateCapability.MANUAL_DOWNLOAD, reason: 'unpackaged'};
}
if (runtime.flatpak) {
- return {capability: ShellUpdateCapability.MANAGED_PACKAGE};
+ return {
+ capability: ShellUpdateCapability.MANAGED_PACKAGE,
+ releaseFeed: runtime.flatpakFromFluxerRepository ? 'fluxer' : 'flathub',
+ };
}
if (runtime.platform === 'linux') {
if (!runtime.portable && runtime.appImage != null) {
return {capability: ShellUpdateCapability.SELF_UPDATE, updater: 'appimage', target: runtime.appImage};
}
- return {capability: ShellUpdateCapability.MANAGED_PACKAGE};
+ return {capability: ShellUpdateCapability.MANAGED_PACKAGE, releaseFeed: 'fluxer'};
}
if (runtime.portable) {
return {capability: ShellUpdateCapability.MANUAL_DOWNLOAD, reason: 'platform'};
@@ -72,6 +76,7 @@ export function resolveShellUpdatePlan(): ShellUpdatePlan {
packaged: app.isPackaged,
portable: isPortableMode(),
flatpak: isFlatpakRuntime(),
+ flatpakFromFluxerRepository: isFlatpakFromFluxerRepository(),
appImage: resolveRunningAppImage(),
platform: process.platform,
});
diff --git a/fluxer_desktop/src/main/Updater.ts b/fluxer_desktop/src/main/Updater.ts
index f9c31431c..0c58e4b83 100644
--- a/fluxer_desktop/src/main/Updater.ts
+++ b/fluxer_desktop/src/main/Updater.ts
@@ -3,6 +3,7 @@ import {isRecord} from '@fluxer/record_utils/src/RecordGuards';
import {errorMessage as getErrorMessage} from '@electron/common/ErrorMessage';
import {checkDesktopUpdateNow} from '@electron/main/DesktopUpdateGate';
+import {getFlatpakAppId} from '@electron/main/LinuxSandbox';
import {compareShellVersions} from '@electron/main/ModuleVersion';
import {MANUAL_DESKTOP_FORMATS, type ManualDesktopFormat} from '@electron/main/ShellDownloadFormats';
import {resolveShellUpdatePlan, ShellUpdateCapability} from '@electron/main/ShellUpdateCapability';
@@ -51,6 +52,7 @@ function send(win: BrowserWindow | null, event: UpdaterEvent) {
let manualLatestCache: {at: number; info: ManualLatestInfo} | null = null;
const MANUAL_CACHE_TTL_MS = 5 * 60 * 1000;
+const FLATHUB_APPSTREAM_URL = 'https://flathub.org/api/v2/appstream';
function parseManualLatestFiles(value: unknown): Partial<Record<ManualDesktopFormat, ManualLatestFile>> {
if (!isRecord(value)) {
@@ -70,11 +72,7 @@ function parseManualLatestFiles(value: unknown): Partial<Record<ManualDesktopFor
return files;
}
-async function fetchManualLatest(options: {forceRefresh?: boolean} = {}): Promise<ManualLatestInfo> {
- const now = Date.now();
- if (!options.forceRefresh && manualLatestCache && now - manualLatestCache.at < MANUAL_CACHE_TTL_MS) {
- return manualLatestCache.info;
- }
+async function fetchFluxerLatest(): Promise<ManualLatestInfo> {
const response = await net.fetch(`${UPDATE_BASE_URL}/latest`, {
cache: 'no-store',
headers: {
@@ -90,11 +88,56 @@ async function fetchManualLatest(options: {forceRefresh?: boolean} = {}): Promis
if (typeof payload.version !== 'string' || payload.version.length === 0) {
throw new Error('Latest version response missing version string');
}
- const info: ManualLatestInfo = {
+ return {
version: payload.version,
pubDate: typeof payload.pub_date === 'string' ? payload.pub_date : null,
files: parseManualLatestFiles(payload.files),
};
+}
+
+function newestFlathubReleaseVersion(payload: unknown): string | null {
+ if (!isRecord(payload) || !Array.isArray(payload.releases)) {
+ return null;
+ }
+ let newest: string | null = null;
+ for (const release of payload.releases) {
+ if (!isRecord(release) || typeof release.version !== 'string') {
+ continue;
+ }
+ if (newest == null || compareShellVersions(release.version, newest) > 0) {
+ newest = release.version;
+ }
+ }
+ return newest;
+}
+
+async function fetchFlathubLatest(): Promise<ManualLatestInfo> {
+ const appId = getFlatpakAppId();
+ if (appId == null) {
+ throw new Error('The Flatpak app id is unknown, so Flathub cannot be asked for a release');
+ }
+ const response = await net.fetch(`${FLATHUB_APPSTREAM_URL}/${encodeURIComponent(appId)}?locale=en`, {
+ cache: 'no-store',
+ headers: {Accept: 'application/json'},
+ });
+ if (!response.ok) {
+ throw new Error(`Flathub release request failed: ${response.status}`);
+ }
+ const version = newestFlathubReleaseVersion(await response.json());
+ if (version == null) {
+ throw new Error('Flathub lists no release version');
+ }
+ return {version, pubDate: null, files: {}};
+}
+
+async function fetchManualLatest(options: {forceRefresh?: boolean} = {}): Promise<ManualLatestInfo> {
+ const now = Date.now();
+ if (!options.forceRefresh && manualLatestCache && now - manualLatestCache.at < MANUAL_CACHE_TTL_MS) {
+ return manualLatestCache.info;
+ }
+ const plan = resolveShellUpdatePlan();
+ const fromFlathub = plan.capability === ShellUpdateCapability.MANAGED_PACKAGE && plan.releaseFeed === 'flathub';
+ const info = fromFlathub ? await fetchFlathubLatest() : await fetchFluxerLatest();
manualLatestCache = {at: now, info};
return info;
}