// @flow import type {Plugin} from '../../../plugins/index'; import {getPlugins} from '../../../plugins/index'; import * as 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'; import {PLUGIN_PATH} from '../../../common/constants'; type State = { plugins: Array, npmPluginValue: string, error: string, isInstallingFromNpm: boolean, isRefreshingPlugins: boolean }; @autobind class Plugins extends React.PureComponent { _isMounted: boolean; constructor (props: any) { super(props); this.state = { plugins: [], npmPluginValue: '', error: '', isInstallingFromNpm: false, isRefreshingPlugins: false }; } _handleClearError () { this.setState({error: ''}); } _handleAddNpmPluginChange (e: Event) { if (e.target instanceof HTMLInputElement) { 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'); } _handleClickShowPluginsFolder () { electron.remote.shell.showItemInFolder(PLUGIN_PATH); trackEvent('Plugins', 'Show Folder'); } 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. See {' '} Documentation for more info.

{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;