summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-04-12 21:30:29 +0300
committerPaul Buetow <paul@buetow.org>2026-04-12 21:30:29 +0300
commitc7f21757c4d7426329c9675b8d7ff85fa044bb8c (patch)
tree54cb46c58ce7e6c479b4ad2904d26c9b0cdab369 /src
parentd58b109edc151389d44a3b610f7ee73949b31238 (diff)
Task 72: isolate companion export sessions
Diffstat (limited to 'src')
-rw-r--r--src/pkjs/index.js32
1 files changed, 20 insertions, 12 deletions
diff --git a/src/pkjs/index.js b/src/pkjs/index.js
index 129d394..4a882ff 100644
--- a/src/pkjs/index.js
+++ b/src/pkjs/index.js
@@ -3,13 +3,6 @@ var Keys = require('message_keys');
var CSV_STORAGE_KEY = 'fastforge.backup.csv';
var CSV_UPDATED_AT_KEY = 'fastforge.backup.csv.updated_at';
-function ensureArraySize(rows, total) {
- if (!rows || rows.length !== total) {
- return new Array(total);
- }
- return rows;
-}
-
function storeCsv(rows) {
var csv = rows.join('\n');
localStorage.setItem(CSV_STORAGE_KEY, csv);
@@ -17,6 +10,13 @@ function storeCsv(rows) {
console.log('FastForge backup stored, bytes=' + csv.length);
}
+function beginExportSession(total) {
+ return {
+ total: total,
+ rows: new Array(total)
+ };
+}
+
function onAppMessage(event) {
var payload = event.payload || {};
var status = payload[Keys.EXPORT_STATUS];
@@ -35,13 +35,21 @@ function onAppMessage(event) {
return;
}
- var rows = ensureArraySize(onAppMessage.rows, total);
- rows[sequence] = row;
- onAppMessage.rows = rows;
+ if (status === 'EXPORT_STARTED' || !onAppMessage.session || onAppMessage.session.total !== total || sequence === 0) {
+ onAppMessage.session = beginExportSession(total);
+ }
+
+ var session = onAppMessage.session;
+ if (!session || session.total !== total) {
+ console.log('FastForge export session mismatch: ' + JSON.stringify(payload));
+ return;
+ }
+
+ session.rows[sequence] = row;
if (sequence + 1 === total) {
- storeCsv(rows);
- onAppMessage.rows = null;
+ storeCsv(session.rows);
+ onAppMessage.session = null;
}
}