Make Background a native feature

- Background replaces the Background Slideshow plugin and the background image of Appearance. It shows a folder as a slideshow, or one image.
- It is on by default. Its module loads at launch only when a folder or an image is chosen.
- Rust keeps the one folder in background-folder.json. The interface never sends a path. Eight background_* commands replace the six deprecated backgrounds_* commands.
- The first start moves the slideshow folder and settings, and keeps the saved image as the image source.
- One blur worker with a cache, fewer folder reads, and a decode before each fade. The hub writes only the changed properties.
- Remove the deprecated folder methods of api.backgrounds. set, get, and subscribe stay for the Project Management plugin.
- Show the view buttons in the workbench test without text, after UI-056.
- Update the tests, the measurement tool, the docs, and UI-057.
This commit is contained in:
Knotty Wyvern
2026-10-29 17:25:17 -07:00
parent 115c32fa92
commit ab868bbe8e
81 changed files with 3179 additions and 812 deletions
+13 -27
View File
@@ -436,9 +436,6 @@ The host still accepts the native calls of released plugins. A later host can re
| Terminal | `invoke("pty_new_window")` | Open a terminal window | `api.pty.openWindow()` |
| Terminal | `invoke("pty_dictation")` | Start Windows voice typing | `api.pty.dictation()` |
| Terminal | `invoke("workspace_read", { rel: ".runestone/tasks.json" })` | Read the task list of the workspace | `api.workspace.read(path)` |
| Background Slideshow | `api.backgrounds.chooseFolder`, `list`, `read`, `defaultFolder`, `readImageSettings`, `writeImageSettings` | Read images and per-image settings from a folder outside the workspace | `api.files` with a folder grant |
| Background Slideshow | `api.workspace.readOptional(".runestone/pm/workspace.json")` | Read the board names of Project Management | A service of Project Management through `api.services` |
The Project Management, Local Autocomplete, PDF Viewer, and CSV Viewer plugins make no native calls.
Their test scripts replace `window.__TAURI_INTERNALS__` with a test double. That is test code and does not go into the package.
@@ -508,27 +505,17 @@ Make the data of a service a documented contract of the provider. Give its name,
## Background API
`api.backgrounds` (`version: 1`) lets a plugin show image frames behind the RuneStone interface.
`api.backgrounds` (`version: 1`) lets a plugin show image frames behind the RuneStone interface, and read the frames of other owners.
Frames stay in the current window and do not change the saved appearance settings.
To read images from a folder outside the workspace, use [folder grants](#folder-grants).
The folder methods are deprecated. They accept a folder path from the plugin. Use [folder grants](#folder-grants) in new code.
The host keeps them for released versions of Background Slideshow.
| Method | Contract |
| --- | --- |
| `set(target, frame)` | Show a frame for a target. `null` removes the frame of this plugin. |
| `get(target)` | Return the active frame for a target, or `null`. |
| `subscribe(listener)` | Receive the target name when a frame changes. Returns a cleanup function. |
| Method | Optional | Contract |
| --- | --- | --- |
| `chooseFolder()` | | Deprecated. Use `files.chooseFolder()`. Open the folder picker. Returns an absolute path, or `null` on cancel. |
| `defaultFolder()` | yes | Deprecated. Use `files.pictureFolder("Backgrounds")`. Create `RuneStone Backgrounds` in the Pictures folder of the user and return its path. |
| `list(folder)` | | Deprecated. Use `files.list(grant)`. Return `{ name }` for PNG, JPEG, GIF, and WebP files directly in the folder. |
| `read(folder, name)` | | Deprecated. Use `files.readBytes(grant, name)`. Read one image as bytes, at most 50 MiB. |
| `readImageSettings(folder)` | yes | Deprecated. Use `files.readSidecar(grant, ".runestone-backgrounds.json")`. Read the per-image settings file text, or `null`. |
| `writeImageSettings(folder, contents, expected)` | yes | Deprecated. Use `files.writeSidecar`. Save the per-image settings file. See [Per-image settings](#per-image-settings). |
| `set(target, frame)` | | Show a frame for a target. `null` removes the frame of this plugin. |
| `get(target)` | | Return the active frame for a target, or `null`. |
| `subscribe(listener)` | | Receive the target name when a frame changes. Returns a cleanup function. |
Folders must be absolute paths without `..` segments.
The host rejects links, files with other extensions, files that are not raster images, and files over the size limit.
File access needs an enabled plugin in the current window. Pending reads fail after the plugin stops.
The folder methods of earlier hosts (`chooseFolder`, `defaultFolder`, `list`, `read`, `readImageSettings`, and `writeImageSettings`) are gone. The native Background feature replaced the Background Slideshow plugin that used them.
### Targets and frames
@@ -554,13 +541,12 @@ When more than one plugin sets a frame for a target, the most recent frame is sh
Disable removes the frames and subscriptions of the plugin before cleanup.
To share saved configuration across windows, use the plugin settings API.
Example: [Background Slideshow](https://git.knottywyvern.com/kwyvern/RuneStone_BG_Slideshow/src/branch/main/docs/development.md#integration) sets frames from local image folders.
Example: the native Background feature (`src/lib/features/background/index.ts`) sets frames from a local image folder through the host frames.
Example: [Project Management](https://git.knottywyvern.com/kwyvern/RuneStone_PM/src/branch/main/development.md#pm-0229-slideshow-backgrounds) reads frames for board backgrounds.
### Per-image settings
The per-image settings file is `.runestone-backgrounds.json` in the image folder.
It must be JSON with `"schema": 1` and an `images` object, at most 1 MiB.
`writeImageSettings` compares the current file to `expected` (`null` when the file does not exist). It fails when the file changed, so external edits are not lost.
`files.writeSidecar` does the same comparison on the same file, but the host checks only that the text is JSON. The plugin checks the schema.
Example: the [Background Slideshow image settings](https://git.knottywyvern.com/kwyvern/RuneStone_BG_Slideshow/src/branch/main/docs/development.md#per-image-settings) give the storage format and the rendering behavior.
The per-image settings file of the Background feature is `.runestone-backgrounds.json` in the image folder.
It is JSON with `"schema": 1` and an `images` object, at most 1 MiB. Each key is a file name. Each value can have `fit` (`cover`, `contain`, `auto`, or `blurred`), `position`, and `overlay`.
A plugin with a folder grant can read and write the same file with `files.readSidecar` and `files.writeSidecar`. `writeSidecar` compares the current file to `expected` (`null` when the file does not exist). It fails when the file changed, so external edits are not lost. The host checks only that the text is JSON. The plugin checks the schema.
Example: `src/lib/features/background/imageSettings.ts` reads the file and applies it.