From 99dcd7868c60c69a2bea11748419ad66d1092489 Mon Sep 17 00:00:00 2001 From: Gordon Williams Date: Tue, 9 Jun 2020 09:23:55 +0100 Subject: [PATCH] Fix apploader node.js app issues - invalid length when uploading (base64 encode issues) and path (when run from directory other than the root) --- bin/apploader.js | 10 ++++++++-- js/appinfo.js | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/bin/apploader.js b/bin/apploader.js index a35778bae..616f3f3f7 100755 --- a/bin/apploader.js +++ b/bin/apploader.js @@ -78,8 +78,12 @@ function cmdListDevices() { }); noble.startScanning([], true); setTimeout(function() { + console.log("Stopping scan"); noble.stopScanning(); - }, 2000); + setTimeout(function() { + process.exit(0); + }, 500); + }, 4000); } function cmdInstallApp(appId, deviceAddress) { @@ -88,7 +92,8 @@ function cmdInstallApp(appId, deviceAddress) { if (app.custom) ERROR(`App ${JSON.stringify(appId)} requires HTML customisation`); return AppInfo.getFiles(app, { fileGetter:function(url) { - return Promise.resolve(require("fs").readFileSync(url).toString()); + console.log(__dirname+"/"+url); + return Promise.resolve(require("fs").readFileSync(__dirname+"/../"+url).toString()); }, settings : SETTINGS}).then(files => { //console.log(files); var command = files.map(f=>f.cmd).join("\n")+"\n"; @@ -101,6 +106,7 @@ function bangleSend(command, deviceAddress) { var args = [].slice.call(arguments); console.log("UART: "+args.join(" ")); } + //console.log("Sending",JSON.stringify(command)); var RESET = true; var DEVICEADDRESS = ""; diff --git a/js/appinfo.js b/js/appinfo.js index 6ed8310ad..54f403f91 100644 --- a/js/appinfo.js +++ b/js/appinfo.js @@ -1,8 +1,8 @@ if (typeof btoa==="undefined") { // Don't define btoa as a function here because Apple's // iOS browser defines the function even though it's in - // an IF statement that is never executed! - btoa = function(d) { return Buffer.from(d).toString('base64'); } + // an IF statement that is never executed + btoa = function(d) { return Buffer.from(d,'binary').toString('base64'); } } // Converts a string into most efficient way to send to Espruino (either json, base64, or compressed base64)