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

95 lines
3.3 KiB
JavaScript
Raw Normal View History

2016-12-29 10:23:28 +01:00
import lbry from '../lbry.js';
import React from 'react';
2017-04-10 14:32:40 +02:00
import {FormField} from '../component/form.js';
2017-04-07 07:15:22 +02:00
import Link from '../component/link';
2017-03-17 23:05:25 +01:00
const fs = require('fs');
const {ipcRenderer} = require('electron');
2016-12-29 10:23:28 +01:00
2017-05-17 10:10:25 +02:00
class DeveloperPage extends React.Component {
constructor(props) {
super(props);
this.state = {
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
};
2017-05-17 10:10:25 +02:00
}
handleShowDeveloperMenuChange(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
});
2017-05-17 10:10:25 +02:00
}
handleUseCustomLighthouseServersChange(event) {
2016-12-29 10:23:28 +01:00
lbry.setClientSetting('useCustomLighthouseServers', event.target.checked);
this.setState({
useCustomLighthouseServers: event.target.checked,
});
2017-05-17 10:10:25 +02:00
}
handleUpgradeFileChange(event) {
2017-03-17 23:05:25 +01:00
this.setState({
upgradePath: event.target.value,
2017-03-17 23:05:25 +01:00
});
2017-05-17 10:10:25 +02:00
}
handleForceUpgradeClick() {
2017-03-17 23:05:25 +01:00
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
}
}
2017-05-17 10:10:25 +02:00
}
render() {
2016-12-29 10:23:28 +01:00
return (
<main>
<section className="card">
<h3>{__("Developer Settings")}</h3>
2016-12-29 10:23:28 +01:00
<div className="form-row">
<label><FormField type="checkbox" onChange={(event) => { 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={(event) => { this.handleUseCustomLighthouseServersChange() }} checked={this.state.useCustomLighthouseServers} /> {__("Use custom search servers")}</label>
2016-12-29 10:23:28 +01:00
</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={(event) => { this.handleCustomLighthouseServersChange() }} checked={this.state.debugMode} /></div>
2016-12-29 10:23:28 +01:00
</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={(event) => { this.handleUpgradeFileChange() }}/>
2017-03-17 23:05:25 +01:00
&nbsp;
<Link label={__("Force Upgrade")} button="alt" onClick={(event) => { this.handleForceUpgradeClick() }} />
2017-03-17 23:05:25 +01:00
</div>
</section>
2016-12-29 10:23:28 +01:00
</main>
);
}
2017-05-17 10:10:25 +02:00
}
2016-12-29 10:23:28 +01:00
export default DeveloperPage;