import { Button, ButtonGroup, Callout, Checkbox, FormGroup, HTMLTable, ButtonProps, Icon, IconName, AnchorButton, Tooltip, } from '@blueprintjs/core'; import { observer } from 'mobx-react'; import * as React from 'react'; import { ElectronReleaseChannel, RunnableVersion, VersionSource, VersionState, } from '../../interfaces'; import { AppState } from '../state'; import { getReleaseChannel, getOldestSupportedMajor } from '../versions'; interface ElectronSettingsProps { appState: AppState; } interface ElectronSettingsState { isDownloadingAll: boolean; isDeletingAll: boolean; } /** * Settings content to manage Electron-related preferences. * * @class ElectronSettings * @extends {React.Component} */ @observer export class ElectronSettings extends React.Component< ElectronSettingsProps, ElectronSettingsState > { constructor(props: ElectronSettingsProps) { super(props); this.handleAddVersion = this.handleAddVersion.bind(this); this.handleChannelChange = this.handleChannelChange.bind(this); this.handleDeleteAll = this.handleDeleteAll.bind(this); this.handleDownloadAll = this.handleDownloadAll.bind(this); this.handleDownloadClick = this.handleDownloadClick.bind(this); this.handleShowObsoleteChange = this.handleShowObsoleteChange.bind(this); this.handleStateChange = this.handleStateChange.bind(this); this.state = { isDownloadingAll: false, isDeletingAll: false, }; } public handleDownloadClick() { this.props.appState.updateElectronVersions(); } /** * Toggles visibility of non-downloaded versions * * @param {React.ChangeEvent} event */ public handleStateChange(event: React.FormEvent) { const { appState } = this.props; const { checked } = event.currentTarget; appState.showUndownloadedVersions = checked; } /** * Toggles visibility of obsolete versions * * @param {React.ChangeEvent} event */ public handleShowObsoleteChange(event: React.FormEvent) { const { appState } = this.props; const { checked } = event.currentTarget; appState.showObsoleteVersions = checked; } /** * Handles a change in which channels should be displayed. * * @param {React.ChangeEvent} event */ public handleChannelChange(event: React.FormEvent) { const { id, checked } = event.currentTarget; const { appState } = this.props; if (!checked) { appState.hideChannels([id as ElectronReleaseChannel]); } else { appState.showChannels([id as ElectronReleaseChannel]); } } /** * Download all visible versions of Electron. * * @returns {Promise} */ public async handleDownloadAll(): Promise { this.setState({ isDownloadingAll: true }); const { downloadVersion, versionsToShow } = this.props.appState; for (const ver of versionsToShow) { await downloadVersion(ver); } this.setState({ isDownloadingAll: false }); } /** * Delete all downloaded versions of Electron. * * @returns {Promise} */ public async handleDeleteAll(): Promise { this.setState({ isDeletingAll: true }); const { versions, removeVersion } = this.props.appState; for (const ver of Object.values(versions)) { await removeVersion(ver); } this.setState({ isDeletingAll: false }); } /** * Opens the "add local version" dialog */ public handleAddVersion(): void { this.props.appState.toggleAddVersionDialog(); } public render() { return (

Electron Settings

{this.renderVersionShowOptions()}
{this.renderAdvancedButtons()} {this.renderTable()}
); } /** * Renders the various buttons for advanced operations * * @private * @returns {JSX.Element} */ private renderAdvancedButtons(): JSX.Element { const { isDownloadingAll, isDeletingAll } = this.state; const { isUpdatingElectronVersions } = this.props.appState; const isWorking = isDownloadingAll || isDeletingAll; return (