Contract stubs: craft-atomic, craft-font-catalog, craft-i18n, craft-host, craft-quit, craft-settings, craft-theme, craft-web-host

This commit is contained in:
Dylan M. Taylor
2026-11-17 22:24:02 -05:00
parent 527c2750e3
commit 830da93f02
19 changed files with 176 additions and 9 deletions
Generated
+2
View File
@@ -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",
+12
View File
@@ -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<File>;
/// 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<File> {
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<File> {
let _ = (path, permissions, keep);
todo!("SH-C33")
}
fn sync(&self, file: &File) -> io::Result<()> {
sync_file(file)
}
+6
View File
@@ -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<PathBuf>) -> Catalog {
let _ = files;
todo!("ED-F4b")
}
/// The process's catalog, for [`FontEnv::from_process`].
pub fn global() -> &'static Arc<Catalog> {
static GLOBAL: OnceLock<Arc<Catalog>> = OnceLock::new();
+11
View File
@@ -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<PathBuf>;
/// 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<PathBuf> {
None
}
+14 -1
View File
@@ -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() }
}
}
+9 -3
View File
@@ -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<ManualJobs>, Arc<AtomicUsize>) {
@@ -15,7 +15,8 @@ fn queue(lanes: usize) -> (JobQueue<&'static str, &'static str>, Arc<ManualJobs>
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");
+9 -1
View File
@@ -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
+3 -1
View File
@@ -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.
+2
View File
@@ -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")]
+8
View File
@@ -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")
}
+1
View File
@@ -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"
+1 -1
View File
@@ -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)]
+33
View File
@@ -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<Option<String>> {
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<PathBuf> {
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<()> {
+2
View File
@@ -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;
+2 -1
View File
@@ -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};
+1 -1
View File
@@ -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};
+1
View File
@@ -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"] }
+57
View File
@@ -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<Picked> {
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<Vec<u8>, 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<PathBuf> {
let _ = purpose;
todo!("SH-C35")
}
}
+2
View File
@@ -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;