Skip to content

Commit

Permalink
fix: handle missing local Electron.app (#1530)
Browse files Browse the repository at this point in the history
* fix: handle missing local Electron.app

* Update src/renderer/components/version-select.tsx

Co-authored-by: Erik Moura <[email protected]>

---------

Co-authored-by: Erik Moura <[email protected]>
  • Loading branch information
codebytere and erikian authored Jan 15, 2024
1 parent 5cfd342 commit 18b8c95
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
18 changes: 10 additions & 8 deletions src/renderer/components/commands-runner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as React from 'react';
import { Button, ButtonProps, Spinner } from '@blueprintjs/core';
import { observer } from 'mobx-react';

import { InstallState } from '../../interfaces';
import { InstallState, VersionSource } from '../../interfaces';
import { AppState } from '../state';

interface RunnerProps {
Expand All @@ -29,7 +29,7 @@ export const Runner = observer(
isOnline,
} = this.props.appState;

const state = currentElectronVersion?.state;
const { downloadProgress, source, state } = currentElectronVersion;
const props: ButtonProps = { disabled: true };

if ([downloading, missing].includes(state) && !isOnline) {
Expand All @@ -41,12 +41,7 @@ export const Runner = observer(
switch (state) {
case downloading: {
props.text = 'Downloading';
props.icon = (
<Spinner
size={16}
value={currentElectronVersion?.downloadProgress}
/>
);
props.icon = <Spinner size={16} value={downloadProgress} />;
break;
}
case installing: {
Expand All @@ -72,6 +67,13 @@ export const Runner = observer(
}
break;
}
case missing: {
if (source === VersionSource.local) {
props.text = 'Unavailable';
props.icon = 'issue';
break;
}
}
default: {
props.text = 'Checking status';
props.icon = <Spinner size={16} />;
Expand Down
10 changes: 8 additions & 2 deletions src/renderer/components/version-select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ const itemListRenderer: ItemListRenderer<RunnableVersion> = ({
* @returns {string}
*/
export function getItemLabel({ source, state, name }: RunnableVersion): string {
// If a version is local, either it's there or it's not.
if (source === VersionSource.local) {
return name || 'Local';
return state === InstallState.missing ? 'Unavailable' : name || 'Local';
}

const installStateLabels: Record<InstallState, string> = {
Expand All @@ -87,7 +88,12 @@ export function getItemLabel({ source, state, name }: RunnableVersion): string {
* @param {RunnableVersion} { state }
* @returns {IconName}
*/
export function getItemIcon({ state }: RunnableVersion): IconName {
export function getItemIcon({ source, state }: RunnableVersion): IconName {
// If a version is local, either it's there or it's not.
if (source === VersionSource.local) {
return state === InstallState.missing ? 'issue' : 'saved';
}

const installStateIcons: Record<InstallState, IconName> = {
missing: 'cloud',
downloading: 'cloud-download',
Expand Down
13 changes: 12 additions & 1 deletion tests/renderer/components/version-select-spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,27 @@ describe('VersionSelect component', () => {
});

describe('getItemLabel()', () => {
it('returns the correct label for a local version', () => {
it('returns the correct label for an available local version', () => {
const input: RunnableVersion = {
...mockVersion1,
state: installed,
source: local,
};

expect(getItemLabel(input)).toBe('Local');
expect(getItemLabel({ ...input, name: 'Hi' })).toBe('Hi');
});

it('returns the correct label for an unavailable local version', () => {
const input: RunnableVersion = {
...mockVersion1,
state: missing,
source: local,
};

expect(getItemLabel(input)).toBe('Unavailable');
});

it('returns the correct label for a version not downloaded', () => {
const input: RunnableVersion = {
...mockVersion1,
Expand Down

0 comments on commit 18b8c95

Please sign in to comment.