Skip to content

Commit f2fb543

Browse files
committed
feat(demo): enhance directory demo to persist across page reloads
- Append visit history to session-log.txt instead of overwriting - Create unique timestamped test files on each visit - Show previous visit count when revisiting the same folder - List all files (no longer truncated at 5)
1 parent 3178c93 commit f2fb543

File tree

2 files changed

+45
-11
lines changed

2 files changed

+45
-11
lines changed

docs/implementation-progress.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Implementation Progress
22

3+
## 2026-01-27: Enhanced Directory Demo
4+
- Updated "Open Directory" demo to support persistence across page reloads.
5+
- Creates a `session-log.txt` that appends visit history (visit count, timestamp, files found).
6+
- Creates a unique timestamped `test-<timestamp>.txt` file on each visit.
7+
- On subsequent visits, reads existing log and increments visit counter.
8+
39
## 2026-01-27: README Update
410
- Refactored `README.md` to be more open-source friendly.
511
- Added "Features", "Interactive Demo", and "Getting Started" sections.

index.html

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,23 +135,51 @@ <h1>Android File System Demo</h1>
135135

136136
log(`📂 Directory selected: ${dirHandle.name}`);
137137

138-
// List contents
139-
let count = 0;
138+
// List contents and count files
139+
const entries = [];
140140
log("--- Listing Files ---");
141141
for await (const entry of dirHandle.values()) {
142+
entries.push(entry);
142143
log(` - ${entry.kind}: ${entry.name}`);
143-
count++;
144-
if(count > 5) { log("... (more files hidden)"); break; }
144+
}
145+
if (entries.length === 0) {
146+
log(" (empty folder)");
145147
}
146148

147-
// Write a test file into this directory
148-
log("📝 Creating 'test-log.txt' in this folder...");
149-
const newFileHandle = await dirHandle.getFileHandle('test-log.txt', { create: true });
150-
const writable = await newFileHandle.createWritable();
151-
await writable.write("This file was created by the web app inside your folder!");
152-
await writable.close();
149+
// Check if session-log.txt exists and read its content
150+
let existingLog = "";
151+
let visitCount = 1;
152+
try {
153+
const existingHandle = await dirHandle.getFileHandle('session-log.txt', { create: false });
154+
const file = await existingHandle.getFile();
155+
existingLog = await file.text();
156+
// Count previous visits
157+
const matches = existingLog.match(/Visit #\d+/g);
158+
visitCount = matches ? matches.length + 1 : 1;
159+
log(`📖 Found existing session-log.txt (${visitCount - 1} previous visits)`);
160+
} catch {
161+
log("📝 No previous session-log.txt found, creating fresh log...");
162+
}
153163

154-
log("✅ 'test-log.txt' created successfully inside folder.");
164+
// Write/append to session log
165+
const timestamp = new Date().toISOString();
166+
const newEntry = `\n--- Visit #${visitCount} ---\nTimestamp: ${timestamp}\nFiles found: ${entries.length}\n`;
167+
168+
const logHandle = await dirHandle.getFileHandle('session-log.txt', { create: true });
169+
const logWritable = await logHandle.createWritable();
170+
await logWritable.write(existingLog + newEntry);
171+
await logWritable.close();
172+
log(`✅ Updated session-log.txt (Visit #${visitCount})`);
173+
174+
// Create a unique timestamped file on each visit
175+
const uniqueFileName = `test-${Date.now()}.txt`;
176+
const uniqueHandle = await dirHandle.getFileHandle(uniqueFileName, { create: true });
177+
const uniqueWritable = await uniqueHandle.createWritable();
178+
await uniqueWritable.write(`Created during visit #${visitCount} at ${timestamp}`);
179+
await uniqueWritable.close();
180+
log(`✅ Created '${uniqueFileName}'`);
181+
182+
log(`\n🎉 Demo complete! Reload page and select same folder to see persistence.`);
155183

156184
} catch (err) {
157185
if (err.name === 'AbortError') log("User cancelled folder picker.");

0 commit comments

Comments
 (0)