Skip to content

Commit 9029058

Browse files
committed
Preventing two commands to be executed at the same time
There is an edge case when the filename is being edited and a file is being requested from the board. Both things will try to execute commands over serial on the board at the same time. There should be a stack/queue of commands to be executed sequentially but this is not in the specification. Meanwhile the filename saving operation will take priority.
1 parent 6817657 commit 9029058

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

ui/arduino/components/filename.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ function FileName(state, emit) {
88
function onBlur(e) {
99
emit('save-filename', e.target.value)
1010
}
11+
function onFocus(e) {
12+
emit('edit-filename')
13+
}
1114
function onKeyDown(e) {
1215
if(e.key.toLowerCase() === 'enter') {
1316
e.target.blur()
@@ -22,6 +25,7 @@ function FileName(state, emit) {
2225
<input
2326
type="text"
2427
value=${state.selectedFile || 'undefined'}
28+
onfocus=${onFocus}
2529
onblur=${onBlur}
2630
onkeydown=${onKeyDown}
2731
/>

ui/arduino/store.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ function store(state, emitter) {
2828
state.isNewFileDialogOpen = false
2929
state.isTerminalOpen = false
3030
state.isFilesOpen = false
31+
state.isEditingFilename = false
3132

3233
state.messageText = 'Disconnected'
3334
state.isShowingMessage = true
@@ -163,7 +164,16 @@ function store(state, emitter) {
163164
})
164165
emitter.on('select-file', async (device, filename) => {
165166
log('select-file')
167+
166168
state.selectedDevice = device
169+
170+
/*
171+
XXX: If user is changing a file name, do not request the file from the board
172+
over serial to prevent two commands being executed at the same time.
173+
TODO: Create a queue of actions and execute them in order
174+
*/
175+
if (state.selectedDevice === 'serial' && state.isEditingFilename) return
176+
167177
state.selectedFile = filename
168178

169179
let content = ''
@@ -275,6 +285,10 @@ function store(state, emitter) {
275285
})
276286

277287
// NAMING/RENAMING FILE
288+
emitter.on('edit-filename', () => {
289+
state.isEditingFilename = true
290+
emitter.emit('render')
291+
})
278292
emitter.on('save-filename', async (filename) => {
279293
log('save-filename', filename)
280294
let oldFilename = state.selectedFile
@@ -304,8 +318,11 @@ function store(state, emitter) {
304318
}
305319
}
306320

321+
state.isEditingFilename = false
307322
emitter.emit('update-files')
308323
emitter.emit('render')
324+
325+
emitter.emit('message', "Filename is saved.", 1000)
309326
})
310327

311328
emitter.on('message', (text, timeout) => {

0 commit comments

Comments
 (0)