Skip to content

Commit f16d8d0

Browse files
committed
added sudo prompt to upload to the board
1 parent 0595e44 commit f16d8d0

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

nw-miniblip/javascript/main.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,23 @@ function detect_board() {
1616
}
1717

1818
function upload_firmware(path_in, path_out) {
19-
var cmd_dd = "sudo dd if="+path_in+" of="+path_out+" bs=512 seek=4 conv=notrunc";
19+
var cmd_dd = "dd if="+path_in+" of="+path_out+" bs=512 seek=4 conv=notrunc";
2020

2121
console.log(cmd_dd);
2222

2323

24+
var sudo = require('sudo-prompt');
25+
var options = {
26+
name: 'MiniBlip Studio',
27+
onChildProcess: function(childProcess) {} // (optional)
28+
};
29+
sudo.exec(cmd_dd, options, function(error, stdout, stderr) {
30+
console.log("error " + error);
31+
console.log("stdout " + stdout);
32+
console.log("stderr " + stderr);
33+
})
34+
35+
/*
2436
var execFile = require
2537
('child_process').execFile, child;
2638
@@ -39,6 +51,7 @@ function upload_firmware(path_in, path_out) {
3951
console.log('Child process exited '+
4052
'with exit code '+ code);
4153
});
54+
*/
4255
}
4356

4457

@@ -82,7 +95,6 @@ function add_item_to_firmware_list(obj, isRemote) {
8295

8396
if (isRemote) {
8497
file_url = get_remote_firmware_url(obj.name);
85-
console.log(file_url);
8698
} else {
8799
file_url = get_local_firmware_path(obj.name);
88100
}
@@ -102,14 +114,13 @@ console.log(file_url);
102114
$div.find(".author").text(obj.author);
103115
$div.find(".source a").attr("href", obj.source);
104116
$(this).fadeIn("500");
105-
106117
});
107118

108119
$div.find("#upload").click(function() {
109120

110121
if (isRemote) {
111-
download_firmware(obj, function() {
112-
upload_firmware(file_url, "/dev/sdb");
122+
download_firmware(obj, function(isOk, local_path) {
123+
if (isOk) upload_firmware(local_path, "/dev/sdb");
113124
});
114125
} else {
115126
upload_firmware(file_url, "/dev/sdb");
@@ -159,7 +170,7 @@ function download_firmware(obj, callback) {
159170
//console.log("md5 nop");
160171
md5result = false;
161172
}
162-
callback(md5result);
173+
callback(md5result, to);
163174
}); //readfile
164175
});
165176
}

0 commit comments

Comments
 (0)