From 830da93f02f441f6765e24ed4317c0a877f884be Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Tue, 17 Nov 2026 22:24:02 -0500 Subject: [PATCH] Contract stubs: craft-atomic, craft-font-catalog, craft-i18n, craft-host, craft-quit, craft-settings, craft-theme, craft-web-host --- Cargo.lock | 2 + crates/atomic/src/lib.rs | 12 ++++++ crates/font-catalog/src/catalog.rs | 6 +++ crates/host/src/files.rs | 11 ++++++ crates/host/src/queue.rs | 15 ++++++- crates/host/src/queue_tests.rs | 12 ++++-- crates/i18n/src/fold.rs | 10 ++++- crates/i18n/src/matcher.rs | 4 +- crates/quit/src/lib.rs | 2 + crates/quit/src/web.rs | 8 ++++ crates/settings/Cargo.toml | 1 + crates/settings/src/error.rs | 2 +- crates/settings/src/files.rs | 33 ++++++++++++++++ crates/settings/src/lib.rs | 2 + crates/settings/src/store.rs | 3 +- crates/settings/src/store/sections.rs | 2 +- crates/web-host/Cargo.toml | 1 + crates/web-host/src/files.rs | 57 +++++++++++++++++++++++++++ crates/web-host/src/lib.rs | 2 + 19 files changed, 176 insertions(+), 9 deletions(-) create mode 100644 crates/quit/src/web.rs create mode 100644 crates/web-host/src/files.rs diff --git a/Cargo.lock b/Cargo.lock index dcdeaed12..c644d01bc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3626,6 +3626,7 @@ dependencies = [ "tempfile", "toml", "toml_edit", + "web-time", ] [[package]] @@ -4221,6 +4222,7 @@ dependencies = [ name = "craft-web-host" version = "0.1.0" dependencies = [ + "craft-host", "wasm-bindgen", "wasm-bindgen-test", "web-sys", diff --git a/crates/atomic/src/lib.rs b/crates/atomic/src/lib.rs index a87a8734d..2ce72b932 100644 --- a/crates/atomic/src/lib.rs +++ b/crates/atomic/src/lib.rs @@ -59,6 +59,13 @@ pub trait AtomicFs { /// request mode `0600` for `Private` or `0666` for `PlatformDefault`; the OS applies its /// umask/default ACL. Other platforms keep their native creation behavior. fn create_new(&self, path: &Path, permissions: NewFilePermissions) -> io::Result; + /// Create the stage like [`AtomicFs::create_new`], carrying over the attributes of the file it + /// replaces. `keep` is the destination's `symlink_metadata`, so a replaced link keeps its own + /// attributes, not its target's. The default ignores `keep` and calls `create_new`. + fn create_new_keeping(&self, path: &Path, permissions: NewFilePermissions, keep: Option<&std::fs::Metadata>) -> io::Result { + let _ = keep; + self.create_new(path, permissions) + } /// Flush a written file to durable storage. fn sync(&self, file: &File) -> io::Result<()>; /// Rename `from` over `to`, replacing it atomically. @@ -99,6 +106,11 @@ impl AtomicFs for RealFs { options.open(path) } + fn create_new_keeping(&self, path: &Path, permissions: NewFilePermissions, keep: Option<&std::fs::Metadata>) -> io::Result { + let _ = (path, permissions, keep); + todo!("SH-C33") + } + fn sync(&self, file: &File) -> io::Result<()> { sync_file(file) } diff --git a/crates/font-catalog/src/catalog.rs b/crates/font-catalog/src/catalog.rs index 10663e6af..09636c391 100644 --- a/crates/font-catalog/src/catalog.rs +++ b/crates/font-catalog/src/catalog.rs @@ -345,6 +345,12 @@ impl Catalog { } } + /// A catalog of exactly `files`, built on the existing scan with no font folders and no store. + pub fn of_files(files: Vec) -> Catalog { + let _ = files; + todo!("ED-F4b") + } + /// The process's catalog, for [`FontEnv::from_process`]. pub fn global() -> &'static Arc { static GLOBAL: OnceLock> = OnceLock::new(); diff --git a/crates/host/src/files.rs b/crates/host/src/files.rs index 4dce84d99..e74cd5bca 100644 --- a/crates/host/src/files.rs +++ b/crates/host/src/files.rs @@ -249,6 +249,12 @@ pub trait Files: Send + Sync { fn write(&self, path: &Path, bytes: &[u8]) -> Result<(), FileError>; /// The folder the last answered pick of `purpose` chose. fn last_folder(&self, purpose: &str) -> Option; + /// Answers the next pick, or the oldest pick still open, with `picked` instead of showing a + /// picker; the answer arrives through [`take_answer`](Files::take_answer) on a later pass. + fn answer_next(&self, picked: Picked) -> Result<(), FileError> { + let _ = picked; + Err(FileError::Unsupported) + } } /// No pickers (every pick answers `Cancelled`); reads and writes go to the file system. The @@ -462,6 +468,11 @@ impl Files for ScriptedFiles { Ok(()) } + fn answer_next(&self, picked: Picked) -> Result<(), FileError> { + let _ = picked; + todo!("WF-W16") + } + fn last_folder(&self, _purpose: &str) -> Option { None } diff --git a/crates/host/src/queue.rs b/crates/host/src/queue.rs index 06cd8d744..a820aeeab 100644 --- a/crates/host/src/queue.rs +++ b/crates/host/src/queue.rs @@ -73,6 +73,19 @@ pub struct QueueOptions { pub lanes: usize, /// The name each lane's job is spawned with (a thread name with `ThreadJobs`). pub name: &'static str, + /// Which of two jobs of equal priority runs first. + pub order: QueueOrder, +} + +/// Which job runs first among jobs of equal priority: the one that arrived last or first. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +#[non_exhaustive] +pub enum QueueOrder { + /// The newest job runs first. + #[default] + NewestFirst, + /// The oldest job runs first. + OldestFirst, } impl QueueOptions { @@ -92,7 +105,7 @@ impl Default for QueueOptions { /// [`default_lanes`](QueueOptions::default_lanes) lanes named `"craft-queue"`. fn default() -> Self { // new: the default every library queue starts from. - Self { lanes: Self::default_lanes(), name: "craft-queue" } + Self { lanes: Self::default_lanes(), name: "craft-queue", order: QueueOrder::default() } } } diff --git a/crates/host/src/queue_tests.rs b/crates/host/src/queue_tests.rs index b819cc3ea..9e77dd6d6 100644 --- a/crates/host/src/queue_tests.rs +++ b/crates/host/src/queue_tests.rs @@ -5,7 +5,7 @@ use std::sync::Arc; use std::sync::atomic::{AtomicUsize, Ordering}; -use crate::queue::{Cancel, Finished, JobQueue, Priority, QueueOptions}; +use crate::queue::{Cancel, Finished, JobQueue, Priority, QueueOptions, QueueOrder}; use crate::{ManualJobs, Wake}; fn queue(lanes: usize) -> (JobQueue<&'static str, &'static str>, Arc, Arc) { @@ -15,7 +15,8 @@ fn queue(lanes: usize) -> (JobQueue<&'static str, &'static str>, Arc let wake = Wake::new(move || { counter.fetch_add(1, Ordering::Relaxed); }); - let queue = JobQueue::new(jobs.clone(), wake, QueueOptions { lanes, name: "test" }); + // P3(pdf-shell-w4): SH-C32 + let queue = JobQueue::new(jobs.clone(), wake, QueueOptions { lanes, name: "test", order: QueueOrder::default() }); (queue, jobs, wakes) } @@ -88,7 +89,12 @@ fn queue_gives_back_a_lane_the_host_dropped() { } } let jobs = Arc::new(Refusing(AtomicUsize::new(0), ManualJobs::new())); - let queue = JobQueue::<&'static str, &'static str>::new(jobs.clone(), Wake::new(|| {}), QueueOptions { lanes: 1, name: "test" }); + // P3(pdf-shell-w4): SH-C32 + let queue = JobQueue::<&'static str, &'static str>::new( + jobs.clone(), + Wake::new(|| {}), + QueueOptions { lanes: 1, name: "test", order: QueueOrder::default() }, + ); queue.submit("a", Priority::VISIBLE, |_| "a"); jobs.0.store(1, Ordering::Relaxed); queue.submit("b", Priority::VISIBLE, |_| "b"); diff --git a/crates/i18n/src/fold.rs b/crates/i18n/src/fold.rs index c1cbc6297..213a90969 100644 --- a/crates/i18n/src/fold.rs +++ b/crates/i18n/src/fold.rs @@ -24,11 +24,15 @@ use icu_normalizer::DecomposingNormalizerBorrowed; use icu_properties::props::{GraphemeExtend, HangulSyllableType}; use icu_properties::{CodePointMapData, CodePointSetData}; +use crate::scripts::{Direction, direction}; + /// Folds text for one locale. Cheap to build and copy. #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct Folder { turkic: bool, accents: bool, + #[allow(dead_code)] // P3(pdf-chrome-w1): CH-C3 + rtl: bool, } impl Folder { @@ -36,7 +40,11 @@ impl Folder { /// or `zh-hant` (any case, `-` or `_`). pub fn new(locale: &str) -> Folder { let language = locale.split(['-', '_', '.', '@']).next().unwrap_or_default(); - Folder { turkic: language.eq_ignore_ascii_case("tr") || language.eq_ignore_ascii_case("az"), accents: false } + Folder { + turkic: language.eq_ignore_ascii_case("tr") || language.eq_ignore_ascii_case("az"), + accents: false, + rtl: direction(locale) == Direction::Rtl, + } } /// Accents count: `é` no longer matches `e`, and a match can't end on a letter whose accent it diff --git a/crates/i18n/src/matcher.rs b/crates/i18n/src/matcher.rs index 344763c46..7b15dccfd 100644 --- a/crates/i18n/src/matcher.rs +++ b/crates/i18n/src/matcher.rs @@ -5,7 +5,7 @@ use crate::fold::{Folded, Folder}; use std::ops::Range; /// How well a text matches, best first: the derived order puts `Whole` before `Prefix` before `WordStart` before -/// `Contains`. +/// `Contains` before `AllWords`. #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] #[non_exhaustive] pub enum Rank { @@ -17,6 +17,8 @@ pub enum Rank { WordStart, /// The query occurs inside a word. Contains, + /// Every word of a multi-word query occurs in the text, in any order (right-to-left locales only). + AllWords, } /// A text that matches the query. diff --git a/crates/quit/src/lib.rs b/crates/quit/src/lib.rs index ef0bc9188..3bf8bb3a2 100644 --- a/crates/quit/src/lib.rs +++ b/crates/quit/src/lib.rs @@ -18,6 +18,8 @@ mod close; #[cfg(target_os = "macos")] mod macos; +#[cfg(target_arch = "wasm32")] +pub mod web; pub use close::{CloseAnswer, CloseGuard, CloseScope, GuardStep, QUIT_MENU_ID}; #[cfg(feature = "ui")] diff --git a/crates/quit/src/web.rs b/crates/quit/src/web.rs new file mode 100644 index 000000000..9918c484b --- /dev/null +++ b/crates/quit/src/web.rs @@ -0,0 +1,8 @@ +//! Holding a browser tab open while work is unsaved. + +/// Keeps one `beforeunload` listener that calls `prevent_default` while the last call said +/// `unsaved`. Call it each frame with whether work is at risk. +pub fn hold_leave(unsaved: bool) { + let _ = unsaved; + todo!("SH-C30") +} diff --git a/crates/settings/Cargo.toml b/crates/settings/Cargo.toml index 5bbc50da5..685a6e477 100644 --- a/crates/settings/Cargo.toml +++ b/crates/settings/Cargo.toml @@ -22,6 +22,7 @@ serde = { version = "1", features = ["derive"] } serde_json = { workspace = true } toml = { version = "1.1", default-features = false, features = ["std", "parse", "serde"] } toml_edit = { version = "0.25", features = ["serde"] } +web-time = "1.1" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] dirs = "7" diff --git a/crates/settings/src/error.rs b/crates/settings/src/error.rs index 86e0ff2a6..996d580f6 100644 --- a/crates/settings/src/error.rs +++ b/crates/settings/src/error.rs @@ -3,7 +3,7 @@ use std::fmt; use std::io; use std::path::PathBuf; -use std::time::Instant; +use web_time::Instant; /// Why a schema migration step failed. #[derive(Debug, Clone, PartialEq, Eq)] diff --git a/crates/settings/src/files.rs b/crates/settings/src/files.rs index dde6e2058..21c033f20 100644 --- a/crates/settings/src/files.rs +++ b/crates/settings/src/files.rs @@ -71,6 +71,39 @@ impl SettingsFiles for DiskFiles { } } +/// Settings kept in the browser's localStorage, keyed by path: the files of a web build. +#[cfg(target_arch = "wasm32")] +#[derive(Clone, Copy, Debug, Default)] +pub struct BrowserFiles; + +#[cfg(target_arch = "wasm32")] +impl SettingsFiles for BrowserFiles { + fn read(&self, path: &Path) -> io::Result> { + let _ = path; + todo!("SH-C29") + } + + fn write(&self, path: &Path, text: &str) -> io::Result<()> { + let _ = (path, text); + todo!("SH-C29") + } + + fn move_aside(&self, path: &Path) -> io::Result { + let _ = path; + todo!("SH-C29") + } + + fn write_backup(&self, path: &Path, text: &str) -> io::Result<()> { + let _ = (path, text); + todo!("SH-C29") + } + + fn check_writable(&self, dir: &Path) -> io::Result<()> { + let _ = dir; + todo!("SH-C29") + } +} + /// New files are owner-only; on a replace `craft-atomic` keeps the existing file's mode. #[cfg(all(unix, not(target_arch = "wasm32")))] fn restrict_permissions(file: &std::fs::File) -> io::Result<()> { diff --git a/crates/settings/src/lib.rs b/crates/settings/src/lib.rs index e3f3ac261..39d9df262 100644 --- a/crates/settings/src/lib.rs +++ b/crates/settings/src/lib.rs @@ -56,6 +56,8 @@ pub mod store; pub mod testing; pub use error::{LoadReport, MigrateError, ReadOnlyReason, SaveStatus, SectionError, SettingsError, Source, TickResult}; +#[cfg(target_arch = "wasm32")] +pub use files::BrowserFiles; #[cfg(not(target_arch = "wasm32"))] pub use files::DiskFiles; pub use files::SettingsFiles; diff --git a/crates/settings/src/store.rs b/crates/settings/src/store.rs index 23efca9a2..1d633d730 100644 --- a/crates/settings/src/store.rs +++ b/crates/settings/src/store.rs @@ -2,9 +2,10 @@ use std::path::{Path, PathBuf}; use std::sync::Arc; -use std::time::{Duration, Instant}; +use std::time::Duration; use toml_edit::DocumentMut; +use web_time::Instant; use crate::Settings; use crate::document::{self, merge_changes, merge_into, set_schema_version}; diff --git a/crates/settings/src/store/sections.rs b/crates/settings/src/store/sections.rs index 491bf89a7..412ca53ad 100644 --- a/crates/settings/src/store/sections.rs +++ b/crates/settings/src/store/sections.rs @@ -1,7 +1,7 @@ //! Library sections: tables beside `T`'s keys in the same document. use std::sync::{Arc, Mutex, MutexGuard}; -use std::time::Instant; +use web_time::Instant; use toml_edit::{DocumentMut, Item}; diff --git a/crates/web-host/Cargo.toml b/crates/web-host/Cargo.toml index f3eabdbee..c4b271f55 100644 --- a/crates/web-host/Cargo.toml +++ b/crates/web-host/Cargo.toml @@ -9,6 +9,7 @@ repository.workspace = true # Already in every web build's Cargo.lock through eframe. [target.'cfg(target_arch = "wasm32")'.dependencies] +craft-host = { workspace = true } wasm-bindgen = "0.2" web-sys = { version = "0.3", features = ["Blob", "CustomEvent", "CustomEventInit", "Element", "Event", "EventTarget", "Location", "MessageEvent", "Window"] } diff --git a/crates/web-host/src/files.rs b/crates/web-host/src/files.rs new file mode 100644 index 000000000..87161d21a --- /dev/null +++ b/crates/web-host/src/files.rs @@ -0,0 +1,57 @@ +//! The file service of a web build: pickers through a file input, saves through the host page. + +use std::path::{Path, PathBuf}; + +use craft_host::{FileError, Files, PickId, PickRequest, Picked, Wake}; + +/// The [`Files`] service of a web build. Open and OpenMany go through a file input to +/// [`Picked::Contents`] and a finished read wakes the app; Save answers the name at once and +/// `write` posts to the host page or downloads; Folder is unavailable. +pub struct BrowserFiles { + #[allow(dead_code)] // P3(pdf-shell-w5): SH-C35 + wake: Wake, +} + +impl BrowserFiles { + /// A service that wakes the app through `wake` when a picked file has been read. + pub fn new(wake: Wake) -> Self { + let _ = wake; + todo!("SH-C35") + } +} + +impl Files for BrowserFiles { + fn pick(&self, request: PickRequest) -> PickId { + let _ = request; + todo!("SH-C35") + } + + fn take_answer(&self, id: PickId) -> Option { + let _ = id; + todo!("SH-C35") + } + + fn forget(&self, id: PickId) { + let _ = id; + todo!("SH-C35") + } + + fn pick_pending(&self) -> bool { + todo!("SH-C35") + } + + fn read(&self, path: &Path) -> Result, FileError> { + let _ = path; + todo!("SH-C35") + } + + fn write(&self, path: &Path, bytes: &[u8]) -> Result<(), FileError> { + let _ = (path, bytes); + todo!("SH-C35") + } + + fn last_folder(&self, purpose: &str) -> Option { + let _ = purpose; + todo!("SH-C35") + } +} diff --git a/crates/web-host/src/lib.rs b/crates/web-host/src/lib.rs index 90e2aa070..3bd078c19 100644 --- a/crates/web-host/src/lib.rs +++ b/crates/web-host/src/lib.rs @@ -32,6 +32,8 @@ use std::cell::{Cell, RefCell}; use std::collections::VecDeque; +#[cfg(target_arch = "wasm32")] +pub mod files; #[cfg(target_arch = "wasm32")] pub mod web;