font-store: the preview service's plain types and PreviewStore build on wasm, so font-manager does again

The 24 Nov main sync (#3300) brought the font manager's preview-service code (#2782), which names LegalText,
PreviewServiceSource, PREVIEW_SERVICE_ENV and PreviewStore on every target, while font-store only had them in its
native-only store and preview modules. craft-font-manager, and with it the craft crate, no longer built for
wasm32 (photocraft's web build).

They move to an ungated service module; PreviewStore::http_client stays native only, and preview keeps its
PreviewStore re-export. The fake store checks a preview-service address only where the native check exists.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
David MannandClaude Opus 5.5 committed 2026-11-24 21:37:52 +01:00
1 parent 28db32fda1
commit 2b6a53aa47
6 files changed
+67 -55

No files matched your search

+1 -1
View File
@@ -13,7 +13,7 @@ use std::sync::{Condvar, Mutex};
#[cfg(not(target_arch = "wasm32"))]
use craft_font_catalog::Catalog;
pub use craft_font_store::preview::PreviewStore;
pub use craft_font_store::PreviewStore;
#[cfg(not(target_arch = "wasm32"))]
use craft_font_store::{Cancel, Client, Face, FontStore, Network, PINNED_INDEX, verify_font};
pub use craft_font_store::{LegalText, PREVIEW_SERVICE_ENV, PreviewServiceSource, UserSource};
+4
View File
@@ -281,7 +281,11 @@ impl Installer for FakeStore {
}
fn set_preview_service(&self, url: Option<&str>) -> Result<(), StoreError> {
// The address check is the native store's; the browser has no preview service to reach.
#[cfg(not(target_arch = "wasm32"))]
let url = url.map(craft_font_store::check_preview_service).transpose().map_err(err)?;
#[cfg(target_arch = "wasm32")]
let url = url.map(str::to_owned);
*self.preview_service.lock().map_err(err)? = url;
Ok(())
}
+3 -4
View File
@@ -24,6 +24,7 @@
mod index;
mod pin;
mod service;
mod source;
mod sources;
mod verify;
@@ -42,6 +43,7 @@ pub use index::{
MAX_FILE_BYTES, MAX_INDEX_BYTES, MAX_LICENSE_BYTES, Sample, Script, SourceProblem, Unavailable, parse_style,
};
pub use pin::{IndexPin, PINNED_INDEX};
pub use service::{LegalText, PREVIEW_SERVICE_ENV, PreviewServiceSource, PreviewStore};
pub use sources::{SourceEntry, SourcesFile};
pub use verify::{VerifyError, is_font, sha256_hex, verify_font};
@@ -67,10 +69,7 @@ pub use language_packs::{
MAX_PACK_INDEX_BYTES, MAX_PACK_UNPACKED_BYTES, PackEntry, PackIndex, PackIndexPin, language_pack_index_overridden,
};
#[cfg(not(target_arch = "wasm32"))]
pub use store::{
Caller, Error, FontStore, InstalledFamily, InstalledFile, LegalText, Network, PREVIEW_SERVICE_ENV, PreviewServiceSource, Problem, Progress,
check_preview_service,
};
pub use store::{Caller, Error, FontStore, InstalledFamily, InstalledFile, Network, Problem, Progress, check_preview_service};
#[cfg(test)]
mod tests;
+1 -25
View File
@@ -246,31 +246,7 @@ pub struct Preview {
pub font: Result<Vec<u8>, PreviewError>,
}
/// What [`Previews`] reads from the font store: the service and the user's setting on each request, the client and
/// the cache folder when the pool is made. The font manager's `Installer` builds on it.
pub trait PreviewStore: Send + Sync {
/// The preview service's base URL, if one is set: [`PREVIEW_SERVICE_ENV`](crate::PREVIEW_SERVICE_ENV), else the
/// font store's `preview_service` setting, else the host's default. Installs try it as a mirror first.
fn preview_service(&self) -> Option<String> {
None
}
/// The store's HTTP client, if it has one. [`Previews`] fetches with it, so a preview service that installs
/// found unreachable is skipped by previews too, and the reverse.
fn http_client(&self) -> Option<Client> {
None
}
/// Whether previews may be fetched from the preview service: the user's setting, on by default.
fn previews_enabled(&self) -> bool {
true
}
/// The folder [`Previews`] caches preview subsets in; none keeps them only for as long as the caller holds them.
fn preview_cache(&self) -> Option<PathBuf> {
None
}
}
pub use crate::service::PreviewStore;
/// How the pool downloads: the store's [`Client`], or a stand-in in tests.
pub trait Fetch: Send + Sync {
+57
View File
@@ -0,0 +1,57 @@
//! What the font store and the preview service's client share with the font manager on every target: which legal
//! text to read, where the preview service comes from, and what the preview pool reads from a store. The store and
//! the client themselves are native only.
use std::path::PathBuf;
/// Which of a family's legal texts [`FontStore::legal_text`](crate::FontStore::legal_text) reads.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum LegalText {
/// The licence file (`OFL.txt`, `LICENSE.txt`).
License,
/// An Apache family's `NOTICE` file.
Notice,
}
/// The environment variable that sets the preview service's base URL; it beats the saved setting.
pub const PREVIEW_SERVICE_ENV: &str = "CRAFT_FONT_PREVIEW_URL";
/// Where the preview service in effect comes from.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum PreviewServiceSource {
/// [`PREVIEW_SERVICE_ENV`]; the setting can't change it.
Env,
/// The `preview_service` setting in `settings.json`.
Saved,
/// The host's default, [`FontStore::with_default_preview_service`](crate::FontStore::with_default_preview_service).
Default,
/// There is no service.
None,
}
/// What [`Previews`](crate::preview::Previews) reads from the font store: the service and the user's setting on each request, the client and
/// the cache folder when the pool is made. The font manager's `Installer` builds on it.
pub trait PreviewStore: Send + Sync {
/// The preview service's base URL, if one is set: [`PREVIEW_SERVICE_ENV`](crate::PREVIEW_SERVICE_ENV), else the
/// font store's `preview_service` setting, else the host's default. Installs try it as a mirror first.
fn preview_service(&self) -> Option<String> {
None
}
/// The store's HTTP client, if it has one. [`Previews`](crate::preview::Previews) fetches with it, so a preview service that installs
/// found unreachable is skipped by previews too, and the reverse.
#[cfg(not(target_arch = "wasm32"))]
fn http_client(&self) -> Option<crate::Client> {
None
}
/// Whether previews may be fetched from the preview service: the user's setting, on by default.
fn previews_enabled(&self) -> bool {
true
}
/// The folder [`Previews`](crate::preview::Previews) caches preview subsets in; none keeps them only for as long as the caller holds them.
fn preview_cache(&self) -> Option<PathBuf> {
None
}
}
+1 -25
View File
@@ -30,6 +30,7 @@ use crate::index::{
Face, Family, FontFile, GOOGLE_FONTS, Index, IndexError, LicenseFile, MAX_INDEX_BYTES, MAX_LICENSE_BYTES, SourceProblem, Unavailable,
};
use crate::pin::IndexPin;
use crate::service::{LegalText, PREVIEW_SERVICE_ENV, PreviewServiceSource};
use crate::source::{is_source_url, safe_dir, safe_file_name, slug};
use crate::sources::{MAX_SOURCES_BYTES, SourceEntry, SourcesFile};
use crate::verify::{VerifyError, is_font, sha256_hex, verify_font};
@@ -237,15 +238,6 @@ pub struct Problem {
pub error: Option<VerifyError>,
}
/// Which of a family's legal texts [`FontStore::legal_text`] reads.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum LegalText {
/// The licence file (`OFL.txt`, `LICENSE.txt`).
License,
/// An Apache family's `NOTICE` file.
Notice,
}
/// A licence or NOTICE file's size and sha256, when the index has them. A format 1.0 index has
/// neither for the licence: the size cap is then the only check.
fn check_license(file: Option<&LicenseFile>, bytes: &[u8]) -> Result<(), VerifyError> {
@@ -690,22 +682,6 @@ pub(crate) fn read_limited(path: &Path, max: u64) -> Option<Vec<u8>> {
std::fs::read(path).ok()
}
/// The environment variable that sets the preview service's base URL; it beats the saved setting.
pub const PREVIEW_SERVICE_ENV: &str = "CRAFT_FONT_PREVIEW_URL";
/// Where the preview service in effect comes from.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum PreviewServiceSource {
/// [`PREVIEW_SERVICE_ENV`]; the setting can't change it.
Env,
/// The `preview_service` setting in `settings.json`.
Saved,
/// The host's default, [`FontStore::with_default_preview_service`].
Default,
/// There is no service.
None,
}
/// The environment value when set and not empty, else the setting; an unusable value counts as
/// unset.
#[cfg(test)]