2016-07-19 04:01:31 +00:00
|
|
|
import React, {Component, PropTypes} from 'react';
|
|
|
|
import {connect} from 'react-redux'
|
|
|
|
import {bindActionCreators} from 'redux';
|
2016-07-07 20:10:55 +00:00
|
|
|
import {Tab, Tabs, TabList, TabPanel} from 'react-tabs'
|
2016-07-16 02:06:10 +00:00
|
|
|
import {shell} from 'electron';
|
2016-05-07 17:29:24 +00:00
|
|
|
|
2016-07-22 22:27:04 +00:00
|
|
|
import Link from '../base/Link';
|
|
|
|
import Modal from '../base/Modal';
|
|
|
|
import ModalBody from '../base/ModalBody';
|
|
|
|
import ModalHeader from '../base/ModalHeader';
|
|
|
|
import ModalFooter from '../base/ModalFooter';
|
2016-07-25 22:27:29 +00:00
|
|
|
import KeyboardShortcutsTable from '../KeyboardShortcutsTable';
|
2016-07-22 22:27:04 +00:00
|
|
|
import * as GlobalActions from '../../redux/modules/global';
|
|
|
|
import * as db from '../../database';
|
|
|
|
import {MASHAPE_URL} from '../../lib/constants';
|
|
|
|
import {getAppVersion} from '../../lib/appInfo';
|
|
|
|
import {getAppName, getAppLongName} from '../../lib/appInfo';
|
2016-05-07 17:29:24 +00:00
|
|
|
|
2016-07-19 04:01:31 +00:00
|
|
|
|
|
|
|
class SettingsTabs extends Component {
|
|
|
|
_importFile () {
|
|
|
|
const workspace = this._getActiveWorkspace(this.props);
|
|
|
|
this.props.actions.global.importFile(workspace);
|
2016-07-22 17:02:42 +00:00
|
|
|
this.props.hide();
|
2016-07-19 04:01:31 +00:00
|
|
|
}
|
|
|
|
|
2016-08-15 22:31:30 +00:00
|
|
|
_exportAll () {
|
2016-07-19 04:01:31 +00:00
|
|
|
this.props.actions.global.exportFile();
|
2016-07-22 17:02:42 +00:00
|
|
|
this.props.hide();
|
2016-07-19 04:01:31 +00:00
|
|
|
}
|
|
|
|
|
2016-08-15 22:31:30 +00:00
|
|
|
_exportWorkspace () {
|
|
|
|
this.props.actions.global.exportFile(this._getActiveWorkspace());
|
|
|
|
this.props.hide();
|
|
|
|
}
|
|
|
|
|
2016-07-19 04:01:31 +00:00
|
|
|
_getActiveWorkspace (props) {
|
|
|
|
// TODO: Factor this out into a selector
|
|
|
|
|
|
|
|
const {entities, workspaces} = props || this.props;
|
|
|
|
let workspace = entities.workspaces[workspaces.activeId];
|
|
|
|
if (!workspace) {
|
|
|
|
workspace = entities.workspaces[Object.keys(entities.workspaces)[0]];
|
|
|
|
}
|
|
|
|
|
|
|
|
return workspace;
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
2016-07-21 16:33:35 +00:00
|
|
|
const {entities, selectedIndex} = this.props;
|
2016-07-19 19:13:51 +00:00
|
|
|
const settings = entities.settings[Object.keys(entities.settings)[0]];
|
|
|
|
|
2016-07-19 04:01:31 +00:00
|
|
|
return (
|
2016-07-21 16:33:35 +00:00
|
|
|
<Tabs selectedIndex={selectedIndex >= 0 ? selectedIndex : 0}>
|
2016-07-19 04:01:31 +00:00
|
|
|
<TabList>
|
|
|
|
<Tab>
|
|
|
|
<button>General</button>
|
|
|
|
</Tab>
|
2016-08-15 17:04:36 +00:00
|
|
|
<Tab>
|
|
|
|
<button>Editor</button>
|
|
|
|
</Tab>
|
2016-07-19 04:01:31 +00:00
|
|
|
<Tab>
|
|
|
|
<button>Import/Export</button>
|
|
|
|
</Tab>
|
|
|
|
<Tab>
|
2016-07-21 22:13:57 +00:00
|
|
|
<button>Shortcuts</button>
|
2016-07-19 04:01:31 +00:00
|
|
|
</Tab>
|
|
|
|
<Tab>
|
2016-07-19 22:28:29 +00:00
|
|
|
<button>About</button>
|
2016-07-19 04:01:31 +00:00
|
|
|
</Tab>
|
|
|
|
</TabList>
|
|
|
|
<TabPanel className="pad">
|
2016-08-15 17:04:36 +00:00
|
|
|
<h2 className="txt-md">
|
|
|
|
<label className="label--small">General Settings</label>
|
|
|
|
</h2>
|
|
|
|
<div>
|
|
|
|
<input
|
|
|
|
id="setting-show-passwords"
|
|
|
|
type="checkbox"
|
|
|
|
checked={settings.showPasswords}
|
|
|
|
onChange={e => db.settingsUpdate(settings, {showPasswords: e.target.checked})}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<label htmlFor="setting-show-passwords">
|
|
|
|
Show passwords in plain-text
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="pad-top">
|
|
|
|
<input
|
|
|
|
id="setting-follow-redirects"
|
|
|
|
type="checkbox"
|
|
|
|
checked={settings.followRedirects}
|
|
|
|
onChange={e => db.settingsUpdate(settings, {followRedirects: e.target.checked})}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<label htmlFor="setting-follow-redirects">
|
|
|
|
Follow redirects automatically
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="pad-top">
|
|
|
|
<input
|
|
|
|
id="setting-validate-ssl"
|
|
|
|
type="checkbox"
|
|
|
|
checked={settings.validateSSL}
|
|
|
|
onChange={e => db.settingsUpdate(settings, {validateSSL: e.target.checked})}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<label htmlFor="setting-validate-ssl">
|
|
|
|
Validate SSL Certificates
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
|
2016-07-19 04:01:31 +00:00
|
|
|
<div>
|
2016-08-15 17:04:36 +00:00
|
|
|
<label htmlFor="setting-request-timeout" className="pad-top">
|
|
|
|
Request Timeout (ms) (0 for no timeout)
|
|
|
|
</label>
|
|
|
|
<div className="form-control form-control--outlined no-margin">
|
2016-07-28 20:10:26 +00:00
|
|
|
<input
|
2016-08-15 17:04:36 +00:00
|
|
|
id="setting-request-timeout"
|
|
|
|
type="number"
|
|
|
|
min={0}
|
|
|
|
value={settings.timeout}
|
|
|
|
onChange={e => db.settingsUpdate(settings, {timeout: parseInt(e.target.value, 10)})}
|
2016-07-19 22:28:29 +00:00
|
|
|
/>
|
|
|
|
</div>
|
2016-08-15 17:04:36 +00:00
|
|
|
</div>
|
|
|
|
<br/>
|
|
|
|
<h2 className="txt-md pad-top-sm">
|
|
|
|
<label className="label--small">Network Proxy (Experimental)</label>
|
|
|
|
</h2>
|
|
|
|
<div>
|
|
|
|
<label htmlFor="setting-http-proxy">
|
|
|
|
HTTP Proxy
|
|
|
|
</label>
|
|
|
|
<div className="form-control form-control--outlined no-margin">
|
2016-07-28 20:10:26 +00:00
|
|
|
<input
|
2016-08-15 17:04:36 +00:00
|
|
|
id="setting-http-proxy"
|
|
|
|
type="string"
|
|
|
|
placeholder="localhost:8005"
|
|
|
|
defaultValue={settings.httpProxy}
|
|
|
|
onChange={e => db.settingsUpdate(settings, {httpProxy: e.target.value})}
|
2016-07-19 22:28:29 +00:00
|
|
|
/>
|
|
|
|
</div>
|
2016-08-15 17:04:36 +00:00
|
|
|
</div>
|
|
|
|
<div className="pad-top-sm">
|
|
|
|
<label htmlFor="setting-https-proxy">
|
|
|
|
HTTPS Proxy
|
|
|
|
</label>
|
|
|
|
<div className="form-control form-control--outlined no-margin">
|
2016-07-28 20:10:26 +00:00
|
|
|
<input
|
2016-08-15 17:04:36 +00:00
|
|
|
id="setting-https-proxy"
|
|
|
|
placeholder="localhost:8005"
|
|
|
|
type="string"
|
|
|
|
defaultValue={settings.httpsProxy}
|
|
|
|
onChange={e => db.settingsUpdate(settings, {httpsProxy: e.target.value})}
|
2016-07-28 20:10:26 +00:00
|
|
|
/>
|
2016-07-19 22:28:29 +00:00
|
|
|
</div>
|
2016-07-19 04:01:31 +00:00
|
|
|
</div>
|
2016-08-15 17:04:36 +00:00
|
|
|
</TabPanel>
|
|
|
|
<TabPanel className="pad">
|
|
|
|
<label className="label--small">Code Editor Settings</label>
|
2016-07-19 22:28:29 +00:00
|
|
|
<div className="pad-top">
|
2016-08-15 17:04:36 +00:00
|
|
|
<input
|
|
|
|
id="setting-editor-line-wrapping"
|
|
|
|
type="checkbox"
|
|
|
|
checked={settings.editorLineWrapping}
|
|
|
|
onChange={e => db.settingsUpdate(settings, {editorLineWrapping: e.target.checked})}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<label htmlFor="setting-editor-line-wrapping">
|
|
|
|
Wrap Long Lines
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<label htmlFor="setting-editor-font-size" className="pad-top">
|
|
|
|
Font Size (px)
|
|
|
|
</label>
|
|
|
|
<div className="form-control form-control--outlined no-margin">
|
2016-07-28 20:10:26 +00:00
|
|
|
<input
|
2016-08-15 17:04:36 +00:00
|
|
|
id="setting-editor-font-size"
|
|
|
|
type="number"
|
|
|
|
min={8}
|
|
|
|
max={20}
|
|
|
|
value={settings.editorFontSize}
|
|
|
|
onChange={e => db.settingsUpdate(settings, {editorFontSize: parseInt(e.target.value, 10)})}
|
2016-07-19 19:13:51 +00:00
|
|
|
/>
|
2016-07-19 04:01:31 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</TabPanel>
|
|
|
|
<TabPanel className="pad">
|
2016-08-15 22:31:30 +00:00
|
|
|
<p>This will export all app data for all workspaces.</p>
|
|
|
|
<p>Be aware that you may be exporting <strong>private data</strong></p>
|
2016-07-19 04:01:31 +00:00
|
|
|
<p>
|
2016-07-19 19:13:51 +00:00
|
|
|
<button className="btn btn--super-compact btn--outlined"
|
|
|
|
onClick={e => this._importFile()}>
|
2016-07-19 04:01:31 +00:00
|
|
|
Import
|
|
|
|
</button>
|
|
|
|
{" "}
|
2016-07-19 19:13:51 +00:00
|
|
|
<button className="btn btn--super-compact btn--outlined"
|
2016-08-15 22:31:30 +00:00
|
|
|
onClick={e => this._exportAll()}>
|
|
|
|
Export All Data
|
|
|
|
</button>
|
|
|
|
{" "}
|
|
|
|
<button className="btn btn--super-compact btn--outlined"
|
|
|
|
onClick={e => this._exportWorkspace()}>
|
|
|
|
Export Current Workspace
|
2016-07-19 04:01:31 +00:00
|
|
|
</button>
|
|
|
|
</p>
|
|
|
|
</TabPanel>
|
|
|
|
<TabPanel className="pad">
|
2016-07-25 22:27:29 +00:00
|
|
|
<KeyboardShortcutsTable />
|
2016-07-19 04:01:31 +00:00
|
|
|
</TabPanel>
|
|
|
|
<TabPanel className="pad">
|
2016-07-25 22:29:35 +00:00
|
|
|
<h1>Hi there!</h1>
|
2016-07-19 04:01:31 +00:00
|
|
|
<p>
|
2016-07-21 22:26:51 +00:00
|
|
|
<Link href="http://insomnia.rest">{getAppName()}</Link> is made with love by me,
|
2016-07-19 04:01:31 +00:00
|
|
|
<Link href="http://schier.co">Gregory Schier</Link>.
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
You can help me out by sending your feedback to
|
2016-08-15 22:31:30 +00:00
|
|
|
<Link href="mailto:support@insomnia.rest">support@insomnia.rest</Link> or tweet
|
2016-07-19 04:01:31 +00:00
|
|
|
<Link href="https://twitter.com/GetInsomnia">@GetInsomnia</Link>.
|
|
|
|
</p>
|
|
|
|
<p>Thanks!</p>
|
|
|
|
<br/>
|
|
|
|
<p>~Gregory</p>
|
|
|
|
</TabPanel>
|
|
|
|
</Tabs>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SettingsTabs.propTypes = {
|
|
|
|
workspaces: PropTypes.shape({
|
|
|
|
activeId: PropTypes.string
|
|
|
|
}),
|
|
|
|
entities: PropTypes.shape({
|
2016-07-19 19:13:51 +00:00
|
|
|
workspaces: PropTypes.object.isRequired,
|
|
|
|
settings: PropTypes.object.isRequired
|
2016-07-19 04:01:31 +00:00
|
|
|
}).isRequired,
|
|
|
|
actions: PropTypes.shape({
|
|
|
|
global: PropTypes.shape({
|
|
|
|
importFile: PropTypes.func.isRequired,
|
|
|
|
exportFile: PropTypes.func.isRequired,
|
|
|
|
})
|
2016-07-21 16:33:35 +00:00
|
|
|
}),
|
|
|
|
|
|
|
|
// Optional
|
|
|
|
selectedIndex: PropTypes.number
|
2016-07-19 04:01:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
function mapStateToProps (state) {
|
|
|
|
return {
|
|
|
|
workspaces: state.workspaces,
|
|
|
|
entities: state.entities,
|
|
|
|
actions: state.actions,
|
|
|
|
loading: state.global.loading
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapDispatchToProps (dispatch) {
|
|
|
|
return {
|
|
|
|
actions: {
|
|
|
|
global: bindActionCreators(GlobalActions, dispatch)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// NOTE: We can't _connect_ the SettingsModal because it hides the public methods
|
|
|
|
const ConnectedSettingsTabs = connect(
|
|
|
|
mapStateToProps,
|
|
|
|
mapDispatchToProps
|
|
|
|
)(SettingsTabs);
|
|
|
|
|
|
|
|
|
2016-08-15 17:04:36 +00:00
|
|
|
class SettingsModal extends Component {
|
2016-07-21 16:33:35 +00:00
|
|
|
constructor (props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
selectedIndex: 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-15 22:31:30 +00:00
|
|
|
_setIndex (selectedIndex) {
|
|
|
|
if (selectedIndex >= 0) {
|
|
|
|
this.setState({selectedIndex});
|
2016-07-21 16:33:35 +00:00
|
|
|
} else {
|
|
|
|
this.setState({selectedIndex: 0});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-15 17:04:36 +00:00
|
|
|
show (selectedIndex = 0) {
|
|
|
|
this.modal.show();
|
|
|
|
this._setIndex(selectedIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
toggle (selectedIndex = 0) {
|
|
|
|
this.modal.toggle();
|
|
|
|
this._setIndex(selectedIndex);
|
|
|
|
}
|
|
|
|
|
2016-07-07 20:10:55 +00:00
|
|
|
render () {
|
2016-07-21 16:33:35 +00:00
|
|
|
const {selectedIndex} = this.state;
|
2016-07-19 04:01:31 +00:00
|
|
|
|
2016-05-07 17:29:24 +00:00
|
|
|
return (
|
2016-08-15 17:04:36 +00:00
|
|
|
<Modal ref={m => this.modal = m} tall={true} {...this.props}>
|
2016-07-19 22:28:29 +00:00
|
|
|
<ModalHeader>
|
2016-07-21 22:26:51 +00:00
|
|
|
{getAppLongName()}
|
|
|
|
|
|
|
|
<span className="faint txt-sm">v{getAppVersion()}</span>
|
2016-07-19 22:28:29 +00:00
|
|
|
</ModalHeader>
|
2016-07-07 20:10:55 +00:00
|
|
|
<ModalBody>
|
2016-08-15 17:04:36 +00:00
|
|
|
<ConnectedSettingsTabs hide={() => this.modal.hide()} selectedIndex={selectedIndex}/>
|
2016-05-07 17:29:24 +00:00
|
|
|
</ModalBody>
|
2016-08-15 17:04:36 +00:00
|
|
|
<ModalFooter>
|
|
|
|
<div className="pull-right">
|
|
|
|
<button className="btn" onClick={() => this.modal.hide()}>Done</button>
|
|
|
|
</div>
|
|
|
|
<div className="inline-block pad relative">
|
2016-07-07 20:10:55 +00:00
|
|
|
Supported By
|
|
|
|
<Link href={MASHAPE_URL}>
|
|
|
|
<img src="images/mashape.png" style={{height: '1.5em'}} className="valign-bottom"/>
|
|
|
|
</Link>
|
|
|
|
</div>
|
|
|
|
</ModalFooter>
|
2016-05-07 17:29:24 +00:00
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
export default SettingsModal;
|