Skip to content

Commit 83eca24

Browse files
committed
Document the engine and its host
1 parent ab20e5a commit 83eca24

2 files changed

Lines changed: 35 additions & 12 deletions

File tree

‎docs/architecture.md‎

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,8 +1126,8 @@ is corrected or a list completed without building the application again.
11261126
- **A Tauri resource**: `crates/engine/resources/identity/` (`names.txt`, `places/*.txt`) is
11271127
declared in `bundle.resources` and lands in `<resources>/identity/` — beside the executable
11281128
on Windows and in a development or e2e build (`tauri-build` copies it into the target
1129-
directory), under the package's own folder on Linux. The two commands take the
1130-
`AppHandle` for nothing else: `resource_dir()`, joined with `identity`. No Tauri permission
1129+
directory), under the package's own folder on Linux. The two commands read
1130+
`Paths::resources`, which the shell resolves from `resource_dir()`, joined with `identity`. No Tauri permission
11311131
is involved — Rust reads the files, the page never does.
11321132
- **Read once, kept for the session** (`data::library`): every file is read at the first card
11331133
and its text given away for as long as the application runs, every name drawn afterwards
@@ -5215,7 +5215,7 @@ already locked. ⚠️ `libraries::open_directory(app)` reads and parses `librar
52155215
every call, so it is kept for what runs while **no** library is open: `vault_state`,
52165216
`create_vault`, `unlock_vault` and the recovery commands. Reading the thumbnail of a
52175217
screenshot used to pay that lookup plus two `create_dir_all`; `attachments/` is now created
5218-
once, by `vault::gate::install`. A module that reaches for `app_data_dir()` directly writes
5218+
once, by `vault::gate::install`. A module that reaches for `Paths::profile` directly writes
52195219
into the profile, which holds no library. The one directory that lives there on purpose is
52205220
`open/`, the decrypted attachment copies: they are ephemeral and swept wholesale, and one
52215221
directory means one sweep catches every library's leftovers.
@@ -5281,7 +5281,9 @@ first launch's own pick of the seeded space is shown, not remembered: nothing wa
52815281

52825282
⚠️ `automaticBackups` stays with the application deliberately: "copy my libraries at
52835283
launch" is a habit rather than a property of one corpus, and it is the one key Rust reads
5284-
out of that file before the front end has booted (`backup::copies::wanted`).
5284+
out of that file before the front end has booted (`backup::copies::wanted`). Rust reads the
5285+
JSON file itself (`backup::wanted_by_preference`), not through `tauri-plugin-store`: the core
5286+
knows no plugin.
52855287

52865288
⚠️ `LibraryPreferencesService` is re-opened on **every** switch, where the application's is
52875289
opened once. A space id means nothing in another library, and a samples marker carried
@@ -5477,12 +5479,33 @@ ids, parents, positions, the request's kind (`http`, `graphql`, `websocket`) and
54775479
- The launch copy and a restore carry them, being in the database; the library export
54785480
(`transfer::Bundle`) does not — a collection travels in a file of its own.
54795481

5482+
## The engine and its host
5483+
5484+
The core (`crates/engine`) owns its state in one `Engine`, which the shell creates once and
5485+
manages as an `Arc<Engine>`: the `Db` slot (empty until `vault::unlock`), the sends, runs and
5486+
sockets under way, the restore set aside. It asks the shell for two things only (`host.rs`):
5487+
5488+
- **`Paths`**, a plain struct resolved before the engine exists: `profile` (`app_data_dir()`:
5489+
the registry, `libraries/`, the application's `preferences.json`, `open/`) and `resources`
5490+
(`resource_dir()`: the identity lists). A struct, not a trait: every host only fills in two
5491+
paths.
5492+
- **`EventSink`**, the one trait: what the core says unasked, as an `EngineEvent` (a socket's
5493+
traffic, a script's console, a run's steps). The Tauri shell's `TauriHost` emits each under
5494+
the name the front listens to (`WEBSOCKET_EVENT`, `HTTP_CONSOLE_EVENT`, `HTTP_RUN_EVENT`);
5495+
tests keep them in a `RecordingSink`.
5496+
5497+
What reaches the platform stays out of the core's work: the clipboard is read before an
5498+
attachment is stored and written after a QR code is drawn, and a decrypted attachment is opened
5499+
once its copy is written — by the command, not inside the body that holds the lock. ⚠️ During
5500+
the egui migration the commands still live in `crates/engine` and take an `AppHandle` to find
5501+
the engine (`db::engine`); `db::blocking` hands their body `&Engine`.
5502+
54805503
## Persistence (Rust)
54815504

54825505
Storage is **SQLite**, queried through **Diesel** and embedded via `libsqlite3-sys` with the
54835506
`bundled` feature — SQLite is compiled from source and statically linked, so nothing has to be
5484-
installed or shipped alongside the executable. The database file lives in Tauri's
5485-
`app_data_dir()`.
5507+
installed or shipped alongside the executable. The database file lives under the profile
5508+
(`Paths::profile`, Tauri's `app_data_dir()`).
54865509

54875510
- **The store is plain functions.** `notes::store` and `spaces::store` take a
54885511
`&mut SqliteConnection`; the `#[tauri::command]`s sit on top. That is what makes persistence

‎docs/egui-migration-plan.md‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -457,11 +457,11 @@ l'écran.
457457
#### 3.3.4 `Paths` et `EventSink` : ce que le cœur demande à sa coquille
458458

459459
```rust
460-
// engine/src/host.rs
461-
pub trait Paths: Send + Sync {
462-
fn profile(&self) -> &Path; // app_data_dir : registre, libraries/, preferences.json
463-
fn resources(&self) -> &Path; // identity/ (listes de l'outil identité)
464-
fn plaintext(&self) -> PathBuf; // copies en clair des pièces jointes ouvertes
460+
// engine/src/host.rs — Paths est une struct (phase 1) : chaque coquille ne fait que remplir
461+
// deux chemins, un trait n'aurait pas de second usage. Les copies en clair sont profile/open/.
462+
pub struct Paths {
463+
pub profile: PathBuf, // app_data_dir : registre, libraries/, preferences.json
464+
pub resources: PathBuf, // identity/ (listes de l'outil identité)
465465
}
466466

467467
pub trait EventSink: Send + Sync {
@@ -1512,7 +1512,7 @@ Windows de S10) et P11 (S9) ; aucune ne remet en cause une décision prise ici s
15121512

15131513
1. Créer le workspace ; `git mv src-tauri/src` (hors coquille) vers `crates/engine/src`,
15141514
avec `migrations/`, `resources/`, `sandbox/`, `benches/`, `tests/`.
1515-
2. Introduire `Engine` et `host.rs` (§ 3.3.2, § 3.3.4) : `trait Paths` et `trait EventSink` ;
1515+
2. Introduire `Engine` et `host.rs` (§ 3.3.2, § 3.3.4) : `struct Paths` et `trait EventSink` ;
15161516
remplacer les usages d'`AppHandle`, `app.state`, `emit`, `resource_dir`, `app_data_dir` ; sortir
15171517
du cœur le presse-papiers (`attach_clipboard_image`, `copy_qr_code`), la lecture de
15181518
`automaticBackups` par le plugin `store`, et `desktop.rs`.

0 commit comments

Comments
 (0)