feat(settings): Appearance category + custom-control escape hatch (T-452)

Add the one bespoke control the schema engine defers to. New
SettingsControlContribution routes a WidgetBuilder into a kernel
SettingsControlRegistry under a customId; a SettingsFieldKind.custom field
names that id, and the renderer draws the registered widget full-width
(label on top, no scope tag — the control owns its own apply + scope).

The theme-picker extension uses it: an Appearance category whose theme field
is custom, backed by AppearanceThemeControl — base-theme chips + a
high-contrast toggle that apply live through ThemeController (persisted by
theme_persistence). Reuses the shared theme_families helpers.

Tests: control registry (register/dup/unregister), the renderer's custom-field
path, and the Appearance contribution + live theme apply.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-17 13:04:52 +02:00
co-authored by Claude Opus 4.8
parent 727fe8fdd4
commit 757d6f71fa
16 changed files with 324 additions and 14 deletions
+7
View File
@@ -26,6 +26,7 @@ import 'package:clide/kernel/src/project.dart';
import 'package:clide/kernel/src/secrets.dart';
import 'package:clide/kernel/src/settings.dart';
import 'package:clide/kernel/src/settings_registry.dart';
import 'package:clide/kernel/src/settings_control_registry.dart';
import 'package:clide/kernel/src/theme/controller.dart';
import 'package:clide/kernel/src/tray.dart';
import 'package:flutter/foundation.dart';
@@ -57,6 +58,7 @@ class ExtensionManager extends ChangeNotifier {
required this.project,
required this.ipc,
required this.settingsRegistry,
required this.settingsControlRegistry,
});
final Logger log;
@@ -84,6 +86,7 @@ class ExtensionManager extends ChangeNotifier {
final ProjectManager project;
final DaemonClient ipc;
final SettingsRegistry settingsRegistry;
final SettingsControlRegistry settingsControlRegistry;
final Map<String, ClideExtension> _known = {};
final Set<String> _activated = {};
@@ -262,6 +265,8 @@ class ExtensionManager extends ChangeNotifier {
case SettingsCategoryContribution s:
// register() throws on a duplicate id, rolling activation back.
settingsRegistry.register(s.category);
case SettingsControlContribution s:
settingsControlRegistry.register(s.customId, s.builder);
}
}
@@ -284,6 +289,8 @@ class ExtensionManager extends ChangeNotifier {
break;
case SettingsCategoryContribution s:
settingsRegistry.unregister(s.category.id);
case SettingsControlContribution s:
settingsControlRegistry.unregister(s.customId);
}
}
+8
View File
@@ -35,6 +35,7 @@ import 'package:clide/kernel/src/scheduler.dart';
import 'package:clide/kernel/src/secrets.dart';
import 'package:clide/kernel/src/settings.dart';
import 'package:clide/kernel/src/settings_registry.dart';
import 'package:clide/kernel/src/settings_control_registry.dart';
import 'package:clide/kernel/src/theme/controller.dart';
import 'package:clide/kernel/src/theme/loader.dart';
import 'package:clide/kernel/src/toolchain.dart';
@@ -83,6 +84,7 @@ class KernelServices {
required this.toast,
required this.logRing,
required this.settingsRegistry,
required this.settingsControlRegistry,
});
final Logger log;
@@ -90,6 +92,9 @@ class KernelServices {
/// Categories registered for the Settings panel (T-444).
final SettingsRegistry settingsRegistry;
/// Bespoke widgets for custom settings fields (T-452).
final SettingsControlRegistry settingsControlRegistry;
final DaemonBus events;
final MessageBus messages;
@@ -161,6 +166,7 @@ class KernelServices {
final settings = SettingsStore(appDir: appDir, onError: (m) => log.warn('settings', m));
await settings.load();
final settingsRegistry = SettingsRegistry();
final settingsControlRegistry = SettingsControlRegistry();
final i18n = I18n(loader: i18nLoader, log: log, defaultLocale: defaultLocale, initialLocale: initialLocale, availableLocales: availableLocales);
for (final ns in preloadNamespaces) {
@@ -245,6 +251,7 @@ class KernelServices {
project: project,
ipc: ipc,
settingsRegistry: settingsRegistry,
settingsControlRegistry: settingsControlRegistry,
);
if (autoStartDaemonClient) {
@@ -256,6 +263,7 @@ class KernelServices {
logRing: logRing,
settings: settings,
settingsRegistry: settingsRegistry,
settingsControlRegistry: settingsControlRegistry,
events: events,
messages: messages,
filterStates: filterStates,
@@ -0,0 +1,26 @@
import 'package:flutter/widgets.dart';
/// Holds the bespoke widgets that draw [SettingsFieldKind.custom] fields
/// (T-452). A subsystem registers a builder under a `customId` (via
/// `SettingsControlContribution`, routed by the extension manager); the
/// settings renderer looks it up when it meets a custom field.
///
/// Controls register at activation, before any settings modal opens, so this
/// is a plain registry — no change notification needed.
class SettingsControlRegistry {
final Map<String, WidgetBuilder> _byId = <String, WidgetBuilder>{};
/// Register the [builder] for [customId]. Throws on a duplicate id so a
/// collision rolls the contributing extension's activation back.
void register(String customId, WidgetBuilder builder) {
if (_byId.containsKey(customId)) {
throw StateError('duplicate settings control id: $customId');
}
_byId[customId] = builder;
}
void unregister(String customId) => _byId.remove(customId);
/// The builder for [customId], or null when none is registered.
WidgetBuilder? builderFor(String customId) => _byId[customId];
}
+11
View File
@@ -24,6 +24,12 @@ enum SettingsFieldKind {
/// of editing a value inline — the action is a command id, keeping the
/// schema widget-free.
file,
/// A bespoke control rendered by a widget the owning subsystem registers
/// (via `SettingsControlContribution`) under [SettingsField.customId]. Keeps
/// the schema widget-free while allowing the one-off controls the generic
/// kinds can't express (e.g. the Appearance theme picker).
custom,
}
/// One choice in a [SettingsFieldKind.select] field.
@@ -53,6 +59,7 @@ class SettingsField {
this.max,
this.fileCommand,
this.applyCommandPrefix,
this.customId,
});
final String key;
@@ -81,6 +88,10 @@ class SettingsField {
/// persists). The current value is still read from [key], so the scope tag
/// and selection still work. Example: `'keymap.preset.'` → `keymap.preset.vim`.
final String? applyCommandPrefix;
/// For [SettingsFieldKind.custom]: the id the renderer looks up in the
/// `SettingsControlRegistry` to find the widget that draws this field.
final String? customId;
}
/// A carded group of fields (surface.md "sectioned cards"). [label] is the