Skip to content

Commit db1a278

Browse files
committed
Formatting file paths on preload and replacing cleanPath
1 parent 13016fe commit db1a278

File tree

3 files changed

+172
-76
lines changed

3 files changed

+172
-76
lines changed

preload.js

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
console.log('preload')
22
const { contextBridge, ipcRenderer } = require('electron')
3+
const path = require('path')
34

45
const Micropython = require('micropython.js')
56
const 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)
@@ -74,8 +73,14 @@ const Serial = {
7473
exit_raw_repl: async () => {
7574
return board.exit_raw_repl()
7675
},
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('/')
7984
}
8085
}
8186

@@ -89,21 +94,27 @@ const Disk = {
8994
ilistFiles: async (folder) => {
9095
return ipcRenderer.invoke('ilist-files', folder)
9196
},
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)
9499
return new TextDecoder().decode(content)
95100
},
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)
98109
},
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)
101112
},
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))
104115
},
105-
cleanPath: async (filePath) => {
106-
return ipcRenderer.invoke('clean-path', filePath)
116+
getParentPath: (navigation) => {
117+
return path.dirname(navigation)
107118
}
108119
}
109120

ui/arduino/components/panel_files.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function PanelFiles(state, emit) {
8484
<div class="path">
8585
${state.isConnected ? Icon('icons/Connect.svg') : Icon('icons/Disconnect.svg')}
8686
<a class="full" href="#" onclick=${() => emit('open-port-dialog')}>
87-
${state.isConnected ? state.serialPath : 'Connect'}
87+
${state.isConnected ? state.serialPort : 'Connect'}
8888
</a>
8989
${removeSerial}
9090
${newSerial}

0 commit comments

Comments
 (0)