Skip to content

Commit

Permalink
fix: disable downloads for Electron <6.0.8 and <7.0.0 on Windows arm64
Browse files Browse the repository at this point in the history
  • Loading branch information
miniak committed Apr 23, 2022
1 parent 2c27a18 commit 1c37bd3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
13 changes: 9 additions & 4 deletions src/utils/disable-download.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import semver from 'semver';

/**
* disables download button for versions below 11.0.0 on Apple Silicon.
* 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}
*
* @param {string} version - electron version
* @returns {boolean}
*/
export function disableDownload(version: string) {
return (
process.platform === 'darwin' &&
process.arch === 'arm64' &&
semver.lt(version, '11.0.0')
(process.platform === 'darwin' &&
process.arch === 'arm64' &&
semver.lt(version, '11.0.0')) ||
(process.platform === 'win32' &&
process.arch === 'arm64' &&
!semver.satisfies(version, '>=6.0.8 || >=7.0.0'))
);
}
20 changes: 16 additions & 4 deletions tests/utils/disable-download-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,24 @@ describe('disableDownload', () => {
resetArch();
});

it('always return false when the system is windows', () => {
it('always return false when the system is windows and the arch is not arm64', () => {
overridePlatform('win32');
overrideArch('x64');

expect(disableDownload('10.0.0')).toBe(false);
expect(disableDownload('11.0.0')).toBe(false);
expect(disableDownload('12.0.0')).toBe(false);
expect(disableDownload('6.0.0')).toBe(false);
expect(disableDownload('6.0.8')).toBe(false);
expect(disableDownload('7.0.0')).toBe(false);
expect(disableDownload('8.0.0')).toBe(false);
});

it('returns true if the system is windows and the arch is arm64', () => {
overridePlatform('win32');
overrideArch('arm64');

expect(disableDownload('6.0.0')).toBe(true);
expect(disableDownload('6.0.8')).toBe(false);
expect(disableDownload('7.0.0')).toBe(false);
expect(disableDownload('8.0.0')).toBe(false);
});

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

0 comments on commit 1c37bd3

Please sign in to comment.