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

145 lines
4 KiB
JavaScript
Raw Normal View History

2017-06-06 23:19:12 +02:00
import lbry from "../lbry.js";
import React from "react";
import { FormField } from "../component/form.js";
import Link from "../component/link";
2017-03-17 23:05:25 +01:00
2017-06-06 23:19:12 +02:00
const fs = require("fs");
const { ipcRenderer } = require("electron");
2016-12-29 10:23:28 +01:00
2017-06-08 06:42:19 +02:00
class DeveloperPage extends React.PureComponent {
2017-05-17 10:10:25 +02:00
constructor(props) {
super(props);
this.state = {
2017-06-06 23:19:12 +02:00
showDeveloperMenu: lbry.getClientSetting("showDeveloperMenu"),
useCustomLighthouseServers: lbry.getClientSetting(
"useCustomLighthouseServers"
),
customLighthouseServers: lbry
.getClientSetting("customLighthouseServers")
.join("\n"),
upgradePath: "",
2016-12-29 10:23:28 +01:00
};
2017-05-17 10:10:25 +02:00
}
handleShowDeveloperMenuChange(event) {
2017-06-06 23:19:12 +02: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) {
2017-06-06 23:19:12 +02:00
lbry.setClientSetting("useCustomLighthouseServers", event.target.checked);
2016-12-29 10:23:28 +01:00
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) {
2017-06-06 23:19:12 +02:00
alert(__("Please select a file to upgrade from"));
2017-03-17 23:05:25 +01:00
} else {
try {
const stats = fs.lstatSync(this.state.upgradePath);
if (stats.isFile()) {
2017-06-06 23:19:12 +02:00
console.log("Starting upgrade using " + this.state.upgradePath);
ipcRenderer.send("upgrade", this.state.upgradePath);
2017-03-17 23:05:25 +01:00
upgradeSent = true;
}
2017-06-06 23:19:12 +02:00
} catch (e) {}
2017-03-17 23:05:25 +01:00
if (!upgradeSent) {
2017-06-06 23:19:12 +02: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">
2017-06-06 23:19:12 +02:00
<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">
2017-06-06 23:19:12 +02:00
<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)")}
2017-06-06 23:19:12 +02:00
<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">
2017-06-06 23:19:12 +02:00
<FormField
name="file"
ref="file"
type="file"
onChange={event => {
this.handleUpgradeFileChange();
}}
/>
2017-03-17 23:05:25 +01:00
&nbsp;
2017-06-06 23:19:12 +02:00
<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;