Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/offline fw update #163

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 22 additions & 20 deletions app/scripts/onlyKey/OnlyKeyComm.js
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,7 @@ OnlyKey.prototype.setDeviceType = function (version = "") {
if (this.getDeviceType()) return; // only allow setting deviceType once
const lastChar = version[version.length - 1].toLowerCase();
let deviceType;
console.info(`lastChar ${lastChar}`);
switch (lastChar) {
case "g":
deviceType = DEVICE_TYPES.GO;
Expand Down Expand Up @@ -2242,20 +2243,23 @@ const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

function checkForNewFW(checkForNewFW, fwUpdateSupport, version) {
if (!fwchecked) {
return new Promise((resolve) => {
return new Promise((resolve, reject) => {
fwchecked = true;
if (checkForNewFW == true && fwUpdateSupport == true) {
//fw checking enabled and firmware version supports app updates
var r = request.get(
"https://github.com/trustcrypto/OnlyKey-Firmware/releases/latest",
function (err, res, body) {
if (err) return reject(err);

console.log(r.uri.href);
console.log(this.uri.href);
//var testupgradeurl = 'https://github.com/trustcrypto/OnlyKey-Firmware/releases/tag/v2.1.0-prod'
//var latestver = testupgradeurl.substr(testupgradeurl.length - 11); //end of redirected URL is the version
var latestver = this.uri.href.substr(this.uri.href.length - 11); //end of redirected URL is the version
console.info(version);
console.info(latestver);
//var latestver = testupgradeurl.split("/tag/v"); //end of redirected URL is the version
var latestver = this.uri.href.split("/tag/v");
latestver = latestver[1];
console.info("Current verion", version);
console.info("Latest verion", latestver);

var thisver_maj = version.slice(1, 2) * 100;
console.info(thisver_maj);
Expand All @@ -2267,17 +2271,20 @@ function checkForNewFW(checkForNewFW, fwUpdateSupport, version) {
var thisver_pat = version.slice(5, 6);
}
var thisver_mod = version.slice(11, 12);
console.info(thisver_mod);
var latestver_maj = latestver.slice(1, 2) * 100;
console.info(latestver_maj);
var latestver_min = latestver.slice(3, 4) * 10;
console.info(latestver_min);
console.info("Current verion mod", thisver_mod);
var latestversplit = latestver.split(".")
console.info(latestversplit);
var latestver_maj = latestversplit[0] * 100;
console.info("Latest verion maj", latestver_maj);
var latestver_min = latestversplit[1] * 10;
console.info("Latest verion min", latestver_min);
if (latestver_maj == 0) {
var latestver_pat = latestver.slice(10, 11);
} else {
var latestver_pat = latestver.slice(5, 6);
var latestver_pat = latestversplit[2].split("-");
}
console.info(latestver_pat);
latestver_pat = latestver_pat[0];
console.info("Latest verion pat", latestver_pat);

if (
thisver_maj + thisver_min + thisver_pat <
Expand All @@ -2304,20 +2311,15 @@ function checkForNewFW(checkForNewFW, fwUpdateSupport, version) {
// https://github.com/trustcrypto/OnlyKey-Firmware/releases/download/
var downloadurl =
"https://github.com/trustcrypto/OnlyKey-Firmware/releases/download/" +
latestver +
"v" + latestver +
"/Signed_OnlyKey_";
downloadurl = latestver_maj
? downloadurl +
downloadurl = downloadurl +
latestver_maj / 100 +
"_" +
latestver_min / 10 +
"_" +
latestver_pat +
"_STD.txt"
: downloadurl +
"Beta" +
latestver_pat +
"_STD_Color.txt";
"_STD.txt";
console.info(downloadurl);
var req = request.get(
downloadurl,
Expand Down
Loading