mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-25 20:14:31 +01:00
# Conflicts: # crates/automation/Cargo.toml # crates/automation/src/access.rs # crates/automation/src/synthetic.rs # crates/automation/tests/it/access.rs # crates/automation/tests/it/synthetic.rs # crates/behavior/src/codec.rs # crates/behavior/src/edit_history.rs # crates/behavior/src/lib.rs # crates/behavior/src/wheel.rs # crates/color-ui/src/ui/paint_chip.rs # crates/color-ui/src/ui/pair.rs # crates/color-ui/src/ui/palette.rs # crates/color-ui/src/ui/palette/stories.rs # crates/dialogs/src/service.rs # crates/draw/src/ui/transform/transform_box.rs # crates/draw/src/ui/transform/transform_box/stories.rs # crates/draw/tests/it/transform_box.rs # crates/font-manager/src/glyphs.rs # crates/font-manager/src/picker.rs # crates/font-manager/src/picker/rank.rs # crates/font-manager/src/picker/rows.rs # crates/font-manager/src/picker/stories.rs # crates/font-manager/tests/it/picker.rs # crates/host/src/lib.rs # crates/menu/src/context.rs # crates/menu/src/mac.rs # crates/menu/src/model.rs # crates/pages/src/ui/view.rs # crates/platform/README.md # crates/platform/src/browser_files.rs # crates/print/src/ui/dialog.rs # crates/print/src/ui/mod.rs # crates/print/src/ui/panel.rs # crates/print/src/ui/stories.rs # crates/print/tests/it/dialog.rs # crates/text/src/ui/character.rs # crates/text/src/ui/character/rows.rs # crates/text/src/ui/editor.rs # crates/text/tests/it/editor.rs # crates/text/tests/it/main.rs # crates/ui-canvas/src/canvas/mod.rs # crates/ui-canvas/src/canvas/split/stories.rs # crates/ui-canvas/src/canvas/tool_host.rs # crates/ui-canvas/src/canvas_controls/outline/mod.rs # crates/ui-canvas/src/canvas_controls/task_bar.rs # crates/ui-canvas/src/canvas_controls/task_bar/stories.rs # crates/ui-canvas/tests/it/canvas/navigate.rs # crates/ui-canvas/tests/it/canvas/tool_keys.rs # crates/ui-canvas/tests/it/canvas_controls/task_bar.rs # crates/ui-contract/src/contract/collection/props.rs # crates/ui-contract/src/contract/cx/pointer.rs # crates/ui-contract/src/contract/items/access.rs # crates/ui-contract/src/contract/items/drag.rs # crates/ui-contract/src/contract/items/lead.rs # crates/ui-contract/src/contract/label.rs # crates/ui-contract/src/contract/mod.rs # crates/ui-contract/src/contract/run.rs # crates/ui-contract/src/contract/steps/report.rs # crates/ui-contract/src/contract/steps/update.rs # crates/ui-contract/src/primitives/mod.rs # crates/ui-contract/src/primitives/sensing.rs # crates/ui-contract/src/primitives/text_adapter.rs # crates/ui-contract/src/primitives/text_input.rs # crates/ui-contract/src/runtime/access/emit.rs # crates/ui-contract/src/runtime/access/text.rs # crates/ui-contract/src/runtime/commands/board.rs # crates/ui-contract/src/runtime/commands/mod.rs # crates/ui-contract/src/runtime/drag.rs # crates/ui-contract/src/runtime/egui/access.rs # crates/ui-contract/src/runtime/egui/access/tree.rs # crates/ui-contract/src/runtime/egui/input.rs # crates/ui-contract/src/runtime/env.rs # crates/ui-contract/src/runtime/focus/nav.rs # crates/ui-contract/src/runtime/frame.rs # crates/ui-contract/src/runtime/keys.rs # crates/ui-contract/src/runtime/keys/claims.rs # crates/ui-contract/src/runtime/keys/input.rs # crates/ui-contract/src/runtime/keys/route.rs # crates/ui-contract/src/runtime/pointer.rs # crates/ui-contract/src/runtime/windows.rs # crates/ui-contract/src/testing/fixture.rs # crates/ui-contract/src/testing/host_key_trials.rs # crates/ui-contract/tests/it/collection/rows.rs # crates/ui-contract/tests/it/drag/mod.rs # crates/ui-contract/tests/it/runtime/wheel.rs # crates/ui-macros/src/props.rs # crates/ui-panels/src/dialog/mod.rs # crates/ui-panels/src/dialog/prompts.rs # crates/ui-panels/src/dialog/recovery.rs # crates/ui-panels/src/dialog/trials.rs # crates/ui-panels/src/dialog/words.rs # crates/ui-panels/src/rails/drawer.rs # crates/ui-panels/src/rails/drawer/stories.rs # crates/ui-panels/src/rails/tool/trials.rs # crates/ui-panels/src/sections/footer.rs # crates/ui-panels/tests/it/rails/drawer.rs # crates/ui-patterns/src/patterns/dock/area.rs # crates/ui-patterns/src/patterns/form_dialogs/about.rs # crates/ui-patterns/src/patterns/form_dialogs/dialog.rs # crates/ui-patterns/src/patterns/form_dialogs/dialog/stories.rs # crates/ui-patterns/src/patterns/form_dialogs/host_requests.rs # crates/ui-patterns/src/patterns/form_dialogs/mod.rs # crates/ui-patterns/src/patterns/form_dialogs/param.rs # crates/ui-patterns/src/patterns/form_dialogs/properties.rs # crates/ui-patterns/src/patterns/form_dialogs/properties/stories.rs # crates/ui-patterns/src/patterns/form_dialogs/rows.rs # crates/ui-patterns/src/patterns/form_dialogs/rows/stories.rs # crates/ui-patterns/src/patterns/panels/history.rs # crates/ui-patterns/src/patterns/preferences/document/model.rs # crates/ui-patterns/src/patterns/preferences/model.rs # crates/ui-patterns/src/patterns/preferences/page.rs # crates/ui-patterns/src/patterns/preferences/rows.rs # crates/ui-patterns/src/patterns/preferences/window.rs # crates/ui-patterns/src/patterns/preferences/window/stories.rs # crates/ui-patterns/src/patterns/presets/browser.rs # crates/ui-patterns/tests/it/docking/group_view.rs # crates/ui-patterns/tests/it/form_dialogs/dialog.rs # crates/ui-patterns/tests/it/form_dialogs/params.rs # crates/ui-patterns/tests/it/preferences/model.rs # crates/ui-shell/src/shell/start.rs # crates/ui-shell/src/shell/start/stories.rs # crates/ui-widgets/src/buttons/icon_button.rs # crates/ui-widgets/src/buttons/mod.rs # crates/ui-widgets/src/buttons/stories.rs # crates/ui-widgets/src/choice/swatch.rs # crates/ui-widgets/src/choice/swatch_table.rs # crates/ui-widgets/src/display/text.rs # crates/ui-widgets/src/form/slider_field.rs # crates/ui-widgets/src/layout_components/mod.rs # crates/ui-widgets/src/list/mod.rs # crates/ui-widgets/src/list/row/paint.rs # crates/ui-widgets/src/list/row/show.rs # crates/ui-widgets/src/list/stories.rs # crates/ui-widgets/src/list/view.rs # crates/ui-widgets/src/list/view_stories.rs # crates/ui-widgets/src/menu/mod.rs # crates/ui-widgets/src/menu/stories.rs # crates/ui-widgets/src/pickers/select.rs # crates/ui-widgets/src/tabs/document.rs # crates/ui-widgets/src/text/number.rs # crates/ui-widgets/src/text/zoom_field.rs # crates/ui-widgets/src/tile_grid/grid.rs # crates/ui-widgets/src/tile_grid/grid/stories.rs # crates/ui-widgets/src/tile_grid/mod.rs # crates/ui-widgets/tests/it/label/tooltip.rs # crates/ui-widgets/tests/it/popover/popup.rs # crates/ui-widgets/tests/it/tabs.rs # crates/ui-widgets/tests/it/text/mod.rs # crates/ui-widgets/tests/it/text/number.rs # crates/ui-widgets/tests/it/tile_grid/grid.rs # crates/window/Cargo.toml # docs/components-index.md # docs/porting.md
110 lines
14 KiB
Markdown
110 lines
14 KiB
Markdown
# craft-platform
|
||
|
||
Small platform lifecycle services for Craft applications. Application state, settings, palettes,
|
||
document policy and native command routing remain in their current owners. Only the services a host enables
|
||
pull in heavier dependencies.
|
||
|
||
| Feature | Shared responsibility |
|
||
| --- | --- |
|
||
| default | Typed dialog outcomes; `PlatformText`; `open` (see below); no backend or toolkit. |
|
||
| always (not wasm) | `dialogs`: reserve waiting workers before eager UI-thread native picker creation; serial requests, failure delivery and completion wakeups. The backend factory belongs to the app. |
|
||
| always | `From<appearance::Reading> for craft_theme::SystemAppearance`, so a host hands the OS answer to `Base::resolve`. |
|
||
| `pointer` | Move the system pointer (`pointer::warp`), installed by the app as craft-ui's `Scrub::install_warp` service for a scrub's screen-edge wrap; macOS only, `false` elsewhere. |
|
||
| `appearance` | Linux/BSD XDG desktop preference observation (colour scheme, contrast, reduced motion, GNOME's text scale, button layout); reduced motion on Windows and macOS; browser contrast and motion media queries; owned cancellable subscriptions, bounded reads/helper capture, legacy compatibility and reconnect. |
|
||
| `browser` | Wasm download link/object URL ownership, cleanup on setup failure or abandonment, and cleanup timer registration before clicking; the file picker and save. |
|
||
| always | `clock::Clock`: monotonic seconds (`web-time`, so also in the browser) for animation, autosave and deadlines, with a manual mode tests set and advance; `monotonic_ms`, `unix_ms`. |
|
||
| always | `pacing`: `FrameCap` (desktop frame-rate cap without vsync), `WindowVisibility` (shown or hidden), `WorkBudget`/`WorkSlice` (background work per call, paused or sliced while hidden). No egui. |
|
||
| always | The app log: `log` records to standard error and `<dir>/<app>.log` with `RUST_LOG`-style filters, rotation to `.1`/`.2`, per-instance logs while another instance runs, a size cap; `logs::crash`: the panic hook, crash log (redacted message, written to standard error only when no logger takes errors), last panic for the error window, and `catch`. |
|
||
| always | `session::Session` and `SessionKeeper`: the documents open at the last quit and where the user was in each, stored in the app's settings (serde) for a "Reopen Last Session" preference; `to_reopen` skips what is already open; a stored list longer than 64 documents is cut. No egui. |
|
||
| `usage` | `usage::sample`: the process's resident memory and the memory it may still use (`MemorySample`, `None` when unknown), for the status readout's Scratch and Efficiency items. Linux reads `/proc`; other platforms return `None`. |
|
||
| always | `open::FileIntake` with `IntakeSender` (OS open requests, second-instance hand-over, the web host and `IntakeSender::dropped` and `quit` feed it; `open::apple_events` under `apple-events` on macOS): one queue, in arrival order, for files the OS asks the app to open (`open`, as `Intake::Open`), files it asks to open for one of the app's own actions such as combining (`open_for`, as `Intake::OpenFor` with the action's name; made absolute and sorted like `open`), files that arrive as bytes with no path (`open_bytes`, as `Intake::Bytes`), files dropped on the window (`DroppedFile`, `DropTarget`: canvas, tab strip or window) and the OS asking the app to quit (`Intake::Quit`). Each batch stays separate, empty input is ignored, and every sender call wakes the UI. `natural_cmp` and `same_file` for opening order and duplicates; `reveal` (on the caller's thread; on Linux and BSD it can wait up to 2 s for the file manager, so hosts run it on their `Jobs`), `open_external` (on the web, a new tab without `window.opener`), `open_with` and `is_application`; the shared open-error texts. No egui. |
|
||
| always | `autosave::Autosave` (the timer: which documents are due, results by revision), `recovery_dir`, `adopt_legacy_recovery` and `RecoveryStore`: the recovery folder of copies with a JSON sidecar each (`RecoveryEntry`, the fields craft-ui's `RecoveryDialog` lists), `AUTOSAVE_FAILED`. The app serializes its documents. |
|
||
| `clipboard`, `clipboard-system` | `clipboard` has no system crates: `Clipboard`, `EventClipboard` (with `LateOffers`), `MemoryClipboard` and the probe. `clipboard-system` adds `SystemClipboard`. `clipboard::Clipboard` over a `ClipboardBackend`: every copy and paste goes through it, with size limits (`ClipboardLimits`, `TooLarge`), a fence that keeps synthetic (automation) input from replacing what the user copied, and `holds_ours` to tell the app's own copy from another app's. `SystemClipboard` (arboard) reads text, HTML, RTF, one bitmap and copied files, and writes one offer; `EventClipboard` is the browser's, fed from paste events (`flavors_from_event`). `EventClipboard` keeps an offered paste for the pass it was offered in and counts passes itself (the pass clock the host gives it), so a menu Paste in a later pass finds nothing and the app has nothing to call at the end of a pass. A write reports which flavor the backend wrote; `holds_ours` asks the backend's owner marker first (`ClipboardBackend::owns`) and compares that flavor's content only when the backend cannot tell. The web writes only the best flavor (eframe makes each copy command its own `navigator.clipboard` write, so a second replaces the first). `has` and `formats` never read or decode: they list the formats on offer (`offer::formats`: Windows' and macOS' formats, Wayland's MIME types, X11's `TARGETS`); a bitmap counts only as `image/png`, the one arboard reads on Linux. `ClipboardProbe` asks a second handle on a worker thread whether Paste has anything, so a slow owner never stalls a frame. Bitmaps are read as straight RGBA8, not PNG: the `BITMAP` and `RGBA8` reads return an `image/x-rgba8` flavor (width and height as little-endian `u32`s, then the pixels) and `read_image` returns `ClipboardImage`; the crate has no PNG encoder, and `SystemClipboard::decoder` takes the app's PNG decoder for writes. SVG and PDF flavors are neither written nor read by `SystemClipboard`; RTF is read, and RTF and MathML are written beside arboard's flavors (a write of only unsupported flavors fails with `Other`); a bitmap offered only as `image/jpeg` or `image/bmp` on Wayland reads as `None`. |
|
||
| always | `watch::FileWatch` and `Changed`: open files that changed on disk. One worker thread (`craft-file-watch`) compares each file's metadata (`FileStamp`) every 250 ms and sleeps while nothing is watched; a changed file is reported once it has settled and, with `ReadPolicy::Whole`, looks complete. The app's own saves are recognised by `known_now`; `disk_differs` answers at Save time; `take_changes` runs on the frame the worker's `Wake` asks for. |
|
||
| always (native) | `default_app::make_default`: the Preferences button that makes the app the system default for its file types. Windows opens Settings › Default apps (`SettingsOpened`), Linux and BSD run `xdg-mime default` (`MadeDefault`, refused inside Flatpak or without an installed desktop entry), macOS answers `Unsupported`. `path_from_arg` and `rejoin_split_paths` read the paths a launcher hands the app. Only a button may call it. |
|
||
| always (native) | `temp::TempDir` and `TempFiles`: private temporary folders created exclusively with owner-only permissions (`0700`, files `0600`, `create_new`), named with the process id and a counter, removed on drop. |
|
||
| always (native) | `owner_only`: files only their user can read on Windows, as mode `0600` makes them on Unix. `restrict_to_owner` and `create_private_dir` give a file or new folder an access list of the user and SYSTEM only, `read_with_sddl` reads a file with its security descriptor through one handle, and `foreign_access` says why a descriptor is not the user's alone. They run the tools Windows ships (`whoami`, PowerShell, `icacls`, from System32) because the security API would need `unsafe`. |
|
||
| always | `PlatformText`: a user-visible message of a platform service (id, English text with `{name}` placeholders) that the app looks up in its own catalog. The open, clipboard, watch, default-app and temp services and craft-dialogs' save flow use it. No words table lists them yet, so the missing-translation list does not show them. |
|
||
| `screen` | Screen capture for the screen colour picker (`craft_platform::screen`). |
|
||
| `apple-events` | Apple Events requests on macOS (`open::apple_events`), through `fmv-macos-events`. |
|
||
|
||
|
||
## Native dialogs
|
||
|
||
`dialogs::wait_prepared(create, deliver)` reserves the worker first. Call it on the native UI thread.
|
||
`create` must call `pick_file`, `save_file`, or the equivalent backend method **before returning its
|
||
future**. Putting that call inside an async block delays native sheet creation until the worker
|
||
polls it. Worker reservation failure never opens the sheet. No live picker has a timeout.
|
||
|
||
`NativeDialogs<Request, Answer>` provides an optional serial queue. Pump it on the event-loop
|
||
thread before consuming answers and after code that can request a picker. Replies become visible
|
||
only after the pump releases transport ownership, so a continuation can enqueue the next picker.
|
||
Dropping a stale reply does not release the actual picker. A host-specific preflight is optional;
|
||
it runs off-thread and must be bounded. Unknown capability permits a picker. Proven absence may
|
||
request an application-owned fallback. Custom save-format sheets and portal choices remain intact.
|
||
|
||
`Outcome::Selected`, explicit `Cancelled`, `Failed` and `Indeterminate` have different evidence.
|
||
An rfd `None` is `Indeterminate`; it cannot prove user cancellation rather than backend failure.
|
||
Disconnected workers are failures. Apps own localization, document identity/revision checks, filters,
|
||
actual save receipts, chained continuations and the decision to close.
|
||
|
||
Retain the actual parent window through queued requests, preflight, the native picker AND any
|
||
unconsumed application continuation. A close request that arrives meanwhile never grants permission to
|
||
discard work: the app runs its normal close policy again afterward.
|
||
`appearance::Watcher` caches the desktop preference and wakes only on changes. Subscription precedes
|
||
the first read. ReadOne/legacy Read, the standard namespace and GNOME fallback are handled together;
|
||
on GNOME the "default" (Light) setting and portal value 0 read as light; elsewhere 0 is no preference.
|
||
Malformed values retain the last valid answer, and explicit no-preference clears it.
|
||
`SystemReader::read()` gives colour scheme, contrast and reduced motion in one call on every target: the watcher on Linux/BSD, the browser's contrast and motion queries on the web, and the colour scheme the host reports from its windowing integration (`report_theme`; the watcher's answer wins where it has one). macOS and Windows have a reduced-motion source and no contrast source. `SystemReader::generation()` rises on each change a source reports (the watcher's theme, contrast or motion, a reported theme), the change notice the craft-ui runtime and apps re-resolve themes on.
|
||
|
||
`Watcher::wait_first(timeout)` blocks until the first answer, a known absence, or the timeout (about 250 ms in an eframe creator), so the first frame uses the desktop theme. Disconnection
|
||
retains the last valid value until a fresh answer. A later service owner triggers a reread; session
|
||
reconnection has bounded backoff. Dropping cancels asynchronous work and waits at most 100 ms
|
||
for acknowledgement, joining only an already-finished worker. A synchronously blocked OS call or caller wake callback can outlive
|
||
the watcher: that exceptional worker is detached and retains its resources until it returns,
|
||
possibly until process exit. Wake callbacks must be nonblocking. No per-helper reader threads
|
||
are created.
|
||
|
||
App-selected Light/Dark/System, custom palettes, window decorations and unknown-theme fallback remain
|
||
application policy. `set_active(false)` suppresses wake notifications while continuing to cache.
|
||
Four existing custom-palette service hooks retain their current signatures and receive change-only
|
||
notifications even in manual mode; they do not change the chosen palette.
|
||
|
||
`Watcher::button_layout()` is GNOME's `org.gnome.desktop.wm.preferences` `button-layout`, read and
|
||
followed on the same portal connection (ReadOne, then legacy Read; `gsettings` once when the portal
|
||
has no answer). It is the string as the desktop reports it, `None` until one arrives, and a change
|
||
runs the same wake callback. Malformed values keep the last one. `wait_first` does not wait for it.
|
||
`craft_window::policy::LayoutWatch` turns it into the caption layout; craft-window takes the string,
|
||
so it needs no D-Bus dependency.
|
||
|
||
### Contrast and reduced motion
|
||
|
||
`Watcher::contrast()` (`Contrast::Standard` or `High`) and `Watcher::reduced_motion()` follow the
|
||
portal's `org.freedesktop.appearance` `contrast` and `reduced-motion` keys. Reduced motion
|
||
combines the portal key, KDE's animation setting and GNOME's `org.gnome.desktop.interface`
|
||
`enable-animations`: any source that turns animation off wins. The portal's three keys (colour
|
||
scheme, contrast, reduced motion) are read beside each other, so `wait_first` returns with them,
|
||
and a change runs the same wake callback. `None` means no answer yet or no such key; where the
|
||
portal has none, the desktop's settings files are read (`appearance/files.rs`); the `gsettings`
|
||
fallback doesn't read them.
|
||
On macOS and Windows a worker polls the system's reduced-motion setting once a second
|
||
(`NSWorkspace`, `UISettings`) and runs the wake callback when it changes. On the web, `browser_contrast()` and `browser_reduced_motion()` evaluate the
|
||
`prefers-contrast: more` and `prefers-reduced-motion: reduce` media queries on each call, with
|
||
no change notification.
|
||
|
||
## Browser downloads
|
||
|
||
`PreparedDownload::{bytes,blob}` owns a detached anchor and URL until click or drop. Call `click`
|
||
with the application's positive URL lifetime; setup/attachment/timer failure releases resources
|
||
without clicking. A successful return means a click was issued, not that the browser saved a file.
|
||
Applications own names, MIME types, pacing, capture hooks and user activation. File System Access
|
||
and print iframe lifetimes remain separate. This service has no native filesystem semantics.
|
||
|
||
## Integration
|
||
|
||
Enable only the services a host uses. Applications retain palettes, settings, document identity,
|
||
close policy, filters, names, MIME types and native command routing. Existing craft-settings,
|
||
craft-atomic, craft-print, craft-docpath and craft-quit remain canonical. `craft-window` owns
|
||
decoration selection and window-button layout; appearance observation here
|
||
do not choose a frame or draw an application header.
|