Skip to content

Commit

Permalink
Merge pull request #55 from arduino/bugfix/clean-repl-before-actions
Browse files Browse the repository at this point in the history
Bugfix/clean repl before actions
  • Loading branch information
murilopolese authored Jun 28, 2023
2 parents 13969a1 + b70a767 commit c6066fd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ const Serial = {
},
stop: async () => {
await board.stop()
return Promise.resolve()
},
exit_raw_repl: async () => {
await board.exit_raw_repl()
return Promise.resolve()
},
Expand Down Expand Up @@ -70,9 +73,6 @@ const Serial = {
createFolder: async (folder) => {
return await board.fs_mkdir(folder)
},
exit_raw_repl: async () => {
return board.exit_raw_repl()
},
getNavigationPath: (navigation, target) => {
return path.posix.join(navigation, target)
},
Expand Down
7 changes: 7 additions & 0 deletions ui/arduino/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,14 @@ function store(state, emitter) {
if (!state.isTerminalOpen) emitter.emit('show-terminal')
let editor = state.cache(AceEditor, 'editor').editor
let code = editor.getValue()
await serial.stop()
await serial.run(code)
emitter.emit('render')
})
emitter.on('stop', async () => {
log('stop')
await serial.stop()
await serial.exit_raw_repl()
emitter.emit('render')
})
emitter.on('reset', async () => {
Expand Down Expand Up @@ -173,6 +175,7 @@ function store(state, emitter) {
emitter.emit('message', `Saving ${filename} on ${deviceName}.`)

if (state.selectedDevice === 'serial') {
await serial.stop()
await serial.saveFileContent(
serial.getFullPath(
state.serialPath,
Expand Down Expand Up @@ -213,6 +216,7 @@ function store(state, emitter) {

if (confirm(`Do you want to remove ${state.selectedFile} from ${deviceName}?`)) {
if (state.selectedDevice === 'serial') {
await serial.stop()
await serial.removeFile(state.serialNavigation + '/' + state.selectedFile)
emitter.emit('new-file', 'serial')
}
Expand Down Expand Up @@ -253,6 +257,7 @@ function store(state, emitter) {

let content = ''
if (state.selectedDevice === 'serial') {
await serial.stop()
content = await serial.loadFile(
serial.getFullPath(
state.serialPath,
Expand Down Expand Up @@ -417,6 +422,7 @@ function store(state, emitter) {
let contents = cleanCharacters(editor.getValue())
editor.setValue(contents)
if (state.unsavedChanges) {
await serial.stop()
await serial.saveFileContent(
serial.getFullPath(
state.serialPath,
Expand Down Expand Up @@ -527,6 +533,7 @@ function store(state, emitter) {
editor.setValue(contents)

if (state.isConnected && state.selectedDevice === 'serial') {
await serial.stop()
// Ask for confirmation to overwrite existing file
let confirmation = true
if (state.serialFiles.find(f => f.path === filename)) {
Expand Down

0 comments on commit c6066fd

Please sign in to comment.