lbry-desktop/ui/js/page/developer.js

88 lines
3.2 KiB
JavaScript
Raw Normal View History

2016-12-29 10:23:28 +01:00
import lbry from '../lbry.js';
import React from 'react';
import FormField from '../component/form.js';
2017-03-17 23:05:25 +01:00
import {Link} from '../component/link.js';
const fs = require('fs');
const {ipcRenderer} = require('electron');
2016-12-29 10:23:28 +01:00
const DeveloperPage = React.createClass({
getInitialState: function() {
return {
2017-03-09 00:14:43 +01:00
showDeveloperMenu: lbry.getClientSetting('showDeveloperMenu'),
2016-12-29 10:23:28 +01:00
useCustomLighthouseServers: lbry.getClientSetting('useCustomLighthouseServers'),
customLighthouseServers: lbry.getClientSetting('customLighthouseServers').join('\n'),
2017-03-17 23:05:25 +01:00
upgradePath: '',
2016-12-29 10:23:28 +01:00
};
},
handleShowDeveloperMenuChange: function(event) {
2017-03-09 00:14:43 +01:00
lbry.setClientSetting('showDeveloperMenu', event.target.checked);
lbry.showMenuIfNeeded();
2016-12-29 10:23:28 +01:00
this.setState({
showDeveloperMenu: event.target.checked,
2016-12-29 10:23:28 +01:00
});
},
handleUseCustomLighthouseServersChange: function(event) {
lbry.setClientSetting('useCustomLighthouseServers', event.target.checked);
this.setState({
useCustomLighthouseServers: event.target.checked,
});
},
2017-03-17 23:05:25 +01:00
handleUpgradeFileChange: function(event) {
this.setState({
upgradePath: event.target.files[0].path,
});
},
handleForceUpgradeClick: function() {
let upgradeSent = false;
if (!this.state.upgradePath) {
alert('Please select a file to upgrade from');
} else {
try {
const stats = fs.lstatSync(this.state.upgradePath);
if (stats.isFile()) {
console.log('Starting upgrade using ' + this.state.upgradePath);
ipcRenderer.send('upgrade', this.state.upgradePath);
upgradeSent = true;
}
}
catch (e) {}
if (!upgradeSent) {
2017-03-17 23:23:29 +01:00
alert('Failed to start upgrade. Is "' + this.state.upgradePath + '" a valid path to the upgrade?');
2017-03-17 23:05:25 +01:00
}
}
},
2016-12-29 10:23:28 +01:00
render: function() {
return (
<main>
<section className="card">
<h3>Developer Settings</h3>
<div className="form-row">
<label><FormField type="checkbox" onChange={this.handleShowDeveloperMenuChange} checked={this.state.showDeveloperMenu} /> Show developer menu</label>
2016-12-29 10:23:28 +01:00
</div>
<div className="form-row">
<label><FormField type="checkbox" onChange={this.handleUseCustomLighthouseServersChange} checked={this.state.useCustomLighthouseServers} /> Use custom search servers</label>
</div>
{this.state.useCustomLighthouseServers
? <div className="form-row">
<label>
Custom search servers (one per line)
<div><FormField type="textarea" className="developer-page__custom-lighthouse-servers" value={this.state.customLighthouseServers} onChange={this.handleCustomLighthouseServersChange} checked={this.state.debugMode} /></div>
</label>
</div>
: null}
</section>
2017-03-17 23:05:25 +01:00
<section className="card">
<div className="form-row">
<FormField name="file" ref="file" type="file" onChange={this.handleUpgradeFileChange}/>
&nbsp;
<Link label="Force Upgrade" button="alt" onClick={this.handleForceUpgradeClick} />
</div>
</section>
2016-12-29 10:23:28 +01:00
</main>
);
}
});
export default DeveloperPage;