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 )
@@ -73,6 +72,15 @@ const Serial = {
73
72
} ,
74
73
exit_raw_repl : async ( ) => {
75
74
return board . exit_raw_repl ( )
75
+ } ,
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 ( '/' )
76
84
}
77
85
}
78
86
@@ -86,18 +94,27 @@ const Disk = {
86
94
ilistFiles : async ( folder ) => {
87
95
return ipcRenderer . invoke ( 'ilist-files' , folder )
88
96
} ,
89
- loadFile : async ( folder , file ) => {
90
- let content = await ipcRenderer . invoke ( 'load-file' , folder , file )
97
+ loadFile : async ( filePath ) => {
98
+ let content = await ipcRenderer . invoke ( 'load-file' , filePath )
91
99
return new TextDecoder ( ) . decode ( content )
92
100
} ,
93
- removeFile : async ( folder , file ) => {
94
- 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 )
109
+ } ,
110
+ getNavigationPath : ( navigation , target ) => {
111
+ return path . join ( navigation , target )
95
112
} ,
96
- saveFileContent : async ( folder , file , content ) => {
97
- return ipcRenderer . invoke ( 'save-file' , folder , file , content )
113
+ getFullPath : ( root , navigation , file ) => {
114
+ return path . resolve ( path . join ( root , navigation , file ) )
98
115
} ,
99
- renameFile : async ( folder , oldName , newName ) => {
100
- return ipcRenderer . invoke ( 'rename-file' , folder , oldName , newName )
116
+ getParentPath : ( navigation ) => {
117
+ return path . dirname ( navigation )
101
118
}
102
119
}
103
120
0 commit comments