Skip to content

Commit 37b1780

Browse files
committed
apploader - install-app-from-files - use onComplete event
1 parent d4edefa commit 37b1780

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

install_from_files.js

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,25 @@
77
function installFromFiles() {
88
return new Promise(resolve => {
99

10-
// Collect all files
11-
const fileCollection = {
12-
files: []
13-
};
14-
1510
// Request multi-file selection from user
1611
Espruino.Core.Utils.fileOpenDialog({
17-
id:"installappfiles",
18-
type:"arraybuffer",
19-
multi:true,
20-
mimeType:"*/*",
21-
onCancel: function() {
12+
id:"installappfiles",
13+
type:"arraybuffer",
14+
multi:true,
15+
mimeType:"*/*",
16+
onComplete: function(files) {
17+
try {
18+
if (!files) return resolve(); // user cancelled
19+
const mapped = files.map(function(f) {
20+
return { name: f.fileName, data: f.contents };
21+
});
22+
processFiles(mapped, resolve);
23+
} catch (err) {
24+
showToast('Install failed: ' + err, 'error');
25+
console.error(err);
2226
resolve();
23-
},
24-
onComplete: function() {
25-
processFiles(fileCollection.files, resolve);
26-
}}, function(fileData, mimeType, fileName) {
27-
28-
// Collect each file as callback is invoked
29-
fileCollection.files.push({
30-
name: fileName,
31-
data: fileData
32-
});
27+
}
28+
}
3329
});
3430
});
3531
}

0 commit comments

Comments
 (0)