Skip to content
Merged
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
9 changes: 8 additions & 1 deletion src/renderer/components/commands-runner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ interface RunnerProps {
export const Runner = observer(
class Runner extends React.Component<RunnerProps> {
public render() {
const { downloading, missing, installing, installed } = InstallState;
const {
downloaded,
downloading,
missing,
installing,
installed,
} = InstallState;
const {
isRunning,
isInstallingModules,
Expand Down Expand Up @@ -53,6 +59,7 @@ export const Runner = observer(
props.icon = <Spinner size={16} />;
break;
}
case downloaded:
case installed: {
props.disabled = false;
if (isRunning) {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/settings-electron.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ export const ElectronSettings = observer(
buttonProps.onClick = () => {
isLocal
? appState.removeVersion(ver)
: appState.downloadVersion(ver, { activate: false });
: appState.downloadVersion(ver);
};
break;
}
Expand Down
31 changes: 6 additions & 25 deletions src/renderer/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -579,18 +579,12 @@ export class AppState {
}

/**
* Download a version of Electron and set it as the current
* version in use unless otherwise specified.
* Download a version of Electron.
*
* @param {RunnableVersion} ver
* @param {Object} opts
* @param {Boolean} [options.activate=true] - Whether to set ver as current
* @returns {Promise<void>}
*/
public async downloadVersion(
ver: RunnableVersion,
opts: { activate: boolean } = { activate: true },
): Promise<void> {
public async downloadVersion(ver: RunnableVersion): Promise<void> {
const { source, state, version } = ver;
const {
electronMirror,
Expand All @@ -603,7 +597,7 @@ export class AppState {
const isInstalling = state === InstallState.installing;
const isReady = state === InstallState.installed;

if (isDownloading || isInstalling) {
if (isDownloaded || isDownloading || isInstalling) {
console.log(`State: Already ${state} ${version}.`);
return;
}
Expand All @@ -613,15 +607,10 @@ export class AppState {
return;
}

if (isDownloaded) {
// The electron zip needs to be unzipped as well
await this.installer.install(version);
return;
}

console.log(`State: Downloading Electron ${version}`);

const options = {
// Download the version without setting it as the current version.
await this.installer.ensureDownloaded(version, {
mirror: {
electronMirror,
electronNightlyMirror,
Expand All @@ -635,15 +624,7 @@ export class AppState {
}
});
},
};

// Download the version without setting it as the current version.
if (!opts.activate) {
await this.installer.ensureDownloaded(version, options);
return;
}

await this.installer.install(version, options);
});
}

/**
Expand Down
12 changes: 9 additions & 3 deletions tests/renderer/state-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ describe('AppState', () => {
let appState: AppState;
let mockVersions: Record<string, RunnableVersion>;
let mockVersionsArray: RunnableVersion[];
let removeSpy: any;
let installSpy: any;
let removeSpy: jest.SpyInstance;
let installSpy: jest.SpyInstance;
let ensureDownloadedSpy: jest.SpyInstance;

beforeEach(() => {
({ mockVersions, mockVersionsArray } = new VersionsMock());
Expand All @@ -61,6 +62,9 @@ describe('AppState', () => {
installSpy = jest
.spyOn(appState.installer, 'install')
.mockResolvedValue('');
ensureDownloadedSpy = jest
.spyOn(appState.installer, 'ensureDownloaded')
.mockResolvedValue({ path: '', alreadyExtracted: false });
});

it('exists', () => {
Expand Down Expand Up @@ -337,7 +341,8 @@ describe('AppState', () => {

await appState.downloadVersion(ver);

expect(installSpy).toHaveBeenCalled();
expect(ensureDownloadedSpy).toHaveBeenCalled();
expect(installSpy).not.toHaveBeenCalled();
});

it('does not download a version if already ready', async () => {
Expand All @@ -346,6 +351,7 @@ describe('AppState', () => {

await appState.downloadVersion(ver);

expect(ensureDownloadedSpy).not.toHaveBeenCalled();
expect(installSpy).not.toHaveBeenCalled();
});
});
Expand Down