fix: daemon not launching on Windows #1101

Merged
IGassmann merged 2 commits from issue/1094 into master 2018-03-14 21:38:56 +01:00
5 changed files with 103 additions and 39 deletions
Showing only changes of commit 9a41ab6c2e - Show all commits

View file

@ -0,0 +1,29 @@
/* eslint-disable no-console,import/no-extraneous-dependencies,import/no-commonjs */
/**
* This script is necessary for checking that the daemon that has been downloaded during the
* yarn installing process is the one for the building target. For example, on Travis the
* Windows package is built on Linux, thus yarn will download the daemon for Linux instead of
* Windows. The script will test that and then download the right daemon for the targeted platform.
*/
const os = require('os');
const downloadDaemon = require('./downloadDaemon');
module.exports = context => {
let currentPlatform = os.platform();
if (currentPlatform === 'darwin') currentPlatform = 'macoss';
if (currentPlatform === 'win32') currentPlatform = 'windows';
let buildingPlatformTarget = context.platform.toString();
if (buildingPlatformTarget === 'mac') buildingPlatformTarget = 'macos';
if (buildingPlatformTarget !== currentPlatform) {
console.log(
"\x1b[34minfo\x1b[0m Daemon platform doesn't match target platform. Redownloading the daemon."
);
return downloadDaemon(buildingPlatformTarget);
}
return Promise.resolve();
};

View file

@ -1,26 +1,32 @@
/* eslint-disable no-console,import/no-commonjs */
/* eslint-disable no-console,import/no-extraneous-dependencies,import/no-commonjs */
const path = require('path');
const fs = require('fs');
const packageJSON = require('../package.json');
// eslint-disable-next-line import/no-extraneous-dependencies
const axios = require('axios');
// eslint-disable-next-line import/no-extraneous-dependencies
const decompress = require('decompress');
const os = require('os');
const del = require('del');
const daemonURLTemplate = packageJSON.lbrySettings.lbrynetDaemonUrlTemplate;
const daemonVersion = packageJSON.lbrySettings.lbrynetDaemonVersion;
let currentPlatform = os.platform();
if (currentPlatform === 'darwin') currentPlatform = 'macos';
if (currentPlatform === 'win32') currentPlatform = 'windows';
const downloadDaemon = targetPlatform =>
new Promise((resolve, reject) => {
const daemonURLTemplate = packageJSON.lbrySettings.lbrynetDaemonUrlTemplate;
const daemonVersion = packageJSON.lbrySettings.lbrynetDaemonVersion;
const daemonDir = packageJSON.lbrySettings.lbrynetDaemonDir;
const daemonFileName = packageJSON.lbrySettings.lbrynetDaemonFileName;
const daemonURL = daemonURLTemplate
let currentPlatform = os.platform();
if (currentPlatform === 'darwin') currentPlatform = 'macos';
if (currentPlatform === 'win32') currentPlatform = 'windows';
const daemonPlatform = targetPlatform || currentPlatform;
const daemonURL = daemonURLTemplate
.replace(/DAEMONVER/g, daemonVersion)
.replace(/OSNAME/g, currentPlatform);
const tmpZipPath = 'build/daemon.zip';
.replace(/OSNAME/g, daemonPlatform);
const tmpZipPath = 'build/daemon.zip';
console.log('\x1b[34minfo\x1b[0m Downloading daemon...');
axios
console.log('\x1b[34minfo\x1b[0m Downloading daemon...');
axios
.request({
responseType: 'arraybuffer',
url: daemonURL,
@ -29,19 +35,36 @@ axios
'Content-Type': 'application/zip',
},
})
.then(result => {
fs.writeFileSync(tmpZipPath, result.data);
return true;
})
.then(() => {
decompress(tmpZipPath, 'static/daemon', {
filter: file =>
path.basename(file.path).replace(path.extname(file.path), '') === 'lbrynet-daemon',
.then(
result =>
new Promise((newResolve, newReject) => {
fs.writeFile(tmpZipPath, result.data, error => {
if (error) return newReject(error);
return newResolve();
});
})
)
.then(() => del(`${daemonDir}/${daemonFileName}*`))
.then(() =>
decompress(tmpZipPath, daemonDir, {
filter: file =>
path.basename(file.path).replace(path.extname(file.path), '') === daemonFileName,
})
)
.then(() => {
console.log('\x1b[32msuccess\x1b[0m Daemon downloaded!');
resolve(true);
})
.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);
});
});
module.exports = downloadDaemon;
require('make-runnable/custom')({
printOutputFrame: false
});

View file

@ -50,5 +50,6 @@
"nsis": {
"perMachine": true
},
"beforeBuild": "./build/checkDaemonPlatform.js",
"artifactName": "${productName}_${version}.${ext}"
}

View file

@ -82,6 +82,7 @@
"babel-preset-react": "^6.24.1",
"babel-preset-stage-2": "^6.18.0",
"decompress": "^4.2.0",
"del": "^3.0.0",
"devtron": "^1.4.0",
"electron": "1.7.10",
"electron-builder": "^20.3.1",
@ -103,6 +104,7 @@
"i18n-extract": "^0.5.1",
"json-loader": "^0.5.4",
"lint-staged": "^7.0.0",
"make-runnable": "^1.3.6",
"node-loader": "^0.6.0",
"node-sass": "^4.7.2",
"prettier": "^1.11.1",
@ -117,6 +119,8 @@
"license": "MIT",
"lbrySettings": {
"lbrynetDaemonVersion": "0.19.0",
"lbrynetDaemonUrlTemplate": "https://github.com/lbryio/lbry/releases/download/vDAEMONVER/lbrynet-daemon-vDAEMONVER-OSNAME.zip"
"lbrynetDaemonUrlTemplate": "https://github.com/lbryio/lbry/releases/download/vDAEMONVER/lbrynet-daemon-vDAEMONVER-OSNAME.zip",
"lbrynetDaemonDir": "static/daemon",
"lbrynetDaemonFileName": "lbrynet-daemon"
}
}

View file

@ -6170,6 +6170,13 @@ make-fetch-happen@^2.4.13, make-fetch-happen@^2.5.0:
socks-proxy-agent "^3.0.1"
ssri "^5.0.0"
make-runnable@^1.3.6:
version "1.3.6"
resolved "https://registry.yarnpkg.com/make-runnable/-/make-runnable-1.3.6.tgz#ca9b1d31b06f051e37570fb7ad98bc5369f982be"
dependencies:
bluebird "^3.5.0"
yargs "^4.7.1"
map-cache@^0.2.2:
version "0.2.2"
resolved "https://registry.yarnpkg.com/map-cache/-/map-cache-0.2.2.tgz#c32abd0bd6525d9b051645bb4f26ac5dc98a0dbf"
@ -10480,7 +10487,7 @@ yargs@^11.0.0:
y18n "^3.2.1"
yargs-parser "^9.0.2"
yargs@^4.2.0:
yargs@^4.2.0, yargs@^4.7.1:
version "4.8.1"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-4.8.1.tgz#c0c42924ca4aaa6b0e6da1739dfb216439f9ddc0"
dependencies: