// @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'; @autobind class Plugins extends React.PureComponent { state: { plugins: Array, npmPluginValue: string, error: string, loading: boolean }; constructor (props: any) { super(props); this.state = { plugins: [], npmPluginValue: '', error: '', loading: 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({loading: true}); const newState = {loading: false, error: ''}; try { await installPlugin(this.state.npmPluginValue); await this._handleRefreshPlugins(); } catch (err) { newState.error = err.message; } this.setState(newState); } _handleOpenDirectory (directory: string) { electron.remote.shell.showItemInFolder(directory); } async _handleRefreshPlugins () { // Get and reload plugins const plugins = await getPlugins(true); reload(); this.setState({plugins}); trackEvent('Plugins', 'Refresh'); } componentDidMount () { this._handleRefreshPlugins(); } render () { const {plugins, error, loading} = this.state; return (

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

{plugins.map(plugin => ( ))}
Name Version Folder
{plugin.name} {plugin.description && ( {plugin.description} )} {plugin.version} Copy Path {' '}
{error && (
{error}
)}

); } } export default Plugins;