Skip to content
Permalink
Browse files

feat(electron): add benchmark timing to setup logging

  • Loading branch information...
devinus committed Nov 27, 2018
1 parent 5ff6a6a commit 23f427a7a56be2376481e6c7b63ec3d41f7b85d8
Showing with 44 additions and 14 deletions.
  1. +20 −5 ember-electron/assets.js
  2. +2 −1 ember-electron/main.js
  3. +1 −0 package.json
  4. +21 −8 yarn.lock
@@ -2,6 +2,8 @@ const path = require('path');
const crypto = require('crypto');

const got = require('got');
const prettyMs = require('pretty-ms');

const lzma = require('lzma-native');
const tar = require('tar-fs');
const tarStream = require('tar-stream');
@@ -50,48 +52,61 @@ const verifyAsset = async (url, savePath, onProgress) => {
}

log.info('Verifying asset:', savePath);

const start = Date.now();
const verifier = crypto.createVerify('SHA256');
const { size } = await fs.statAsync(savePath);
const progress = createProgressStream(size, onProgress);
await pump(fs.createReadStream(savePath), progress, verifier);

const publicKey = await fs.readFileAsync(path.join(__dirname, 'assets.pem'));
const signature = Buffer.from(String(headers[SIGNATURE_HEADER]).trim(), 'base64');
return verifier.verify(publicKey, signature);
const verified = verifier.verify(publicKey, signature);
const elapsed = Date.now() - start;
log.info('Asset verified:', savePath, `(took ${prettyMs(elapsed)})`);
return verified;
};

