2017-07-20 01:55:40 +00:00
|
|
|
// @flow
|
|
|
|
import type {Plugin} from '../../../plugins/index';
|
|
|
|
import {createPlugin, getPlugins} from '../../../plugins/index';
|
|
|
|
import React from 'react';
|
2017-06-01 02:04:27 +00:00
|
|
|
import autobind from 'autobind-decorator';
|
|
|
|
import * as electron from 'electron';
|
|
|
|
import Button from '../base/button';
|
|
|
|
import CopyButton from '../base/copy-button';
|
|
|
|
import {showPrompt} from '../modals/index';
|
2017-06-09 01:10:12 +00:00
|
|
|
import {trackEvent} from '../../../analytics/index';
|
2017-07-11 01:05:54 +00:00
|
|
|
import {reload} from '../../../templating/index';
|
2017-06-01 02:04:27 +00:00
|
|
|
|
2017-07-20 01:55:40 +00:00
|
|
|
type DefaultProps = void;
|
|
|
|
type Props = void;
|
|
|
|
type State = {
|
|
|
|
plugins: Array<Plugin>,
|
|
|
|
npmPluginValue: string
|
|
|
|
};
|
|
|
|
|
2017-06-01 02:04:27 +00:00
|
|
|
@autobind
|
2017-07-20 01:55:40 +00:00
|
|
|
class Plugins extends React.PureComponent<DefaultProps, Props, State> {
|
|
|
|
props: Props;
|
|
|
|
state: State;
|
|
|
|
|
|
|
|
constructor (props: Props) {
|
2017-06-01 02:04:27 +00:00
|
|
|
super(props);
|
|
|
|
this.state = {
|
2017-07-20 01:55:40 +00:00
|
|
|
plugins: [],
|
|
|
|
npmPluginValue: ''
|
2017-06-01 02:04:27 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-07-20 01:55:40 +00:00
|
|
|
_handleAddNpmPluginChange (e: Event & {target: HTMLButtonElement}) {
|
|
|
|
this.setState({npmPluginValue: e.target.value});
|
|
|
|
}
|
|
|
|
|
|
|
|
_handleAddFromNpm () {
|
|
|
|
console.log('ADD FROM NPM', this.state.npmPluginValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
_handleOpenDirectory (directory: string) {
|
2017-06-01 02:04:27 +00:00
|
|
|
electron.remote.shell.showItemInFolder(directory);
|
|
|
|
}
|
|
|
|
|
|
|
|
_handleGeneratePlugin () {
|
|
|
|
showPrompt({
|
2017-07-20 01:55:40 +00:00
|
|
|
title: 'Plugin Name',
|
2017-06-01 02:04:27 +00:00
|
|
|
defaultValue: 'My Plugin',
|
|
|
|
submitName: 'Generate Plugin',
|
|
|
|
selectText: true,
|
|
|
|
placeholder: 'My Cool Plugin',
|
|
|
|
label: 'Plugin Name',
|
|
|
|
onComplete: async name => {
|
|
|
|
await createPlugin(name);
|
2017-07-20 01:55:40 +00:00
|
|
|
await this._handleRefreshPlugins();
|
2017-06-09 01:10:12 +00:00
|
|
|
trackEvent('Plugins', 'Generate');
|
2017-06-01 02:04:27 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-07-20 01:55:40 +00:00
|
|
|
async _handleRefreshPlugins () {
|
2017-07-11 01:05:54 +00:00
|
|
|
// Get and reload plugins
|
2017-07-20 01:55:40 +00:00
|
|
|
const plugins = await getPlugins(true);
|
2017-07-11 01:05:54 +00:00
|
|
|
reload();
|
|
|
|
|
|
|
|
this.setState({plugins});
|
2017-06-09 01:10:12 +00:00
|
|
|
trackEvent('Plugins', 'Refresh');
|
2017-06-01 02:04:27 +00:00
|
|
|
}
|
|
|
|
|
2017-07-20 01:55:40 +00:00
|
|
|
componentDidMount () {
|
|
|
|
this._handleRefreshPlugins();
|
|
|
|
}
|
|
|
|
|
2017-06-01 02:04:27 +00:00
|
|
|
render () {
|
|
|
|
const {plugins} = this.state;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<p className="notice info no-margin-top">
|
2017-06-09 21:42:19 +00:00
|
|
|
Plugins are experimental and compatibility may break in future releases
|
2017-06-01 02:04:27 +00:00
|
|
|
</p>
|
|
|
|
<table className="table--fancy table--striped margin-top margin-bottom">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>Name</th>
|
|
|
|
<th>Version</th>
|
|
|
|
<th>Folder</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
{plugins.map(plugin => (
|
|
|
|
<tr key={plugin.name}>
|
|
|
|
<td>{plugin.name}</td>
|
|
|
|
<td>{plugin.version}</td>
|
|
|
|
<td className="no-wrap" style={{width: '10rem'}}>
|
|
|
|
<CopyButton className="btn btn--outlined btn--super-duper-compact"
|
|
|
|
title={plugin.directory}
|
|
|
|
content={plugin.directory}>
|
|
|
|
Copy Path
|
|
|
|
</CopyButton>
|
|
|
|
{' '}
|
|
|
|
<Button className="btn btn--outlined btn--super-duper-compact"
|
|
|
|
onClick={this._handleOpenDirectory}
|
|
|
|
value={plugin.directory}>
|
|
|
|
Show Folder
|
|
|
|
</Button>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
))}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
<p className="text-right">
|
|
|
|
</p>
|
2017-07-20 01:55:40 +00:00
|
|
|
<div className="form-row">
|
|
|
|
<div className="form-control form-control--outlined">
|
|
|
|
<input onChange={this._handleAddNpmPluginChange}
|
|
|
|
type="text"
|
|
|
|
placeholder="insomnia-foo-bar"/>
|
|
|
|
</div>
|
|
|
|
<div className="form-control width-auto">
|
|
|
|
<button className="btn btn--clicky" onClick={this._handleAddFromNpm}>
|
|
|
|
Add From NPM
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<div className="form-control width-auto">
|
|
|
|
<button className="btn btn--clicky" onClick={this._handleRefreshPlugins}>
|
|
|
|
Reload
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<div className="form-control width-auto">
|
|
|
|
<button className="btn btn--clicky" onClick={this._handleGeneratePlugin}>
|
|
|
|
New Plugin
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
2017-06-01 02:04:27 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Plugins;
|