1
1
console . log ( 'preload' )
2
2
const { contextBridge, ipcRenderer } = require ( 'electron' )
3
+ const path = require ( 'path' )
3
4
4
5
const Micropython = require ( 'micropython.js' )
5
6
const board = new Micropython ( )
@@ -53,14 +54,12 @@ const Serial = {
53
54
saveFileContent : async ( filename , content , dataConsumer ) => {
54
55
return board . fs_save ( content || ' ' , filename , dataConsumer )
55
56
} ,
56
- uploadFile : async ( diskFolder , serialFolder , filename , dataConsumer ) => {
57
- let src = `${ diskFolder } /${ filename } `
58
- let dest = `${ serialFolder } /${ filename } `
57
+ uploadFile : async ( src , dest , dataConsumer ) => {
59
58
return board . fs_put ( src , dest , dataConsumer )
60
59
} ,
61
- downloadFile : async ( serialFolder , diskFolder , filename ) => {
62
- let contents = await Serial . loadFile ( ` ${ serialFolder } / ${ filename } ` )
63
- return ipcRenderer . invoke ( 'save-file' , diskFolder , filename , contents )
60
+ downloadFile : async ( src , dest ) => {
61
+ let contents = await Serial . loadFile ( src )
62
+ return ipcRenderer . invoke ( 'save-file' , dest , contents )
64
63
} ,
65
64
renameFile : async ( oldName , newName ) => {
66
65
return board . fs_rename ( oldName , newName )
@@ -74,8 +73,14 @@ const Serial = {
74
73
exit_raw_repl : async ( ) => {
75
74
return board . exit_raw_repl ( )
76
75
} ,
77
- cleanPath : ( filePath ) => {
78
- return '/' + filePath . split ( '/' ) . filter ( f => f ) . join ( '/' )
76
+ getNavigationPath : ( navigation , target ) => {
77
+ return [ navigation , target ] . filter ( p => p ) . join ( '/' )
78
+ } ,
79
+ getFullPath : ( root , navigation , file ) => {
80
+ return root + [ navigation , file ] . filter ( p => p ) . join ( '/' )
81
+ } ,
82
+ getParentPath : ( filePath ) => {
83
+ return filePath . split ( '/' ) . slice ( 0 , - 1 ) . join ( '/' )
79
84
}
80
85
}
81
86
@@ -89,21 +94,27 @@ const Disk = {
89
94
ilistFiles : async ( folder ) => {
90
95
return ipcRenderer . invoke ( 'ilist-files' , folder )
91
96
} ,
92
- loadFile : async ( folder , file ) => {
93
- let content = await ipcRenderer . invoke ( 'load-file' , folder , file )
97
+ loadFile : async ( filePath ) => {
98
+ let content = await ipcRenderer . invoke ( 'load-file' , filePath )
94
99
return new TextDecoder ( ) . decode ( content )
95
100
} ,
96
- removeFile : async ( folder , file ) => {
97
- return ipcRenderer . invoke ( 'remove-file' , folder , file )
101
+ removeFile : async ( filePath ) => {
102
+ return ipcRenderer . invoke ( 'remove-file' , filePath )
103
+ } ,
104
+ saveFileContent : async ( filePath , content ) => {
105
+ return ipcRenderer . invoke ( 'save-file' , filePath , content )
106
+ } ,
107
+ renameFile : async ( oldName , newName ) => {
108
+ return ipcRenderer . invoke ( 'rename-file' , oldName , newName )
98
109
} ,
99
- saveFileContent : async ( folder , file , content ) => {
100
- return ipcRenderer . invoke ( 'save-file' , folder , file , content )
110
+ getNavigationPath : ( navigation , target ) => {
111
+ return path . join ( navigation , target )
101
112
} ,
102
- renameFile : async ( folder , oldName , newName ) => {
103
- return ipcRenderer . invoke ( 'rename-file' , folder , oldName , newName )
113
+ getFullPath : ( root , navigation , file ) => {
114
+ return path . resolve ( path . join ( root , navigation , file ) )
104
115
} ,
105
- cleanPath : async ( filePath ) => {
106
- return ipcRenderer . invoke ( 'clean-path' , filePath )
116
+ getParentPath : ( navigation ) => {
117
+ return path . dirname ( navigation )
107
118
}
108
119
}
109
120
0 commit comments