// @flow import type {Plugin} from '../../../plugins/index'; import {getPlugins} from '../../../plugins/index'; import React from 'react'; import autobind from 'autobind-decorator'; import * as electron from 'electron'; import Button from '../base/button'; import CopyButton from '../base/copy-button'; import {trackEvent} from '../../../analytics/index'; import {reload} from '../../../templating/index'; import installPlugin from '../../../plugins/install'; import HelpTooltip from '../help-tooltip'; import Link from '../base/link'; import {delay} from '../../../common/misc'; @autobind class Plugins extends React.PureComponent { state: { plugins: Array, npmPluginValue: string, error: string, isInstallingFromNpm: boolean, isRefreshingPlugins: boolean }; _isMounted: boolean; constructor (props: any) { super(props); this.state = { plugins: [], npmPluginValue: '', error: '', isInstallingFromNpm: false, isRefreshingPlugins: false }; } _handleClearError () { this.setState({error: ''}); } _handleAddNpmPluginChange (e: Event & {target: HTMLButtonElement}) { this.setState({npmPluginValue: e.target.value}); } async _handleAddFromNpm (e: Event): Promise { e.preventDefault(); this.setState({isInstallingFromNpm: true}); const newState = {isInstallingFromNpm: false, error: ''}; try { await installPlugin(this.state.npmPluginValue); await this._handleRefreshPlugins(); } catch (err) { newState.error = err.message; } this.setState(newState); } _handleOpenDirectory (directory: string): void { electron.remote.shell.showItemInFolder(directory); } async _handleRefreshPlugins (): Promise { const start = Date.now(); this.setState({isRefreshingPlugins: true}); // Get and reload plugins const plugins = await getPlugins(true); reload(); // Delay loading for at least 500ms. UX FTW! const delta = Date.now() - start; await delay(500 - delta); if (this._isMounted) { this.setState({plugins, isRefreshingPlugins: false}); } } async _handleClickRefreshPlugins () { await this._handleRefreshPlugins(); trackEvent('Plugins', 'Refresh'); } componentDidMount () { this._isMounted = true; this._handleRefreshPlugins(); } componentWillUnmount () { this._isMounted = false; } render () { const {plugins, error, isInstallingFromNpm, isRefreshingPlugins} = this.state; return (

Plugins is still an experimental feature. Please {' '} Submit Feedback if you have any.

{plugins.length === 0 ? (
No Plugins Added
) : ( {plugins.map(plugin => ( ))}
Name Version Folder
{plugin.name} {plugin.description && ( {plugin.description} )} {plugin.version} Copy Path {' '}
)} {error && (
{error}
)}

); } } export default Plugins;