const extractAsset = async (savePath, extractDir, onProgress) => {
log.info('Extracting asset:', savePath);

const start = Date.now();
const extract = tarStream.extract();
const { size } = await fs.statAsync(savePath);
return pump(
const result = await pump(
fs.createReadStream(savePath),
createProgressStream(size, onProgress),
lzma.createDecompressor({ flags: lzma.CONCATENATED }),
lzma.createDecompressor(),
tar.extract(extractDir, {
fs,
extract,
fmode: 0o600,
dmode: 0o700,
}),
);

const elapsed = Date.now() - start;
log.info('Asset extracted:', savePath, `(took ${prettyMs(elapsed)})`);
return result;
};

const downloadAsset = async (sender, url, onStarted, onProgress) => {
log.info('Downloading asset:', url);

const start = Date.now();
const dl = await download(sender, url, {
onStarted,
onProgress,
showBadge: false,
});

const elapsed = Date.now() - start;
const savePath = dl.getSavePath();
log.info('Asset downloaded:', savePath, `(took ${prettyMs(elapsed)})`);
if (!sender.isDestroyed()) {
sender.send('download-verify');
}

const savePath = dl.getSavePath();
const verified = await verifyAsset(url, savePath, onProgress);
if (!verified) {
throw new Error('Verification failed');
@@ -101,7 +116,7 @@ const downloadAsset = async (sender, url, onStarted, onProgress) => {
sender.send('download-extract');
}

const assetName = path.basename(savePath, '.tar.xz');
const assetName = path.basename(savePath, '.tar.br');
const extractDir = path.join(path.dirname(savePath), productName, assetName);
await makeDir(extractDir);
await extractAsset(savePath, extractDir, onProgress);
@@ -52,6 +52,7 @@ const semver = require('semver');
const locale2 = require('locale2');
const makeDir = require('make-dir');
const pathExists = require('path-exists');
const prettyMs = require('pretty-ms');

const electron = require('electron');
const debug = require('electron-debug');
@@ -218,7 +219,7 @@ const run = async () => {

mainWindow.once('ready-to-show', () => {
const elapsed = Date.now() - appLaunchTimestamp;
log.info(`Application window ready to show (took ${elapsed}ms):`, mainWindow.getTitle());
log.info(`Application window ready to show (took ${prettyMs(elapsed)}):`, mainWindow.getTitle());
mainWindow.show();
});

@@ -114,6 +114,7 @@
"node-forge": "^0.7.6",
"normalize-newline": "^3.0.0",
"path-exists": "^3.0.0",
"pretty-ms": "^4.0.0",
"progress-stream": "^2.0.0",
"pump": "^3.0.0",
"selfsigned": "^1.10.4",
@@ -1216,13 +1216,14 @@
universal-user-agent "^2.0.1"
url-template "^2.0.8"

"@octokit/request@2.1.1":
version "2.1.1"
resolved "https://registry.yarnpkg.com/@octokit/request/-/request-2.1.1.tgz#2c6c6356f2bced33fb6352df8d44f9f50e076e76"
integrity sha512-N0I01iWwbogadLyCbVJ048hDMet3uGrB93VeJgB+jeuugRUr1DXncEu2tpiWgSk1azGDFPe5RTRvfx4Uadf+Fw==
"@octokit/request@2.1.2":
version "2.1.2"
resolved "https://registry.yarnpkg.com/@octokit/request/-/request-2.1.2.tgz#a506e06cb3fd73617bd82710047cf3ee7e657835"
integrity sha512-RtC+7Np9hWWYfnXyT1qwBR6Y9uMArq2yY475o4sFp4qis5hAgOUEZMWknR+dfDpRRXoFOPSAAIjc900Gs7qI6Q==
dependencies:
"@octokit/endpoint" "^3.0.0"
is-plain-object "^2.0.4"
node-fetch "^2.3.0"
universal-user-agent "^2.0.1"

"@octokit/rest@^14.0.4":
@@ -1238,11 +1239,11 @@
url-template "^2.0.8"

"@octokit/rest@^16.0.1":
version "16.0.1"
resolved "https://registry.yarnpkg.com/@octokit/rest/-/rest-16.0.1.tgz#053c1a80aca11c096ad6e09626ba5a18576c1aa0"
integrity sha512-4Vbn3TtKADUOSk9usbfJ6XsEErt9h6Thms6EejI/MWMeVqdY5a3NevbAp7rVSXBl2xYIw3erPLkeFpGg+RmkoQ==
version "16.0.3"
resolved "https://registry.yarnpkg.com/@octokit/rest/-/rest-16.0.3.tgz#22d76ef7fa4bccc464a5b6dc1af433459d3cfa04"
integrity sha512-OOm7JmQZfA8J6motwkl/KeMcqhCKZNZqxMSr3lUaOSAD1TY4BRzm83pQ8db0gd7vcQMb/snz9GxLUBvqT/H7Gg==
dependencies:
"@octokit/request" "2.1.1"
"@octokit/request" "2.1.2"
before-after-hook "^1.2.0"
btoa-lite "^1.0.0"
lodash.get "^4.4.2"
resolved "https://registry.yarnpkg.com/parse-ms/-/parse-ms-1.0.1.tgz#56346d4749d78f23430ca0c713850aef91aa361d"
integrity sha1-VjRtR0nXjyNDDKDHE4UK75GqNh0=

parse-ms@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/parse-ms/-/parse-ms-2.0.0.tgz#7b3640295100caf3fa0100ccceb56635b62f9d62"
integrity sha512-AddiXFSLLCqj+tCRJ9MrUtHZB4DWojO3tk0NVZ+g5MaMQHF2+p2ktqxuoXyPFLljz/aUK0Nfhd/uGWnhXVXEyA==

parse-passwd@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/parse-passwd/-/parse-passwd-1.0.0.tgz#6d5b934a456993b23d37f40a382d6f1666a8e5c6"
dependencies:
parse-ms "^1.0.0"

pretty-ms@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/pretty-ms/-/pretty-ms-4.0.0.tgz#31baf41b94fd02227098aaa03bd62608eb0d6e92"
integrity sha512-qG66ahoLCwpLXD09ZPHSCbUWYTqdosB7SMP4OffgTgL2PBKXMuUsrk5Bwg8q4qPkjTXsKBMr+YK3Ltd/6F9s/Q==
dependencies:
parse-ms "^2.0.0"

printf@^0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/printf/-/printf-0.5.1.tgz#e0466788260859ed153006dc6867f09ddf240cf3"

0 comments on commit 23f427a

Please sign in to comment.
You can’t perform that action at this time.