Skip to content

Commit 3ae37b4

Browse files
authored
Merge pull request #601 from makermelissa-ai-assistant/fix/issue-27-workflow-switching
Fix workflow switching and scope BLE partial writes
2 parents 3793c2f + 4dee2f6 commit 3ae37b4

4 files changed

Lines changed: 122 additions & 81 deletions

File tree

‎js/common/ble-file-transfer.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ class FileTransferClient extends BLEFileTransferClient {
88
constructor(bleDevice, bufferSize, workflow = null) {
99
super(bleDevice, bufferSize);
1010
this._workflow = workflow;
11+
this.fileChangeAttempts = 0;
1112
}
1213

1314
_signalMutatingOp() {
15+
// Even a failed operation may have changed the board's files.
16+
this.fileChangeAttempts++;
1417
if (this._workflow && typeof this._workflow.markMutatingOp === 'function') {
1518
this._workflow.markMutatingOp();
1619
}
@@ -100,4 +103,4 @@ class FileTransferClient extends BLEFileTransferClient {
100103
}
101104
}
102105

103-
export {FileTransferClient};
106+
export {FileTransferClient};

‎js/common/utilities.js‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,17 @@ function getUrlParam(name, remove = true) {
130130
}
131131

132132
// Switch to a new url with the current document state and reload the page if the host and path are the same
133-
function switchUrl(url, documentState, backend = null) {
133+
function switchUrl(url, documentState, backend = null, {preserveUnloadWarning = false} = {}) {
134134
let params ={state: encodeURIComponent(JSON.stringify(documentState))}
135135
if (backend) {
136136
params.backend = backend;
137137
}
138138
let server = makeUrl(url, params);
139139
let oldHost = window.location.host;
140140
let oldPath = window.location.pathname;
141-
window.onbeforeunload = () => {};
141+
if (!preserveUnloadWarning) {
142+
window.onbeforeunload = () => {};
143+
}
142144
window.location.href = server;
143145
let serverUrl = new URL(server);
144146
if (serverUrl.host == oldHost && serverUrl.pathname == oldPath) {
@@ -204,4 +206,4 @@ export {
204206
readUploadedFileAsArrayBuffer,
205207
loadSetting,
206208
saveSetting
207-
};
209+
};

0 commit comments

Comments
 (0)