Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 25 additions & 12 deletions src/renderer/utils/disable-download.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
import semver from 'semver';

const lastIa32AndArmv7lVersion = '44.0.0-alpha.3';

/**
* Rules for Electron versions that have no build for a platform and
* architecture. Combinations without a rule can download any version.
*/
const unavailableVersions: Partial<
Record<string, (version: string) => boolean>
> = {
// Apple Silicon builds start with 11.0.0.
// Reference: {@link https://www.electronjs.org/blog/apple-silicon}
'darwin-arm64': (version) => semver.lt(version, '11.0.0'),
// Windows arm64 builds start with 6.0.8.
'win32-arm64': (version) => !semver.satisfies(version, '>=6.0.8 || >=7.0.0'),
// Windows ia32 and Linux armv7l builds are no longer published after
// 44.0.0-alpha.3.
// Reference: {@link https://github.com/electron/electron/blob/main/docs/breaking-changes.md#removed-windows-32-bit-ia32-and-linux-32-bit-arm-armv7l-support}
'win32-ia32': (version) => semver.gt(version, lastIa32AndArmv7lVersion),
'linux-arm': (version) => semver.gt(version, lastIa32AndArmv7lVersion),
};

/**
* disables download button for versions:
* - below 11.0.0 on Apple Silicon.
* - below 6.0.8 and 7.0.0 on Windows arm64
* Reference: {@link https://www.electronjs.org/blog/apple-silicon}
* Whether the download button is disabled for an Electron version, because
* no build of it exists for the current platform and architecture.
*
* @param version - electron version
*/
export function disableDownload(version: string): boolean {
return (
(window.ElectronFiddle.platform === 'darwin' &&
window.ElectronFiddle.arch === 'arm64' &&
semver.lt(version, '11.0.0')) ||
(window.ElectronFiddle.platform === 'win32' &&
window.ElectronFiddle.arch === 'arm64' &&
!semver.satisfies(version, '>=6.0.8 || >=7.0.0'))
);
const { platform, arch } = window.ElectronFiddle;
return unavailableVersions[`${platform}-${arch}`]?.(version) ?? false;
}
22 changes: 22 additions & 0 deletions tests/renderer/utils/disable-download.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,28 @@ describe('disableDownload', () => {
expect(disableDownload('8.0.0')).toBe(false);
});

it('returns true for Electron 44 and higher on 32-bit Windows', () => {
overrideRendererPlatform('win32');
overrideRendererArch('ia32');

expect(disableDownload('43.0.0')).toBe(false);
expect(disableDownload('44.0.0-alpha.3')).toBe(false);
expect(disableDownload('44.0.0-alpha.4')).toBe(true);
expect(disableDownload('44.0.0')).toBe(true);
expect(disableDownload('44.5.1')).toBe(true);
expect(disableDownload('46.0.0-nightly.20261021')).toBe(true);
});

it('returns true for Electron 44 and higher on 32-bit ARM Linux', () => {
overrideRendererPlatform('linux');
overrideRendererArch('arm');

expect(disableDownload('43.0.0')).toBe(false);
expect(disableDownload('44.0.0-alpha.3')).toBe(false);
expect(disableDownload('44.0.0-alpha.4')).toBe(true);
expect(disableDownload('44.5.1')).toBe(true);
});

it('always return false when the system is linux', () => {
overrideRendererPlatform('linux');

Expand Down
Loading