11console . log ( 'preload' )
22const { contextBridge, ipcRenderer } = require ( 'electron' )
3+ const path = require ( 'path' )
34
45const Micropython = require ( 'micropython.js' )
56const board = new Micropython ( )
@@ -53,14 +54,12 @@ const Serial = {
5354 saveFileContent : async ( filename , content , dataConsumer ) => {
5455 return board . fs_save ( content || ' ' , filename , dataConsumer )
5556 } ,
56- uploadFile : async ( diskFolder , serialFolder , filename , dataConsumer ) => {
57- let src = `${ diskFolder } /${ filename } `
58- let dest = `${ serialFolder } /${ filename } `
57+ uploadFile : async ( src , dest , dataConsumer ) => {
5958 return board . fs_put ( src , dest , dataConsumer )
6059 } ,
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 )
6463 } ,
6564 renameFile : async ( oldName , newName ) => {
6665 return board . fs_rename ( oldName , newName )
@@ -73,6 +72,15 @@ const Serial = {
7372 } ,
7473 exit_raw_repl : async ( ) => {
7574 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 ( '/' )
7684 }
7785}
7886
@@ -86,18 +94,27 @@ const Disk = {
8694 ilistFiles : async ( folder ) => {
8795 return ipcRenderer . invoke ( 'ilist-files' , folder )
8896 } ,
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 )
9199 return new TextDecoder ( ) . decode ( content )
92100 } ,
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 )
95112 } ,
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 ) )
98115 } ,
99- renameFile : async ( folder , oldName , newName ) => {
100- return ipcRenderer . invoke ( 'rename-file' , folder , oldName , newName )
116+ getParentPath : ( navigation ) => {
117+ return path . dirname ( navigation )
101118 }
102119}
103120
0 commit comments