library: the walk position belongs to the origin, so the app beside the browser carries a reading on instead of listing the roll again

This commit is contained in:
2026-09-30 16:26:42 +07:00
parent 851563ed73
commit 325d5c0470
3 changed files with 238 additions and 10 deletions
+16 -7
View File
@@ -361,10 +361,13 @@ export interface ScanProgress {
// the catalogue only holds the frames that were read — so the reading would
// start again at the top of the roll and walk every folder a second time.
//
// Session storage holds exactly that position, and holds it because it is the
// tab's: the tab that reloads carries on from the frame it stopped at, and a new
// tab starts a reading of its own from the top. The key goes when the reading
// finishes.
// Local storage holds exactly that position, and holds it for the whole origin,
// which is the point: the tab that reloads carries on from the frame it stopped
// at, and so does the next context to open the app — the installed one beside the
// browser, where session storage, being the tab's own, handed it nothing and the
// walk started at the top of the roll a second time, every folder listed again
// and every frame it already held read again only to be skipped. The key goes
// when the reading finishes.
const WALK_KEY = (folder: string) => `recipescam.library.walk.${folder}`;
interface WalkSaved {
@@ -383,8 +386,14 @@ interface WalkSaved {
}
function loadWalk(folder: string): WalkSaved | null {
// One reading at a time: a peer that has announced this folder is walking it
// right now, and what it has written down is a step of a walk still in
// progress. Taken up here, two readings would write the same roll down at
// once, each undoing the other's queue. In the tab's own storage this could not
// come up; now that the position is the origin's, it can.
if (peer?.folder === folder) return null;
try {
const raw = sessionStorage.getItem(WALK_KEY(folder));
const raw = localStorage.getItem(WALK_KEY(folder));
if (!raw) return null;
const saved = JSON.parse(raw) as WalkSaved;
return Array.isArray(saved?.walked) &&
@@ -410,7 +419,7 @@ function saveWalk(
progress: ScanProgress
): void {
try {
sessionStorage.setItem(WALK_KEY(folder), JSON.stringify({ walked, pending, frames, restored, progress } satisfies WalkSaved));
localStorage.setItem(WALK_KEY(folder), JSON.stringify({ walked, pending, frames, restored, progress } satisfies WalkSaved));
} catch {
// Nothing to write down: the reading starts from the top, as it did before.
}
@@ -418,7 +427,7 @@ function saveWalk(
function clearWalk(folder: string): void {
try {
sessionStorage.removeItem(WALK_KEY(folder));
localStorage.removeItem(WALK_KEY(folder));
} catch {
// Nothing to clear.
}