Mailspring/internal_packages/preferences/lib/tabs/preferences-general.jsx
Annie b061bf079f build(preferences): Add two buttons to the bottom of the general preferences page that clear email and clear all .nylas
Summary:
Wanted a way to reset configuration settings. I added button in N1 general preferences to remove `.nylas` folder and reboot titled 'Reset Accounts and Settings' as well as one to exclusively remove `.nylas/edgehill.db` titled 'Reset Email Cache'.

Not sure about the wording of the button descriptions.

Test Plan: Tested with different file paths on my machine. Was going to write tests, but the two buttons just call previously tested functions onClick -- rimraf and fs.unlink. Testing might be excessive?

Reviewers: bengotow, juan

Reviewed By: juan

Subscribers: juan

Differential Revision: https://phab.nylas.com/D3127
2016-07-26 16:53:45 -07:00

95 lines
2.6 KiB
JavaScript

/* eslint global-require: 0*/
import React from 'react';
import fs from 'fs';
import ConfigSchemaItem from './config-schema-item';
import WorkspaceSection from './workspace-section';
import SendingSection from './sending-section';
class PreferencesGeneral extends React.Component {
static displayName = 'PreferencesGeneral'
static propTypes = {
config: React.PropTypes.object,
configSchema: React.PropTypes.object,
};
_reboot = () => {
const app = require('electron').remote.app;
app.relaunch()
app.quit()
}
_resetAccountsAndSettings = () => {
const rimraf = require('rimraf')
rimraf(NylasEnv.getConfigDirPath(), {disableGlob: true}, (err) => {
if (err) console.log(err)
else this._reboot()
})
}
_resetEmailCache = () => {
const dataPath = `${NylasEnv.getConfigDirPath()}/edgehill.db`
fs.unlink(dataPath, (err) => {
if (err) console.log(err)
else this._reboot()
})
}
render() {
return (
<div className="container-general" style={{maxWidth: 600}}>
<WorkspaceSection config={this.props.config} configSchema={this.props.configSchema} />
<ConfigSchemaItem
configSchema={this.props.configSchema.properties.notifications}
keyName="Notifications"
keyPath="core.notifications"
config={this.props.config}
/>
<div className="platform-note platform-linux-only">
N1 desktop notifications on Linux require Zenity. You may need to install
it with your package manager (i.e., <code>sudo apt-get install zenity</code>).
</div>
<ConfigSchemaItem
configSchema={this.props.configSchema.properties.reading}
keyName="Reading"
keyPath="core.reading"
config={this.props.config}
/>
<ConfigSchemaItem
configSchema={this.props.configSchema.properties.composing}
keyName="Composing"
keyPath="core.composing"
config={this.props.config}
/>
<SendingSection config={this.props.config} configSchema={this.props.configSchema} />
<ConfigSchemaItem
configSchema={this.props.configSchema.properties.attachments}
keyName="Attachments"
keyPath="core.attachments"
config={this.props.config}
/>
<div className="local-data">
<h6>Local Data</h6>
<div className="btn" onClick={this._resetEmailCache}>Reset Email Cache</div>
<div className="btn" onClick={this._resetAccountsAndSettings}>Reset Accounts and Settings</div>
</div>
</div>
)
}
}
export default PreferencesGeneral;