feat: add auto update support (#65)

This commit is contained in:
2026-05-16 00:09:14 -07:00
committed by GitHub
parent 105713361e
commit 91a01b86a9
71 changed files with 2368 additions and 188 deletions
+227 -1
View File
@@ -1,6 +1,13 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { configureAutoUpdater, type ElectronAutoUpdaterLike } from './app-updater';
import {
configureAutoUpdater,
createElectronAppUpdater,
isKnownLinuxPackageManagedAppImage,
isNativeUpdaterSupported,
resolveMacAppBundlePath,
type ElectronAutoUpdaterLike,
} from './app-updater';
type UpdaterLogger = {
info: (message: string) => void;
@@ -53,3 +60,222 @@ test('configureAutoUpdater allows prereleases only for the prerelease channel',
configureAutoUpdater(updater, () => {}, 'stable');
assert.equal(updater.allowPrerelease, false);
});
test('configureAutoUpdater handles late updater error events', () => {
const logged: string[] = [];
const errorListeners: Array<(error: unknown) => void> = [];
const updater: ElectronAutoUpdaterLike & {
on: (event: string, listener: (error: unknown) => void) => typeof updater;
} = {
autoDownload: true,
allowPrerelease: false,
allowDowngrade: true,
logger: null,
checkForUpdates: async () => null,
downloadUpdate: async () => [],
quitAndInstall: () => {},
on: (event, listener) => {
if (event === 'error') errorListeners.push(listener);
return updater;
},
};
configureAutoUpdater(updater, (message) => logged.push(message));
const [errorListener] = errorListeners;
assert.ok(errorListener);
errorListener(new Error('APPIMAGE env is not defined'));
assert.deepEqual(logged, ['Updater error event: APPIMAGE env is not defined']);
});
test('app updater skips native update checks when native updater is unsupported', async () => {
let checked = false;
const updater: ElectronAutoUpdaterLike = {
autoDownload: true,
allowPrerelease: false,
allowDowngrade: true,
logger: null,
checkForUpdates: async () => {
checked = true;
return {
updateInfo: {
version: '0.15.0',
},
};
},
downloadUpdate: async () => [],
quitAndInstall: () => {},
};
const logged: string[] = [];
const appUpdater = createElectronAppUpdater({
currentVersion: '0.14.0',
isPackaged: true,
updater,
log: (message) => logged.push(message),
isNativeUpdaterSupported: () => false,
});
const result = await appUpdater.checkForUpdates('stable');
assert.equal(checked, false);
assert.deepEqual(result, {
available: false,
version: '0.14.0',
canUpdate: false,
});
assert.deepEqual(logged, [
'Skipping native app update check because native updater is unsupported.',
]);
});
test('app updater skips native downloads when native updater is unsupported', async () => {
let downloaded = false;
const updater: ElectronAutoUpdaterLike = {
autoDownload: true,
allowPrerelease: false,
allowDowngrade: true,
logger: null,
checkForUpdates: async () => null,
downloadUpdate: async () => {
downloaded = true;
return [];
},
quitAndInstall: () => {},
};
const logged: string[] = [];
const appUpdater = createElectronAppUpdater({
currentVersion: '0.14.0',
isPackaged: true,
updater,
log: (message) => logged.push(message),
isNativeUpdaterSupported: () => false,
});
await appUpdater.downloadUpdate();
assert.equal(downloaded, false);
assert.deepEqual(logged, ['Skipping app update download because native updater is unsupported.']);
});
test('resolveMacAppBundlePath resolves packaged macOS executable path', () => {
assert.equal(
resolveMacAppBundlePath('/Applications/SubMiner.app/Contents/MacOS/SubMiner'),
'/Applications/SubMiner.app',
);
assert.equal(resolveMacAppBundlePath('/usr/local/bin/SubMiner'), null);
});
test('mac native updater is unsupported for ad-hoc signed app bundles', async () => {
const logged: string[] = [];
const supported = await isNativeUpdaterSupported({
platform: 'darwin',
isPackaged: true,
execPath: '/Applications/SubMiner.app/Contents/MacOS/SubMiner',
readCodeSignature: () =>
['Signature=adhoc', 'TeamIdentifier=not set', 'Runtime Version=26.0.0'].join('\n'),
log: (message) => logged.push(message),
});
assert.equal(supported, false);
assert.deepEqual(logged, ['Skipping native macOS updater because this build is ad-hoc signed.']);
});
test('mac native updater is supported for Developer ID signed app bundles', async () => {
const supported = await isNativeUpdaterSupported({
platform: 'darwin',
isPackaged: true,
execPath: '/Applications/SubMiner.app/Contents/MacOS/SubMiner',
readCodeSignature: () =>
['Authority=Developer ID Application: Example', 'TeamIdentifier=ABCDE12345'].join('\n'),
});
assert.equal(supported, true);
});
test('linux native updater is unsupported even for writable direct AppImage installs', async () => {
const logged: string[] = [];
const supported = await isNativeUpdaterSupported({
platform: 'linux',
isPackaged: true,
execPath: '/tmp/.mount_SubMiner/SubMiner',
env: {
APPIMAGE: '/home/tester/.local/bin/SubMiner.AppImage',
},
log: (message) => logged.push(message),
});
assert.equal(supported, false);
assert.deepEqual(logged, [
'Skipping native Linux updater because Linux tray checks use GitHub release assets.',
]);
});
test('linux native updater is unsupported when APPIMAGE is missing', async () => {
const logged: string[] = [];
const supported = await isNativeUpdaterSupported({
platform: 'linux',
isPackaged: true,
execPath: '/tmp/.mount_SubMiner/SubMiner',
env: {},
log: (message) => logged.push(message),
});
assert.equal(supported, false);
assert.deepEqual(logged, [
'Skipping native Linux updater because Linux tray checks use GitHub release assets.',
]);
});
test('linux native updater is unsupported for non-writable AppImage installs', async () => {
const logged: string[] = [];
const supported = await isNativeUpdaterSupported({
platform: 'linux',
isPackaged: true,
execPath: '/tmp/.mount_SubMiner/SubMiner',
env: {
APPIMAGE: '/home/tester/.local/bin/SubMiner.AppImage',
},
log: (message) => logged.push(message),
});
assert.equal(supported, false);
assert.deepEqual(logged, [
'Skipping native Linux updater because Linux tray checks use GitHub release assets.',
]);
});
test('linux native updater is unsupported for package-managed AppImage installs', async () => {
const logged: string[] = [];
const supported = await isNativeUpdaterSupported({
platform: 'linux',
isPackaged: true,
execPath: '/tmp/.mount_SubMiner/SubMiner',
env: {
APPIMAGE: '/opt/SubMiner/SubMiner.AppImage',
},
log: (message) => logged.push(message),
});
assert.equal(supported, false);
assert.deepEqual(logged, [
'Skipping native Linux updater because Linux tray checks use GitHub release assets.',
]);
});
test('known Linux package-managed AppImage detection follows the canonical AUR path', () => {
assert.equal(isKnownLinuxPackageManagedAppImage('/opt/SubMiner/SubMiner.AppImage'), true);
assert.equal(
isKnownLinuxPackageManagedAppImage('/home/tester/.local/bin/SubMiner.AppImage'),
false,
);
});
test('native updater is unsupported on Windows by default', async () => {
const supported = await isNativeUpdaterSupported({
platform: 'win32',
isPackaged: true,
execPath: 'C:\\Program Files\\SubMiner\\SubMiner.exe',
});
assert.equal(supported, false);
});