@@ -3,6 +3,15 @@ const serial = window.BridgeSerial
3
3
const disk = window . BridgeDisk
4
4
const win = window . BridgeWindow
5
5
6
+ function extract ( out ) {
7
+ /*
8
+ * Message ($msg) will come out following this template:
9
+ * "OK${msg}\x04${err}\x04>"
10
+ * TODO: consider error handling
11
+ */
12
+ return out . slice ( 2 , - 3 )
13
+ }
14
+
6
15
const newFileContent = `# This program was created in Arduino Lab for MicroPython
7
16
8
17
print('Hello, MicroPython!')
@@ -54,12 +63,11 @@ def get_file_tree(path = '.'):
54
63
if file_path in ('.', os.getcwd()):
55
64
continue
56
65
file_name = file_path.split('/')[len(file_path.split('/'))-1]
57
- tree_list.insert(0, ( depth, file_path, file_name, is_folder))
66
+ tree_list.insert(0, list(( depth, file_path, file_name, 'folder' if is_folder else 'file') ))
58
67
return tree_list
59
68
60
69
def print_file_tree(path = '.'):
61
- for depth, file_path, file_name, is_folder in get_file_tree(path):
62
- print([file_path, file_name, is_folder])
70
+ print(get_file_tree(path))
63
71
`
64
72
async function store ( state , emitter ) {
65
73
win . setWindowSize ( 720 , 640 )
@@ -422,19 +430,10 @@ async function store(state, emitter) {
422
430
} )
423
431
emitter . emit ( 'render' )
424
432
} )
425
- // emitter.on('remove-folder', async () => {
426
- // state.isRemoving = true
427
- // console.log('store > remove-folder')
428
- // emitter.emit('render')
429
- // })
430
433
emitter . on ( 'remove-files' , async ( ) => {
431
434
state . isRemoving = true
432
435
emitter . emit ( 'render' )
433
- console . log ( 'store > remove-files' )
434
-
435
-
436
436
if ( state . selectedBoardFiles . length > 0 ) {
437
- console . log ( state . selectedBoardFiles )
438
437
const fileNames = state . selectedBoardFiles . filter ( ( f ) => f . source === 'board' ) . map ( ( f ) => f . fileName )
439
438
const confirmBoardDeletion = confirm ( `Delete these items from the board?\n ${ fileNames . join ( '\n' ) } ?` , 'Cancel' , 'Yes' )
440
439
if ( confirmBoardDeletion ) {
@@ -461,7 +460,6 @@ async function store(state, emitter) {
461
460
}
462
461
463
462
if ( state . selectedDiskFiles . length > 0 ) {
464
- console . log ( state . selectedDiskFiles )
465
463
const fileNames = state . selectedDiskFiles . filter ( ( f ) => f . source === 'disk' ) . map ( ( f ) => f . fileName )
466
464
const confirmDiskDeletion = confirm ( `Delete these items from the disk?\n ${ fileNames . join ( '\n' ) } ?` , 'Cancel' , 'Yes' )
467
465
if ( confirmDiskDeletion ) {
@@ -548,7 +546,6 @@ async function store(state, emitter) {
548
546
emitter . on ( 'finish-renaming' , ( ) => { } )
549
547
emitter . on ( 'finish-creating' , async ( value ) => {
550
548
if ( ! state . creatingFile && ! state . creatingFolder ) {
551
- console . log ( 'neither creating file nor folder' )
552
549
return
553
550
}
554
551
@@ -609,7 +606,6 @@ async function store(state, emitter) {
609
606
emitter . on ( 'close-file-options' , ( ) => { } )
610
607
611
608
emitter . on ( 'toggle-file-selection' , ( file , source , event ) => {
612
- console . log ( event , file , source )
613
609
const isSelected = state . selectedFiles . find ( ( f ) => {
614
610
return f . fileName === file . fileName && f . source === source
615
611
} )
@@ -643,10 +639,8 @@ async function store(state, emitter) {
643
639
parentFolder : file . parentFolder
644
640
} )
645
641
emitter . emit ( 'open-selected-files' )
646
- console . log ( 'open-single-file' , file )
647
642
} )
648
643
emitter . on ( 'open-selected-files' , async ( ) => {
649
- console . log ( 'open-selected-files' )
650
644
let files = [ ]
651
645
for ( let i in state . selectedFiles ) {
652
646
let selectedFile = state . selectedFiles [ i ]
@@ -702,7 +696,6 @@ async function store(state, emitter) {
702
696
} )
703
697
704
698
if ( files . length > 0 ) {
705
- // console.log(state.openFiles, files)
706
699
state . openFiles = state . openFiles . concat ( files )
707
700
state . editingFile = files [ 0 ] . id
708
701
}
@@ -765,9 +758,31 @@ async function store(state, emitter) {
765
758
let command = microPythonFShelpers
766
759
command += microPythonFileTree
767
760
command += `print_file_tree('${ folder_path } ')`
768
- const output = await serial . run ( command )
769
- console . log ( output )
770
- const confirmAction = alert ( `Folder transfer not yet available` )
761
+ let output = await serial . run ( command )
762
+ output = extract ( output )
763
+ output = output . replace ( / ' / g, '"' )
764
+ output = output . split ( 'OK' )
765
+ let files = JSON . parse ( output )
766
+ for ( f in files ) {
767
+ const sourcePath = ( files [ f ] [ 1 ] )
768
+ const type = files [ f ] [ 3 ]
769
+ const sourceRelativePath = sourcePath . split ( state . boardNavigationPath ) [ 1 ]
770
+ if ( type === 'folder' ) {
771
+ const newFolderPath = disk . getFullPath ( state . diskNavigationRoot , state . diskNavigationPath , `/${ sourceRelativePath } ` )
772
+ await disk . createFolder ( newFolderPath )
773
+ } else {
774
+ const fileDestinationPath = disk . getFullPath ( state . diskNavigationRoot , state . diskNavigationPath , `/${ sourceRelativePath } ` )
775
+ state . transferringProgress = sourcePath
776
+ await serial . downloadFile (
777
+ sourcePath ,
778
+ fileDestinationPath ,
779
+ ( e ) => {
780
+ state . transferringProgress = e
781
+ emitter . emit ( 'render' )
782
+ } )
783
+ emitter . emit ( 'render' )
784
+ }
785
+ }
771
786
continue
772
787
}
773
788
await serial . downloadFile (
@@ -1001,7 +1016,6 @@ function canUpload({ isConnected, selectedFiles }) {
1001
1016
}
1002
1017
1003
1018
function deselectFilesFromSource ( source , selectedFiles ) {
1004
- console . log ( 'deselectFilesFromSource' , source , selectedFiles )
1005
1019
if ( selectedFiles . length === 0 ) return [ ]
1006
1020
return selectedFiles . filter ( ( f ) => f . source !== source )
1007
1021
}
0 commit comments