herdr-gentle-shell 1.8.1 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DESIGN.md +87 -7
- package/README.md +46 -8
- package/docs/theme-sync.md +51 -10
- package/extensions/gentle-herdr-state.ts +278 -14
- package/extensions/herdr-theme-sync.ts +4 -0
- package/lib/customize-rows.js +366 -0
- package/package.json +1 -1
package/DESIGN.md
CHANGED
|
@@ -1008,6 +1008,45 @@ nothing:
|
|
|
1008
1008
|
settings entry actually changed, because that entry is the only part that
|
|
1009
1009
|
waits for the next Pi extension load.
|
|
1010
1010
|
|
|
1011
|
+
The command always exists and the page is additive.
|
|
1012
|
+
`/herdr-gentle:customize` is registered in the extension factory, unconditionally
|
|
1013
|
+
and before the pane gate, exactly as it always was; when gentle-shell-bridge
|
|
1014
|
+
answers its handshake — the `gentle-shell-bridge/api/v1` object published on
|
|
1015
|
+
`globalThis`, gated exactly like the bridge's own `isBridgeApi` — the extension
|
|
1016
|
+
ALSO registers one row provider (`registerRows`, a row `category`, never
|
|
1017
|
+
`registerSection`) on the `Herdr` page of Gentle Shell's own `/gentle:customize`
|
|
1018
|
+
menu, holding exactly the four options S1 names: `Herd agents`, `Moshi`,
|
|
1019
|
+
`Theme sync`, `Select theme`. Two surfaces coexisting is by design: Pi gives an
|
|
1020
|
+
extension no way to withdraw a registered command, and a bridge with no host
|
|
1021
|
+
menu must never leave the user with none. The page is asked for at
|
|
1022
|
+
`session_start` and again on the bridge's `gentle-shell-bridge:ready` announce,
|
|
1023
|
+
so a bridge that publishes after this extension or after the session start still
|
|
1024
|
+
produces it; the live provider is its own guard, so a second `session_start` or a
|
|
1025
|
+
repeated announce never stacks a second page, and only the provider is disposed
|
|
1026
|
+
at `session_shutdown` while the command stays as registered.
|
|
1027
|
+
|
|
1028
|
+
Each row is that switch and nothing else: its action calls the same
|
|
1029
|
+
`applyCustomizePanel` the panel calls, so the writes, the `moshi-hook`
|
|
1030
|
+
prerequisite gate and the "a refusal writes nothing" promise are identical by
|
|
1031
|
+
construction, and the model is re-read on every menu build so `current()` is the
|
|
1032
|
+
stored value rather than a copy taken at registration. The page's four lines are
|
|
1033
|
+
the same four switches under their row names — `Herd agents` for
|
|
1034
|
+
`Sidebar agent rows`, `Moshi` for `Moshi notifications`, `Theme sync` and
|
|
1035
|
+
`Select theme` for the two `Herdr Theme` settings — one row per value, applied
|
|
1036
|
+
with `Enter` (the bridge stages `applyOnMove: false` on every row it
|
|
1037
|
+
contributes), with the theme rows hidden while the sync is on instead of
|
|
1038
|
+
refused in place. One accepted limitation: a row action receives only the
|
|
1039
|
+
inline helpers (`input`, `confirm`, `capture`), so it has no reload handle —
|
|
1040
|
+
the Moshi toggle still writes the settings exclusion and then asks for a
|
|
1041
|
+
restart (`Restart Pi so the new Moshi hook exclusion takes effect.`) where the
|
|
1042
|
+
command and the panel reload immediately (`Reloading now to apply the change.`).
|
|
1043
|
+
Every string that sends the user back to these switches names
|
|
1044
|
+
`/herdr-gentle:customize`, byte-identical to the pre-page build: the command
|
|
1045
|
+
always exists, so no message needs a surface-dependent wording — the Moshi gate
|
|
1046
|
+
refusals end `… re-apply On from /herdr-gentle:customize.` and the follower's
|
|
1047
|
+
missing-theme notice says `… pick an installed theme in
|
|
1048
|
+
/herdr-gentle:customize.`
|
|
1049
|
+
|
|
1011
1050
|
`/herdr-gentle:customize status` prints one read-only line; an unknown
|
|
1012
1051
|
argument, Esc, or a cancelled menu writes nothing. With no argument the
|
|
1013
1052
|
command opens the floating panel (`lib/customize-panel.js`, painted through its
|
|
@@ -1162,10 +1201,12 @@ exactly one mechanism writes each piece of state.
|
|
|
1162
1201
|
`worktree_close` / `worktree_session_open` / `worktree_warp`), the warp
|
|
1163
1202
|
panel, the ODD and Issues readers, and the `Plugin tools` toggles no longer
|
|
1164
1203
|
ship. This package publishes the Herdr producer sidecar and the Moshi channel
|
|
1165
|
-
only; `bin/gentle-sidebar.js` is its one CLI and
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1204
|
+
only; `bin/gentle-sidebar.js` is its one CLI and the customize switches are
|
|
1205
|
+
reached two ways, additively: `/herdr-gentle:customize`, always, and — when
|
|
1206
|
+
gentle-shell-bridge answers its handshake — the `Herdr` page of Gentle Shell's
|
|
1207
|
+
own `/gentle:customize` menu as well (§7). The former
|
|
1208
|
+
in-process provider slot `globalThis[Symbol.for("herdr-gentle.customize.v1")]`
|
|
1209
|
+
stays removed.
|
|
1169
1210
|
- Rollback: disable this plugin → producer stops writing; consumer sweeps
|
|
1170
1211
|
only `gentle_*` tokens + labels it set (O5); pi-tree re-enable restores
|
|
1171
1212
|
`↳N` behavior with zero data migration.
|
|
@@ -1257,8 +1298,10 @@ list, not silent.
|
|
|
1257
1298
|
## 12. Theme sync (Pi palette → Herdr theme)
|
|
1258
1299
|
|
|
1259
1300
|
Herdr's palette follows the theme active in Gentle Shell / Pi, or one theme
|
|
1260
|
-
pinned while the sync is off (S1–S7). The switch lives with the other two
|
|
1261
|
-
`/herdr-gentle:customize
|
|
1301
|
+
pinned while the sync is off (S1–S7). The switch lives with the other two on
|
|
1302
|
+
`/herdr-gentle:customize` and, beside it, on the `Herdr` page of Gentle Shell's
|
|
1303
|
+
own customize menu whenever the bridge answers the handshake (§7), where it is
|
|
1304
|
+
the `Theme sync` and `Select theme` rows; the user-facing reference is
|
|
1262
1305
|
[docs/theme-sync.md](docs/theme-sync.md). Six modules with one owner — this Pi
|
|
1263
1306
|
package — and one direction of data:
|
|
1264
1307
|
|
|
@@ -1482,7 +1525,8 @@ socket/config path). The follower reports `not-herdr`, `remote` and
|
|
|
1482
1525
|
`unsupported` as one `info` notice per session and asks again only when the
|
|
1483
1526
|
palette itself changes.
|
|
1484
1527
|
|
|
1485
|
-
**The panel.** `/herdr-gentle:customize`
|
|
1528
|
+
**The panel.** `/herdr-gentle:customize` — the surface that always exists (§7) —
|
|
1529
|
+
reuses Gentle Shell's own card shape:
|
|
1486
1530
|
one left `CATEGORIES` list, one right pane headed `<Category> · n/m`, one line
|
|
1487
1531
|
per setting with its options inline (`●` stored, `›` cursor elsewhere, `○` the
|
|
1488
1532
|
rest). The arrows move the option cursor and only Enter applies; Enter keeps the
|
|
@@ -1500,10 +1544,46 @@ on, and a host that exposes no list shows one note instead of an empty picker.
|
|
|
1500
1544
|
The panel writes nothing itself: it calls the extension's apply path, swaps in
|
|
1501
1545
|
the model that path re-read, and keeps the cursor by structural option ids.
|
|
1502
1546
|
|
|
1547
|
+
**The page.** The `Herdr` page of Gentle Shell's own customize menu (§7) is not
|
|
1548
|
+
this card: Gentle Shell paints its own rows and enters their actions. The
|
|
1549
|
+
switch side is the same — two rows, `Theme sync` and `Select theme`, built from
|
|
1550
|
+
the same model by `lib/customize-rows.js`, applied through the same
|
|
1551
|
+
`applyCustomizePanel` — so the notices above are the same strings, a theme row
|
|
1552
|
+
keeps its swatch, and the theme rows are hidden while the sync is on rather
|
|
1553
|
+
than refused in place. The sync never needs a Pi reload on either surface; the
|
|
1554
|
+
one surface-specific difference in this feature is Moshi's, which asks for a
|
|
1555
|
+
restart on the page because a row action has no reload handle (§7).
|
|
1556
|
+
|
|
1557
|
+
The page's row set is FIXED for the life of the menu, and the cache in
|
|
1558
|
+
`lib/customize-rows.js` is what makes that affordable: one model read per paint
|
|
1559
|
+
burst (one synchronous `configure.js --check`, not one per callback), dropped
|
|
1560
|
+
after an `apply` settles and after a one-second TTL. Two properties follow and
|
|
1561
|
+
are accepted rather than promised away. First, an external write while the menu
|
|
1562
|
+
is idle becomes visible on the first read after the cache expires, or on a
|
|
1563
|
+
rebuild: the cache never asks the host to repaint, so a repaint that lands
|
|
1564
|
+
before expiry redraws the previous model and the displayed state has no upper
|
|
1565
|
+
freshness bound. Second, when an external write hides the row the user had
|
|
1566
|
+
focused (the theme
|
|
1567
|
+
picker, with the sync turned on elsewhere), the host clamps the focus to the
|
|
1568
|
+
neighbouring row, so Enter can act on that one; the clamp itself writes nothing.
|
|
1569
|
+
The fixed row set is also why a theme applied from a row is checked against a
|
|
1570
|
+
fresh `ctx.ui.getAllThemes()` read at apply time: a theme removed after the
|
|
1571
|
+
build refuses and writes nothing instead of pinning a name this install no
|
|
1572
|
+
longer has. That check lives on the page's own apply path, so the command's
|
|
1573
|
+
picker and the mounted panel keep the `865d360` write (S2).
|
|
1574
|
+
|
|
1503
1575
|
**Limits** (the §10 style, none of them a promise this design makes):
|
|
1504
1576
|
|
|
1505
1577
|
- The 500 ms tick is the whole observation granularity — there is no event to
|
|
1506
1578
|
subscribe to, so a theme change is noticed within one tick and not sooner.
|
|
1579
|
+
- The page's displayed state has **no upper freshness bound**: its row cache
|
|
1580
|
+
never requests a repaint, so a write from another process while the menu is
|
|
1581
|
+
idle appears on the first read after the cache expires, or on a rebuild, not
|
|
1582
|
+
when it lands; a repaint that lands before expiry redraws the previous model,
|
|
1583
|
+
and on a menu nobody touches the write is not shown at all.
|
|
1584
|
+
- The page cannot keep the cursor on a row an external write hid: the host clamps
|
|
1585
|
+
the focus to the neighbouring row, so the next Enter can act on that neighbour.
|
|
1586
|
+
The clamp writes nothing; it only moves the cursor.
|
|
1507
1587
|
- The automated evidence is a stubbed Pi host plus a real binary stand-in on
|
|
1508
1588
|
disk; **no live Pi TUI run is recorded**. `ctx.ui.theme`, `getTheme`,
|
|
1509
1589
|
`getAllThemes`, `notify` and the host component contract are used as
|
package/README.md
CHANGED
|
@@ -484,9 +484,34 @@ See [DESIGN.md](DESIGN.md) §4 (producer) and §5 (consumer), and
|
|
|
484
484
|
managed Herdr rows and records the owned native-extension exclusion;
|
|
485
485
|
`disable` removes only our owned rows and exclusion, never a user table.
|
|
486
486
|
See [docs/sidebar-control.md](docs/sidebar-control.md).
|
|
487
|
-
- In-Pi switches (`/herdr-gentle:customize`
|
|
488
|
-
|
|
489
|
-
|
|
487
|
+
- In-Pi switches (`/herdr-gentle:customize`, plus the `Herdr` page of Gentle
|
|
488
|
+
Shell's customize menu when gentle-shell-bridge answers): three switches, all
|
|
489
|
+
local state and all reachable from a plain Pi session outside a Herdr pane.
|
|
490
|
+
The command is registered in the extension factory and always exists; the page
|
|
491
|
+
is ADDITIVE. The second surface is a handshake, never a package dependency:
|
|
492
|
+
when gentle-shell-bridge answers — its `gentle-shell-bridge/api/v1` object is
|
|
493
|
+
published on `globalThis` — the extension also contributes one `Herdr` page to
|
|
494
|
+
Gentle Shell's own `/gentle:customize` menu with exactly the four options
|
|
495
|
+
`Herd agents`, `Moshi`, `Theme sync` and `Select theme`, and contributes no
|
|
496
|
+
page when nothing answers. The page is asked for at session start and again on
|
|
497
|
+
the bridge's announce (`gentle-shell-bridge:ready`), so a bridge that loads
|
|
498
|
+
late still produces it; the live provider is its own guard, so a second
|
|
499
|
+
session start or a repeated announce never stacks a second page, and only the
|
|
500
|
+
page is dropped on session shutdown (`/reload` replaces it) while the command
|
|
501
|
+
stays registered. Two surfaces coexisting is by design — no user can end up
|
|
502
|
+
with none — and a bridge that answers yet refuses the page (no
|
|
503
|
+
`lib/customize-rows.js`, a provider its bus rejects) simply leaves the command
|
|
504
|
+
working. Each row is that same switch through the
|
|
505
|
+
same apply path — `Herd agents` drives `bin/configure.js` exactly as
|
|
506
|
+
`Sidebar agent rows` does, `Moshi` writes the flag and the settings exclusion
|
|
507
|
+
exactly as `Moshi notifications` does, and `Theme sync` and `Select theme`
|
|
508
|
+
are the two `Herdr Theme` settings — so the writes and the "a refusal writes
|
|
509
|
+
nothing" promise are identical on both surfaces. On the page a setting is one
|
|
510
|
+
line of `On`/`Off` (or theme) values that the arrows walk and only `Enter`
|
|
511
|
+
applies, a theme row carries its own swatch and is simply not shown while the
|
|
512
|
+
sync is on, and the rows carry no `status`: `status` belongs to the command,
|
|
513
|
+
the surface that exists without the bridge. With
|
|
514
|
+
no argument that command opens the floating panel in Gentle Shell's own
|
|
490
515
|
layout: one left `CATEGORIES` list (`Herdr Sidebar`, `Moshi notifications`,
|
|
491
516
|
`Herdr Theme`)
|
|
492
517
|
and one right pane headed `<Category> · n/m`, where each setting is ONE line
|
|
@@ -528,7 +553,16 @@ See [DESIGN.md](DESIGN.md) §4 (producer) and §5 (consumer), and
|
|
|
528
553
|
below and adds or removes the `-extensions/moshi-hooks.ts` exclusion in Pi's
|
|
529
554
|
`settings.json`, running the `moshi-hook` pairing gate before enabling (a
|
|
530
555
|
refusal writes nothing) and reloading Pi only when that settings entry
|
|
531
|
-
actually changed.
|
|
556
|
+
actually changed. On the page that last reload is the one accepted
|
|
557
|
+
limitation: a menu row receives no reload handle, so `Moshi` writes the
|
|
558
|
+
exclusion and asks for a restart (`Restart Pi so the new Moshi hook exclusion
|
|
559
|
+
takes effect.`) where the command and the panel reload immediately
|
|
560
|
+
(`Reloading now to apply the change.`). Every message that points back at
|
|
561
|
+
these switches names `/herdr-gentle:customize`
|
|
562
|
+
(`… re-apply On from /herdr-gentle:customize.`), byte-identical to the
|
|
563
|
+
pre-page build, because the command always exists and no string needs a
|
|
564
|
+
surface-dependent wording. `/herdr-gentle:customize status` prints
|
|
565
|
+
one read-only line
|
|
532
566
|
(`customize status: sidebar=<on|off|unknown> moshi=<on|off>
|
|
533
567
|
theme-sync=<on|off|unknown> theme=<name|none|unknown>`); an unknown
|
|
534
568
|
argument, Esc, or a cancelled menu writes nothing. A sidebar verdict of
|
|
@@ -546,8 +580,8 @@ See [DESIGN.md](DESIGN.md) §4 (producer) and §5 (consumer), and
|
|
|
546
580
|
mkdir -p "$dir" && echo '{"enabled":true}' > "$dir/gentle-moshi.json"
|
|
547
581
|
```
|
|
548
582
|
|
|
549
|
-
|
|
550
|
-
and enabling there first
|
|
583
|
+
`Moshi notifications` in the command, or `Moshi` on the menu's `Herdr` page,
|
|
584
|
+
writes this flag for you, and enabling there first
|
|
551
585
|
requires the `moshi-hook` CLI on `PATH` with `moshi-hook status --json`
|
|
552
586
|
reporting `paired: true` (an unpaired host is refused and nothing is
|
|
553
587
|
written).
|
|
@@ -597,12 +631,16 @@ See [DESIGN.md](DESIGN.md) §4 (producer) and §5 (consumer), and
|
|
|
597
631
|
row), while every other Herdr failure still aborts and opens nothing. The
|
|
598
632
|
other worktree tools and the ODD and issues panels live
|
|
599
633
|
in `odd-worktree` now; the sidebar and Moshi switches stayed here and are
|
|
600
|
-
reached through `/herdr-gentle:customize
|
|
634
|
+
reached through `/herdr-gentle:customize` and, when gentle-shell-bridge
|
|
635
|
+
answers, also through the Gentle Shell customize menu's `Herdr` page. See
|
|
601
636
|
[docs/herdr-session-open.md](docs/herdr-session-open.md).
|
|
602
637
|
|
|
603
638
|
### Theme sync (Herdr palette follows Pi)
|
|
604
639
|
|
|
605
|
-
|
|
640
|
+
`Theme sync` and `Select theme` — the `Herdr Theme` settings of
|
|
641
|
+
`/herdr-gentle:customize`, and the `Theme sync` and `Select theme` rows of the
|
|
642
|
+
Gentle Shell customize menu's `Herdr` page when the bridge answers — are one
|
|
643
|
+
switch and one pinned theme.
|
|
606
644
|
`Theme sync` is **OFF by default**: while it is on, Herdr's palette is the
|
|
607
645
|
palette of the theme Pi is showing, and it follows a theme change while Pi keeps
|
|
608
646
|
running. While it is off, `Gentle Shell theme` pins one Gentle Shell / Pi theme
|
package/docs/theme-sync.md
CHANGED
|
@@ -18,8 +18,14 @@ plugin-side planner and no 1.8.0 managed block.
|
|
|
18
18
|
|
|
19
19
|
## The switch
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
The whole feature is two settings: `Theme sync` and `Select theme`. They are
|
|
22
|
+
served on `/herdr-gentle:customize` → `Herdr Theme` always, and — when
|
|
23
|
+
gentle-shell-bridge answers its handshake (its `gentle-shell-bridge/api/v1`
|
|
24
|
+
object is published on `globalThis`) — also on the `Herdr` page of Gentle Shell's
|
|
25
|
+
own `/gentle:customize` menu, laid out like the rest of the card (see
|
|
26
|
+
[Panel](#panel)). The command always exists and the page is additive; the page's
|
|
27
|
+
rows come from the same model and the same apply path, so everything below holds
|
|
28
|
+
on both:
|
|
23
29
|
|
|
24
30
|
- `Theme sync` is **OFF by default**. `On` makes Herdr's palette the palette of
|
|
25
31
|
the theme Pi is showing, and it follows a change of the active theme while Pi
|
|
@@ -47,12 +53,14 @@ The notices are fixed strings:
|
|
|
47
53
|
| Toggle already in that state | `Theme sync already on/off; nothing was changed.` |
|
|
48
54
|
| Theme setting while the sync is on | `Turn Theme sync off to pick a specific theme.` |
|
|
49
55
|
| Theme assigned | `Gentle Shell theme set to <name>.` |
|
|
50
|
-
| Pin cleared | `Gentle Shell theme set to Off; Herdr keeps the palette it was last given.` (the stored value stays `null` and the inline list marks `None`; only this notice — and the
|
|
56
|
+
| Pin cleared | `Gentle Shell theme set to Off; Herdr keeps the palette it was last given.` (the stored value stays `null` and the inline list marks `None`; only this notice — and the `Off (no theme assigned)` entry of the fallback menu and of the Gentle Shell page — spell it `Off`) |
|
|
51
57
|
| Host exposes no theme list | `Could not read Pi's theme list (this host exposes no getAllThemes()); nothing was changed.` |
|
|
52
58
|
| Theme store missing | `Could not reach the theme store (lib/theme-store.js is unavailable); nothing was changed.` |
|
|
53
59
|
| State file not writable | `Could not write the theme store: <detail>; nothing was changed.` |
|
|
54
60
|
|
|
55
|
-
`/herdr-gentle:customize status` prints one read-only line and writes nothing
|
|
61
|
+
`/herdr-gentle:customize status` prints one read-only line and writes nothing.
|
|
62
|
+
The subcommand belongs to the command; the menu page offers no `status`
|
|
63
|
+
operation:
|
|
56
64
|
|
|
57
65
|
```text
|
|
58
66
|
customize status: sidebar=<on|off|unknown> moshi=<on|off> theme-sync=<on|off|unknown> theme=<name|none|unknown>
|
|
@@ -543,7 +551,12 @@ no-op, and every user-visible outcome is a fixed string:
|
|
|
543
551
|
- **Pinned theme not installed**: `The Pi theme "<name>" is not installed, so
|
|
544
552
|
Herdr's palette was left unchanged; pick an installed theme in
|
|
545
553
|
/herdr-gentle:customize.` — once per session; a later install of that exact
|
|
546
|
-
theme is picked up without a restart.
|
|
554
|
+
theme is picked up without a restart. The notice names the command, which
|
|
555
|
+
always exists, byte-identical to the pre-page build. The customize surfaces
|
|
556
|
+
reuse the same sentence when a theme row outlives the catalogue it was built
|
|
557
|
+
from: applying a theme re-reads `ctx.ui.getAllThemes()` first, and a name that
|
|
558
|
+
is gone refuses as a `warning` write-nothing instead of pinning a theme this
|
|
559
|
+
install no longer has.
|
|
547
560
|
- **Nothing to project**: `Herdr theme not applied: <theme name> has no concrete
|
|
548
561
|
colours to project.` (`the active theme` replaces the name when the active
|
|
549
562
|
theme exposes none) — once per session, `warning`. A palette with no concrete
|
|
@@ -690,10 +703,12 @@ Tests and isolated runs:
|
|
|
690
703
|
|
|
691
704
|
## Panel
|
|
692
705
|
|
|
693
|
-
`/herdr-gentle:customize` with no argument opens the card
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
706
|
+
`/herdr-gentle:customize` with no argument opens the card — the surface that
|
|
707
|
+
always exists, whether or not the bridge adds its page. It behaves like Gentle
|
|
708
|
+
Shell's own: one left `CATEGORIES` list and one
|
|
709
|
+
right pane headed `<Category> · n/m`, with one line per setting and its options
|
|
710
|
+
inline — `●` the stored option, `›` the cursor while it sits elsewhere, `○`
|
|
711
|
+
the rest.
|
|
697
712
|
|
|
698
713
|
- The arrows move the option cursor and **only Enter applies**; Enter keeps the
|
|
699
714
|
card open (only a Moshi settings change that needs a Pi reload closes it),
|
|
@@ -724,6 +739,31 @@ Gentle Shell's own: one left `CATEGORIES` list and one right pane headed
|
|
|
724
739
|
note (`Themes unavailable; use Pi /settings`) instead of an empty picker, and
|
|
725
740
|
an unreadable store adds `state unknown; Enter pins a theme`.
|
|
726
741
|
|
|
742
|
+
When gentle-shell-bridge answers, this card is still there and the same two
|
|
743
|
+
settings are ALSO the `Theme sync` and `Select theme` rows of the `Herdr` page in
|
|
744
|
+
Gentle Shell's own menu, painted by that host. One row per value, walked with
|
|
745
|
+
the arrows and applied with `Enter` (the bridge never applies on a cursor move),
|
|
746
|
+
the theme row keeps its own swatch, and the theme rows are simply not shown
|
|
747
|
+
while the sync is on instead of being refused in place. The notices are the
|
|
748
|
+
same fixed strings, and the sync needs no Pi reload on either surface.
|
|
749
|
+
|
|
750
|
+
The page's rows are FIXED for as long as the menu is open, which is why its
|
|
751
|
+
theme rows cost one model read per paint burst instead of one per row. Two
|
|
752
|
+
consequences are accepted: an external write while the menu is idle becomes
|
|
753
|
+
visible on the first read after the cache expires, or on a rebuild (the cache
|
|
754
|
+
never asks the host to repaint, so a repaint that lands before expiry redraws
|
|
755
|
+
the previous model and the display has no upper freshness bound), and an
|
|
756
|
+
external write that hides the focused row leaves the host to clamp the cursor to
|
|
757
|
+
the neighbouring row, so `Enter` can act on that one — the clamp itself writes
|
|
758
|
+
nothing. Because a row can outlive the catalogue it was built from, the page's
|
|
759
|
+
own apply path re-reads `ctx.ui.getAllThemes()` before it writes: a theme
|
|
760
|
+
removed after the build is refused with the sync's own not-installed notice
|
|
761
|
+
(`The Pi theme "<name>" is not installed, …`) and the store is left untouched,
|
|
762
|
+
and a catalogue that cannot be read at apply time is refused with
|
|
763
|
+
`Could not read Pi's theme list at apply time; nothing was changed.` The
|
|
764
|
+
command's own picker and the mounted panel do not run that check, so both keep
|
|
765
|
+
the `865d360` behavior byte for byte (S2).
|
|
766
|
+
|
|
727
767
|
## Implementation
|
|
728
768
|
|
|
729
769
|
| File | Role |
|
|
@@ -733,5 +773,6 @@ Gentle Shell's own: one left `CATEGORIES` list and one right pane headed
|
|
|
733
773
|
| `lib/herdr-theme-config.js` | The pure planner — a **line splicer**, not a TOML validator: table-boundary scanning, opaque bytes outside the two theme tables, a strict theme-table grammar, the whole-line `was` marker with byte-exact restoration (the user's latest trailing comment wins), the one regenerated block (`begin` / `begin created` … `end` / `end after a missing line ending`), the ambiguity refusal above a block being removed or moved, the 1.8.0 marker-pair migration, the BOM and the enforced splice invariant. |
|
|
734
774
|
| `lib/herdr-theme-apply.js` | The writer: availability guards, bounded snapshot, compare-and-swap, atomic non-overwriting backup (a regular existing file is accepted as is), retried temp cleanup that reports a survivor and never deletes a temp it did not create, growth limit, `forceReload`, reload. |
|
|
735
775
|
| `extensions/herdr-theme-sync.ts` | The follower: session-start evaluation, 500 ms tick, fingerprint, owed-reload repair, the notices. |
|
|
736
|
-
| `extensions/gentle-herdr-state.ts` | The switch: `applyThemeSync`, `writeThemeChoice`, `applyCustomizePanel`, `customize status
|
|
776
|
+
| `extensions/gentle-herdr-state.ts` | The switch: `applyThemeSync`, `writeThemeChoice`, `applyCustomizePanel`, `customize status`, and the page registration beside the always-registered command (`registerCustomizePage`). |
|
|
737
777
|
| `lib/customize-panel.js` | The card: categories, option lines, sideways window, Preview block, legends, pointer hits. |
|
|
778
|
+
| `lib/customize-rows.js` | The page: the same model and settings translated into the four `Herdr` row lines Gentle Shell renders. |
|
|
@@ -2075,6 +2075,11 @@ function lastFinishedLabel(taskMap) {
|
|
|
2075
2075
|
// unavailable. The removed `Plugin tools` and `Reset` sections and the
|
|
2076
2076
|
// cross-extension provider slot are deliberately NOT restored: they switched
|
|
2077
2077
|
// worktree/ODD/issues surfaces this package no longer contains.
|
|
2078
|
+
//
|
|
2079
|
+
// With gentle-shell-bridge present the same four options are ALSO served as the
|
|
2080
|
+
// `Herdr` page of Gentle Shell's own `/gentle:customize` menu (see
|
|
2081
|
+
// `registerCustomizePage` below). The page is additive: this command is
|
|
2082
|
+
// registered unconditionally, exactly as before, and the apply path is shared.
|
|
2078
2083
|
// ---------------------------------------------------------------------------
|
|
2079
2084
|
|
|
2080
2085
|
const CUSTOMIZE_TITLE = "Customize · Herdr Gentle Shell";
|
|
@@ -2106,9 +2111,27 @@ const THEME_SYNC_OFF_TEXT = "Theme sync off; Herdr keeps the palette it was last
|
|
|
2106
2111
|
const THEME_SYNC_REFUSED_TEXT = "Turn Theme sync off to pick a specific theme.";
|
|
2107
2112
|
const THEME_LIST_UNAVAILABLE_TEXT =
|
|
2108
2113
|
"Could not read Pi's theme list (this host exposes no getAllThemes()); nothing was changed.";
|
|
2114
|
+
// The page's OWN apply-time notice, for a catalogue it could read when it built
|
|
2115
|
+
// its rows and cannot read now. It deliberately does not reuse the sentence
|
|
2116
|
+
// above: that one says the host exposes no `getAllThemes()`, which is a
|
|
2117
|
+
// different fact and stays untouched for the command and the panel (S2).
|
|
2118
|
+
const THEME_LIST_UNREADABLE_AT_APPLY_TEXT =
|
|
2119
|
+
"Could not read Pi's theme list at apply time; nothing was changed.";
|
|
2109
2120
|
const THEME_STORE_UNAVAILABLE_TEXT =
|
|
2110
2121
|
"Could not reach the theme store (lib/theme-store.js is unavailable); nothing was changed.";
|
|
2111
2122
|
|
|
2123
|
+
// S4 (odd/tasks/herdr-customize-page.md): `/herdr-gentle:customize` is registered
|
|
2124
|
+
// unconditionally (S1), so it always exists and every message that sends the user
|
|
2125
|
+
// back to the four options names it — byte for byte the text `865d360` shipped.
|
|
2126
|
+
// No string is surface-dependent: the page added beside the command changes no
|
|
2127
|
+
// wording, and a message never points at a menu that may be absent.
|
|
2128
|
+
|
|
2129
|
+
// The Moshi settings entry waits for the next Pi extension load. A customize ROW
|
|
2130
|
+
// has no reload handle (the bridge hands `action` only inline helpers), so the
|
|
2131
|
+
// page writes the exclusion and asks for a restart instead of promising a reload
|
|
2132
|
+
// it cannot perform. The command and the panel keep reloading immediately.
|
|
2133
|
+
const MOSHI_RESTART_TEXT = "Restart Pi so the new Moshi hook exclusion takes effect.";
|
|
2134
|
+
|
|
2112
2135
|
// The former panel's geometry and overlay options, unchanged. The helpers
|
|
2113
2136
|
// module (@earendil-works/pi-tui) is resolved lazily through the injectable
|
|
2114
2137
|
// seam below so registering the extension never depends on it and tests can
|
|
@@ -2149,6 +2172,18 @@ function customizePanelModule() {
|
|
|
2149
2172
|
}
|
|
2150
2173
|
}
|
|
2151
2174
|
|
|
2175
|
+
// The bridge row builder (lib/customize-rows.js, odd/tasks/herdr-customize-page.md
|
|
2176
|
+
// T1). Loaded lazily beside the panel module and for the same reason: an
|
|
2177
|
+
// installed copy without the sibling library keeps every other surface working
|
|
2178
|
+
// and answers no page instead of failing this extension.
|
|
2179
|
+
function customizeRowsModule() {
|
|
2180
|
+
try {
|
|
2181
|
+
return nodeRequire(join(customizeLibDir(), "customize-rows.js"));
|
|
2182
|
+
} catch {
|
|
2183
|
+
return null;
|
|
2184
|
+
}
|
|
2185
|
+
}
|
|
2186
|
+
|
|
2152
2187
|
function themeStoreModule() {
|
|
2153
2188
|
try {
|
|
2154
2189
|
return nodeRequire(join(customizeLibDir(), "theme-store.js"));
|
|
@@ -2624,13 +2659,19 @@ async function applyCustomizeSwitch(id, value, ctx, options = {}) {
|
|
|
2624
2659
|
? applyThemeSync(want)
|
|
2625
2660
|
: applyMoshiNotifications(want);
|
|
2626
2661
|
const notify = ctx?.ui?.notify;
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
//
|
|
2631
|
-
//
|
|
2632
|
-
//
|
|
2633
|
-
|
|
2662
|
+
// The reload sentence is a PROMISE about what happens next, so it is written
|
|
2663
|
+
// from what this surface can actually do. `deferReload` hands the reload to the
|
|
2664
|
+
// caller that mounted the overlay (the card closes first, then it reloads), and
|
|
2665
|
+
// `noReload` is the Gentle Shell customize page, where a row action receives no
|
|
2666
|
+
// ctx and therefore no reload handle: there the only honest sentence is a
|
|
2667
|
+
// restart. Every other combination is the command's own immediate reload.
|
|
2668
|
+
const canReload = options.deferReload !== true && options.noReload !== true
|
|
2669
|
+
&& typeof ctx?.reload === "function";
|
|
2670
|
+
const reloadNotice = result.needsReload
|
|
2671
|
+
? (options.noReload === true ? ` ${MOSHI_RESTART_TEXT}` : " Reloading now to apply the change.")
|
|
2672
|
+
: "";
|
|
2673
|
+
if (typeof notify === "function") notify(`${result.text}${reloadNotice}`, result.level);
|
|
2674
|
+
if (result.needsReload && canReload) await ctx.reload();
|
|
2634
2675
|
return result;
|
|
2635
2676
|
}
|
|
2636
2677
|
|
|
@@ -2712,10 +2753,36 @@ function themeSelectionOptions(names) {
|
|
|
2712
2753
|
return { options: [...names, unassign], unassign };
|
|
2713
2754
|
}
|
|
2714
2755
|
|
|
2715
|
-
//
|
|
2716
|
-
//
|
|
2717
|
-
//
|
|
2718
|
-
//
|
|
2756
|
+
// T10 (odd/tasks/herdr-customize-page.md): a surface that holds its own rows can
|
|
2757
|
+
// outlive the catalogue it built them from. Only the Herdr PAGE does: it keeps
|
|
2758
|
+
// one row per theme for as long as Gentle Shell shows the menu, while the
|
|
2759
|
+
// command's picker reads `getAllThemes()` when it prompts and the mounted panel
|
|
2760
|
+
// keeps the 865d360 write. The guard therefore lives on the page's apply path (`applyCustomizePageChoice`), never in the write the command and the
|
|
2761
|
+
// panel share (S2).
|
|
2762
|
+
//
|
|
2763
|
+
// The wording is the notice the theme sync already gives for a stored name this
|
|
2764
|
+
// install does not have (`extensions/herdr-theme-sync.ts`, S4): one sentence for
|
|
2765
|
+
// one fact, spelled once. A catalogue that cannot be read at all gets the page's
|
|
2766
|
+
// own apply-time sentence, because a name nothing verified is never written.
|
|
2767
|
+
function themeNotInstalledText(name) {
|
|
2768
|
+
return `The Pi theme "${name}" is not installed, so Herdr's palette was left unchanged; pick an installed theme in /herdr-gentle:customize.`;
|
|
2769
|
+
}
|
|
2770
|
+
|
|
2771
|
+
// A FRESH read, never the page's row cache: `readHostThemeNames` calls the host
|
|
2772
|
+
// accessor again on every call, so the answer describes the install as it is at
|
|
2773
|
+
// APPLY time.
|
|
2774
|
+
function themeStillInstalled(ctx, name) {
|
|
2775
|
+
const names = readHostThemeNames(ctx);
|
|
2776
|
+
if (names === null) return { ok: false, text: THEME_LIST_UNREADABLE_AT_APPLY_TEXT };
|
|
2777
|
+
return names.includes(name) ? { ok: true, text: null } : { ok: false, text: themeNotInstalledText(name) };
|
|
2778
|
+
}
|
|
2779
|
+
|
|
2780
|
+
// One write for the pinned theme, shared by the inline panel setting, the Herdr
|
|
2781
|
+
// page rows and the `ctx.ui.select` fallback: the refusal, the missing store and
|
|
2782
|
+
// a failure all write NOTHING, so the stored document only ever changes to a
|
|
2783
|
+
// value the user actually picked (S7). No catalogue check lives here: the
|
|
2784
|
+
// command's picker cannot outlive its catalogue, and the page's own guard runs
|
|
2785
|
+
// before this call (T10), so neither surface can inherit a new refusal.
|
|
2719
2786
|
function writeThemeChoice(ctx, name) {
|
|
2720
2787
|
const notify = ctx?.ui?.notify;
|
|
2721
2788
|
const store = themeStoreModule();
|
|
@@ -2814,7 +2881,7 @@ async function applyCustomizeChoice(choice, ctx) {
|
|
|
2814
2881
|
// uses, and answers with a freshly read model so the panel shows the real state
|
|
2815
2882
|
// instead of guessing it. `close` is only true when Pi must reload: the caller
|
|
2816
2883
|
// closes the overlay first and reloads after it resolved.
|
|
2817
|
-
async function applyCustomizePanel(choice, ctx) {
|
|
2884
|
+
async function applyCustomizePanel(choice, ctx, options = {}) {
|
|
2818
2885
|
const model = () => customizePanelModel(ctx);
|
|
2819
2886
|
if (!isRecord(choice)) return { model: model(), close: false, reload: false };
|
|
2820
2887
|
const { settingId, optionId } = choice;
|
|
@@ -2827,7 +2894,12 @@ async function applyCustomizePanel(choice, ctx) {
|
|
|
2827
2894
|
}
|
|
2828
2895
|
if (!CUSTOMIZE_SWITCH_IDS.includes(settingId)) return { model: model(), close: false, reload: false };
|
|
2829
2896
|
if (optionId !== "on" && optionId !== "off") return { model: model(), close: false, reload: false };
|
|
2830
|
-
const result = await applyCustomizeSwitch(
|
|
2897
|
+
const result = await applyCustomizeSwitch(
|
|
2898
|
+
settingId,
|
|
2899
|
+
optionId,
|
|
2900
|
+
ctx,
|
|
2901
|
+
options.noReload === true ? { noReload: true } : { deferReload: true },
|
|
2902
|
+
);
|
|
2831
2903
|
const reload = Boolean(result && result.needsReload);
|
|
2832
2904
|
return { model: model(), close: reload, reload };
|
|
2833
2905
|
}
|
|
@@ -2964,9 +3036,200 @@ async function executeCustomize(rawArgs, ctx) {
|
|
|
2964
3036
|
await runCustomizeFallback(ctx);
|
|
2965
3037
|
}
|
|
2966
3038
|
|
|
3039
|
+
// ---------------------------------------------------------------------------
|
|
3040
|
+
// The Gentle Shell customize PAGE (odd/tasks/herdr-customize-page.md T7;
|
|
3041
|
+
// specs S1, S2, S4).
|
|
3042
|
+
//
|
|
3043
|
+
// `/herdr-gentle:customize` is registered in the FACTORY, unconditionally, exactly
|
|
3044
|
+
// as on `865d360`. This section ADDS a second surface on top of it: when
|
|
3045
|
+
// gentle-shell-bridge answers its handshake, the same four switches also appear as
|
|
3046
|
+
// the `Herdr` page of Gentle Shell's own `/gentle:customize` menu. The page never
|
|
3047
|
+
// replaces the command — two surfaces coexisting is by design, because Pi gives an
|
|
3048
|
+
// extension no way to withdraw a registered command and a bridge with no host menu
|
|
3049
|
+
// must never leave the user with none.
|
|
3050
|
+
//
|
|
3051
|
+
// The bridge is reached as a HANDSHAKE, never a dependency: its object sits at a
|
|
3052
|
+
// `Symbol.for` key on `globalThis`, and the key, the schema and the members this
|
|
3053
|
+
// file calls are inlined here, so nothing resolves `gentle-shell-bridge` as a
|
|
3054
|
+
// module (`examples/bash-card.ts:1214-1244` in that package is the same pattern).
|
|
3055
|
+
//
|
|
3056
|
+
// WHEN the page appears. `session_start` asks the symbol; when it is absent the
|
|
3057
|
+
// page cannot be built yet, so the factory has already subscribed to
|
|
3058
|
+
// `BRIDGE_READY_EVENT` and the announce asks again. That covers Pi's load order,
|
|
3059
|
+
// which does not guarantee that a configured package's module publishes before a
|
|
3060
|
+
// global extension's `session_start`: a late bridge still produces the page. The
|
|
3061
|
+
// announce is a notification, never a registry — the symbol stays the authority,
|
|
3062
|
+
// so a copy that publishes an incompatible slot announces nothing usable and the
|
|
3063
|
+
// gate below answers ABSENT.
|
|
3064
|
+
//
|
|
3065
|
+
// ONE provider, never two. Registration is guarded by the live provider itself, so
|
|
3066
|
+
// a second `session_start`, an announce after a start and a repeated announce all
|
|
3067
|
+
// leave exactly one registration; the bridge's bus is never asked twice. The
|
|
3068
|
+
// provider is session-scoped and the command is not: only the provider is disposed
|
|
3069
|
+
// on session shutdown.
|
|
3070
|
+
// ---------------------------------------------------------------------------
|
|
3071
|
+
const BRIDGE_API_KEY = Symbol.for("gentle-shell-bridge/api/v1");
|
|
3072
|
+
const BRIDGE_API_SCHEMA = "gentle-shell-bridge/api";
|
|
3073
|
+
const BRIDGE_API_VERSION = 1;
|
|
3074
|
+
// The channel the bridge announces itself on. The string MIRRORS `src/api.ts`:
|
|
3075
|
+
// this file cannot import it, so the two are kept in sync by hand.
|
|
3076
|
+
const BRIDGE_READY_EVENT = "gentle-shell-bridge:ready";
|
|
3077
|
+
// The provider's stable id: the bridge replaces a provider registered under the
|
|
3078
|
+
// same id in place, so one page is one page however often it is registered.
|
|
3079
|
+
const CUSTOMIZE_PAGE_PROVIDER_ID = "herdr-gentle:customize";
|
|
3080
|
+
|
|
3081
|
+
// The published object, gated exactly like the bridge's own `isBridgeApi`
|
|
3082
|
+
// (`src/api.ts`): identity strings plus the members this file calls. A foreign
|
|
3083
|
+
// payload, another major version or a partial object is ABSENT — never an error,
|
|
3084
|
+
// never guessed at, never overwritten.
|
|
3085
|
+
function publishedBridge() {
|
|
3086
|
+
const slot = globalThis[BRIDGE_API_KEY];
|
|
3087
|
+
if (!isRecord(slot)) return null;
|
|
3088
|
+
if (slot.schema !== BRIDGE_API_SCHEMA || slot.version !== BRIDGE_API_VERSION) return null;
|
|
3089
|
+
if (typeof slot.registerRows !== "function") return null;
|
|
3090
|
+
if (typeof slot.registerSection !== "function" || typeof slot.createStore !== "function") return null;
|
|
3091
|
+
return slot;
|
|
3092
|
+
}
|
|
3093
|
+
|
|
3094
|
+
// A row's apply path — and it IS the overlay's own path (`applyCustomizePanel`),
|
|
3095
|
+
// not a copy: the same `writeThemeChoice` for the pinned theme, the same
|
|
3096
|
+
// `applyCustomizeSwitch` for the three switched settings, and therefore the same
|
|
3097
|
+
// Moshi prerequisite gate and the same "a refusal writes nothing" promise by
|
|
3098
|
+
// construction. It adds the two facts the overlay does not need: a row action
|
|
3099
|
+
// receives no ctx, so the page has no reload handle and the shared path reports a
|
|
3100
|
+
// restart instead of reloading (see `applyCustomizeSwitch`), and the page's rows
|
|
3101
|
+
// outlive the theme catalogue they were built from (T10).
|
|
3102
|
+
//
|
|
3103
|
+
// The catalogue guard lives HERE, on the page's own call site, and not in the
|
|
3104
|
+
// shared write: the command's picker and the mounted panel keep the 865d360
|
|
3105
|
+
// behavior byte for byte (S2), and no other surface can be affected by
|
|
3106
|
+
// construction. A name removed after the build is refused with the not-installed
|
|
3107
|
+
// notice and writes nothing; a catalogue that cannot be read at apply time gets
|
|
3108
|
+
// the page's own honest sentence and also writes nothing.
|
|
3109
|
+
//
|
|
3110
|
+
// A refusal is NOT re-thrown: the shared path reports it through the host's own
|
|
3111
|
+
// `ui.notify` and returns, which is one report — the same one the command gives.
|
|
3112
|
+
// Throwing on top of that would report it twice (the bridge reports a thrown
|
|
3113
|
+
// action again), so only an unexpected exception travels into the bridge's
|
|
3114
|
+
// channel.
|
|
3115
|
+
async function applyCustomizePageChoice(choice, ctx) {
|
|
3116
|
+
if (isRecord(choice) && choice.settingId === CUSTOMIZE_THEME_SETTING_ID) {
|
|
3117
|
+
const optionId = choice.optionId;
|
|
3118
|
+
// The sync gate answers FIRST, exactly as it does on every other surface.
|
|
3119
|
+
// While sync is on the pinned theme is not available at all, so asking the
|
|
3120
|
+
// catalogue whether the theme still exists would answer a question the row
|
|
3121
|
+
// cannot act on and would bury the one thing the user has to do first.
|
|
3122
|
+
const syncOn = readCustomizeThemeState().sync === true;
|
|
3123
|
+
if (!syncOn && typeof optionId === "string" && optionId.startsWith(CUSTOMIZE_THEME_OPTION_PREFIX)) {
|
|
3124
|
+
const installed = themeStillInstalled(ctx, optionId.slice(CUSTOMIZE_THEME_OPTION_PREFIX.length));
|
|
3125
|
+
if (!installed.ok) {
|
|
3126
|
+
const notify = ctx?.ui?.notify;
|
|
3127
|
+
if (typeof notify === "function") notify(installed.text, "warning");
|
|
3128
|
+
return { model: customizePanelModel(ctx), close: false, reload: false };
|
|
3129
|
+
}
|
|
3130
|
+
}
|
|
3131
|
+
}
|
|
3132
|
+
return applyCustomizePanel(choice, ctx, { noReload: true });
|
|
3133
|
+
}
|
|
3134
|
+
|
|
3135
|
+
// The one provider this extension contributes: the `Herdr` page (a row
|
|
3136
|
+
// CATEGORY, never `registerSection`, which is a sidebar card). `rows()` is called
|
|
3137
|
+
// on every menu build, so the model — and every `current()`, swatch and sync gate
|
|
3138
|
+
// inside it — is read live rather than captured at registration.
|
|
3139
|
+
function customizePageProvider(rowsModule, hostCtx) {
|
|
3140
|
+
return {
|
|
3141
|
+
id: CUSTOMIZE_PAGE_PROVIDER_ID,
|
|
3142
|
+
category: rowsModule.CUSTOMIZE_ROWS_CATEGORY,
|
|
3143
|
+
rows() {
|
|
3144
|
+
const ctx = hostCtx();
|
|
3145
|
+
// No session ctx means no theme catalogue and no notify channel; an empty
|
|
3146
|
+
// page is the honest answer, and `customizeRows` answers no rows for a
|
|
3147
|
+
// model it cannot read anyway.
|
|
3148
|
+
if (!ctx) return [];
|
|
3149
|
+
return rowsModule.customizeRows({
|
|
3150
|
+
model: () => customizePanelModel(ctx),
|
|
3151
|
+
apply: (choice) => applyCustomizePageChoice(choice, ctx),
|
|
3152
|
+
});
|
|
3153
|
+
},
|
|
3154
|
+
};
|
|
3155
|
+
}
|
|
3156
|
+
|
|
3157
|
+
// The Gentle Shell customize page as a REGISTRATION LIFECYCLE, bound by the
|
|
3158
|
+
// factory beside the command (which is registered there too, unconditionally).
|
|
3159
|
+
// Additive by construction: nothing here can unregister or shadow the command.
|
|
3160
|
+
function registerCustomizePage(pi) {
|
|
3161
|
+
let pageContext = null;
|
|
3162
|
+
let disposePage = null;
|
|
3163
|
+
|
|
3164
|
+
function clearPage() {
|
|
3165
|
+
const dispose = disposePage;
|
|
3166
|
+
disposePage = null;
|
|
3167
|
+
if (typeof dispose !== "function") return;
|
|
3168
|
+
try {
|
|
3169
|
+
dispose();
|
|
3170
|
+
} catch {
|
|
3171
|
+
// The bridge owns its own bus: a disposer that fails cannot make this file
|
|
3172
|
+
// host a second page, so the failure is contained here.
|
|
3173
|
+
}
|
|
3174
|
+
}
|
|
3175
|
+
|
|
3176
|
+
// The one registration path `session_start` and the announce both use, so an
|
|
3177
|
+
// announce and a later session cannot both register and a repeated announce
|
|
3178
|
+
// cannot stack a second provider. A live provider IS the guard: re-registering
|
|
3179
|
+
// would only ask the bus to replace an identical entry.
|
|
3180
|
+
function registerPage() {
|
|
3181
|
+
if (disposePage !== null) return;
|
|
3182
|
+
// No session yet: `session_start` asks again once there is a ctx to build the
|
|
3183
|
+
// model from.
|
|
3184
|
+
if (!pageContext) return;
|
|
3185
|
+
const bridge = publishedBridge();
|
|
3186
|
+
// S2: nothing answered the handshake, so today's command stands alone.
|
|
3187
|
+
if (!bridge) return;
|
|
3188
|
+
const rowsModule = customizeRowsModule();
|
|
3189
|
+
// An install without the sibling lib/ has no page to offer; the command and
|
|
3190
|
+
// every other surface keep working.
|
|
3191
|
+
if (!rowsModule) return;
|
|
3192
|
+
let dispose = null;
|
|
3193
|
+
try {
|
|
3194
|
+
dispose = bridge.registerRows(customizePageProvider(rowsModule, () => pageContext));
|
|
3195
|
+
} catch {
|
|
3196
|
+
// A bus that refuses the provider (a host with no customize menu asks for
|
|
3197
|
+
// nothing else): the command is already registered, so no surface is lost.
|
|
3198
|
+
dispose = null;
|
|
3199
|
+
}
|
|
3200
|
+
if (typeof dispose === "function") disposePage = dispose;
|
|
3201
|
+
}
|
|
3202
|
+
|
|
3203
|
+
// The symbol first: when the bridge is already published there is nothing to
|
|
3204
|
+
// wait for and no listener is taken. Otherwise the announce is the only way a
|
|
3205
|
+
// bridge that loads AFTER this extension is ever heard.
|
|
3206
|
+
const events = pi?.events;
|
|
3207
|
+
if (events && typeof events.on === "function" && !publishedBridge()) {
|
|
3208
|
+
try {
|
|
3209
|
+
events.on(BRIDGE_READY_EVENT, registerPage);
|
|
3210
|
+
} catch {
|
|
3211
|
+
// No bus and no ready event: `session_start` still tries the symbol.
|
|
3212
|
+
}
|
|
3213
|
+
}
|
|
3214
|
+
|
|
3215
|
+
pi.on("session_start", (_event, ctx) => {
|
|
3216
|
+
pageContext = isRecord(ctx) ? ctx : null;
|
|
3217
|
+
registerPage();
|
|
3218
|
+
});
|
|
3219
|
+
|
|
3220
|
+
pi.on("session_shutdown", () => {
|
|
3221
|
+
// The bridge's bus outlives the session, so only the provider is dropped:
|
|
3222
|
+
// the command stays as registered, and the next session adds one page again
|
|
3223
|
+
// instead of stacking a second one.
|
|
3224
|
+
clearPage();
|
|
3225
|
+
pageContext = null;
|
|
3226
|
+
});
|
|
3227
|
+
}
|
|
3228
|
+
|
|
2967
3229
|
export default function (pi) {
|
|
2968
3230
|
// Registered before the pane gate on purpose: the switches are local state and
|
|
2969
|
-
// must stay reachable from a plain Pi session outside a Herdr pane.
|
|
3231
|
+
// must stay reachable from a plain Pi session outside a Herdr pane. S1: this is
|
|
3232
|
+
// unconditional — the page below is additive, never a replacement.
|
|
2970
3233
|
if (typeof pi?.registerCommand === "function") {
|
|
2971
3234
|
pi.registerCommand("herdr-gentle:customize", {
|
|
2972
3235
|
description: "Customize Herdr Gentle Shell: sidebar agent rows, Moshi notifications and the Herdr theme",
|
|
@@ -2975,6 +3238,7 @@ export default function (pi) {
|
|
|
2975
3238
|
},
|
|
2976
3239
|
});
|
|
2977
3240
|
}
|
|
3241
|
+
registerCustomizePage(pi);
|
|
2978
3242
|
if (!enabled()) return;
|
|
2979
3243
|
|
|
2980
3244
|
let rootSession = false;
|
|
@@ -292,6 +292,10 @@ export default function (pi) {
|
|
|
292
292
|
seen.missingTheme = true;
|
|
293
293
|
notify(
|
|
294
294
|
ctx,
|
|
295
|
+
// S4 (odd/tasks/herdr-customize-page.md): `/herdr-gentle:customize`
|
|
296
|
+
// is registered unconditionally, so it is the one surface this notice
|
|
297
|
+
// can name — the Herdr page of Gentle Shell's customize menu sits
|
|
298
|
+
// beside it, never instead of it.
|
|
295
299
|
`The Pi theme "${chosen}" is not installed, so Herdr's palette was left unchanged; pick an installed theme in /herdr-gentle:customize.`,
|
|
296
300
|
);
|
|
297
301
|
}
|
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// The Herdr page of Gentle Shell's own `/gentle:customize` menu
|
|
4
|
+
// (odd/tasks/herdr-customize-page.md T1; specs S1, S3).
|
|
5
|
+
//
|
|
6
|
+
// This module is a PURE TRANSLATION: it reads the customize model the panel
|
|
7
|
+
// already computes (`customizePanelModel` in lib/customize-panel.js) and answers
|
|
8
|
+
// bridge rows for exactly the four options of S1 — `herd agents`, `moshi`,
|
|
9
|
+
// `theme sync`, `select theme` — in that order. It owns no state, reads no file,
|
|
10
|
+
// notifies nobody and reloads nothing: the extension injects `apply`, which is
|
|
11
|
+
// the same choice shape `applyCustomizePanel` accepts, so a row drives the very
|
|
12
|
+
// write path (and therefore the very refusal) the panel and the removed command
|
|
13
|
+
// drive.
|
|
14
|
+
//
|
|
15
|
+
// Two facts about the host decide the shape below, and both were verified against
|
|
16
|
+
// the bridge's own code rather than assumed:
|
|
17
|
+
//
|
|
18
|
+
// 1. The line a user reads is `choice.setting`, NOT `label`: the renderer draws
|
|
19
|
+
// `entry.setting` as the line's name and `choice.value` as each value word
|
|
20
|
+
// (gentle-shell `lib/visual-customize-view.ts:396-404,594`; `docs/contract.md`
|
|
21
|
+
// §4, and the bridge's own toggle rows say so in `src/sections-rows.ts:66-72`
|
|
22
|
+
// — "the id is not a label and never appears here"). So every row of a
|
|
23
|
+
// setting shares the S1 NAME as its `choice.setting`, while the apply path's
|
|
24
|
+
// own setting id (`sidebar`, `moshi`, `theme-sync`, `theme`) rides in the
|
|
25
|
+
// row's closure and is what `apply` receives.
|
|
26
|
+
// 2. The bridge refuses a row whose `label` is not a row name — one to three
|
|
27
|
+
// plain words with no arrow, colon, dot, pipe, slash or bracket
|
|
28
|
+
// (`src/row-names.ts`), and it refuses rather than rewrites. Every label here
|
|
29
|
+
// therefore goes through `rowName()` below, because a host theme name is user
|
|
30
|
+
// data and may freely carry any of those marks.
|
|
31
|
+
//
|
|
32
|
+
// A hidden row is still a row: `visible()` is handed to the host untouched, so
|
|
33
|
+
// the theme rows exist while the sync is on and simply do not show — the honest
|
|
34
|
+
// answer the contract asks for instead of an in-panel refusal.
|
|
35
|
+
//
|
|
36
|
+
// One build is ONE model read (F3). The model the extension hands over runs a
|
|
37
|
+
// synchronous `configure.js --check` subprocess, so a read per callback is
|
|
38
|
+
// unbounded work while the menu opens (41 checks for a 30-theme build, 68 more
|
|
39
|
+
// for the values, ~2.6 s). `customizeRows` therefore takes its snapshot once and
|
|
40
|
+
// every `current()`, `visible()` and `preview()` answers from it; live-ness is
|
|
41
|
+
// across BUILDS, which is exactly what the host does — it rebuilds the rows after
|
|
42
|
+
// every action, and `rows()` calls `customizeRows` again.
|
|
43
|
+
|
|
44
|
+
// The page is a row `category`, never `registerSection`: a section adds a
|
|
45
|
+
// sidebar card, a category is the menu's own page. `Keymaps` is the one
|
|
46
|
+
// reserved category (`src/row-names.ts`) and is never used here.
|
|
47
|
+
const CUSTOMIZE_ROWS_CATEGORY = "Herdr";
|
|
48
|
+
|
|
49
|
+
// The four S1 options, in the order S1 names them, and the panel's own setting
|
|
50
|
+
// ids from the model (`lib/customize-panel.js` `customizePanelModel`). The
|
|
51
|
+
// theme-sync setting lives beside the theme picker in the panel's own category,
|
|
52
|
+
// but S1 puts it third on this page, so the order is stated here instead of
|
|
53
|
+
// inherited from the model's category nesting.
|
|
54
|
+
const SETTINGS = Object.freeze([
|
|
55
|
+
{ id: "sidebar", line: "Herd agents" },
|
|
56
|
+
{ id: "moshi", line: "Moshi" },
|
|
57
|
+
{ id: "theme-sync", line: "Theme sync" },
|
|
58
|
+
]);
|
|
59
|
+
const THEME_SETTING = Object.freeze({ id: "theme", line: "Select theme" });
|
|
60
|
+
|
|
61
|
+
// The theme picker's structural ids, the same ones lib/customize-panel.js and
|
|
62
|
+
// the extension use: `none` is the "no theme assigned" choice and `theme:<name>`
|
|
63
|
+
// a real theme, so an installed theme literally called `None` or `Off` keeps its
|
|
64
|
+
// own option and stays pinnable.
|
|
65
|
+
const THEME_NONE_OPTION_ID = "none";
|
|
66
|
+
const THEME_OPTION_PREFIX = "theme:";
|
|
67
|
+
|
|
68
|
+
// The unassign entry's text and row name. The text is the extension's documented
|
|
69
|
+
// sentinel and deliberately NOT `Off`: `Off` is what the panel paints for a
|
|
70
|
+
// stored `null`, and a Pi theme may legitimately be named `Off`, so reusing that
|
|
71
|
+
// spelling as the sentinel would make such a theme unpinnable. Its row name is
|
|
72
|
+
// its own too (the sentinel text carries a bracket and four words, so it can
|
|
73
|
+
// never be a row name, and clamping it would keep the `Off` spelling).
|
|
74
|
+
const THEME_UNASSIGN_TEXT = "Off (no theme assigned)";
|
|
75
|
+
const THEME_UNASSIGN_LABEL = "No theme assigned";
|
|
76
|
+
|
|
77
|
+
// The bridge's row-name shape (`src/row-names.ts`): at most three words, and
|
|
78
|
+
// none of the marks that make a name read as a path, a key or a breadcrumb.
|
|
79
|
+
const ROW_NAME_MAX_WORDS = 3;
|
|
80
|
+
const ROW_NAME_MARKS = Object.freeze([
|
|
81
|
+
"\u2192", "\u2190", "\u2191", "\u2193", ":", ".", "|", "/", "\\", "[", "]", "(", ")", "{", "}",
|
|
82
|
+
]);
|
|
83
|
+
|
|
84
|
+
// THE label rule. `text` is the thing the row names (a value's word, a theme's
|
|
85
|
+
// name); the answer is a name the bridge accepts, or `null` when nothing usable
|
|
86
|
+
// survived. Every mark becomes a word break, along with any other punctuation
|
|
87
|
+
// (`-` and `_` are word characters and stay, so `one-dark` is one word), runs of
|
|
88
|
+
// space collapse, and the first three words are kept. The exact string is never
|
|
89
|
+
// rewritten in a name: a theme's real name rides in its option id
|
|
90
|
+
// (`theme:<name>`) and in the value the host prints, so a row still applies —
|
|
91
|
+
// and shows — precisely the theme it names.
|
|
92
|
+
function rowName(text) {
|
|
93
|
+
if (typeof text !== "string") return null;
|
|
94
|
+
const broken = text.split("").map((char) => (ROW_NAME_MARKS.includes(char) ? " " : char)).join("");
|
|
95
|
+
const words = broken.replace(/[^\p{L}\p{N}_-]+/gu, " ").trim().split(/\s+/).filter((word) => word.length > 0);
|
|
96
|
+
return words.length > 0 ? words.slice(0, ROW_NAME_MAX_WORDS).join(" ") : null;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// One build is ONE model read, and a synchronous paint burst is one more at
|
|
100
|
+
// most. The model the extension hands over runs a synchronous
|
|
101
|
+
// `configure.js --check` subprocess, so a read per callback is unbounded work
|
|
102
|
+
// while the menu opens (the verifier measured 41 checks for a 30-theme build plus
|
|
103
|
+
// 68 more for the values, ~2.6 s).
|
|
104
|
+
//
|
|
105
|
+
// The freshness rule is NOT "one snapshot per build". The host does not rebuild
|
|
106
|
+
// the row objects after an action: Gentle Shell's VisualCustomizeView repaints the
|
|
107
|
+
// rows it already holds and calls `choice.current()` and the visibility gate again
|
|
108
|
+
// on the SAME objects (`lib/visual-customize-view.ts:224-231`, `:391-392`). So the
|
|
109
|
+
// snapshot is a CACHE WITH EXPLICIT INVALIDATION: it is dropped whenever an
|
|
110
|
+
// `apply` settles, which is the only moment the stored state can have changed
|
|
111
|
+
// because of this page, and a short TTL covers the reads that arrive while nothing
|
|
112
|
+
// was applied.
|
|
113
|
+
|
|
114
|
+
// How long one snapshot serves repeated reads (milliseconds). Two facts decide it:
|
|
115
|
+
//
|
|
116
|
+
// - A paint burst is synchronous — the host evaluates every `current()`, gate and
|
|
117
|
+
// swatch of the page in one tick — so the cache is what makes a burst cost ONE
|
|
118
|
+
// `--check` instead of ~109.
|
|
119
|
+
// - The arrows only move the cursor (the bridge stages `applyOnMove: false`), so
|
|
120
|
+
// repaints arrive on a human key cadence: one second covers consecutive presses
|
|
121
|
+
// while still noticing a change written by someone else (another process
|
|
122
|
+
// touching the theme store or the managed config) within a second.
|
|
123
|
+
//
|
|
124
|
+
// The TTL is NOT the correctness mechanism: what must be fresh is the state an
|
|
125
|
+
// `apply` produced, and that is `invalidate()` below, never a timer.
|
|
126
|
+
//
|
|
127
|
+
// Two consequences of a FIXED row set repainted on input are ACCEPTED, not fixed,
|
|
128
|
+
// and they are stated here because they follow from this cache by construction:
|
|
129
|
+
//
|
|
130
|
+
// - An external write while the menu is idle becomes visible on the first read
|
|
131
|
+
// after the cache expires, or on a rebuild. The cache never asks the host to
|
|
132
|
+
// repaint, so a repaint that lands before expiry redraws the previous model
|
|
133
|
+
// and the displayed state has no upper freshness bound — on a menu nobody
|
|
134
|
+
// touches the change is not visible at all. That is what buys one `--check`
|
|
135
|
+
// per burst instead of ~109 of them.
|
|
136
|
+
// - If an external write hides the row the user had focused (the theme picker,
|
|
137
|
+
// when the sync is turned on from another process), nothing can keep the cursor
|
|
138
|
+
// on a row that is no longer there: the HOST clamps the focus to the
|
|
139
|
+
// neighbouring row, so Enter acts on that neighbour. The clamp itself writes
|
|
140
|
+
// nothing — the cursor moved, no action ran.
|
|
141
|
+
//
|
|
142
|
+
// Neither is a correctness hole in the stored state: the write a row performs is
|
|
143
|
+
// always checked against a FRESH read of what it writes (a theme name against the
|
|
144
|
+
// host catalogue on the page's own apply path, a switch against its own stored
|
|
145
|
+
// state).
|
|
146
|
+
const MODEL_CACHE_TTL_MS = 1000;
|
|
147
|
+
|
|
148
|
+
// The model is resolved through this cache, never directly by a callback. A
|
|
149
|
+
// function is accepted because the extension's natural source is
|
|
150
|
+
// `() => customizePanelModel(ctx)`; a missing or unreadable model answers no rows
|
|
151
|
+
// instead of throwing.
|
|
152
|
+
function readModel(model) {
|
|
153
|
+
let value = model;
|
|
154
|
+
if (typeof model === "function") {
|
|
155
|
+
try {
|
|
156
|
+
value = model();
|
|
157
|
+
} catch {
|
|
158
|
+
return [];
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return Array.isArray(value) ? value : [];
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function createModelCache(model) {
|
|
165
|
+
let snapshot = null;
|
|
166
|
+
let expiresAt = 0;
|
|
167
|
+
return {
|
|
168
|
+
read() {
|
|
169
|
+
if (snapshot !== null && Date.now() < expiresAt) return snapshot;
|
|
170
|
+
snapshot = readModel(model);
|
|
171
|
+
expiresAt = Date.now() + MODEL_CACHE_TTL_MS;
|
|
172
|
+
return snapshot;
|
|
173
|
+
},
|
|
174
|
+
// Called when an `apply` settles (resolved OR refused): the host repaints the
|
|
175
|
+
// same rows immediately afterwards, and that repaint must read what the apply
|
|
176
|
+
// wrote. A refusal writes nothing, so dropping the cache is only an extra read.
|
|
177
|
+
invalidate() {
|
|
178
|
+
snapshot = null;
|
|
179
|
+
expiresAt = 0;
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function findSetting(rows, settingId) {
|
|
185
|
+
for (const category of rows) {
|
|
186
|
+
const settings = category && Array.isArray(category.settings) ? category.settings : [];
|
|
187
|
+
for (const setting of settings) {
|
|
188
|
+
if (setting && setting.id === settingId) return setting;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function findOption(rows, settingId, optionId) {
|
|
195
|
+
const setting = findSetting(rows, settingId);
|
|
196
|
+
const options = setting && Array.isArray(setting.options) ? setting.options : [];
|
|
197
|
+
for (const option of options) {
|
|
198
|
+
if (option && option.id === optionId) return option;
|
|
199
|
+
}
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// The option ids in the model's own order: this is what makes one row per value,
|
|
204
|
+
// with the structural ids the panel and the fallback menu already apply.
|
|
205
|
+
function optionIds(rows, settingId) {
|
|
206
|
+
const setting = findSetting(rows, settingId);
|
|
207
|
+
const options = setting && Array.isArray(setting.options) ? setting.options : [];
|
|
208
|
+
return options
|
|
209
|
+
.filter((option) => option && typeof option.id === "string")
|
|
210
|
+
.map((option) => option.id);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// The stored value, read from the snapshot. An option the model no longer lists
|
|
214
|
+
// (or a state the model could not read, which marks NO option current) is never
|
|
215
|
+
// a guess.
|
|
216
|
+
function isCurrent(rows, settingId, optionId) {
|
|
217
|
+
const option = findOption(rows, settingId, optionId);
|
|
218
|
+
return option !== null && option.current === true;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// S3: the picker is only available while the stored sync is off. A store the
|
|
222
|
+
// model could not read is not "sync on", so it hides nothing.
|
|
223
|
+
function themeSyncOn(rows) {
|
|
224
|
+
return isCurrent(rows, "theme-sync", "on");
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// The word the host prints for one value. The model's own label is reused
|
|
228
|
+
// (`On`, `Off`, the theme's name); the unassign entry keeps the extension's
|
|
229
|
+
// sentinel text instead of the panel's short `None`, because the bridge page has
|
|
230
|
+
// no note line to explain it.
|
|
231
|
+
function valueText(option, optionId) {
|
|
232
|
+
if (option && typeof option.label === "string" && option.label.length > 0) return option.label;
|
|
233
|
+
if (optionId.startsWith(THEME_OPTION_PREFIX)) return optionId.slice(THEME_OPTION_PREFIX.length);
|
|
234
|
+
return optionId;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// S6's swatch, resolved from the model's optional preview source: the model may
|
|
238
|
+
// carry the read-only `{ title, sample }` pair or the factory that produces it.
|
|
239
|
+
// Anything unreadable — a throw, a missing source, a pair of the wrong shape —
|
|
240
|
+
// answers `undefined`, which the host paints as `Preview unavailable` instead of
|
|
241
|
+
// the row ever breaking.
|
|
242
|
+
function optionPreview(rows, settingId, optionId) {
|
|
243
|
+
const option = findOption(rows, settingId, optionId);
|
|
244
|
+
if (!option) return undefined;
|
|
245
|
+
let value = option.preview;
|
|
246
|
+
if (typeof value === "function") {
|
|
247
|
+
try {
|
|
248
|
+
value = value();
|
|
249
|
+
} catch {
|
|
250
|
+
return undefined;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
if (!value || typeof value !== "object") return undefined;
|
|
254
|
+
const { title, sample } = value;
|
|
255
|
+
if (typeof title !== "string" || typeof sample !== "string") return undefined;
|
|
256
|
+
return { title, sample };
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// The one write a row can cause. `apply` is the extension's injected async
|
|
260
|
+
// function (the `{ settingId, optionId }` shape `applyCustomizePanel` accepts)
|
|
261
|
+
// and it is awaited with the row's own setting and option and NOTHING else: the
|
|
262
|
+
// inline helpers the host hands to `action` are not forwarded, so a row cannot
|
|
263
|
+
// open a dialog the apply path does not own. A rejection is never caught here —
|
|
264
|
+
// the bridge turns a throw into the user-visible refusal and records it, so
|
|
265
|
+
// swallowing it (or notifying) would hide the only channel the user has. The
|
|
266
|
+
// cache is dropped in `finally`, because the host's repaint of the SAME rows
|
|
267
|
+
// follows either way.
|
|
268
|
+
async function dispatch(cache, apply, settingId, optionId) {
|
|
269
|
+
try {
|
|
270
|
+
await apply({ settingId, optionId });
|
|
271
|
+
} finally {
|
|
272
|
+
cache.invalidate();
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function toggleRow(cache, apply, setting, optionId) {
|
|
277
|
+
const option = findOption(cache.read(), setting.id, optionId);
|
|
278
|
+
const text = valueText(option, optionId);
|
|
279
|
+
return {
|
|
280
|
+
category: CUSTOMIZE_ROWS_CATEGORY,
|
|
281
|
+
// A row name, never the value word it happens to sit beside.
|
|
282
|
+
label: rowName(text) ?? setting.line,
|
|
283
|
+
choice: {
|
|
284
|
+
// The line's NAME, shared by every value of this setting, so the host
|
|
285
|
+
// draws one line and ←/→ walks its values (Enter applies: the bridge
|
|
286
|
+
// stages `applyOnMove: false` on every row it contributes).
|
|
287
|
+
setting: setting.line,
|
|
288
|
+
value: text,
|
|
289
|
+
current: () => isCurrent(cache.read(), setting.id, optionId),
|
|
290
|
+
},
|
|
291
|
+
action: () => dispatch(cache, apply, setting.id, optionId),
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// The unassign entry's printed text, disambiguated against the installed themes
|
|
296
|
+
// exactly like the command's own picker does (`themeSelectionOptions` in
|
|
297
|
+
// extensions/gentle-herdr-state.ts): a theme literally named
|
|
298
|
+
// `Off (no theme assigned)` would otherwise give the page two rows whose value
|
|
299
|
+
// word is identical while their option ids differ — one pins that theme, the
|
|
300
|
+
// other clears the pin. The suffix moves the UNASSIGN entry, never a theme: a
|
|
301
|
+
// theme's text is the name its row applies, so the page still shows it verbatim.
|
|
302
|
+
function unassignText(rows) {
|
|
303
|
+
const texts = [];
|
|
304
|
+
for (const optionId of optionIds(rows, THEME_SETTING.id)) {
|
|
305
|
+
if (optionId === THEME_NONE_OPTION_ID) continue;
|
|
306
|
+
texts.push(valueText(findOption(rows, THEME_SETTING.id, optionId), optionId));
|
|
307
|
+
}
|
|
308
|
+
let text = THEME_UNASSIGN_TEXT;
|
|
309
|
+
let attempt = 2;
|
|
310
|
+
while (texts.includes(text)) {
|
|
311
|
+
text = `${THEME_UNASSIGN_TEXT} ${attempt}`;
|
|
312
|
+
attempt += 1;
|
|
313
|
+
}
|
|
314
|
+
return text;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function themeRow(cache, apply, optionId, index, noneText) {
|
|
318
|
+
const option = findOption(cache.read(), THEME_SETTING.id, optionId);
|
|
319
|
+
const isNone = optionId === THEME_NONE_OPTION_ID;
|
|
320
|
+
const text = isNone ? noneText : valueText(option, optionId);
|
|
321
|
+
return {
|
|
322
|
+
category: CUSTOMIZE_ROWS_CATEGORY,
|
|
323
|
+
// The unassign entry's name is its own; a theme is named after itself (its
|
|
324
|
+
// marks already turned into word breaks), and a name that survives as no
|
|
325
|
+
// word at all still gets a legal, distinguishable one — the exact theme is
|
|
326
|
+
// in the option id either way.
|
|
327
|
+
label: isNone ? THEME_UNASSIGN_LABEL : (rowName(text) ?? `Theme ${index + 1}`),
|
|
328
|
+
choice: {
|
|
329
|
+
setting: THEME_SETTING.line,
|
|
330
|
+
value: text,
|
|
331
|
+
current: () => isCurrent(cache.read(), THEME_SETTING.id, optionId),
|
|
332
|
+
},
|
|
333
|
+
// The theme's own swatch, read from the model's preview source.
|
|
334
|
+
preview: () => optionPreview(cache.read(), THEME_SETTING.id, optionId),
|
|
335
|
+
// Present while the sync is off, hidden while it is on — and the answer is
|
|
336
|
+
// re-read on every repaint, so turning the sync on hides the picker on the
|
|
337
|
+
// rows the host already mounted.
|
|
338
|
+
visible: () => !themeSyncOn(cache.read()),
|
|
339
|
+
action: () => dispatch(cache, apply, THEME_SETTING.id, optionId),
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// The page's rows: the three switches in S1 order, then the theme picker. The
|
|
344
|
+
// cache starts cold, so a build is one model read; the values the host paints
|
|
345
|
+
// afterwards are served by it until an apply settles or the TTL runs out.
|
|
346
|
+
function customizeRows({ model, apply } = {}) {
|
|
347
|
+
const cache = createModelCache(model);
|
|
348
|
+
const rows = cache.read();
|
|
349
|
+
const built = [];
|
|
350
|
+
for (const setting of SETTINGS) {
|
|
351
|
+
for (const optionId of optionIds(rows, setting.id)) {
|
|
352
|
+
built.push(toggleRow(cache, apply, setting, optionId));
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
const noneText = unassignText(rows);
|
|
356
|
+
optionIds(rows, THEME_SETTING.id).forEach((optionId, index) => {
|
|
357
|
+
built.push(themeRow(cache, apply, optionId, index, noneText));
|
|
358
|
+
});
|
|
359
|
+
return built;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
module.exports = {
|
|
363
|
+
CUSTOMIZE_ROWS_CATEGORY,
|
|
364
|
+
MODEL_CACHE_TTL_MS,
|
|
365
|
+
customizeRows,
|
|
366
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "herdr-gentle-shell",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"description": "Pi package for Herdr sidebar states: the Pi extension sidecar that publishes session facts as Herdr pane-metadata tokens, the optional Moshi notification channel, and the Pi-side helpers the Herdr Gentle Shell plugin drives.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|