feat(device): flash device firmware from Agent (#499)

* add dataModelVersion, usbProtocolVersion, slaveProtocolVersion

* read the package.json at appstart

* flash firmware

* update firmware

* fix extra resource path

* fix import modules

* update lock files

* fix imports

* terminal window

* exclude tmp folder from git repo

* ok button

* auto scroll in xterm

* fix maxTry count calculation

* optimize logging

* optimize timeout

* readSync

* Add extra delay

* fix async call

* fix error message in log

* fix ok button disable state

* retry

* list devices

* close device after reenumeration

* retry snooze

* kboot maxtry 10

* retry 100

* remove deprecated toPayload ngrx helper

* flash firmware with custom file

* fix tslint
This commit is contained in:
Róbert Kiss
2017-11-27 22:12:43 +01:00
committed by László Monda
parent f608791a09
commit 297fd3be79
52 changed files with 3914 additions and 894 deletions

10
scripts/copy-blhost.js Normal file
View File

@@ -0,0 +1,10 @@
const fse = require('fs-extra');
const path = require('path');
fse.copy(
path.join(__dirname, '../packages/usb/blhost'),
path.join(__dirname, '../tmp/packages/blhost'),
{
overwrite:true,
recursive:true
});

View File

@@ -0,0 +1,48 @@
const request = require('request');
const decompress = require('decompress');
const decompressTarbz = require('decompress-tarbz2');
const path = require('path');
const fs = require('fs');
const fse = require('fs-extra');
async function downloadFirmware(version) {
const url = `https://github.com/UltimateHackingKeyboard/firmware/releases/download/${version}/uhk-firmware-${version}.tar.bz2`;
const outputDir = path.join(__dirname, `../tmp`);
const output = path.join(outputDir, `uhk-firmware-${version}.tar.bz2`);
if (!fs.existsSync(outputDir))
fs.mkdirSync(outputDir);
await downloadFile(url, output);
return Promise.resolve(output);
}
async function downloadFile(url, output) {
return new Promise((resolve, reject) => {
console.log(`Start download ${url}`);
const r = request(url);
r.on('end', () => {
resolve(output);
});
r.on('error', (error) => {
reject(error);
});
r.pipe(fs.createWriteStream(output));
})
}
(async function main() {
const agentJson = require('../packages/uhk-agent/src/package.json');
const extractedFirmwareDir = path.join(__dirname, '../tmp/packages/firmware');
await fse.emptyDir(extractedFirmwareDir);
// Download the firmware and add as extra resources
const firmwarePath = await downloadFirmware(agentJson.firmwareVersion);
await decompress(firmwarePath, extractedFirmwareDir, {plugins: [decompressTarbz()]});
await fse.remove(firmwarePath);
})();

View File

@@ -3,6 +3,8 @@ const jsonfile = require('jsonfile');
const exec = require('child_process').execSync;
const TEST_BUILD = process.env.TEST_BUILD;// set true if you would like to test on your local machine
// set true if running on your dev mac machine where yarn is installed or not need to install
const RUNNING_IN_DEV_MODE = process.env.RUNNING_IN_DEV_MODE === 'true';
const DIR = process.env.DIR;
// electron-builder security override.
@@ -40,11 +42,13 @@ if (!isReleaseCommit) {
process.exit(0)
}
if (process.platform === 'darwin') {
if (process.platform === 'darwin' && !RUNNING_IN_DEV_MODE) {
exec('brew install yarn --without-node');
}
exec("yarn add electron-builder");
if (!RUNNING_IN_DEV_MODE) {
exec("yarn add electron-builder");
}
const path = require('path');
const builder = require("electron-builder");
@@ -83,11 +87,13 @@ if (process.platform === 'darwin') {
//require('./setup-macos-keychain').registerKeyChain();
}
let version = '';
if (TEST_BUILD || gitTag) {
const jsonVersion = require('../package.json').version;
version = gitTag;
updateVersionNumberIn2rndPackageJson(jsonVersion);
const rootJson = require('../package.json');
update2ndPackageJson(rootJson);
// Add firmware and blhost to extra resources
const extractedFirmwareDir = path.join(__dirname, '../tmp/packages');
extraResources.push({from: extractedFirmwareDir, to: 'packages/'});
builder.build({
dir: DIR,
@@ -98,7 +104,7 @@ if (TEST_BUILD || gitTag) {
author: {
name: 'Ultimate Gadget Laboratories'
},
version: jsonVersion
version: rootJson.version
},
config: {
directories: {
@@ -107,7 +113,8 @@ if (TEST_BUILD || gitTag) {
appId: 'com.ultimategadgetlabs.uhk.agent',
productName: 'UHK Agent',
mac: {
category: 'public.app-category.utilities'
category: 'public.app-category.utilities',
extraResources
},
win: {
extraResources
@@ -133,15 +140,13 @@ if (TEST_BUILD || gitTag) {
else {
console.log('No git tag');
// TODO: Need it?
version = sha.substr(0, 8);
process.exit(1);
}
function updateVersionNumberIn2rndPackageJson(version) {
function update2ndPackageJson(rootJson) {
const jsonPath = path.join(__dirname, '../packages/uhk-agent/dist/package.json');
const json = require(jsonPath);
json.version = version;
json.version = rootJson.version;
jsonfile.writeFileSync(jsonPath, json, {spaces: 2})
}