Skip to content

Commit ec54896

Browse files
committed
update download functions
1 parent 73106a8 commit ec54896

4 files changed

Lines changed: 74 additions & 17 deletions

File tree

nw-miniblip/index.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
var editor;
1414
$( document ).ready(function() {
1515
bind_buttons();
16-
get_list_firmwares_local();
16+
hide_all_sections();
17+
show_section_firmware_list();
18+
//get_list_firmwares_local();
19+
get_list_firmwares_remote();
1720

1821
editor = ace.edit("editor");
1922
editor.setTheme("ace/theme/monokai");

nw-miniblip/javascript/main.js

Lines changed: 66 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
// TODO
2+
// GET REMOTE JSON
3+
// DOWNLOAD FILE ON ITEM CLICK
4+
// CHECK BOARD STATUS
5+
// UPLOAD FIRMWARE
6+
//
7+
var fs = require("fs");
8+
var http = require('http');
9+
10+
111
function detect_board() {
212

313

@@ -38,7 +48,15 @@ function init_console(div) {
3848

3949
function get_list_firmwares_remote() {
4050

51+
var url = "https://raw.githubusercontent.com/hack-miniblip/apps/master/firmware_list.json";
52+
53+
$.get(url, function(data) {
54+
var obj = $.parseJSON(data);
55+
$.each(obj, function(i, value) {
56+
add_item_to_firmware_list(obj[i], true);
57+
});
4158

59+
});
4260
}
4361

4462
function get_local_firmware_path(firmware_name) {
@@ -50,43 +68,78 @@ function get_local_firmware_path(firmware_name) {
5068
return path;
5169
}
5270

53-
function get_remote_firmware_url() {
71+
function get_remote_firmware_url(name) {
72+
return "https://github.com/hack-miniblip/apps/raw/master/"+name+"/firmware.bin";
73+
}
5474

75+
function add_item_to_firmware_list(obj, isRemote) {
76+
console.log("added " + obj.name);
77+
var file_url = "";
78+
if (isRemote) {
79+
file_url = get_remote_firmware_url(obj.name);
80+
console.log(file_url);
81+
} else {
82+
file_url = get_local_firmware_path(obj.name);
83+
}
84+
85+
$("#firmware-list").append('<div class="item" id = '+obj.id +'><div class="name">' + obj.name +'</div><div class="author">'+obj.author+'</div></div>');
86+
$("#firmware-list #" + obj.id).click(function() {
87+
88+
if (isRemote) {
89+
download_firmware(file_url, function() {
90+
//upload_firmware(file_url, "/dev/sdb");
91+
});
92+
} else {
93+
upload_firmware(file_url, "/dev/sdb");
94+
}
5595

96+
});
5697
}
5798

5899
function get_list_firmwares_local() {
59-
var fs = require("fs");
60100
console.log(process.cwd());
61101

62102
fs.readFile("firmwares.json", "utf8", function(error, data) {
63103
console.log(data);
64104
var obj = $.parseJSON( data );
65105

66106
$.each(obj, function(i, value) {
67-
console.log(obj[i].name);
68-
$("#firmware-list").append('<div class="item" id = '+obj[i].id +'><div class="name">' + obj[i].name +'</div><div class="author">'+obj[i].author+'</div></div>');
69-
$("#firmware-list #" + obj[i].id).click(function() {
70-
upload_firmware(get_local_firmware_path(obj[i].id), "/dev/sdb");
71-
});
107+
add_item_to_firmware_list(obj[i]);
72108
});
73109
//console.log(obj);
74-
});
75-
}
110+
});
111+
}
112+
113+
114+
//TODO check md5
115+
function download_firmware(name, url, callback) {
116+
if (!fs.existsSync("./tmp")){
117+
fs.mkdirSync("./tmp");
118+
}
76119

120+
var path = process.cwd() + "/" + name;
77121

78-
//check md5
79-
function download_firmware() {
122+
var file = fs.createWriteStream(path);
80123

124+
var request = http.get(url, function (response) {
125+
response.pipe(file);
126+
callback();
127+
});
81128
}
82129

83130

131+
function show_section_firmware_list() {
132+
$("#main #firmware-list").show();
133+
}
84134

135+
function show_section_code() {
136+
$("#main #editor-container").show();
137+
}
85138

86139
function bind_buttons() {
87140
$("#toolbar #list").click(function() {
88141
hide_all_sections();
89-
$("#main #firmware-list").show();
142+
show_section_firmware_list();
90143
});
91144

92145
$("#toolbar #console").click(function() {
@@ -96,7 +149,7 @@ function bind_buttons() {
96149

97150
$("#toolbar #code").click(function() {
98151
hide_all_sections();
99-
$("#main #editor-container").show();
152+
show_section_code();
100153
});
101154
}
102155

nw-miniblip/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
"version": "0.0.1",
44
"main": "index.html",
55
"window": {
6-
"toolbar": true,
6+
"toolbar": false,
77
"width": 960,
8-
"height": 800
8+
"height": 800,
9+
"resizable": false
910
}
1011
}

nw-miniblip/styles/main.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ body {
130130

131131
#editor {
132132
width: 875px;
133-
height: 761px;
133+
height: 800px;
134134
top: 0;
135135
position: absolute;
136136
left: -15px;

0 commit comments

Comments
 (0)