From 530b95c7fca43887ee72c961b2e5a3981c91a7fb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9s=20De=20Freitas?=
<6485562+adefreitas@users.noreply.github.com>
Date: Tue, 1 Dec 2026 13:24:18 +0000
Subject: [PATCH 1/4] feat(extensions): a calendar capability for trusted
extensions
---
.../ExtensionCatalogTests.swift | 4 ++++
.../ExtensionManifestTests.swift | 2 +-
.../ExtensionSettingsPageTests.swift | 1 +
.../StackNudgePanelCoreTests/ExtensionTierTests.swift | 10 ++++++++++
docs/design/service-extensions.md | 6 +++---
docs/extensions.md | 6 +++---
panel/ExtensionManifest.swift | 7 ++++---
panel/ExtensionTier.swift | 2 +-
panel/Info.plist | 6 +++++-
panel/PanelNav.swift | 2 ++
panel/entitlements.plist | 7 +++++++
11 files changed, 41 insertions(+), 12 deletions(-)
diff --git a/Tests/StackNudgePanelCoreTests/ExtensionCatalogTests.swift b/Tests/StackNudgePanelCoreTests/ExtensionCatalogTests.swift
index 2d64667e..141b043e 100644
--- a/Tests/StackNudgePanelCoreTests/ExtensionCatalogTests.swift
+++ b/Tests/StackNudgePanelCoreTests/ExtensionCatalogTests.swift
@@ -884,6 +884,10 @@ final class ExtensionCatalogTests: XCTestCase {
XCTAssertEqual(ExtensionCatalog.confirmationText(for: tiered("service",
capabilities: ["bluetooth", "event:idle"])),
"Runs in the background. Asks for: knowing how long the Mac has been idle. " + again)
+ XCTAssertEqual(ExtensionCatalog.confirmationText(for: tiered("trusted", capabilities: ["calendar"])),
+ "Runs in the background. Asks for: reading your calendar. " + again)
+ XCTAssertEqual(ExtensionCatalog.confirmationText(for: tiered("service", capabilities: ["calendar"])),
+ "Runs in the background. " + again)
// A view extension is granted nothing and doesn't run in the background.
XCTAssertEqual(ExtensionCatalog.confirmationText(for: tiered("trusted", capabilities: ["bluetooth"],
mode: "view")), again)
diff --git a/Tests/StackNudgePanelCoreTests/ExtensionManifestTests.swift b/Tests/StackNudgePanelCoreTests/ExtensionManifestTests.swift
index d65cce76..4e6c61d3 100644
--- a/Tests/StackNudgePanelCoreTests/ExtensionManifestTests.swift
+++ b/Tests/StackNudgePanelCoreTests/ExtensionManifestTests.swift
@@ -444,7 +444,7 @@ final class ExtensionManifestTests: XCTestCase {
// Every capability the host knows, by the name a manifest uses for it.
func testEveryKnownCapabilityIsAccepted() {
- let names = ["bluetooth", "signal:presence", "event:idle", "event:panel",
+ let names = ["bluetooth", "calendar", "signal:presence", "event:idle", "event:panel",
"event:session", "event:nudge", "feed", "mcp", "event:settings"]
let list = names.map { "\"\($0)\"" }.joined(separator: ",")
guard case .success(let m) = service(#","mode":"service","capabilities":["# + list + "]")
diff --git a/Tests/StackNudgePanelCoreTests/ExtensionSettingsPageTests.swift b/Tests/StackNudgePanelCoreTests/ExtensionSettingsPageTests.swift
index d1e46abf..124eebf3 100644
--- a/Tests/StackNudgePanelCoreTests/ExtensionSettingsPageTests.swift
+++ b/Tests/StackNudgePanelCoreTests/ExtensionSettingsPageTests.swift
@@ -637,6 +637,7 @@ final class ExtensionSettingsPageTests: XCTestCase {
func testCapabilitiesReadInPlainWords() {
XCTAssertEqual(ExtensionCapability.bluetooth.plainWords, "Bluetooth")
+ XCTAssertEqual(ExtensionCapability.calendar.plainWords, "Read your calendar")
XCTAssertEqual(ExtensionCapability.signalPresence.plainWords, "Lock the Mac when you're away")
for capability in ExtensionCapability.allCases {
XCTAssertFalse(capability.plainWords.contains(":"), "\(capability) reads as a key")
diff --git a/Tests/StackNudgePanelCoreTests/ExtensionTierTests.swift b/Tests/StackNudgePanelCoreTests/ExtensionTierTests.swift
index bfab97ad..f2ba552a 100644
--- a/Tests/StackNudgePanelCoreTests/ExtensionTierTests.swift
+++ b/Tests/StackNudgePanelCoreTests/ExtensionTierTests.swift
@@ -34,6 +34,16 @@ final class ExtensionTierTests: XCTestCase {
ExtensionCapability.allCases)
}
+ // Reading the calendar is a hardware capability: trusted only.
+ func testOnlyATrustedExtensionIsGrantedTheCalendar() {
+ let manifest = service(["calendar", "event:idle"])
+ XCTAssertEqual(ExtensionTier.grants(for: manifest, tier: .trusted), [.calendar, .eventIdle])
+ XCTAssertEqual(ExtensionTier.grants(for: manifest, tier: .service), [.eventIdle])
+ XCTAssertEqual(ExtensionTier.grants(for: manifest, tier: .view), [])
+ XCTAssertFalse(ExtensionTier.service.allows(.calendar))
+ XCTAssertTrue(ExtensionTier.trusted.allows(.calendar))
+ }
+
// A tier is a ceiling, not a gift: nothing undeclared is granted.
func testNothingUndeclaredIsGranted() {
XCTAssertEqual(ExtensionTier.grants(for: service(["event:idle"]), tier: .trusted), [.eventIdle])
diff --git a/docs/design/service-extensions.md b/docs/design/service-extensions.md
index f3bd257f..e3375a04 100644
--- a/docs/design/service-extensions.md
+++ b/docs/design/service-extensions.md
@@ -82,7 +82,7 @@ What the bump touches:
- `mode`: `"view"` (the default, today's behaviour) or `"service"`.
- `capabilities`: what the extension asks the app for. The app can only
*enforce* what passes through it (signals, events, feed events), and it refuses
- those unless declared and granted. Hardware capabilities such as `bluetooth` are
+ those unless declared and granted. Hardware capabilities such as `bluetooth` and `calendar` are
declarations for review and for the install prompt, not a gate: a child process
inherits the app's TCC access whether it declared it or not (docs/extensions.md,
Trust). See [Privilege tiers](#privilege-tiers).
@@ -250,7 +250,7 @@ decides which it **asks for**.
|---|---|---|
| **view** | any curated extension | today's view mode only |
| **service** | curated extensions flagged `service` in the index | service mode, `event:idle`, `event:panel`, `feed` |
-| **trusted** | first-party extensions flagged `trusted` in the index | also `signal:*`, `event:session`, `event:nudge`, and hardware capabilities (`bluetooth`) |
+| **trusted** | first-party extensions flagged `trusted` in the index | also `signal:*`, `event:session`, `event:nudge`, and hardware capabilities (`bluetooth`, `calendar`) |
The tier comes from the **index**, not the manifest, so an extension can't
promote itself. The host records the tier at install, in a host-owned file under
@@ -264,7 +264,7 @@ capabilities (the tier itself isn't shown). Installing one that asks for more th
for and needs confirming.
Hardware capabilities need the app's Info.plist to carry the usage string, as
-`NSBluetoothAlwaysUsageDescription` does on the prototype branch. We add those
+`NSBluetoothAlwaysUsageDescription` and `NSCalendarsFullAccessUsageDescription` do. We add those
one at a time, deliberately, and the app asks for the permission only when the
first extension holding that capability starts.
diff --git a/docs/extensions.md b/docs/extensions.md
index 65de3920..c53e9cc8 100644
--- a/docs/extensions.md
+++ b/docs/extensions.md
@@ -485,7 +485,7 @@ adding a catalogue to that list is a change to the app.
A tier is how far the app trusts an extension: `view`, `service` or `trusted`.
The manifest says what an extension asks for; the tier says what it can have.
A service extension needs at least `service`, and `trusted` adds signals and
-hardware capabilities such as `bluetooth`. The full table is in the design
+hardware capabilities such as `bluetooth` and `calendar`. The full table is in the design
note, under "Privilege tiers".
The tier is the reviewers' call, not the extension's, so it lives outside the
@@ -498,7 +498,7 @@ package, in the catalogue's `extensions/tiers.json`:
Anything not listed is `view`. Validation refuses a `tiers.json` naming an
extension that doesn't exist or a tier that isn't one of the three, and an
extension asking for something its tier can't grant: a service at `view`, or
-`bluetooth` at `service`.
+`bluetooth` or `calendar` at `service`.
The packager folds it into each index entry as `"tier"`. Hosts that predate
tiers ignore the field. A newer host records it in
@@ -588,7 +588,7 @@ list. Top to bottom it shows:
load, say), the row sits on the Extensions list instead, so the toggle
exists whenever something can lock the screen;
- read-only lines saying what it was **allowed** (its granted capabilities, in
- plain words: "Bluetooth", "Lock the Mac when you're away") and, when it also
+ plain words: "Bluetooth", "Read your calendar", "Lock the Mac when you're away") and, when it also
has a tab, "Also a tab · ⌘3";
- **Update to x.y**, only when there is one, and **Remove**. Remove takes `⌘⌫`
(not `⏎`, since it has no confirmation), which also removes from the
diff --git a/panel/ExtensionManifest.swift b/panel/ExtensionManifest.swift
index 21d4c9ab..82041e40 100644
--- a/panel/ExtensionManifest.swift
+++ b/panel/ExtensionManifest.swift
@@ -660,11 +660,12 @@ enum ConfigKind: Equatable {
// What an extension may ask the app for. The app can only enforce what passes
// through it (signals, events and feed events) and refuses those unless they
-// were granted. `bluetooth` is a declaration for review and the install prompt,
-// not a gate: a child process inherits the app's TCC access whether it declared
-// it or not.
+// were granted. `bluetooth` and `calendar` are declarations for review and the
+// install prompt, not a gate: a child process inherits the app's TCC access
+// whether it declared it or not.
enum ExtensionCapability: String, CaseIterable, Equatable {
case bluetooth
+ case calendar
case signalPresence = "signal:presence"
case eventIdle = "event:idle"
case eventPanel = "event:panel"
diff --git a/panel/ExtensionTier.swift b/panel/ExtensionTier.swift
index c5aa640a..8a4d802a 100644
--- a/panel/ExtensionTier.swift
+++ b/panel/ExtensionTier.swift
@@ -26,7 +26,7 @@ enum ExtensionTier: String, Comparable, CaseIterable {
switch capability {
case .eventIdle, .eventPanel, .feed, .mcp, .eventSettings:
return self >= .service
- case .signalPresence, .eventSession, .eventNudge, .bluetooth:
+ case .signalPresence, .eventSession, .eventNudge, .bluetooth, .calendar:
return self >= .trusted
}
}
diff --git a/panel/Info.plist b/panel/Info.plist
index fa701eae..cc3017ee 100644
--- a/panel/Info.plist
+++ b/panel/Info.plist
@@ -26,7 +26,11 @@
alert
NSBluetoothAlwaysUsageDescription
StackNudge listens for your phone's Bluetooth signal to tell when you've stepped away from your Mac, if you install the Away extension.
+ NSCalendarsFullAccessUsageDescription
+ StackNudge reads your calendar on this Mac to remind you before meetings, if you install the Meetings extension. Nothing leaves your Mac.
+ NSCalendarsUsageDescription
+ StackNudge reads your calendar on this Mac to remind you before meetings, if you install the Meetings extension. Nothing leaves your Mac.
NSAppleEventsUsageDescription
- StackNudge uses System Events to focus the correct window when you act on a notification.
+ StackNudge uses System Events to focus the correct window when you act on a notification, and, if the Meetings extension's join detection is on, reads the open tab addresses of your browser to see whether you have joined a meeting.
diff --git a/panel/PanelNav.swift b/panel/PanelNav.swift
index e3b63c5e..6f1064de 100644
--- a/panel/PanelNav.swift
+++ b/panel/PanelNav.swift
@@ -3085,6 +3085,7 @@ extension ExtensionCapability {
var plainWords: String {
switch self {
case .bluetooth: return "Bluetooth"
+ case .calendar: return "Read your calendar"
case .signalPresence: return "Lock the Mac when you're away"
case .eventIdle: return "Know how long the Mac has been idle"
case .eventPanel: return "Know when the panel opens"
@@ -3100,6 +3101,7 @@ extension ExtensionCapability {
var askingWords: String {
switch self {
case .bluetooth: return "Bluetooth"
+ case .calendar: return "reading your calendar"
case .signalPresence: return "locking the Mac when you're away"
case .eventIdle: return "knowing how long the Mac has been idle"
case .eventPanel: return "knowing when the panel opens"
diff --git a/panel/entitlements.plist b/panel/entitlements.plist
index 420db393..3edfebdb 100644
--- a/panel/entitlements.plist
+++ b/panel/entitlements.plist
@@ -52,5 +52,12 @@
-->
com.apple.security.automation.apple-events
+
+
+ com.apple.security.personal-information.calendars
+
From 4c439fe11338228b31cfd8e417c25f1f73537ba8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9s=20De=20Freitas?=
<6485562+adefreitas@users.noreply.github.com>
Date: Tue, 1 Dec 2026 17:04:50 +0000
Subject: [PATCH 2/4] feat(extensions): multi-select config keys
---
.../ExtensionHostServiceTests.swift | 16 +-
.../ExtensionSettingsPageTests.swift | 196 +++++++++++++++++-
docs/design/service-extensions.md | 8 +-
docs/extensions.md | 18 +-
docs/panel.md | 2 +-
panel/ExtensionConfigValue.swift | 84 ++++++++
panel/ExtensionHost.swift | 5 +
panel/ExtensionManifest.swift | 37 +++-
panel/Panel.swift | 43 +++-
panel/PanelNav.swift | 58 ++++++
panel/Settings.swift | 55 ++++-
11 files changed, 501 insertions(+), 21 deletions(-)
diff --git a/Tests/StackNudgePanelCoreTests/ExtensionHostServiceTests.swift b/Tests/StackNudgePanelCoreTests/ExtensionHostServiceTests.swift
index d48229bb..6a891ccc 100644
--- a/Tests/StackNudgePanelCoreTests/ExtensionHostServiceTests.swift
+++ b/Tests/StackNudgePanelCoreTests/ExtensionHostServiceTests.swift
@@ -459,7 +459,8 @@ final class ExtensionHostServiceTests: XCTestCase {
{"id":"away","name":"Away","version":"1","schema":2,"mode":"service",
"surfaces":["settings"],"glance":true,
"config":[{"key":"STACKNUDGE_EXT_AWAY_PHONE","type":"dynamic"},
- {"key":"STACKNUDGE_EXT_AWAY_IDLE","type":"number","options":[10,30]}]}
+ {"key":"STACKNUDGE_EXT_AWAY_IDLE","type":"number","options":[10,30]},
+ {"key":"STACKNUDGE_EXT_AWAY_CALS","type":"dynamic","multiple":true}]}
""".utf8)) else { fatalError("fixture manifest didn't parse") }
return m
}
@@ -505,6 +506,19 @@ final class ExtensionHostServiceTests: XCTestCase {
XCTAssertEqual(host.choices, [:])
}
+ // A multiple key stores its values joined with a comma, so a choices
+ // message offering a value with one is refused whole.
+ func testChoicesForAMultipleKeyWithACommaAreRefusedWhole() {
+ tiers = ["away": .service]
+ let host = host()
+ host.load(.init(installed: [settingsOnly()]))
+ spawner.last.ready()
+ spawner.last.say(#"{"type":"choices","key":"STACKNUDGE_EXT_AWAY_CALS","options":[{"value":"Work","label":"Work"},{"value":"a,b","label":"a,b"}]}"#)
+ XCTAssertEqual(host.choices, [:])
+ spawner.last.say(#"{"type":"choices","key":"STACKNUDGE_EXT_AWAY_CALS","options":[{"value":"Work","label":"Work"}]}"#)
+ XCTAssertEqual(host.choices["away"]?["STACKNUDGE_EXT_AWAY_CALS"]?.map(\.value), ["Work"])
+ }
+
func testQuittingStopsEveryServiceAndStartsNothingAfter() {
tiers = ["away": .service, "radar": .service]
let host = host()
diff --git a/Tests/StackNudgePanelCoreTests/ExtensionSettingsPageTests.swift b/Tests/StackNudgePanelCoreTests/ExtensionSettingsPageTests.swift
index 124eebf3..0adc8d5b 100644
--- a/Tests/StackNudgePanelCoreTests/ExtensionSettingsPageTests.swift
+++ b/Tests/StackNudgePanelCoreTests/ExtensionSettingsPageTests.swift
@@ -149,8 +149,8 @@ final class ExtensionSettingsPageTests: XCTestCase {
// Away installed, its page open through the real way in: the Extensions
// list's row, then ⏎.
private func nav(saved: [String: String] = [:], holder: String? = nil,
- available: String? = nil) -> PanelNav {
- guard let m = manifest(typed) else { fatalError("fixture manifest didn't parse") }
+ available: String? = nil, config: String? = nil) -> PanelNav {
+ guard let m = manifest(config ?? typed) else { fatalError("fixture manifest didn't parse") }
let nav = PanelNav()
nav.persistExtensionValue = { [unowned self] key, value in self.written.append((key, value)) }
nav.onExtensionConfigChanged = { [unowned self] id in self.changed.append(id) }
@@ -612,6 +612,198 @@ final class ExtensionSettingsPageTests: XCTestCase {
backTo: "Extensions", editingText: true).map(\.label), ["Save"])
}
+ // MARK: - Multiple keys
+
+ private let multiple = #"""
+ "config":[
+ {"key":"STACKNUDGE_EXT_CAL","type":"dynamic","multiple":true,"label":"Calendars"},
+ {"key":"STACKNUDGE_EXT_TAGS","type":"choice","multiple":true,"default":"a,b",
+ "options":[{"value":"a","label":"Alpha"},{"value":"b","label":"Beta"},{"value":"c","label":"Gamma"}]}]
+ """#
+ private let cal = "STACKNUDGE_EXT_CAL"
+ private let tags = "STACKNUDGE_EXT_TAGS"
+
+ private func offer(_ nav: PanelNav, _ values: [String]) {
+ nav.extensionChoices = ["away": [cal: values.map { ConfigOption(value: $0, label: $0.uppercased()) }]]
+ }
+
+ func testMultipleParsesOnChoiceAndDynamicOnly() {
+ guard let m = manifest(multiple) else { return }
+ XCTAssertEqual(m.config.map(\.multiple), [true, true])
+ XCTAssertEqual(m.config[1].defaultValue, "a,b")
+ func config(_ entry: String) -> String? { refusal(#""config":["# + entry + "]") }
+ for type in ["text", "toggle"] {
+ XCTAssertEqual(config(#"{"key":"STACKNUDGE_EXT_A","type":"\#(type)","multiple":true}"#),
+ #"config key "STACKNUDGE_EXT_A" is type "\#(type)", which can't be multiple"#)
+ }
+ XCTAssertNotNil(config(#"{"key":"STACKNUDGE_EXT_A","type":"number","options":[1,2],"multiple":true}"#))
+ XCTAssertNotNil(config(#"{"key":"STACKNUDGE_EXT_A","multiple":true}"#), "an untyped key is text")
+ XCTAssertNil(config(#"{"key":"STACKNUDGE_EXT_A","type":"toggle","multiple":false}"#))
+ XCTAssertNotNil(config(#"{"key":"STACKNUDGE_EXT_A","type":"dynamic","multiple":"yes"}"#))
+ }
+
+ func testAMultipleOptionValueCannotContainAComma() {
+ XCTAssertNotNil(refusal(#""config":[{"key":"STACKNUDGE_EXT_A","type":"choice","multiple":true,"options":[{"value":"a,b","label":"x"}]}]"#))
+ XCTAssertNil(refusal(#""config":[{"key":"STACKNUDGE_EXT_A","type":"choice","options":[{"value":"a,b","label":"x"}]}]"#),
+ "a single choice may")
+ }
+
+ func testAMultipleDefaultMustBeASubsetOfItsOptions() {
+ func config(_ def: String) -> String? {
+ refusal(#""config":[{"key":"STACKNUDGE_EXT_A","type":"choice","multiple":true,"default":"\#(def)","options":[{"value":"a","label":"A"},{"value":"b","label":"B"}]}]"#)
+ }
+ XCTAssertNil(config("a"))
+ XCTAssertNil(config("b,a"))
+ XCTAssertNotNil(config("a,z"))
+ XCTAssertNotNil(config(","))
+ }
+
+ func testAMultipleKeyRoundTripsThroughTheIndex() throws {
+ guard let m = manifest(multiple) else { return }
+ let data = try JSONEncoder().encode(m.config)
+ let back = try JSONDecoder().decode([ExtensionManifest.ConfigKey].self, from: data)
+ XCTAssertEqual(back.map(\.multiple), [true, true])
+ }
+
+ func testSplitAndJoinKeepOptionOrder() {
+ XCTAssertEqual(ExtensionConfigValue.split("Work, Team,,Work"), ["Work", "Team"])
+ XCTAssertEqual(ExtensionConfigValue.split(nil), [])
+ XCTAssertEqual(ExtensionConfigValue.join(["c", "a"], order: ["a", "b", "c"]), "a,c")
+ XCTAssertEqual(ExtensionConfigValue.join(["gone", "a"], order: ["a", "b"]), "a,gone",
+ "values not on offer keep their place after the offered ones")
+ XCTAssertNil(ExtensionConfigValue.join([], order: ["a"]))
+ XCTAssertEqual(ExtensionConfigValue.summary(of: [], unset: "All"), "All")
+ XCTAssertEqual(ExtensionConfigValue.summary(of: ["Work", "Team"], unset: ""), "Work, Team")
+ XCTAssertEqual(ExtensionConfigValue.summary(of: ["a", "b", "c", "d"], unset: ""), "a, b +2")
+ }
+
+ func testTheChecklistMovesAndTogglesTheHighlightedOption() {
+ var list = ExtensionChecklist(id: "away", key: cal,
+ options: ["a", "b", "c"].map { ConfigOption(value: $0, label: $0) },
+ saved: ["c"])
+ list.move(-1)
+ XCTAssertEqual(list.highlighted, 2, "wraps")
+ list.toggle()
+ XCTAssertNil(list.value)
+ list.move(1)
+ list.toggle()
+ list.move(2)
+ list.toggle()
+ XCTAssertEqual(list.value, "a,c")
+ }
+
+ func testAChecklistWritesOnceWhenItClosesJoinedInOptionOrder() {
+ let nav = nav(config: multiple)
+ offer(nav, ["w", "t", "p"])
+ select(nav, cal)
+ XCTAssertTrue(nav.selectedRowIsPicker)
+ XCTAssertEqual(nav.extensionValueLabel("away", cal), "Not set")
+ nav.activate()
+ XCTAssertTrue(nav.pickingValue)
+ XCTAssertNotNil(nav.extensionChecklist)
+ nav.moveChecklistHighlight(2)
+ nav.toggleChecklistOption()
+ nav.moveChecklistHighlight(-2)
+ nav.toggleChecklistOption()
+ XCTAssertEqual(nav.extensionValueLabel("away", cal), "w, p")
+ nav.cycleForward()
+ XCTAssertTrue(written.isEmpty, "nothing is written while it is open, and arrows do nothing")
+ nav.activate()
+ XCTAssertNil(nav.extensionChecklist)
+ XCTAssertEqual(written.map(\.0), [cal])
+ XCTAssertEqual(written.map(\.1), ["w,p"])
+ XCTAssertEqual(changed, ["away"])
+ XCTAssertEqual(nav.extensionConfigValues[cal], "w,p")
+ }
+
+ func testClosingAChecklistUnchangedWritesNothing() {
+ let nav = nav(saved: [cal: "p, w"], config: multiple)
+ offer(nav, ["w", "t", "p"])
+ select(nav, cal)
+ nav.activate()
+ nav.toggleChecklistOption()
+ nav.toggleChecklistOption()
+ nav.activate()
+ XCTAssertTrue(written.isEmpty)
+ XCTAssertTrue(changed.isEmpty)
+ }
+
+ func testUntickingEverythingUnsetsTheKey() {
+ let nav = nav(saved: [cal: "w"], config: multiple)
+ offer(nav, ["w", "t"])
+ select(nav, cal)
+ nav.activate()
+ nav.toggleChecklistOption()
+ nav.activate()
+ XCTAssertEqual(written.count, 1)
+ XCTAssertNil(written[0].1)
+ XCTAssertNil(nav.extensionConfigValues[cal])
+ }
+
+ func testASavedValueNotOfferedIsShownCheckedAndCanBeUnticked() {
+ let nav = nav(saved: [cal: "gone,w"], config: multiple)
+ offer(nav, ["w", "t"])
+ select(nav, cal)
+ nav.activate()
+ let list = nav.extensionChecklist
+ XCTAssertEqual(list?.options.map(\.value), ["w", "t", "gone"])
+ XCTAssertEqual(list?.checked, ["gone", "w"])
+ nav.moveChecklistHighlight(2)
+ nav.toggleChecklistOption()
+ nav.activate()
+ XCTAssertEqual(written.map(\.1), ["w"])
+ }
+
+ func testMovingOffAChecklistRowSettlesItAndADefaultCountsAsSelected() {
+ let nav = nav(config: multiple)
+ select(nav, tags)
+ XCTAssertEqual(nav.extensionValueLabel("away", tags), "Alpha, Beta")
+ nav.activate()
+ nav.moveChecklistHighlight(2)
+ nav.toggleChecklistOption()
+ XCTAssertEqual(nav.extensionValueLabel("away", tags), "Alpha, Beta +1")
+ nav.pickingValue = false
+ XCTAssertEqual(written.map(\.1), ["a,b,c"])
+ }
+
+ func testAMultipleKeyShownAsPlaceholderWhenUnset() {
+ guard let m = manifest(#""config":[{"key":"STACKNUDGE_EXT_CAL","type":"dynamic","multiple":true,"placeholder":"All"}]"#)
+ else { return }
+ let nav = PanelNav()
+ nav.extensionSettingsPages = [ExtensionSettingsPage(id: "away", name: "Away", keys: m.config)]
+ XCTAssertEqual(nav.extensionValueLabel("away", cal), "All")
+ }
+
+ func testChecklistKeyActions() {
+ func action(_ code: UInt16, _ modifiers: NSEvent.ModifierFlags = [], checklist: Bool = true,
+ isRepeat: Bool = false) -> PanelController.SettingsDetailKeyAction? {
+ PanelController.settingsDetailKeyAction(keyCode: code, modifiers: modifiers, picking: true,
+ checklist: checklist, isRepeat: isRepeat)
+ }
+ XCTAssertEqual(action(126), .moveHighlight(-1))
+ XCTAssertEqual(action(125), .moveHighlight(1))
+ XCTAssertEqual(action(49), .toggleOption)
+ XCTAssertEqual(action(36), .settle)
+ XCTAssertEqual(action(123), .settle)
+ XCTAssertEqual(action(124), .step(1), "steps nothing: the checklist has no value")
+ XCTAssertEqual(action(48), .moveRow(1), "Tab leaves the row, settling it")
+ XCTAssertEqual(action(49, isRepeat: true), .ignoreRepeat)
+ XCTAssertEqual(action(36, isRepeat: true), .ignoreRepeat)
+ XCTAssertEqual(action(125, isRepeat: true), .moveHighlight(1), "moving repeats")
+ XCTAssertEqual(action(126, checklist: false), .moveRow(-1), "a single picker's ↑ still moves the row")
+ XCTAssertNil(action(49, .command))
+ }
+
+ func testTheChecklistFooterKeepsItsHintsAndDimsWhatDoesNotApply() {
+ let some = SettingsView.checklistFooterHints(optionCount: 3)
+ let none = SettingsView.checklistFooterHints(optionCount: 0)
+ XCTAssertEqual(some.map(\.label), ["Toggle", "Move", "Done"])
+ XCTAssertEqual(none.map(\.label), some.map(\.label))
+ XCTAssertEqual(some.map(\.dimmed), [false, false, false])
+ XCTAssertEqual(none.map(\.dimmed), [true, true, false])
+ XCTAssertEqual(SettingsView.checklistFooterHints(optionCount: 1).map(\.dimmed), [false, true, false])
+ }
+
// MARK: - The list's status
func testTheListStatusPrecedence() {
diff --git a/docs/design/service-extensions.md b/docs/design/service-extensions.md
index e3375a04..998c9c04 100644
--- a/docs/design/service-extensions.md
+++ b/docs/design/service-extensions.md
@@ -178,7 +178,8 @@ no capability. Additive: an extension that predates it skips the type.
- `choices` offers the values a `dynamic` config key may take right now, for its
Settings picker (see [Where an extension appears](#where-an-extension-appears)).
Kept only for a key the manifest declared as `dynamic`; at most 64 options,
- each storable in the config file. Additive: no protocol bump, since unknown
+ each storable in the config file, and none containing a comma when the key is
+ `"multiple": true` (the whole message is refused otherwise). Additive: no protocol bump, since unknown
types are already ignored.
Limits: a `document` line up to 8 MB, any other line up to 64 KB, and at most 20
@@ -410,8 +411,9 @@ manifest field:
asks for, from the index entry's `mode` and `capabilities`; installing
refuses a package whose manifest differs from that entry. Config keys gain an
optional `type` (`text`, `toggle`,
- `choice`, `number` with an optional `unit: "seconds"`, `dynamic`), checked at
- parse time and again on save. The status is a readout above the rows rather
+ `choice`, `number` with an optional `unit: "seconds"`, `dynamic`, and
+ `"multiple": true` on `choice` and `dynamic`, which stores the selection
+ joined with `,`), checked at parse time and again on save. The status is a readout above the rows rather
than a selectable row, like About's version. A picker writes only when it
settles, so a service hears one `config` per change. The page of whichever
extension holds `presence` also carries the app's own "Lock screen when away"
diff --git a/docs/extensions.md b/docs/extensions.md
index c53e9cc8..86555cbf 100644
--- a/docs/extensions.md
+++ b/docs/extensions.md
@@ -117,9 +117,9 @@ and each type is drawn there as the matching control.
|---|---|---|
| `text` (default) | anything the config file can hold, as today | a row whose `⏎` turns it into a field: `⏎` saves, `Esc` (or `⌫` when empty) puts it back |
| `toggle` | `"true"` or `"false"` | an on/off row: `Space` or `⏎` flips it |
-| `choice` | one of `options: [{"value": "…", "label": "…"}]` | a picker |
+| `choice` | one of `options: [{"value": "…", "label": "…"}]`, or several with `"multiple": true` | a picker, or a checklist |
| `number` | one of `options: [15, 30, 60]`, with an optional `"unit": "seconds"` | a picker, labelled "15 s", "2 min" with the unit |
-| `dynamic` | one of the values your running service offers (a `choices` message, below) | a picker over what you last offered, plus the saved value |
+| `dynamic` | one of the values your running service offers (a `choices` message, below), or several with `"multiple": true` | a picker over what you last offered, plus the saved value, or a checklist |
An optional `default` (`30`, `true`, or a string) is what the row shows while
the key is unset; your extension still decides what an unset key means.
@@ -134,6 +134,20 @@ with at most 64 options. The same rule is applied to a manifest's options, to a
`choices` message, when a value is saved, and by the config writer itself. An unknown `type` or `unit`, missing or repeated options, or a
`default` that isn't one of the options is refused with the key named.
+`"multiple": true` is allowed on `choice` and `dynamic` only; on any other type the
+manifest is refused with the key named. The saved value is the selected option
+values joined with `,` in option order (for `dynamic`, the order of your last
+list; saved values you no longer offer follow the offered ones), and it reaches
+your extension as that string, both as the environment variable and as a
+`settings` event value. Nothing selected removes the key. So an option value of a
+multiple key can't contain a comma: the manifest is refused, and a `choices`
+message with one is refused whole. A `default` is a comma-joined subset of the
+options. The row shows the selected labels (`Work, Team +2` past two) or, when
+nothing is selected, the key's `placeholder` if it has one and "Not set" if not.
+`⏎` or `Space` opens a checklist under the row: `↑` / `↓` move, `Space` ticks the
+highlighted option, `⏎` or `←` close it. It writes once, when it closes. Values
+saved but not on offer stay in the list, ticked, so they can be unticked.
+
`dynamic` is for a service extension: it sends what may be picked as
```json
diff --git a/docs/panel.md b/docs/panel.md
index fa9d8ec0..e3328da5 100644
--- a/docs/panel.md
+++ b/docs/panel.md
@@ -174,7 +174,7 @@ An extension that asks for a Settings page gets one under Extensions. A pending
| `→` / `⏎` / `Tab` in the sidebar | Open it |
| `↑ ↓` / `Tab` / `⇧Tab` | Move between rows |
| `⌘↑` / `⌘↓` | Previous / next category |
-| `Space` / `⏎` | Activate (toggles flip, action rows fire, hotkey row records a new combo, an extension's text setting opens its field). On a value row (sound, voice, duration, threshold, an extension's picker) it starts picking. |
+| `Space` / `⏎` | Activate (toggles flip, action rows fire, hotkey row records a new combo, an extension's text setting opens its field). On a value row (sound, voice, duration, threshold, an extension's picker) it starts picking. On an extension's multi-select it opens a checklist: `↑` / `↓` move, `Space` ticks, `⏎` or `←` close and save. |
| `←` / `→` while picking | Step through the values (sounds and voices preview as you go) |
| `Space` / `⏎` while picking | Settle on the value. Moving to another row settles it too. |
| `→` / `⏎` on an Extensions or Integrations row | Open that extension's or integration's page (or the browser, from Browse extensions) |
diff --git a/panel/ExtensionConfigValue.swift b/panel/ExtensionConfigValue.swift
index 78b3c4e0..017b54fc 100644
--- a/panel/ExtensionConfigValue.swift
+++ b/panel/ExtensionConfigValue.swift
@@ -67,4 +67,88 @@ enum ExtensionConfigValue {
ConfigFile.remove(key: key)
}
}
+
+ // A multiple key's saved value is its selected option values joined with
+ // this, so an option value can't contain it.
+ static let separator = ","
+
+ // The values in a stored multiple value, trimmed so a hand-edited
+ // "Work, Team" reads as two. Empty parts are dropped; repeats are not
+ // kept.
+ static func split(_ stored: String?) -> [String] {
+ var seen = Set()
+ return (stored ?? "").components(separatedBy: separator)
+ .map { $0.trimmingCharacters(in: .whitespaces) }
+ .filter { !$0.isEmpty && seen.insert($0).inserted }
+ }
+
+ // The selection as stored: in the order of `order`, then any selected
+ // value it doesn't list. Nil when nothing is selected, which unsets the
+ // key.
+ static func join(_ selected: Set, order: [String]) -> String? {
+ let ordered = order.filter(selected.contains)
+ let extras = selected.subtracting(order).sorted()
+ let all = ordered + extras
+ return all.isEmpty ? nil : all.joined(separator: separator)
+ }
+
+ // What a multiple key's row shows: the first two labels, then how many
+ // more. `unset` stands for nothing selected.
+ static func summary(of labels: [String], unset: String) -> String {
+ guard !labels.isEmpty else { return unset }
+ let shown = labels.prefix(2).joined(separator: ", ")
+ return labels.count > 2 ? "\(shown) +\(labels.count - 2)" : shown
+ }
+}
+
+// A multiple key's checklist while it is open: what is on offer, what is
+// ticked and which option Space would toggle. A value type so the keys that
+// drive it are testable without a page.
+struct ExtensionChecklist: Equatable {
+ let id: String
+ let key: String
+ let options: [ConfigOption]
+ var checked: Set
+ var highlighted = 0
+
+ init(id: String, key: String, options: [ConfigOption], saved: [String]) {
+ self.id = id
+ self.key = key
+ self.options = options
+ self.checked = Set(saved)
+ }
+
+ // Wraps, as the row selection does.
+ mutating func move(_ delta: Int) {
+ guard !options.isEmpty else { return }
+ highlighted = (highlighted + delta + options.count) % options.count
+ }
+
+ mutating func toggle() {
+ guard options.indices.contains(highlighted) else { return }
+ let value = options[highlighted].value
+ if !checked.insert(value).inserted { checked.remove(value) }
+ }
+
+ var value: String? {
+ ExtensionConfigValue.join(checked, order: options.map(\.value))
+ }
+}
+
+extension ExtensionManifest.ConfigKey {
+
+ // What a multiple key's checklist offers: the declared or offered values
+ // in their order, then saved values that aren't on offer, so what's set is
+ // always shown and can be unticked.
+ func checklistOptions(offered: [ConfigOption], saved: [String]) -> [ConfigOption] {
+ let listed = kind.options(offered: kind == .dynamic ? offered : [], saved: nil)
+ let extras = saved.filter { value in !listed.contains { $0.value == value } }
+ return listed + extras.map { ConfigOption(value: $0, label: $0) }
+ }
+
+ // Whether a selection may be saved: every value on offer or already saved.
+ func acceptsSelection(_ values: [String], offered: [ConfigOption], saved: [String]) -> Bool {
+ let allowed = Set(checklistOptions(offered: offered, saved: saved).map(\.value))
+ return values.allSatisfy(allowed.contains)
+ }
}
diff --git a/panel/ExtensionHost.swift b/panel/ExtensionHost.swift
index ef0e2425..cee716d6 100644
--- a/panel/ExtensionHost.swift
+++ b/panel/ExtensionHost.swift
@@ -718,6 +718,11 @@ final class ExtensionHost: ObservableObject {
declared.kind == .dynamic else {
return log(id, "sent choices for \(key), which it didn't declare as dynamic")
}
+ // Values are joined with a comma when stored, so one holding a
+ // comma would read back as two.
+ if declared.multiple, options.contains(where: { $0.value.contains(ExtensionConfigValue.separator) }) {
+ return log(id, "sent choices for \(key), which is multiple, with a value containing \"\(ExtensionConfigValue.separator)\"")
+ }
choices[id, default: [:]][key] = options
case .feed(let post):
guard let manifest = running[id]?.manifest else { return }
diff --git a/panel/ExtensionManifest.swift b/panel/ExtensionManifest.swift
index 82041e40..81c95ad0 100644
--- a/panel/ExtensionManifest.swift
+++ b/panel/ExtensionManifest.swift
@@ -54,6 +54,9 @@ struct ExtensionManifest: Equatable {
// Why the object form's type couldn't be read, kept here so `parse`
// can refuse the manifest with the reason rather than a decoder's.
var typeProblem: String? = nil
+ // A choice or dynamic key that holds several values, stored joined
+ // with ",": see ExtensionConfigValue.join.
+ var multiple = false
// What a form puts next to the field. Falling back to the key with its
// namespace stripped is not pretty, but it is always right and it is
@@ -465,7 +468,7 @@ struct ExtensionManifest: Equatable {
extension ExtensionManifest.ConfigKey: Codable {
private enum CodingKeys: String, CodingKey {
- case key, label, help, placeholder, type, options, unit
+ case key, label, help, placeholder, type, options, unit, multiple
case defaultValue = "default"
}
@@ -498,9 +501,34 @@ extension ExtensionManifest.ConfigKey: Codable {
case .success(let kind): self.kind = kind
case .failure(let why): typeProblem = why.message
}
- if typeProblem == nil, let fallback = defaultValue, kind != .text, kind != .dynamic,
- !kind.accepts(fallback, offered: []) {
- typeProblem = "has a default, \"\(fallback)\", that isn't one of its values"
+ if typeProblem == nil, container.contains(.multiple) {
+ if let flag = try? container.decode(Bool.self, forKey: .multiple) {
+ multiple = flag
+ } else {
+ typeProblem = "has a \"multiple\" that isn't true or false"
+ }
+ }
+ if typeProblem == nil, multiple {
+ switch kind {
+ case .choice(let options):
+ if options.contains(where: { $0.value.contains(ExtensionConfigValue.separator) }) {
+ typeProblem = "is multiple, so its option values can't contain \"\(ExtensionConfigValue.separator)\""
+ }
+ case .dynamic:
+ break
+ case .text, .toggle, .number:
+ typeProblem = "is type \"\(typeName)\", which can't be multiple"
+ }
+ }
+ if typeProblem == nil, let fallback = defaultValue, kind != .text, kind != .dynamic {
+ if multiple {
+ let parts = ExtensionConfigValue.split(fallback)
+ if parts.isEmpty || !parts.allSatisfy({ kind.accepts($0, offered: []) }) {
+ typeProblem = "has a default, \"\(fallback)\", that isn't a list of its values"
+ }
+ } else if !kind.accepts(fallback, offered: []) {
+ typeProblem = "has a default, \"\(fallback)\", that isn't one of its values"
+ }
}
}
@@ -516,6 +544,7 @@ extension ExtensionManifest.ConfigKey: Codable {
try container.encodeIfPresent(help, forKey: .help)
try container.encodeIfPresent(placeholder, forKey: .placeholder)
try container.encodeIfPresent(defaultValue, forKey: .defaultValue)
+ if multiple { try container.encode(true, forKey: .multiple) }
switch kind {
case .text: break
case .toggle: try container.encode("toggle", forKey: .type)
diff --git a/panel/Panel.swift b/panel/Panel.swift
index de39b91d..e95e957f 100644
--- a/panel/Panel.swift
+++ b/panel/Panel.swift
@@ -5314,7 +5314,8 @@ final class PanelController: NSObject, NSApplicationDelegate, PanelKeyDelegate,
}
switch Self.settingsDetailKeyAction(for: event, picking: nav.pickingValue,
- rightOpens: nav.selectedRowOpensOnRight) {
+ rightOpens: nav.selectedRowOpensOnRight,
+ checklist: nav.extensionChecklist != nil) {
case .ignoreRepeat:
break
case .back:
@@ -5329,6 +5330,12 @@ final class PanelController: NSObject, NSApplicationDelegate, PanelKeyDelegate,
delta < 0 ? nav.selectPrevRow() : nav.selectNextRow()
case .activate:
nav.activate()
+ case .moveHighlight(let delta):
+ nav.moveChecklistHighlight(delta)
+ case .toggleOption:
+ nav.toggleChecklistOption()
+ case .settle:
+ nav.pickingValue = false
case nil:
return false
}
@@ -5726,6 +5733,11 @@ final class PanelController: NSObject, NSApplicationDelegate, PanelKeyDelegate,
case step(Int)
case moveRow(Int)
case activate
+ // An open checklist: ↑/↓ move its highlight, Space ticks the
+ // highlighted option, ⏎ or ← close it (writing once).
+ case moveHighlight(Int)
+ case toggleOption
+ case settle
}
// Settings' rows, once a category is open. While a value row is being
@@ -5737,28 +5749,45 @@ final class PanelController: NSObject, NSApplicationDelegate, PanelKeyDelegate,
// On the Extensions list, → opens the selected row's page as ⏎ does, since
// every row there is a door (`rightOpens`); it is never a value change.
static func settingsDetailKeyAction(for event: NSEvent, picking: Bool,
- rightOpens: Bool) -> SettingsDetailKeyAction? {
+ rightOpens: Bool, checklist: Bool = false) -> SettingsDetailKeyAction? {
settingsDetailKeyAction(keyCode: event.keyCode,
modifiers: event.modifierFlags.intersection([.command, .control, .option, .shift]),
- picking: picking, rightOpens: rightOpens, isRepeat: event.isARepeat)
+ picking: picking, rightOpens: rightOpens, checklist: checklist,
+ isRepeat: event.isARepeat)
}
static func settingsDetailKeyAction(keyCode: UInt16,
modifiers: NSEvent.ModifierFlags,
picking: Bool,
rightOpens: Bool = false,
+ checklist: Bool = false,
isRepeat: Bool = false) -> SettingsDetailKeyAction? {
let action = settingsDetailKeyActionIgnoringRepeat(keyCode: keyCode, modifiers: modifiers,
- picking: picking, rightOpens: rightOpens)
+ picking: picking, rightOpens: rightOpens,
+ checklist: checklist)
// Moving and stepping repeat as they always have; acting doesn't.
- if isRepeat, action == .activate { return .ignoreRepeat }
- return action
+ switch action {
+ case .activate, .toggleOption, .settle: return isRepeat ? .ignoreRepeat : action
+ default: return action
+ }
}
private static func settingsDetailKeyActionIgnoringRepeat(keyCode: UInt16,
modifiers: NSEvent.ModifierFlags,
picking: Bool,
- rightOpens: Bool) -> SettingsDetailKeyAction? {
+ rightOpens: Bool,
+ checklist: Bool) -> SettingsDetailKeyAction? {
+ // Tab still moves to the next row (settling), and → steps nothing.
+ if checklist {
+ switch (keyCode, modifiers) {
+ case (KeyCode.upArrow, []): return .moveHighlight(-1)
+ case (KeyCode.downArrow, []): return .moveHighlight(1)
+ case (KeyCode.space, []): return .toggleOption
+ case (KeyCode.returnKey, []), (KeyCode.numpadEnter, []), (KeyCode.leftArrow, []):
+ return .settle
+ default: break
+ }
+ }
switch (keyCode, modifiers) {
case (KeyCode.leftArrow, []): return picking ? .step(-1) : .back
case (KeyCode.rightArrow, []): return !picking && rightOpens ? .activate : .step(1)
diff --git a/panel/PanelNav.swift b/panel/PanelNav.swift
index 6f1064de..e57d5ea4 100644
--- a/panel/PanelNav.swift
+++ b/panel/PanelNav.swift
@@ -1358,6 +1358,9 @@ final class PanelNav: ObservableObject {
var value: String
}
@Published private(set) var extensionPick: ExtensionPick?
+ // The checklist of a multiple key while it is open. Like a pick, it is
+ // written once, when it settles.
+ @Published private(set) var extensionChecklist: ExtensionChecklist?
// Told after an extension's value is saved, so the host can pass it on.
var onExtensionConfigChanged: (String) -> Void = { _ in }
// The page's Update and Remove rows, and ⌘⌫ on the list.
@@ -2819,6 +2822,7 @@ final class PanelNav: ObservableObject {
// the saved one (or the default the manifest names), by its label.
func extensionValueLabel(_ id: String, _ key: String) -> String {
guard let declared = extensionConfigKey(id, key) else { return "" }
+ if declared.multiple { return multipleValueLabel(id, declared) }
let value: String
if let pick = extensionPick, pick.id == id, pick.key == key { value = pick.value }
else { value = extensionConfigValues[key] ?? declared.defaultValue ?? Self.unsetValue }
@@ -2838,6 +2842,22 @@ final class PanelNav: ObservableObject {
}
}
+ // The selected labels of a multiple key, live while its checklist is open.
+ // A dynamic key's saved values are shown as they are: its labels carry
+ // live detail that is for choosing.
+ private func multipleValueLabel(_ id: String, _ declared: ExtensionManifest.ConfigKey) -> String {
+ let values: [String]
+ if let list = extensionChecklist, list.id == id, list.key == declared.key {
+ values = list.options.map(\.value).filter(list.checked.contains)
+ } else {
+ values = ExtensionConfigValue.split(currentExtensionValue(declared))
+ }
+ let options = declared.kind.options(offered: [], saved: nil)
+ let labels = values.map { value in options.first { $0.value == value }?.label ?? value }
+ let unset = declared.placeholder.flatMap { $0.isEmpty ? nil : $0 } ?? "Not set"
+ return ExtensionConfigValue.summary(of: labels, unset: unset)
+ }
+
private func currentExtensionValue(_ declared: ExtensionManifest.ConfigKey) -> String {
extensionConfigValues[declared.key] ?? declared.defaultValue ?? Self.unsetValue
}
@@ -2845,10 +2865,47 @@ final class PanelNav: ObservableObject {
private func beginExtensionPick() {
guard case .extensionSetting(let id, let key)? = selectedRow,
let declared = extensionConfigKey(id, key), declared.kind.isPicker else { return }
+ if declared.multiple {
+ let saved = ExtensionConfigValue.split(currentExtensionValue(declared))
+ let options = declared.checklistOptions(offered: extensionChoices[id]?[key] ?? [], saved: saved)
+ extensionChecklist = ExtensionChecklist(id: id, key: key, options: options, saved: saved)
+ return
+ }
extensionPick = ExtensionPick(id: id, key: key, value: currentExtensionValue(declared))
}
+ func moveChecklistHighlight(_ delta: Int) {
+ extensionChecklist?.move(delta)
+ }
+
+ func setChecklistHighlight(_ index: Int) {
+ guard let list = extensionChecklist, list.options.indices.contains(index) else { return }
+ extensionChecklist?.highlighted = index
+ }
+
+ func toggleChecklistOption() {
+ extensionChecklist?.toggle()
+ }
+
+ // Writes what the checklist ticked when it closes, if that differs from
+ // what the key holds. Nothing ticked removes the key.
+ private func settleExtensionChecklist() {
+ guard let list = extensionChecklist else { return }
+ extensionChecklist = nil
+ guard let declared = extensionConfigKey(list.id, list.key) else { return }
+ let held = ExtensionConfigValue.split(currentExtensionValue(declared))
+ guard list.checked != Set(held) else { return }
+ let value = list.value
+ let offered = extensionChoices[list.id]?[list.key] ?? []
+ let saved = ExtensionConfigValue.split(extensionConfigValues[list.key])
+ guard value != nil || extensionConfigValues[list.key] != nil else { return }
+ guard declared.acceptsSelection(ExtensionConfigValue.split(value), offered: offered,
+ saved: saved) else { return }
+ saveExtensionValue(list.id, list.key, value)
+ }
+
private func stepExtensionPick(_ id: String, _ key: String, forward: Bool) {
+ // A checklist has no value to step; ←/→ do nothing while it is open.
guard var pick = extensionPick, pick.id == id, pick.key == key,
let declared = extensionConfigKey(id, key) else { return }
let list = extensionPickerOptions(id, declared).map(\.value)
@@ -2867,6 +2924,7 @@ final class PanelNav: ObservableObject {
// Settling where it started writes nothing, so opening a picker and
// closing it again doesn't make the extension reconfigure.
private func settleExtensionPick() {
+ settleExtensionChecklist()
guard let pick = extensionPick else { return }
extensionPick = nil
guard let declared = extensionConfigKey(pick.id, pick.key),
diff --git a/panel/Settings.swift b/panel/Settings.swift
index b367b801..1b55c3c0 100644
--- a/panel/Settings.swift
+++ b/panel/Settings.swift
@@ -44,6 +44,10 @@ struct SettingsView: View {
// Esc cancels it too; PageFooter shows that as its last hint.
FooterHint(label: "Press a combo with ⌘ / ⇧ / ⌥ / ⌃", keys: [], primary: true)
FooterHint(label: "Cancel and move", keys: ["↑", "↓"])
+ } else if let list = nav.extensionChecklist {
+ ForEach(Self.checklistFooterHints(optionCount: list.options.count).indices, id: \.self) {
+ FooterHintRow(spec: Self.checklistFooterHints(optionCount: list.options.count)[$0])
+ }
} else if nav.pickingValue {
FooterHint(label: "Choose", keys: ["←", "→"], primary: true)
FooterHint(label: "Done", keys: ["␣", "⏎"])
@@ -568,6 +572,51 @@ struct SettingsView: View {
return hints
}
+ // The open checklist's hints. Toggle and Move stay in place and dim when
+ // there is nothing to tick or move between.
+ static func checklistFooterHints(optionCount: Int) -> [FooterHintSpec] {
+ [FooterHintSpec(label: "Toggle", keys: ["␣"], primary: true, dimmed: optionCount == 0),
+ FooterHintSpec(label: "Move", keys: ["↑", "↓"], dimmed: optionCount < 2),
+ FooterHintSpec(label: "Done", keys: ["⏎", "←"])]
+ }
+
+ private func extensionChecklistView(_ list: ExtensionChecklist) -> some View {
+ VStack(alignment: .leading, spacing: 2) {
+ if list.options.isEmpty {
+ Text("Nothing to choose from yet.")
+ .font(.caption)
+ .foregroundStyle(.secondary)
+ }
+ ForEach(list.options.indices, id: \.self) { index in
+ let option = list.options[index]
+ let ticked = list.checked.contains(option.value)
+ HStack(spacing: 8) {
+ Image(systemName: ticked ? "checkmark.square.fill" : "square")
+ .foregroundStyle(ticked ? Color.accentColor : Color.secondary)
+ Text(option.label)
+ .font(.subheadline)
+ .lineLimit(1)
+ .truncationMode(.tail)
+ Spacer()
+ }
+ .padding(.horizontal, 8)
+ .padding(.vertical, 4)
+ .background(
+ RoundedRectangle(cornerRadius: 6, style: .continuous)
+ .fill(index == list.highlighted ? Color.accentColor.opacity(0.22) : Color.clear)
+ )
+ .contentShape(Rectangle())
+ .onTapGesture {
+ nav.setChecklistHighlight(index)
+ nav.toggleChecklistOption()
+ }
+ }
+ }
+ .padding(.leading, 24)
+ .padding(.trailing, 10)
+ .padding(.bottom, 4)
+ }
+
// The release version, which is what the bundled changelog is keyed by.
private var appVersion: String {
Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "?"
@@ -929,9 +978,13 @@ struct SettingsView: View {
.id(nav.index(of: .extensionSetting(id, key)))
} else {
row(.extensionSetting(id, key), label: declared.displayLabel,
- kind: declared.kind == .toggle ? .toggle : declared.kind.isPicker ? .cycle : .action,
+ kind: declared.kind == .toggle ? .toggle
+ : declared.multiple ? .action : declared.kind.isPicker ? .cycle : .action,
value: nav.extensionValueLabel(id, key),
detail: nav.extensionRowDetail(id, key))
+ if let list = nav.extensionChecklist, list.id == id, list.key == key {
+ extensionChecklistView(list)
+ }
}
}
case .extensionUpdate(let id):
From 6775a74a6710db9adea26c5ee91b136bcd91913f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9s=20De=20Freitas?=
<6485562+adefreitas@users.noreply.github.com>
Date: Tue, 1 Dec 2026 17:08:33 +0000
Subject: [PATCH 3/4] fix(extensions): name a dynamic multi-select's picks by
their labels
---
.../ExtensionSettingsPageTests.swift | 20 ++++++++++++++++++-
panel/PanelNav.swift | 6 +++---
2 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/Tests/StackNudgePanelCoreTests/ExtensionSettingsPageTests.swift b/Tests/StackNudgePanelCoreTests/ExtensionSettingsPageTests.swift
index 0adc8d5b..ea03f071 100644
--- a/Tests/StackNudgePanelCoreTests/ExtensionSettingsPageTests.swift
+++ b/Tests/StackNudgePanelCoreTests/ExtensionSettingsPageTests.swift
@@ -705,7 +705,7 @@ final class ExtensionSettingsPageTests: XCTestCase {
nav.toggleChecklistOption()
nav.moveChecklistHighlight(-2)
nav.toggleChecklistOption()
- XCTAssertEqual(nav.extensionValueLabel("away", cal), "w, p")
+ XCTAssertEqual(nav.extensionValueLabel("away", cal), "W, P")
nav.cycleForward()
XCTAssertTrue(written.isEmpty, "nothing is written while it is open, and arrows do nothing")
nav.activate()
@@ -716,6 +716,24 @@ final class ExtensionSettingsPageTests: XCTestCase {
XCTAssertEqual(nav.extensionConfigValues[cal], "w,p")
}
+ // The row names picks by the last offered labels (a calendar's name, not
+ // its UUID); a saved value that isn't on offer stays raw.
+ func testAMultipleDynamicRowUsesOfferedLabelsAndRawValuesForTheRest() {
+ let nav = nav(saved: [cal: "u1,u2,gone,u3"], config: multiple)
+ nav.extensionChoices = ["away": [cal: [
+ ConfigOption(value: "u1", label: "Work · Google"),
+ ConfigOption(value: "u2", label: "Team · iCloud"),
+ ConfigOption(value: "u3", label: "Home"),
+ ]]]
+ XCTAssertEqual(nav.extensionValueLabel("away", cal), "Work · Google, Team · iCloud +2")
+ nav.extensionConfigValues[cal] = "gone,u2"
+ XCTAssertEqual(nav.extensionValueLabel("away", cal), "gone, Team · iCloud")
+ select(nav, cal)
+ nav.activate()
+ XCTAssertEqual(nav.extensionChecklist?.options.map(\.label), ["Work · Google", "Team · iCloud", "Home", "gone"])
+ XCTAssertEqual(nav.extensionValueLabel("away", cal), "Team · iCloud, gone")
+ }
+
func testClosingAChecklistUnchangedWritesNothing() {
let nav = nav(saved: [cal: "p, w"], config: multiple)
offer(nav, ["w", "t", "p"])
diff --git a/panel/PanelNav.swift b/panel/PanelNav.swift
index e57d5ea4..3fa8d192 100644
--- a/panel/PanelNav.swift
+++ b/panel/PanelNav.swift
@@ -2843,8 +2843,8 @@ final class PanelNav: ObservableObject {
}
// The selected labels of a multiple key, live while its checklist is open.
- // A dynamic key's saved values are shown as they are: its labels carry
- // live detail that is for choosing.
+ // Each value is named by its label in the declared or last offered list,
+ // and shown raw only when it isn't in it (a saved value not on offer).
private func multipleValueLabel(_ id: String, _ declared: ExtensionManifest.ConfigKey) -> String {
let values: [String]
if let list = extensionChecklist, list.id == id, list.key == declared.key {
@@ -2852,7 +2852,7 @@ final class PanelNav: ObservableObject {
} else {
values = ExtensionConfigValue.split(currentExtensionValue(declared))
}
- let options = declared.kind.options(offered: [], saved: nil)
+ let options = declared.kind.options(offered: extensionChoices[id]?[declared.key] ?? [], saved: nil)
let labels = values.map { value in options.first { $0.value == value }?.label ?? value }
let unset = declared.placeholder.flatMap { $0.isEmpty ? nil : $0 } ?? "Not set"
return ExtensionConfigValue.summary(of: labels, unset: unset)
From d9f152974460e6d28b1d3cd0b62b67c22d76f648 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9s=20De=20Freitas?=
<6485562+adefreitas@users.noreply.github.com>
Date: Wed, 2 Dec 2026 11:11:17 +0000
Subject: [PATCH 4/4] feat(extensions): a row tooltip, shown on hover
A row may carry `tooltip`, up to 1024 characters, drawn nowhere but on
hover, so an extension can offer a longer description than the 256
characters a drawn field holds.
Co-Authored-By: Claude Opus 5.5
---
.../ExtensionDocumentTests.swift | 18 ++++++++++++++++++
docs/extensions.md | 6 +++++-
panel/ExtensionDocument.swift | 10 ++++++++--
panel/ExtensionTabView.swift | 1 +
4 files changed, 32 insertions(+), 3 deletions(-)
diff --git a/Tests/StackNudgePanelCoreTests/ExtensionDocumentTests.swift b/Tests/StackNudgePanelCoreTests/ExtensionDocumentTests.swift
index 9bcd4bbe..4d8e64f9 100644
--- a/Tests/StackNudgePanelCoreTests/ExtensionDocumentTests.swift
+++ b/Tests/StackNudgePanelCoreTests/ExtensionDocumentTests.swift
@@ -362,6 +362,24 @@ final class ExtensionDocumentTests: XCTestCase {
// Truncated rather than refused: an over-long title is a formatting slip,
// and every field is line-limited on screen anyway. The cap is about what
// gets parsed and held.
+ // A tooltip only shows on hover, so it gets a longer cap than the drawn
+ // fields: an event's description is worth reading past 256 characters.
+ func testTooltipHasItsOwnLongerCap() {
+ let long = String(repeating: "x", count: ExtensionDocument.maxTooltipLength + 50)
+ let mid = String(repeating: "y", count: ExtensionDocument.maxTextLength + 50)
+ let json = """
+ {"schema":1,"rows":[{"id":"a","title":"A","tooltip":"\(long)"},
+ {"id":"b","title":"B","tooltip":"\(mid)"},
+ {"id":"c","title":"C","tooltip":" "},
+ {"id":"d","title":"D"}]}
+ """
+ guard let d = document(json), d.rows.count == 4 else { return XCTFail("rows") }
+ XCTAssertEqual(d.rows[0].tooltip?.count, ExtensionDocument.maxTooltipLength)
+ XCTAssertEqual(d.rows[1].tooltip?.count, ExtensionDocument.maxTextLength + 50)
+ XCTAssertNil(d.rows[2].tooltip)
+ XCTAssertNil(d.rows[3].tooltip)
+ }
+
func testOverlongTextIsTruncatedNotRejected() {
let long = String(repeating: "x", count: ExtensionDocument.maxTextLength + 400)
let json = """
diff --git a/docs/extensions.md b/docs/extensions.md
index 86555cbf..86587122 100644
--- a/docs/extensions.md
+++ b/docs/extensions.md
@@ -283,6 +283,10 @@ guaranteed to be drawn. Everything else degrades.
Row ids must be unique; duplicates are dropped. A row missing `id` or `title` is
dropped **on its own**, without costing the rest of the list.
+`tooltip` is text shown when the pointer rests on the row, and nowhere else. It
+may run to 1024 characters, where the drawn fields stop at 256, so it suits a
+longer description. Hosts that predate the field ignore it.
+
### `track`
A bar, with an optional paler bar behind it.
@@ -762,7 +766,7 @@ reviewer should check that are easy to miss:
| stdout | 8 MB, 12 s |
| rows | 500 |
| actions | 16 per list |
-| text fields | 256 characters |
+| text fields | 256 characters (a row `tooltip`, 1024) |
| sprite | 32 frames × 24 rows × 64 columns, 30 fps |
| ornaments | 4 per row |
| tab label | 16 characters |
diff --git a/panel/ExtensionDocument.swift b/panel/ExtensionDocument.swift
index c4f72246..5b9a0c41 100644
--- a/panel/ExtensionDocument.swift
+++ b/panel/ExtensionDocument.swift
@@ -64,6 +64,8 @@ struct ExtensionDocument: Equatable {
let subtitle: String?
let value: String?
let footnote: String?
+ // Shown on hover only, so it may run longer than the drawn fields.
+ let tooltip: String?
let track: Track?
// Plural, because one row can want more than one decoration: a marker
// fixed at the end of the track and something riding the fill are two
@@ -152,6 +154,7 @@ struct ExtensionDocument: Equatable {
subtitle: clamp(row.subtitle),
value: clamp(row.value),
footnote: clamp(row.footnote),
+ tooltip: clamp(row.tooltip, to: maxTooltipLength),
track: row.track.flatMap { track in
track.fill.map {
Track(fill: clampFraction($0),
@@ -202,10 +205,11 @@ struct ExtensionDocument: Equatable {
// value it doesn't have — which is the natural thing for a shell script to
// do — would otherwise get a rendered element reserving space for nothing,
// so one row sits indented past its neighbours for no visible reason.
- private static func clamp(_ text: String?) -> String? {
+ private static func clamp(_ text: String?, to limit: Int = maxTextLength) -> String? {
guard let text else { return nil }
let trimmed = text.trimmingCharacters(in: .whitespacesAndNewlines)
- return trimmed.isEmpty ? nil : clamp(text)
+ guard !trimmed.isEmpty else { return nil }
+ return text.count <= limit ? text : String(text.prefix(limit))
}
private static func clampFraction(_ value: Double) -> Double {
@@ -228,6 +232,7 @@ struct ExtensionDocument: Equatable {
static let maxRows = 500
static let maxActions = 16
static let maxTextLength = 256
+ static let maxTooltipLength = 1024
static let maxSpriteFrames = 32
static let maxSpriteRows = 24
static let maxSpriteColumns = 64
@@ -316,6 +321,7 @@ struct ExtensionDocument: Equatable {
let subtitle: String?
let value: String?
let footnote: String?
+ let tooltip: String?
let track: Track?
let ornament: Ornament?
let ornaments: [Ornament]?
diff --git a/panel/ExtensionTabView.swift b/panel/ExtensionTabView.swift
index 0e3b1b41..048a81ee 100644
--- a/panel/ExtensionTabView.swift
+++ b/panel/ExtensionTabView.swift
@@ -216,6 +216,7 @@ struct ExtensionTabView: View {
.background(RoundedRectangle(cornerRadius: 5)
.fill(selected ? Color.primary.opacity(0.08) : .clear))
.contentShape(Rectangle())
+ .help(row.tooltip.map { Text($0) } ?? Text(verbatim: ""))
.onTapGesture { host.selectRow(row.id, on: id) }
.accessibilityElement(children: .combine)
.accessibilityAddTraits(selected ? [.isSelected] : [])