You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: prompt.md
+93Lines changed: 93 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -170,3 +170,96 @@ work.ppt
170
170
Every 30 seconds the system will update the session database (if there is a change), and check for all of the other sessions in the database folder to see if there are updates, and if there are merge them with Yjs.
171
171
172
172
How does that sound?
173
+
174
+
--- day #3 start ---
175
+
176
+
# OneFolder Technical Documentation – Session and Backup System
177
+
178
+
This document summarizes the key technical changes implemented in OneFolder. These updates cover session management (via a unique UUID stored in a `session.json` file), IPC-based retrieval of the session ID, and an enhanced backup scheduler with dual backup mechanisms.
179
+
180
+
## 1. Session Management
181
+
182
+
### Session UUID Generation and Storage
183
+
184
+
-**UUID Generation:**
185
+
- On first run, OneFolder generates a unique session ID using `crypto.randomUUID()` if available; otherwise, it falls back to Node's crypto module.
186
+
-**Persistent Storage:**
187
+
- The generated UUID is stored in a dedicated file (`session.json`) located in the application's `userData` directory.
188
+
-**Purpose:**
189
+
- This ensures each OneFolder installation has a unique identifier, isolating its backups from others.
190
+
191
+
### IPC Retrieval
192
+
193
+
-**IPC Handler:**
194
+
- An IPC handler (`GET_SESSION_ID`) is registered in the main process.
195
+
-**Usage:**
196
+
- The renderer process retrieves the session ID using `RendererMessenger.getSessionId()`, ensuring that all backup operations (folder structure, dumps, etc.) are tied to the correct session.
197
+
198
+
## 2. Backup Folder Structure
199
+
200
+
-**New Structure:**
201
+
- Backups are stored in:
202
+
`<baseBackupDirectory>/database/<sessionId>/`
203
+
-**Benefit:**
204
+
- This isolates backups per session and supports syncing through cloud storage without conflicts.
205
+
206
+
## 3. Backup Scheduler Enhancements
207
+
208
+
### Dual Backup Mechanisms
209
+
210
+
#### Auto Backup (Snapshot) Functionality
211
+
212
+
-**Trigger:**
213
+
- Activated via the `schedule()` method using a debounced function.
214
+
-**Operation:**
215
+
- Creates snapshot files named `auto-backup-<index>.json`.
216
+
- Additionally, it makes daily and weekly copies to `daily.json` and `weekly.json`.
217
+
218
+
#### Auto Dump Functionality
219
+
220
+
-**Operation:**
221
+
- Independently dumps the entire Y.Doc state to a file.
222
+
- The dump file is named `database.yjs.db` (instead of `database.db`).
223
+
- This dump is performed every `SYNC_INTERVAL` milliseconds.
224
+
-**Configurability:**
225
+
- The interval is configurable via the constant `SYNC_INTERVAL` (default set to 10,000 ms).
226
+
227
+
### Directory Updates
228
+
229
+
-**updateBackupDirectory():**
230
+
- Updates the backup directory to a new base path while preserving the structure `<newDir>/database/<sessionId>`.
231
+
- Restarts the auto dump functionality so that future dumps are written to the new location.
232
+
233
+
## 4. Restoration Process
234
+
235
+
-**restoreFromFile():**
236
+
- Clears the persistent y-indexeddb storage.
237
+
- Destroys the current Y.Doc and creates a new one.
238
+
- Applies the backup update from the file.
239
+
- Reinitializes the y-indexeddb provider and reloads the application once syncing is complete.
240
+
241
+
## 5. Configurability and Constants
242
+
243
+
-**SYNC_INTERVAL:**
244
+
- A constant defined at the top of the backup scheduler file that controls the auto dump interval.
245
+
- This allows for easy adjustment of the dump frequency.
246
+
247
+
## Summary
248
+
249
+
-**Unique Session Identification:**
250
+
- Each installation is uniquely identified using a UUID stored in `session.json` and retrieved via IPC.
251
+
-**Session-Specific Backup Storage:**
252
+
- Backups are organized under `<baseBackupDirectory>/database/<sessionId>/`, ensuring isolation and safe syncing.
253
+
-**Dual Backup Mechanisms:**
254
+
- The scheduler provides both periodic JSON snapshot backups (with daily/weekly copies) and continuous Y.Doc dumps (to `database.yjs.db`), with the dump interval configurable by `SYNC_INTERVAL`.
255
+
-**Robust Restoration:**
256
+
- The restoration process clears existing storage, reapplies the backup, and reinitializes the application state seamlessly.
257
+
258
+
These enhancements provide a robust, flexible, and session-specific backup system that underpins OneFolder’s local-first, cloud-synced design.
259
+
260
+
--- day #3 end ---
261
+
262
+
Notes for day 4:
263
+
We are getting very close, now we just need to sync with the other sessions.
264
+
265
+
In the same loop as the dump of the db, we now have to first check the other `uuid`'s databases, and merge them with ours.
0 commit comments