Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Guidance for Claude Code in this repository. `docs/architecture/` is the detaile

## Project

DevNotes — desktop notes app for developers, in **Rust alone**: an **egui** window over a core, in one process (since 1.0.0; no WebView, no IPC). The core is **`crates/engine`** (SQLite via Diesel, vault, the in-memory index, HTTP, tools); the interface is `crates/ui`, the binary `crates/app` (`devnotes`); beside them `text` (the editing core), `richtext`, `drawing`, `i18n` and `platform` (what is asked of the OS). Notes are snippets (body + language + `{{fields}}`), Notes (Markdown, written formatted), todo lists, Calcul sheets (one result a line) or drawings; they live in spaces and folders, with search, tags, a canvas and a board, trash with undo, revisions, bulk actions, attachments, import/export, a palette, requests, tools and spaces. Libraries are **encrypted**, several, each behind its own passphrase.
DevNotes — desktop notes app for developers, in **Rust alone**: an **egui** window over a core, in one process (since 1.0.0; no WebView, no IPC). The core is **`crates/engine`** (SQLite via Diesel, vault, the in-memory index, HTTP, tools); the interface is `crates/ui`, the binary `crates/app` (`devnotes`); beside them `text` (the editing core), `richtext`, `drawing`, `i18n`, `platform` (what is asked of the OS) and `brand` (the application's names). Notes are snippets (body + language + `{{fields}}`), Notes (Markdown, written formatted), todo lists, Calcul sheets (one result a line) or drawings; they live in spaces and folders, with search, tags, a canvas and a board, trash with undo, revisions, bulk actions, attachments, import/export, a palette, requests, tools and spaces. Libraries are **encrypted**, several, each behind its own passphrase.

The Angular application is no longer in the tree: it stays whole at the tag `angular-reference` (its `src/` and `e2e/`; `git show angular-reference:src/app/…`, D32). A screen that existed there keeps its look and behaviour; its captures are the files of the `angular-reference` pre-release.

Expand Down Expand Up @@ -33,7 +33,7 @@ Principles:
- ⚠️ **Nothing answers until unlocked**: `Db = Mutex<Option<Library>>` is empty until `vault::unlock`; services answer `Locked`. → "Encryption at rest".
- **Sealed vs plain**: titles, bodies, sources, items, names, field values, attachments are sealed; what SQL filters/sorts/joins on (tags, instants, ids, `kind`, `language`, `priority`) is not. Never SQLCipher. → "What is sealed, and what is not".
- **Passphrase wraps the key** and is `zeroize`d before a service returns. ⚠️ Changing it re-wraps every retained backup's `vault.json`. The 12-char floor applies only when _choosing_ a phrase, not unlocking. → "Changing the passphrase", "The floor".
- ⚠️ An open library answers `Library::directory()`; `libraries::open_directory` is only for when none is open. Names in `layout.rs` are the address of an installed library — never rename. → "Several libraries, and the registry beside them".
- ⚠️ An open library answers `Library::directory()`; `libraries::open_directory` is only for when none is open. Names in `layout.rs` are the address of an installed library: they follow D36's values, and renaming is the owner's call alone. → "Several libraries, and the registry beside them", "The application's names".
- **Switching library resets the library scope of the UI** (→ "State between frames"); neither the open nor the last library can be deleted.
- **Two `preferences.json`**: `devnotes.notes.*` is per library, the rest per application (`automaticBackups` stays application-level: the interface reads it and hands the core a plain flag). → "Two scopes of preference, one prefix apart".
- **Profiles**: the binary defaults to `com.devnotes.app`, the packages' identifier (`com.devnotes.app.dev` until 1.0.0, D16); ⚠️ never two processes on one profile — the in-memory index assumes it is the only writer (D16).
Expand All @@ -60,7 +60,7 @@ Principles:
- ⚠️ **Request scripts run in the app relaunched as a script host** (`--devnotes-script-host`, read in `main` before any window): QuickJS, one host per request, a phase at a time; `pm.sendRequest` is sent by the parent. What `require` finds is bundled by `crates/engine/sandbox/build.mjs` into the committed `sandbox/dist/`. → "Request scripts, in a process of their own".
- **JSON explorer/visualiser**: inputs only; Rust owns the model (`explore_json`, nesting capped at 256, node/row caps). → "Exploring a JSON snippet", "The JSON visualiser's model".
- `closed_enum!` declares enums once. **Imports degrade rather than fail**, in one transaction; an added variant does not bump `FORMAT_VERSION`. → "Import, export and copying out".
- App metadata is read from `Cargo.toml` at compile time; the changelog is baked in (`include_str!`).
- ⚠️ **Every name of the application is `brand`'s** (D36): six values of the root `Cargo.toml`'s `[workspace.metadata]`; never type the name, the slug, the identifier, the extension or the site. Other metadata is read from `Cargo.toml` at compile time; the changelog is baked in (`include_str!`). → "The application's names".

### Interface (egui)

Expand Down
10 changes: 9 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
resolver = "3"
members = ["crates/engine", "crates/text", "crates/richtext", "crates/drawing", "crates/i18n", "crates/platform", "crates/ui", "crates/app", "e2e"]
members = ["crates/brand", "crates/engine", "crates/text", "crates/richtext", "crates/drawing", "crates/i18n", "crates/platform", "crates/ui", "crates/app", "e2e"]

[workspace.package]
version = "1.3.0"
Expand All @@ -12,7 +12,18 @@ authors = ["Valentin MILLET"]
repository = "https://github.com/vmillet-dev/devnotes-rs"
license = "GPL-3.0-only"

# The application's names, read by `crates/brand` alone (D36): what a person is shown, the author's
# handle, the technical name, the bundle identifier, the export's extension and the website.
[workspace.metadata]
display-name = "DevNotes"
author-handle = "@vmillet-dev"
slug = "devnotes"
identifier = "com.devnotes.app"
file-extension = "devnotes"
site = "https://devnotes.fr"

[workspace.dependencies]
brand = { path = "crates/brand" }
drawing = { path = "crates/drawing" }
engine = { path = "crates/engine" }
i18n = { path = "crates/i18n" }
Expand Down
16 changes: 16 additions & 0 deletions crates/brand/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "brand"
description = "The application's names, read once from the root manifest"
version.workspace = true
edition.workspace = true
rust-version.workspace = true
authors.workspace = true
repository.workspace = true
license.workspace = true
publish = false

[build-dependencies]
toml.workspace = true

[lints]
workspace = true
48 changes: 48 additions & 0 deletions crates/brand/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//! The only reader of `[workspace.metadata]` in the root `Cargo.toml` (D36): Cargo hands no
//! metadata to a crate, so the values are read here and handed over as environment variables.

use std::path::Path;

const MANIFEST: &str = "../../Cargo.toml";

/// What a value must look like.
type Holds = fn(&str) -> bool;

/// Each value, and what it must look like: a value that cannot name a file, a folder, a URL or a
/// key stops the build rather than an installed copy.
const VALUES: [(&str, Holds); 6] = [
("display-name", |value| !value.trim().is_empty()),
("author-handle", |value| value.starts_with('@')),
("slug", |value| word(value, "-")),
("identifier", |value| value.split('.').count() >= 2 && value.split('.').all(|part| word(part, "-"))),
("file-extension", |value| word(value, "")),
("site", |value| value.starts_with("https://") && !value.ends_with('/')),
];

/// Lowercase ASCII letters and digits, and `also`, not empty and not starting with `also`.
fn word(value: &str, also: &str) -> bool {
let plain = |c: char| c.is_ascii_lowercase() || c.is_ascii_digit();
value.chars().next().is_some_and(plain) && value.chars().all(|c| plain(c) || also.contains(c))
}

fn main() {
println!("cargo::rerun-if-changed={MANIFEST}");
let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").expect("cargo sets CARGO_MANIFEST_DIR");
let text = std::fs::read_to_string(Path::new(&manifest_dir).join(MANIFEST))
.expect("the root manifest is readable");
let manifest: toml::Table = toml::from_str(&text).expect("the root manifest is TOML");
let values = manifest
.get("workspace")
.and_then(|workspace| workspace.get("metadata"))
.expect("the root manifest has [workspace.metadata]");

for (key, holds) in VALUES {
let value = values
.get(key)
.and_then(toml::Value::as_str)
.unwrap_or_else(|| panic!("[workspace.metadata] {key} is a string"));
assert!(holds(value), "[workspace.metadata] {key} = {value:?} cannot be used");
let name = key.to_uppercase().replace('-', "_");
println!("cargo::rustc-env=BRAND_{name}={value}");
}
}
21 changes: 21 additions & 0 deletions crates/brand/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//! The application's names, written once in the root `Cargo.toml`'s `[workspace.metadata]` and
//! read here alone (D36). Every name in the code, on the disk and in the packages is one of these,
//! or made from one.

/// What a person is shown: the window, the menus, the request header.
pub const NAME: &str = env!("BRAND_DISPLAY_NAME");

/// The author's handle, on the about card.
pub const AUTHOR_HANDLE: &str = env!("BRAND_AUTHOR_HANDLE");

/// The technical name: the binary, the library's file, the preference keys, the system's names.
pub const SLUG: &str = env!("BRAND_SLUG");

/// The profile's folder, and the packages' bundle identifier.
pub const IDENTIFIER: &str = env!("BRAND_IDENTIFIER");

/// The extension of an exported library, without its dot.
pub const EXTENSION: &str = env!("BRAND_FILE_EXTENSION");

/// The website, without a trailing slash.
pub const SITE: &str = env!("BRAND_SITE");
5 changes: 1 addition & 4 deletions crates/engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ license.workspace = true
readme = "../../README.md"
autobenches = false

[package.metadata.devnotes]
display-name = "DevNotes"
author-handle = "@vmillet-dev"

[lib]
bench = false

Expand All @@ -27,6 +23,7 @@ bench = false
toml.workspace = true

[dependencies]
brand.workspace = true
serde.workspace = true
serde_json = { workspace = true, features = ["preserve_order", "raw_value"] }
diesel.workspace = true
Expand Down
31 changes: 4 additions & 27 deletions crates/engine/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,16 @@ fn main() {
list_the_documentation();
}

/// Cargo does not pass `[package.metadata]` to the crate, so it is read here and handed
/// over as environment variables the code reads with `env!` — resolved at compile time,
/// and the manifest stays the only place these values are written.
/// What the about card says that Cargo hands no crate: the one author it names, and the toolchain
/// pinned. The application's names are `brand`'s (D36).
fn export_metadata() {
println!("cargo:rerun-if-changed=Cargo.toml");

let manifest_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR is set by cargo");
let text =
fs::read_to_string(Path::new(&manifest_dir).join("Cargo.toml")).expect("Cargo.toml is readable");
let manifest: toml::Table = toml::from_str(&text).expect("Cargo.toml is valid TOML");

let metadata = manifest
.get("package")
.and_then(|package| package.get("metadata"))
.and_then(|metadata| metadata.get("devnotes"))
.expect("Cargo.toml declares [package.metadata.devnotes]");

for key in ["display-name", "author-handle"] {
let value = metadata
.get(key)
.and_then(toml::Value::as_str)
.unwrap_or_else(|| panic!("[package.metadata.devnotes] {key} is a string"));
let name = format!("DEVNOTES_{}", key.to_uppercase().replace('-', "_"));

println!("cargo:rustc-env={name}={value}");
}

// Cargo joins `authors` with `;`; the about card names one person.
let authors = env::var("CARGO_PKG_AUTHORS").unwrap_or_default();
let author = authors.split(';').next().unwrap_or_default();

println!("cargo:rustc-env=DEVNOTES_AUTHOR={author}");
println!("cargo:rustc-env=DEVNOTES_RUST_VERSION={}", pinned_toolchain(&manifest_dir));
println!("cargo:rustc-env=ENGINE_AUTHOR={author}");
println!("cargo:rustc-env=ENGINE_RUST_VERSION={}", pinned_toolchain(&manifest_dir));
}

/// Every page of `docs/content`, by language and name, for `docs.rs` to embed: a page added there
Expand Down
16 changes: 8 additions & 8 deletions crates/engine/src/app_info.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//! What Cargo has no field for comes from `[package.metadata.devnotes]` and
//! `rust-toolchain.toml`, read by `build.rs`: Cargo does not pass `[package.metadata]` to the
//! crate. No version here: the front asks the running binary, which cannot go stale.
//! What the application says about itself: its names are `brand`'s (D36), its author and
//! toolchain are read by `build.rs` from what Cargo hands it and from `rust-toolchain.toml`. No
//! version here: the front asks the running binary, which cannot go stale.

/// A constant rather than a command: the titlebar reads the name synchronously.
pub struct AppMetadata {
/// What the user is shown, which is not the crate name (`devnotes`).
/// What the user is shown, which is not the technical name (`brand::SLUG`).
pub name: &'static str,
/// Opened by the about card, as an `https` link.
pub repository: &'static str,
Expand All @@ -15,9 +15,9 @@ pub struct AppMetadata {
}

pub const METADATA: AppMetadata = AppMetadata {
name: env!("DEVNOTES_DISPLAY_NAME"),
name: brand::NAME,
repository: env!("CARGO_PKG_REPOSITORY"),
author: env!("DEVNOTES_AUTHOR"),
author_handle: env!("DEVNOTES_AUTHOR_HANDLE"),
rust_version: env!("DEVNOTES_RUST_VERSION"),
author: env!("ENGINE_AUTHOR"),
author_handle: brand::AUTHOR_HANDLE,
rust_version: env!("ENGINE_RUST_VERSION"),
};
2 changes: 1 addition & 1 deletion crates/i18n/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ license.workspace = true
publish = false

[dependencies]
brand.workspace = true
chrono = { workspace = true, features = ["clock", "std"] }
serde_json.workspace = true
sys-locale.workspace = true
Expand All @@ -19,7 +20,6 @@ chrono-tz.workspace = true

[build-dependencies]
serde_json.workspace = true
toml.workspace = true

[lints]
workspace = true
13 changes: 0 additions & 13 deletions crates/i18n/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,9 @@ use std::path::Path;
use serde_json::Value;

const SOURCE: &str = "translations/fr.json";
/// Where the application's name is written, once.
const MANIFEST: &str = "../engine/Cargo.toml";

fn main() {
println!("cargo::rerun-if-changed={SOURCE}");
println!("cargo::rerun-if-changed={MANIFEST}");
println!("cargo::rustc-env=DEVNOTES_DISPLAY_NAME={}", display_name());
let text = std::fs::read_to_string(SOURCE).expect("fr.json is readable");
let root: Value = serde_json::from_str(&text).expect("fr.json is JSON");
let Value::Object(entries) = root else {
Expand Down Expand Up @@ -53,15 +49,6 @@ fn module(out: &mut String, entries: &serde_json::Map<String, Value>, prefix: &s
}
}

fn display_name() -> String {
let text = std::fs::read_to_string(MANIFEST).expect("the engine's manifest is readable");
let manifest: toml::Table = toml::from_str(&text).expect("the engine's manifest is TOML");
manifest["package"]["metadata"]["devnotes"]["display-name"]
.as_str()
.expect("[package.metadata.devnotes] display-name is a string")
.to_string()
}

/// `unlockTitle` is `UNLOCK_TITLE`, `fr-FR` is `FR_FR`, `1` is `_1`.
fn constant_name(segment: &str) -> String {
let mut name = String::new();
Expand Down
2 changes: 1 addition & 1 deletion crates/i18n/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl Message {
}

/// The application's name, which no translation spells out: a string carries `{{app}}`.
const APP: &str = env!("DEVNOTES_DISPLAY_NAME");
const APP: &str = brand::NAME;

/// The text of `key` in `language` as it is written, for a sentence that speaks of `{{ }}`
/// itself.
Expand Down
Loading