Keep preferences in one settings file and move tab transfer to the host
Keep the user preferences in settings.json in the app config folder. WebView storage can be lost, and the host cannot read it. The file has a schema number, a revision number, and one value for each section: general, appearance, customThemes, customThemesLegacy, and language. - settings_read gives all sections, the revision, and a one-time notice. - settings_write replaces one section, writes the file atomically, and sends settings-changed to all windows. The limit is 8 MiB. - settings_migrate writes the first file only when no file exists. - The host moves a damaged file to settings.corrupt-<seconds>.json, starts from the defaults, and reports this one time. Each window loads the sections before its first render. One store in src/lib/settings/store.ts replaces the storage listeners. When no file exists, the window normalizes the old localStorage values and migrates them. The old keys stay in place for one release. The window layout and the open tabs stay in localStorage on purpose. The browser preview keeps all preferences in localStorage. Keep tab transfer offers in host memory, not in localStorage, because an offer can hold unsaved text. A window takes an offer once. The host checks the workspace root and a 120 second expiry. When the receiver accepts the tab, the host sends tab-transfer-accepted to the source window only. A refused offer stays open, and the source tab stays open. A new window and a drop on the tab ribbon use one check. The smoke harness serves the new commands from one shared state for each browser context. Tests read saved values from the mock settings file. Rust, unit, and smoke tests cover the changes.
This commit is contained in:
+40
-1
@@ -68,6 +68,8 @@ Windows is the primary platform. macOS and Linux builds are experimental.
|
||||
| `backgrounds.rs` | Background image folders for themes and plugins |
|
||||
| `spelling.rs` | Spelling suggestions from the operating system (Windows) |
|
||||
| `settings.rs`, `theme.rs` | The Settings window and theme export |
|
||||
| `preferences.rs` | The settings file of the user. It reads, writes, and migrates the file, and replaces a damaged file. |
|
||||
| `tab_transfer.rs` | Tab transfer between windows. The offers stay in memory. |
|
||||
| `completion.rs` | A local proxy to a completion model server |
|
||||
|
||||
The interface calls Rust commands through Tauri `invoke`. Most calls go through the wrappers in `src/lib/workspace/api.ts`.
|
||||
@@ -79,7 +81,8 @@ A new command needs an entry in `generate_handler!` in `lib.rs`, in the command
|
||||
| --- | --- |
|
||||
| `layout/` | The app shell (`Workbench.svelte`), the file tree, tabs, panes, Settings, and dialogs |
|
||||
| `editor/` | The Writer view (`LiveWriter.svelte`), the source editor (`EditorHost.svelte`), tables, links, images, and editor menus |
|
||||
| `workspace/` | Tauri wrappers, document buffers, the note index and backlinks, paths, and templates |
|
||||
| `workspace/` | Tauri wrappers, document buffers, the note index and backlinks, paths, templates, and tab transfer (`tabTransfer.ts`) |
|
||||
| `settings/` | The settings store (`store.ts`), and the code that moves the old browser values to the settings file (`migration.ts`) |
|
||||
| `plugins/` | The plugin runtime, the SDK types (`sdk.ts`), and Settings → Plug-ins |
|
||||
| `browser/` | The interface of the built-in browser |
|
||||
| `completion/`, `git/` | Contracts and services that plugins use |
|
||||
@@ -107,6 +110,38 @@ A new command needs an entry in `generate_handler!` in `lib.rs`, in the command
|
||||
| Documents | Ordinary files in the workspace folder |
|
||||
| Workspace state: tab order, pins, bookmarks, templates, Project Management boards | `.runestone/` in the workspace |
|
||||
| Installed plugins and their settings | The app data folder. See [plugin storage](plugin-host.md#storage-and-recovery). |
|
||||
| Preferences: general settings, appearance, custom themes, display language | `settings.json` in the app config folder |
|
||||
| Window layout and the open tabs of each workspace | The WebView storage (`localStorage`) of the app. RuneStone can lose these values without harm. |
|
||||
|
||||
#### The settings file
|
||||
|
||||
`src-tauri/src/preferences.rs` keeps the preferences in `settings.json` in the Tauri `app_config_dir()`.
|
||||
On Windows, this is `%APPDATA%\com.runestone.app\`, the same folder as the app data.
|
||||
On macOS, it is `~/Library/Application Support/<identifier>/`. On Linux, it is `~/.config/<identifier>/`.
|
||||
|
||||
```json
|
||||
{
|
||||
"schema": 1,
|
||||
"revision": 12,
|
||||
"general": { "autosaveEnabled": true, "autosaveSeconds": 5, "showInternalFolder": false },
|
||||
"appearance": { "theme": "default", "mode": "dark" },
|
||||
"customThemes": [],
|
||||
"customThemesLegacy": [],
|
||||
"language": "en"
|
||||
}
|
||||
```
|
||||
|
||||
| Rule | Detail |
|
||||
| --- | --- |
|
||||
| Sections | `general`, `appearance`, `customThemes`, `customThemesLegacy` (the original version 1 themes), and `language`. The host does not interpret their values. The frontend normalizes each section. |
|
||||
| Size | At most 8 MiB in total. The appearance can hold an image data URL of up to 3,000,000 characters. |
|
||||
| Writes | `settings_write` replaces one section. The host writes a complete temporary file and renames it. Then it sends `settings-changed` to all windows with the section, the revision, and the value. |
|
||||
| Damaged file | The host moves the file to `settings.corrupt-<seconds>.json` and writes a new file with the defaults. The first window that reads the settings shows a message one time. |
|
||||
| First start | When no file exists, the window reads the old `localStorage` keys and normalizes their values. The keys are `runestone.settings`, `runestone.appearance`, `runestone.custom-themes`, `runestone.custom-themes.legacy`, and `runestone.language`. `settings_migrate` writes the values only when no file exists. RuneStone keeps the old keys for one release, but does not use them. |
|
||||
| Browser preview | Without the desktop host (`pnpm dev`), the preferences stay in `localStorage` under the old keys. |
|
||||
|
||||
Each window loads all sections one time before its first render (`src/routes/+layout.ts`).
|
||||
After that, `src/lib/settings/store.ts` reads the sections from memory and tells subscribers about changes.
|
||||
|
||||
## Product boundaries
|
||||
|
||||
@@ -186,6 +221,10 @@ A test states what it needs near its top. The runner skips the test, with the re
|
||||
| `PLAYWRIGHT_MODULE` | A different Playwright package |
|
||||
|
||||
To write a smoke test, start from an existing test in the same area. The harness in `tests/smoke/_harness/index.mjs` starts the browser, mocks the Tauri commands, and gives an in-memory workspace.
|
||||
|
||||
The harness also has default handlers for the settings file and for tab transfers. All pages of one browser context share them.
|
||||
To seed preferences, set the old `localStorage` keys before the first load. The app then migrates them.
|
||||
To read or change a section later, use `window.__TEST__.settings(section)` and `window.__TEST__.writeSettings(section, value)`.
|
||||
A failed test saves `failure.png` in its output folder and prints the page console errors and warnings.
|
||||
You can also run one test file directly while `pnpm dev` runs, for example `node tests/smoke/tabs/order.smoke.mjs`.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user