Skip to content

Fix/root detection #185

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 24, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion ui/arduino/helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import os
import json
os.chdir('/')
import sys

def get_root(has_flash_mount = True):
if '/flash' in sys.path:
return '/flash'
else:
return '/'

def is_directory(path):
return True if os.stat(path)[0] == 0x4000 else False

Expand All @@ -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)))

Expand All @@ -30,3 +40,5 @@ def delete_folder(path):
if file['type'] == 'folder':
os.rmdir(file['path'])
os.rmdir(path)

os.chdir(get_root())
27 changes: 24 additions & 3 deletions ui/arduino/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ async function store(state, emitter) {
// Connected and ready
state.isConnecting = false
state.isConnected = true
state.boardNavigationRoot = await getBoardRoot()
updateMenu()
if (state.view === 'editor' && state.panelHeight <= PANEL_CLOSED) {
state.panelHeight = state.savedPanelHeight
Expand Down Expand Up @@ -284,7 +285,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')
Expand Down Expand Up @@ -602,7 +606,7 @@ async function store(state, emitter) {
}
await serialBridge.saveFileContent(
serialBridge.getFullPath(
'/',
state.boardNavigationRoot,
state.boardNavigationPath,
fileNameParameter
),
Expand Down Expand Up @@ -781,7 +785,7 @@ async function store(state, emitter) {
if (file.source === 'board') {
await serialBridge.removeFile(
serialBridge.getFullPath(
'/',
state.boardNavigationRoot,
state.boardNavigationPath,
file.fileName
)
Expand Down Expand Up @@ -1691,6 +1695,23 @@ async function getAvailablePorts() {
return await serialBridge.loadPorts()
}

async function getBoardRoot() {
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)
Expand Down
2 changes: 1 addition & 1 deletion ui/arduino/views/components/new-file-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down