Skip to content

Commit

Permalink
Merge pull request #53 from arduino/bugfix/windows-path
Browse files Browse the repository at this point in the history
Bugfix/windows path
  • Loading branch information
murilopolese authored Jun 28, 2023
2 parents 15eb66b + 07e0d7a commit db8a85f
Show file tree
Hide file tree
Showing 5 changed files with 198 additions and 126 deletions.
26 changes: 11 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ function ilistFolder(folder, filesOnly) {
return files
}


// LOCAL FILE SYSTEM ACCESS
ipcMain.handle('open-folder', async (event) => {
console.log('ipcMain', 'open-folder')
Expand All @@ -64,16 +63,14 @@ ipcMain.handle('ilist-files', async (event, folder) => {
return ilistFolder(folder)
})

ipcMain.handle('load-file', (event, folder, filename) => {
console.log('ipcMain', 'load-file', folder, filename )
let filePath = path.resolve(folder, filename)
ipcMain.handle('load-file', (event, filePath) => {
console.log('ipcMain', 'load-file', filePath)
let content = fs.readFileSync(filePath)
return content
})

ipcMain.handle('save-file', (event, folder, filename, content) => {
console.log('ipcMain', 'save-file', folder, filename, content)
let filePath = path.resolve(folder, filename)
ipcMain.handle('save-file', (event, filePath, content) => {
console.log('ipcMain', 'save-file', filePath, content)
fs.writeFileSync(filePath, content, 'utf8')
return true
})
Expand All @@ -89,21 +86,20 @@ ipcMain.handle('update-folder', (event, folder) => {
return { folder, files }
})

ipcMain.handle('remove-file', (event, folder, filename) => {
console.log('ipcMain', 'remove-file', folder, filename)
let filePath = path.resolve(folder, filename)
ipcMain.handle('remove-file', (event, filePath) => {
console.log('ipcMain', 'remove-file', filePath)
fs.unlinkSync(filePath)
return true
})

ipcMain.handle('rename-file', (event, folder, filename, newFilename) => {
console.log('ipcMain', 'rename-file', folder, filename, newFilename)
let filePath = path.resolve(folder, filename)
let newFilePath = path.resolve(folder, newFilename)
ipcMain.handle('rename-file', (event, filePath, newFilePath) => {
console.log('ipcMain', 'rename-file', filePath, newFilePath)
fs.renameSync(filePath, newFilePath)
return newFilename
return true
})

// WINDOW MANAGEMENT

ipcMain.handle('set-window-size', (event, minWidth, minHeight) => {
console.log('ipcMain', 'set-window-size', minWidth, minHeight)
if (!win) {
Expand Down
54 changes: 27 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 31 additions & 14 deletions preload.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
console.log('preload')
const { contextBridge, ipcRenderer } = require('electron')
const path = require('path')

const Micropython = require('micropython.js')
const board = new Micropython()
Expand Down Expand Up @@ -53,14 +54,12 @@ const Serial = {
saveFileContent: async (filename, content, dataConsumer) => {
return board.fs_save(content || ' ', filename, dataConsumer)
},
uploadFile: async (diskFolder, serialFolder, filename, dataConsumer) => {
let src = `${diskFolder}/${filename}`
let dest = `${serialFolder}/${filename}`
uploadFile: async (src, dest, dataConsumer) => {
return board.fs_put(src, dest, dataConsumer)
},
downloadFile: async (serialFolder, diskFolder, filename) => {
let contents = await Serial.loadFile(`${serialFolder}/${filename}`)
return ipcRenderer.invoke('save-file', diskFolder, filename, contents)
downloadFile: async (src, dest) => {
let contents = await Serial.loadFile(src)
return ipcRenderer.invoke('save-file', dest, contents)
},
renameFile: async (oldName, newName) => {
return board.fs_rename(oldName, newName)
Expand All @@ -73,6 +72,15 @@ const Serial = {
},
exit_raw_repl: async () => {
return board.exit_raw_repl()
},
getNavigationPath: (navigation, target) => {
return [navigation, target].filter(p => p).join('/')
},
getFullPath: (root, navigation, file) => {
return root + [navigation, file].filter(p => p).join('/')
},
getParentPath: (filePath) => {
return filePath.split('/').slice(0, -1).join('/')
}
}

Expand All @@ -86,18 +94,27 @@ const Disk = {
ilistFiles: async (folder) => {
return ipcRenderer.invoke('ilist-files', folder)
},
loadFile: async (folder, file) => {
let content = await ipcRenderer.invoke('load-file', folder, file)
loadFile: async (filePath) => {
let content = await ipcRenderer.invoke('load-file', filePath)
return new TextDecoder().decode(content)
},
removeFile: async (folder, file) => {
return ipcRenderer.invoke('remove-file', folder, file)
removeFile: async (filePath) => {
return ipcRenderer.invoke('remove-file', filePath)
},
saveFileContent: async (filePath, content) => {
return ipcRenderer.invoke('save-file', filePath, content)
},
renameFile: async (oldName, newName) => {
return ipcRenderer.invoke('rename-file', oldName, newName)
},
getNavigationPath: (navigation, target) => {
return path.join(navigation, target)
},
saveFileContent: async (folder, file, content) => {
return ipcRenderer.invoke('save-file', folder, file, content)
getFullPath: (root, navigation, file) => {
return path.resolve(path.join(root, navigation, file))
},
renameFile: async (folder, oldName, newName) => {
return ipcRenderer.invoke('rename-file', folder, oldName, newName)
getParentPath: (navigation) => {
return path.dirname(navigation)
}
}

Expand Down
2 changes: 1 addition & 1 deletion ui/arduino/components/panel_files.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function PanelFiles(state, emit) {
<div class="path">
${state.isConnected ? Icon('icons/Connect.svg') : Icon('icons/Disconnect.svg')}
<a class="full" href="#" onclick=${() => emit('open-port-dialog')}>
${state.isConnected ? state.serialPath : 'Connect'}
${state.isConnected ? state.serialPort : 'Connect'}
</a>
${removeSerial}
${newSerial}
Expand Down
Loading

0 comments on commit db8a85f

Please sign in to comment.