diff --git a/ui/arduino/helpers.py b/ui/arduino/helpers.py index cb7b757..15ab644 100644 --- a/ui/arduino/helpers.py +++ b/ui/arduino/helpers.py @@ -1,6 +1,13 @@ import os import json -os.chdir('/') +import sys + +def get_root(): + if '/flash' in sys.path: + return '/flash' + else: + return '/' + def is_directory(path): return True if os.stat(path)[0] == 0x4000 else False @@ -18,6 +25,9 @@ def get_all_files(path, array_of_files = []): return array_of_files +def iget_root(): + print(get_root(), end='') + def ilist_all(path): print(json.dumps(get_all_files(path))) @@ -30,3 +40,5 @@ def delete_folder(path): if file['type'] == 'folder': os.rmdir(file['path']) os.rmdir(path) + +os.chdir(get_root()) \ No newline at end of file diff --git a/ui/arduino/store.js b/ui/arduino/store.js index f82c992..966e906 100644 --- a/ui/arduino/store.js +++ b/ui/arduino/store.js @@ -179,6 +179,7 @@ async function store(state, emitter) { // Connected and ready state.isConnecting = false state.isConnected = true + state.boardNavigationPath = await getBoardNavigationPath() updateMenu() if (state.view === 'editor' && state.panelHeight <= PANEL_CLOSED) { state.panelHeight = state.savedPanelHeight @@ -288,7 +289,10 @@ async function store(state, emitter) { } emitter.emit('open-panel') emitter.emit('render') - await serialBridge.getPrompt() + if (state.isConnected) { + await serialBridge.getPrompt() + } + }) emitter.on('reset', async () => { log('reset') @@ -606,7 +610,7 @@ async function store(state, emitter) { } await serialBridge.saveFileContent( serialBridge.getFullPath( - '/', + state.boardNavigationRoot, state.boardNavigationPath, fileNameParameter ), @@ -785,7 +789,7 @@ async function store(state, emitter) { if (file.source === 'board') { await serialBridge.removeFile( serialBridge.getFullPath( - '/', + state.boardNavigationRoot, state.boardNavigationPath, file.fileName ) @@ -1695,6 +1699,23 @@ async function getAvailablePorts() { return await serialBridge.loadPorts() } +async function getBoardNavigationPath() { + let output = await serialBridge.execFile(await getHelperFullPath()) + output = await serialBridge.run(`iget_root()`) + let boardRoot = '' + try { + // Extracting the json output from serial response + output = output.substring( + output.indexOf('OK')+2, + output.indexOf('\x04') + ) + boardRoot = output + } catch (e) { + log('error', output) + } + return boardRoot +} + async function getBoardFiles(path) { await serialBridge.getPrompt() let files = await serialBridge.ilistFiles(path) diff --git a/ui/arduino/views/components/new-file-dialog.js b/ui/arduino/views/components/new-file-dialog.js index 83ace3f..8e00d9e 100644 --- a/ui/arduino/views/components/new-file-dialog.js +++ b/ui/arduino/views/components/new-file-dialog.js @@ -65,7 +65,7 @@ function NewFileDialog(state, emit) { ` if (state.isNewFileDialogOpen) { - const el = newFileDialog.querySelector('#dialog-new-file .dialog-contents > input') + const el = newFileDialog.querySelector('#dialog-new-file .dialog-content > input') if (el) { el.focus() }