build(android): add fdroid distribution flavor

This commit is contained in:
Tommaso Casaburi
2026-04-30 18:58:50 +07:00
parent ea03d04cd9
commit fdbb650baa
25 changed files with 259 additions and 75 deletions
+22
View File
@@ -43,6 +43,7 @@ describe('app-update', () => {
testState.electronDownloadAndInstallUpdateMock.mockReset();
testState.electronGetPlatformMock.mockReset();
testState.fetchMock.mockReset();
vi.stubEnv('VITE_APP_VERSION', '0.8.1');
vi.stubGlobal('fetch', testState.fetchMock);
window.electronApi = undefined;
Object.defineProperty(navigator, 'serviceWorker', {
@@ -91,6 +92,27 @@ describe('app-update', () => {
expect(result).toBeNull();
});
it('disables update checks for F-Droid builds', async () => {
vi.stubEnv('VITE_APP_DISTRIBUTION', 'fdroid');
testState.capacitorPlatform = 'android';
const { applyAvailableAppUpdate, isAppUpdateEnabled, resolveAvailableAppUpdate } = await loadModule();
await expect(resolveAvailableAppUpdate()).resolves.toBeNull();
await expect(
applyAvailableAppUpdate({
runtime: 'android',
targetVersion: '9.9.9',
assetName: '5chan-9.9.9.apk',
downloadUrl: 'https://github.com/bitsocialnet/5chan/releases/download/v9.9.9/5chan-9.9.9.apk',
releaseUrl: 'https://github.com/bitsocialnet/5chan/releases/tag/v9.9.9',
}),
).rejects.toThrow('App updates are disabled for this build');
expect(isAppUpdateEnabled).toBe(false);
expect(testState.fetchMock).not.toHaveBeenCalled();
expect(testState.androidDownloadAndInstallUpdateMock).not.toHaveBeenCalled();
});
it('selects the matching electron release asset for the current desktop platform', async () => {
window.electronApi = {
isElectron: true,
+4
View File
@@ -0,0 +1,4 @@
const appDistribution = import.meta.env.VITE_APP_DISTRIBUTION?.trim().toLowerCase();
const isAppUpdateEnabled = appDistribution !== 'fdroid';
export { isAppUpdateEnabled };
+11 -2
View File
@@ -1,5 +1,5 @@
import { Capacitor } from '@capacitor/core';
import AppUpdater from '../plugins/app-updater';
import { isAppUpdateEnabled } from './app-distribution';
import { currentAppVersion } from './app-version';
import { getDefaultReleaseUrl, getReleaseApiUrl, isAllowedDownloadUrl } from './app-update-config';
@@ -180,6 +180,10 @@ const fetchLatestReleaseUpdate = async (runtime: Extract<AppRuntime, 'electron'
};
const resolveAvailableAppUpdate = async (): Promise<AvailableAppUpdate | null> => {
if (!isAppUpdateEnabled) {
return null;
}
const runtime = getAppRuntime();
if (runtime === 'web') {
@@ -201,6 +205,10 @@ const resolveAvailableAppUpdate = async (): Promise<AvailableAppUpdate | null> =
};
const applyAvailableAppUpdate = async (update: AvailableAppUpdate): Promise<void> => {
if (!isAppUpdateEnabled) {
throw new Error('App updates are disabled for this build');
}
if (update.runtime === 'web') {
await refreshServiceWorkerRegistration().catch((error) => {
console.error('Failed to refresh service worker registration', error);
@@ -221,6 +229,7 @@ const applyAvailableAppUpdate = async (update: AvailableAppUpdate): Promise<void
return;
}
const { default: AppUpdater } = await import('../plugins/app-updater');
await AppUpdater.downloadAndInstallUpdate({
url: update.downloadUrl,
fileName: update.assetName,
@@ -228,4 +237,4 @@ const applyAvailableAppUpdate = async (update: AvailableAppUpdate): Promise<void
};
export type { AppRuntime, AvailableAppUpdate, NativeAppUpdateInfo, WebAppUpdateInfo };
export { applyAvailableAppUpdate, fetchLatestStableVersion, getAppRuntime, isElectron, refreshServiceWorkerRegistration, resolveAvailableAppUpdate };
export { applyAvailableAppUpdate, fetchLatestStableVersion, getAppRuntime, isAppUpdateEnabled, isElectron, refreshServiceWorkerRegistration, resolveAvailableAppUpdate };
+1 -3
View File
@@ -1,5 +1,3 @@
import packageJson from '../../package.json';
const resolveCurrentAppVersion = (): string => {
const configuredVersion = import.meta.env.VITE_APP_VERSION;
@@ -7,7 +5,7 @@ const resolveCurrentAppVersion = (): string => {
return configuredVersion.trim();
}
return packageJson.version;
return '0.0.0';
};
const currentAppVersion = resolveCurrentAppVersion();