From 8ee5c5c667f29a620bc585e9665988ab35926c25 Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Sun, 3 Feb 2019 13:14:46 -0500 Subject: [PATCH] cleanup --- build/download-daemon.js | 47 ++-- package.json | 27 +-- src/main/daemon.js | 9 +- src/main/index.html | 7 - src/main/index.js | 20 +- src/renderer/index.js | 5 +- yarn.lock | 505 ++++++++++++++++++++++++++++++++------- 7 files changed, 455 insertions(+), 165 deletions(-) diff --git a/build/download-daemon.js b/build/download-daemon.js index 46dde55..07f8bf4 100644 --- a/build/download-daemon.js +++ b/build/download-daemon.js @@ -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); }); } diff --git a/package.json b/package.json index 60621f2..fa0a100 100644 --- a/package.json +++ b/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" } diff --git a/src/main/daemon.js b/src/main/daemon.js index 174b9f1..17e1f64 100644 --- a/src/main/daemon.js +++ b/src/main/daemon.js @@ -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() { diff --git a/src/main/index.html b/src/main/index.html index f7e403a..54b213c 100644 --- a/src/main/index.html +++ b/src/main/index.html @@ -5,13 +5,6 @@ LBRY Starter