Trash Lifecycle
Relevant source files
The following files were used as context for generating this wiki page:
The Trash Lifecycle in Augenblick governs the movement, retention, and permanent deletion of notes. It serves as a buffer for the app's auto-expiry system, ensuring that notes are not immediately lost after their expiration period or manual removal. The system handles two distinct storage types—Drafts and Saved notes—applying different file system operations to each while maintaining a unified database state.
Entry into Trash
Notes enter the trash through two primary triggers: manual user action (via hotkeys like Cmd+W or the Delete key) and the automated expiry sweep. When a note is moved to trash, its database record is updated with a trashed_at timestamp, and its is_pinned status is forced to false.
Sources: src-tauri/src/notes/trash.rs:11-15, plans/migration.inventory.md:118-124
Trashing Logic by Storage Type
The backend handles file operations differently based on the note's storage classification:
| Storage Type | Database Action | File System Action |
|---|---|---|
| Draft | Update is_trashed=1, update file_path | Move file from drafts/ directory to trash/ directory |
| Saved | Update is_trashed=1 | No action; the external user file remains in its original location |
Sources: src-tauri/src/notes/trash.rs:20-27, plans/migration.inventory.md:125-128
Dirty Note Guard
Before moving a Saved note to trash, the frontend checks if the note has unsaved changes (isDirtySaved). If dirty, a dialog prompts the user to "Save", "Don't Save", or "Cancel" the operation. Discarding changes clears the dirtySavedById flag in the state.
Sources: src/routes/pageActions.ts:88-103, src/stores/notesStore.ts:311-314
Trash State Management
Once a note is trashed, the notesStore updates the local UI state to move the note from the active list to the trashed list. Trashed notes are sorted primarily by their trashed_at timestamp in descending order.
Trash Preview
Trashed notes are displayed in a read-only state. The TrashPreview component (and viewMode="trash" in the store) ensures that the editor is non-editable while a trashed note is selected. Auto-save timers for drafts are explicitly cleared when a note enters the trash.
Sources: src/stores/notesStore.ts:257-259, plans/migration.inventory.md:144-147
Restoration and Deletion
Notes can be moved out of the trash (restored) or permanently removed (deleted forever).
Restoration
Restoring a note reverses the trashing process. For drafts, the file is moved back from the trash/ directory to the drafts/ directory. The trashed_at timestamp is nulled in the database.
Sources: src-tauri/src/notes/trash.rs:48-73, src/stores/notesStore.ts:324-331
Permanent Deletion
Permanent deletion is destructive and requires a confirmation dialog.
- Drafts: The local file is deleted from the filesystem, and the database row is removed.
- Saved Notes: Only the database row is removed; the app does not delete the user's external markdown file.
Automated Retention
The "Auto Sweeper" is a background thread that runs every 60 seconds. It performs auto-deletion by querying the database for any notes where trashed_at is older than the configured trash_retention_days (default 30 days).
| Configuration | Default | Options |
|---|---|---|
| Trash Retention | 30 Days | 7, 14, 30, 60, 90 days |
Sources: plans/migration.inventory.md:167-175, plans/migration.inventory.md:209-211
Summary
The Trash Lifecycle provides a safe recovery window for notes before permanent deletion. By separating the logic for internal drafts and external saved files, it ensures that Augenblick manages its internal resources efficiently while respecting the persistence of user-managed files. The lifecycle is completed either by manual user intervention or the automated background sweep based on the retention settings.