Skip to content

Commit ab945b4

Browse files
committed
Bridge listeners, file-manager header redundant code.
Signed-off-by: ubi de feo <me@ubidefeo.com>
1 parent 3b97363 commit ab945b4

2 files changed

Lines changed: 12 additions & 13 deletions

File tree

backend/serial/serial-bridge.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,22 +78,26 @@ const SerialBridge = {
7878
return await ipcRenderer.invoke('serial', 'removeFile', file)
7979
},
8080
saveFileContent: async (filename, content, dataConsumer) => {
81-
if (ipcRenderer.listeners("serial-on-file-save-progress").length > 0) {
82-
ipcRenderer.removeAllListeners("serial-on-file-save-progress")
83-
}
81+
ipcRenderer.removeAllListeners("serial-on-file-save-progress")
8482
ipcRenderer.on('serial-on-file-save-progress', (event, progress) => {
8583
dataConsumer(progress)
8684
})
87-
return await ipcRenderer.invoke('serial', 'saveFileContent', filename, content)
88-
},
89-
saveFileContentAtomic: async (filename, content, dataConsumer) => {
90-
if (ipcRenderer.listeners("serial-on-file-save-progress").length > 0) {
85+
try {
86+
return await ipcRenderer.invoke('serial', 'saveFileContent', filename, content)
87+
} finally {
9188
ipcRenderer.removeAllListeners("serial-on-file-save-progress")
9289
}
90+
},
91+
saveFileContentAtomic: async (filename, content, dataConsumer) => {
92+
ipcRenderer.removeAllListeners("serial-on-file-save-progress")
9393
ipcRenderer.on('serial-on-file-save-progress', (event, progress) => {
9494
dataConsumer(progress)
9595
})
96-
return await ipcRenderer.invoke('serial', 'saveFileContentAtomic', filename, content)
96+
try {
97+
return await ipcRenderer.invoke('serial', 'saveFileContentAtomic', filename, content)
98+
} finally {
99+
ipcRenderer.removeAllListeners("serial-on-file-save-progress")
100+
}
97101
},
98102
uploadFile: async (src, dest, dataConsumer) => {
99103
if (ipcRenderer.listeners("serial-on-upload-progress").length > 0) {

ui/arduino/views/file-manager.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,10 @@ function FileManagerView(state, emit) {
1616
const sourceSelected = source === 'board' ? boardSelected : diskSelected
1717
const selectionActive = sourceSelected.length > 0
1818

19-
const allowTransfer = source === 'board'
20-
? canDownload({ isConnected, selectedFiles })
21-
: canUpload({ isConnected, selectedFiles })
2219
const allowOpen = canEdit({ selectedFiles: sourceSelected })
2320
const allowRename = sourceSelected.length === 1
2421
const allowDelete = sourceSelected.length > 0
2522

26-
const transferIcon = source === 'board' ? 'download.svg' : 'upload.svg'
27-
2823
const defaultButtons = html`
2924
<button disabled=${source === 'board' && !isConnected} onclick=${() => emit('create-folder', source)} data-tooltip="New folder">
3025
<img class="icon" src="media/new-folder.svg" />

0 commit comments

Comments
 (0)