cleanup
This commit is contained in:
parent
1731530253
commit
8ee5c5c667
7 changed files with 455 additions and 165 deletions
|
@ -1,8 +1,7 @@
|
|||
/* eslint-disable no-console,import/no-extraneous-dependencies,import/no-commonjs */
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const packageJSON = require("../package.json");
|
||||
const axios = require("axios");
|
||||
const fetch = require("node-fetch");
|
||||
const decompress = require("decompress");
|
||||
const os = require("os");
|
||||
const del = require("del");
|
||||
|
@ -11,19 +10,13 @@ const downloadDaemon = targetPlatform =>
|
|||
new Promise((resolve, reject) => {
|
||||
const daemonURLTemplate = packageJSON.lbrySettings.lbrynetDaemonUrlTemplate;
|
||||
const daemonVersion = packageJSON.lbrySettings.lbrynetDaemonVersion;
|
||||
const daemonDir = path.join(
|
||||
__dirname,
|
||||
"..",
|
||||
packageJSON.lbrySettings.lbrynetDaemonDir
|
||||
);
|
||||
const daemonDir = path.join(__dirname, "..", packageJSON.lbrySettings.lbrynetDaemonDir);
|
||||
let daemonFileName = packageJSON.lbrySettings.lbrynetDaemonFileName;
|
||||
|
||||
let currentPlatform = os.platform();
|
||||
|
||||
var daemonPlatform =
|
||||
process.env.TARGET || targetPlatform || currentPlatform;
|
||||
if (daemonPlatform === "mac" || daemonPlatform === "darwin")
|
||||
daemonPlatform = "mac";
|
||||
var daemonPlatform = process.env.TARGET || targetPlatform || currentPlatform;
|
||||
if (daemonPlatform === "mac" || daemonPlatform === "darwin") daemonPlatform = "mac";
|
||||
if (daemonPlatform === "win32" || daemonPlatform === "windows") {
|
||||
daemonPlatform = "windows";
|
||||
daemonFileName = daemonFileName + ".exe";
|
||||
|
@ -31,9 +24,7 @@ const downloadDaemon = targetPlatform =>
|
|||
const daemonFilePath = path.join(daemonDir, daemonFileName);
|
||||
const daemonVersionPath = path.join(__dirname, "daemon.ver");
|
||||
const tmpZipPath = path.join(__dirname, "..", "dist", "daemon.zip");
|
||||
const daemonURL = daemonURLTemplate
|
||||
.replace(/DAEMONVER/g, daemonVersion)
|
||||
.replace(/OSNAME/g, daemonPlatform);
|
||||
const daemonURL = daemonURLTemplate.replace(/DAEMONVER/g, daemonVersion).replace(/OSNAME/g, daemonPlatform);
|
||||
|
||||
// If a daemon and daemon.ver exists, check to see if it matches the current daemon version
|
||||
const hasDaemonDownloaded = fs.existsSync(daemonFilePath);
|
||||
|
@ -43,25 +34,19 @@ const downloadDaemon = targetPlatform =>
|
|||
downloadedDaemonVersion = fs.readFileSync(daemonVersionPath, "utf8");
|
||||
}
|
||||
|
||||
if (
|
||||
hasDaemonDownloaded &&
|
||||
hasDaemonVersion &&
|
||||
downloadedDaemonVersion === daemonVersion
|
||||
) {
|
||||
if (hasDaemonDownloaded && hasDaemonVersion && downloadedDaemonVersion === daemonVersion) {
|
||||
console.log("\x1b[34minfo\x1b[0m Daemon already downloaded");
|
||||
resolve("Done");
|
||||
return;
|
||||
} else {
|
||||
console.log("\x1b[34minfo\x1b[0m Downloading daemon...");
|
||||
axios
|
||||
.request({
|
||||
responseType: "arraybuffer",
|
||||
url: daemonURL,
|
||||
method: "get",
|
||||
headers: {
|
||||
"Content-Type": "application/zip"
|
||||
}
|
||||
})
|
||||
fetch(daemonURL, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/zip"
|
||||
}
|
||||
})
|
||||
.then(response => response.buffer())
|
||||
.then(
|
||||
result =>
|
||||
new Promise((newResolve, newReject) => {
|
||||
|
@ -72,7 +57,7 @@ const downloadDaemon = targetPlatform =>
|
|||
fs.mkdirSync(distPath);
|
||||
}
|
||||
|
||||
fs.writeFile(tmpZipPath, result.data, error => {
|
||||
fs.writeFile(tmpZipPath, result, error => {
|
||||
if (error) return newReject(error);
|
||||
return newResolve();
|
||||
});
|
||||
|
@ -94,9 +79,7 @@ const downloadDaemon = targetPlatform =>
|
|||
resolve("Done");
|
||||
})
|
||||
.catch(error => {
|
||||
console.error(
|
||||
`\x1b[31merror\x1b[0m Daemon download failed due to: \x1b[35m${error}\x1b[0m`
|
||||
);
|
||||
console.error(`\x1b[31merror\x1b[0m Daemon download failed due to: \x1b[35m${error}\x1b[0m`);
|
||||
reject(error);
|
||||
});
|
||||
}
|
||||
|
|
27
package.json
27
package.json
|
@ -8,32 +8,29 @@
|
|||
"dev": "NODE_ENV=development electron ./src/main/index.js",
|
||||
"postinstall": "node build/download-daemon.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/lbry-developers/lbry-electron-starter.git"
|
||||
},
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/lbry-developers/lbry-electron-starter/issues"
|
||||
},
|
||||
"homepage": "https://github.com/lbry-developers/lbry-electron-starter#readme",
|
||||
"dependencies": {
|
||||
"electron": "^3.0.8",
|
||||
"electron": "^4.0.4",
|
||||
"find-process": "^1.2.0",
|
||||
"lbry-redux": "lbryio/lbry-redux",
|
||||
"node-fetch": "^2.3.0",
|
||||
"url": "^0.11.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"axios": "^0.18.0",
|
||||
"decompress": "^4.2.0",
|
||||
"del": "^3.0.0",
|
||||
"electron-reload": "^1.2.5"
|
||||
},
|
||||
"lbrySettings": {
|
||||
"lbrynetDaemonVersion": "0.30.0",
|
||||
"lbrynetDaemonVersion": "0.30.4",
|
||||
"lbrynetDaemonUrlTemplate": "https://github.com/lbryio/lbry/releases/download/vDAEMONVER/lbrynet-OSNAME.zip",
|
||||
"lbrynetDaemonDir": "static/daemon",
|
||||
"lbrynetDaemonDir": "dist/daemon",
|
||||
"lbrynetDaemonFileName": "lbrynet"
|
||||
}
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/lbry-developers/lbry-electron-starter.git"
|
||||
},
|
||||
"author": "https://github.com/lbryio/electron-starter/graphs/contributors",
|
||||
"license": "MIT",
|
||||
"homepage": "https://github.com/lbry-developers/lbry-electron-starter#readme"
|
||||
}
|
||||
|
|
|
@ -3,21 +3,18 @@ const { spawn, execSync } = require("child_process");
|
|||
|
||||
class Daemon {
|
||||
constructor() {
|
||||
this.path =
|
||||
process.env.LBRY_DAEMON ||
|
||||
path.join(__dirname, "../../static/daemon/lbrynet");
|
||||
this.path = process.env.LBRY_DAEMON || path.join(__dirname, "../../dist/daemon/lbrynet");
|
||||
this.handlers = [];
|
||||
this.subprocess = undefined;
|
||||
}
|
||||
|
||||
launch() {
|
||||
console.log("launching daemon");
|
||||
this.subprocess = spawn(this.path, ["start"]);
|
||||
this.subprocess.stdout.on("data", data => console.log(`Daemon: ${data}`));
|
||||
this.subprocess.stderr.on("data", data => console.error(`Daemon: ${data}`));
|
||||
this.subprocess.on("exit", () => this.fire("exit"));
|
||||
this.subprocess.on("error", error =>
|
||||
console.error(`Daemon error: ${error}`)
|
||||
);
|
||||
this.subprocess.on("error", error => console.error(`Daemon error: ${error}`));
|
||||
}
|
||||
|
||||
quit() {
|
||||
|
|
|
@ -5,13 +5,6 @@
|
|||
<title>LBRY Starter</title>
|
||||
</head>
|
||||
<style>
|
||||
body: {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
#resolve {
|
||||
display: none;
|
||||
}
|
||||
|
|
|
@ -17,26 +17,18 @@ if (IS_DEV) {
|
|||
app.on("ready", function() {
|
||||
createWindow();
|
||||
|
||||
const processListArgs =
|
||||
process.platform === "win32" ? "lbrynet" : "lbrynet start";
|
||||
// Determine if the LBRY SDK is already running, or if it needs to be started
|
||||
// This allows you to run the sdk binary separately and have your app connect to it
|
||||
const processListArgs = process.platform === "win32" ? "lbrynet" : "lbrynet start";
|
||||
findProcess("name", processListArgs).then(processList => {
|
||||
const isDaemonRunning = processList.length > 0;
|
||||
|
||||
if (!isDaemonRunning) {
|
||||
daemon = new Daemon();
|
||||
daemon.on("exit", () => {
|
||||
if (!isDev) {
|
||||
daemon = null;
|
||||
if (!appState.isQuitting) {
|
||||
dialog.showErrorBox(
|
||||
"Daemon has Exited",
|
||||
"The daemon may have encountered an unexpected error, or another daemon instance is already running. \n\n" +
|
||||
"For more information please visit: \n" +
|
||||
"https://lbry.io/faq/startup-troubleshooting"
|
||||
);
|
||||
}
|
||||
app.quit();
|
||||
}
|
||||
daemon = null;
|
||||
dialog.showErrorBox("Daemon has Exited");
|
||||
app.quit();
|
||||
});
|
||||
daemon.launch();
|
||||
}
|
||||
|
|
|
@ -2,20 +2,21 @@ const { Lbry } = require("lbry-redux");
|
|||
|
||||
Lbry.connect().then(checkDaemonStarted);
|
||||
|
||||
// This waits until the daemon is fully started before doing anything else
|
||||
function checkDaemonStarted() {
|
||||
Lbry.status().then(status => {
|
||||
if (status.is_running) {
|
||||
// Daemon is now running
|
||||
const resolveWrapper = document.getElementById("resolve");
|
||||
const loadingWrapper = document.getElementById("loading");
|
||||
|
||||
loadingWrapper.style.display = "none";
|
||||
resolveWrapper.style.display = "block";
|
||||
return;
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
checkDaemonStarted();
|
||||
}, 500);
|
||||
}, 250);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue