GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — feat(app): let GUI plugins add color themes by Hona · Pull Request #61485 · anomalyco/opencode Conversation
|
| Before | After |
|---|---|
![]() |
![]() |
Theme registry and the types ThemeVariant, ThemePaletteColors and ThemeSeedColors in @opencode/plugin/gui (packages/plugin/src/gui/registries.ts).
string, the type a JSON import gives them, so a theme file needs no cast.seeds and palette fails to compile.PluginThemes (packages/app/src/runtime/plugin/render.tsx) registers each contributed theme as <plugin id>:<theme id>.
registerTheme now returns a disposer, and a new settle() marks the point after which a missing theme is not coming. A stored theme id that matches no theme is no longer reset to oc-2 at startup.
ThemeProvider starts. Without this, a selected plugin theme would be replaced with oc-2 on every reload.onThemeApplied still fires, so desktop windows show on the cached colors.onThemeApplied now takes (mode, scheme). Its only caller already ignored the theme argument.sequenceDiagram
participant P as oc-theme-preload.js
participant T as ThemeProvider
participant H as PluginThemes
P->>P: paint cached CSS for "acme:midnight"
T->>T: themeId = "acme:midnight" (kept)
T-->>T: onThemeApplied (window shows on cached colors)
alt plugin contributes the theme
H->>T: registerTheme(acme:midnight)
T->>T: apply, re-cache CSS
else plugin uninstalled or disabled
H->>T: settle() once every plugin is active, failed or disabled
T->>T: show oc-2, clear cached CSS, keep the stored id
end
| Start | Root theme over time | Picker |
|---|---|---|
| Plugin present | acme:midnight (cached) |
Midnight |
| Plugin removed, 1st start | acme:midnight (cached) → oc-2, cache cleared |
OpenCode |
| Plugin removed, 2nd start | base → oc-2 |
OpenCode |
| Plugin back | acme:midnight |
Midnight |
Themes section in build/plugins/gui, plus a row in the registry table in packages/gui-plugins/README.md.packages/ui/src/theme/context.tsx is now lint-clean. The type assertions and typeof checks are replaced by readScheme, an instanceof check and a typed store.<svg xmlns="http://www.w3.org/2000/svg" width="240" height="72" viewBox="0 0 240 72" fill="none"> <rect x="8" y="8" width="96" height="56" stroke="currentColor" stroke-opacity=".3"/> <rect x="16" y="16" width="40" height="6" fill="currentColor" opacity=".35"/> <rect x="16" y="28" width="80" height="4" fill="currentColor" opacity=".2"/> <rect x="16" y="36" width="64" height="4" fill="currentColor" opacity=".2"/> <rect x="16" y="44" width="72" height="4" fill="currentColor" opacity=".2"/> <rect x="8" y="8" width="96" height="56" fill="currentColor" opacity="0"> <animate attributeName="opacity" values="0;0;.14;.14;0" keyTimes="0;.45;.55;.9;1" dur="4s" repeatCount="indefinite"/> </rect> <path d="M112 36h12m-4-4 4 4-4 4" stroke="currentColor" stroke-opacity=".4"/> <rect x="132" y="8" width="100" height="56" stroke="currentColor" stroke-opacity=".3"/> <rect x="140" y="15" width="56" height="4" fill="currentColor" opacity=".3"/> <rect x="140" y="25" width="44" height="4" fill="currentColor" opacity=".3"/> <rect x="140" y="35" width="62" height="4" fill="currentColor" opacity=".3"/> <g opacity="1"> <animate attributeName="opacity" values="0;0;1;1;0" keyTimes="0;.2;.3;.9;1" dur="4s" repeatCount="indefinite"/> <animateTransform attributeName="transform" type="translate" values="0 6;0 6;0 0;0 0;0 0" keyTimes="0;.2;.3;.9;1" dur="4s" repeatCount="indefinite"/> <rect x="136" y="43" width="92" height="14" fill="currentColor" opacity=".12"/> <rect x="140" y="48" width="40" height="4" fill="currentColor" opacity=".8"/> <path d="M214 50l3 3 6-6" stroke="currentColor" stroke-width="1.5" opacity=".8"/> </g> </svg>
Added by the opencode bot (AI-generated).
Related: #54235
Public API: adds the Theme registry and the ThemeVariant, ThemePaletteColors and ThemeSeedColors types to @opencode/plugin/gui; registerTheme now returns a disposer (backwards compatible)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Adds a public Theme registry to the GUI plugin SDK that takes the app's own theme file format. The window host lists each contributed theme in Settings > Appearance > Theme under <plugin>:<id> and withdraws it with the plugin; a user's choice survives the plugin loading after startup or being disabled.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I reviewed the code but couldn't run it. The GUI component test needs browsers that aren't installed here. Type checks for plugin, ui and app pass, as do the ui theme tests and app theme-preload tests. There's one problem that should block the merge (see the inline comment).
Public API (additions only, backwards compatible):
@opencode/plugin/gui: the Theme registry and the types Theme, ThemeVariant, ThemePaletteColors and ThemeSeedColors.useTheme().registerTheme now returns a disposer instead of void. Existing callers that ignore the return value are unaffected.opencode-theme-id is no longer reset to oc-2 when no theme has that id.The blocking problem: if a stored plugin theme never registers, ThemeProvider never applies a theme. Then onThemeApplied never fires, and the desktop app relies on it to show secondary windows and set the titlebar. The same path also stops clearing stale theme ids, so a removed theme's cached colors stay on screen.
I couldn't take before/after screenshots. Could you add them, or a short video, for the startup case with a plugin theme selected and its plugin disabled or uninstalled?
Related: #54235
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| // Keep what is on screen while a bundled theme loads, and at startup, the CSS cached from the last run until a | ||
| // registered theme arrives. A registered theme missing later was withdrawn: show the default theme until it | ||
| // returns. | ||
| if (knownThemes().has(store.themeId) || !document.getElementById(THEME_STYLE_ID)) return |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
When the stored id belongs to a theme that never registers (plugin disabled at startup, uninstalled, or failing to load), this returns forever. applyTheme never runs, so onThemeApplied never fires.
The desktop renderer only sends themeReady and calls setTitlebar from onThemeApplied (packages/desktop/src/renderer/desktop-app.tsx). Every window except the first restored one is created with show: false and only appears after themeReady (packages/desktop/src/main/windows/index.ts). So:
Together with dropping the reset at line 203, a stale id is also never cleared. After a plugin is uninstalled, or a bundled theme is dropped, the preload script keeps painting that theme's cached CSS on every start, and the picker shows nothing selected.
This also goes against the description's claim that the default theme shows while the plugin is disabled: that only holds if the plugin is disabled during the session. One possible fix: fall back to oc-2 once the plugin host has settled and the theme still hasn't registered, keeping the stored choice. Either way, onThemeApplied should still fire at startup.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Fixed in ff459d2.
onThemeApplied fires at startup: while a registered theme may still arrive, the provider reports the window ready, and the colors cached from the last run stay on screen. Desktop windows no longer wait for plugins.settle(). PluginThemes calls it once the plugin list has arrived (always true on the web) and every plugin is active, failed or disabled. After that, a selected theme that no plugin contributes:
oc-2, and the picker shows OpenCode;onThemeApplied signature: it now takes (mode, scheme). Its only caller (app.tsx) already ignored the theme argument.I ran the startup cases against the dev app, with the plugin turned on and off between reloads:
| Start | Root theme over time | Picker |
|---|---|---|
| Plugin present | acme:midnight (cached) |
Midnight |
| Plugin removed, 1st start | acme:midnight (cached) → oc-2, cache cleared |
OpenCode |
| Plugin removed, 2nd start | base → oc-2 |
OpenCode |
| Plugin back | acme:midnight |
Midnight |
New component case: "a selected plugin theme that never returns shows the default theme once plugins settle".
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The fix holds up. I read ff459d2 and didn't find anything that breaks.
context.tsx (~L340) now calls onThemeApplied without applying CSS. The desktop renderer gets themeReady/setTitlebar, so hidden windows still show. Theme id, mode and scheme changes all re-run the effect.active() returns the stored id only while the theme is bundled, registered, or !settled. After that it returns oc-2, and the picker uses active for themeId, so it shows OpenCode. clear() followed by applyTheme(oc2…) really does leave no cache, because applyThemeCss never writes cache for oc-2 (L161). The preload script then paints nothing on the next start, which matches your "2nd start" row. The stored id is never written, so the choice comes back with the plugin.host.tsx ~L883) and also requires the plugin list from main (plugins() !== undefined; the web starts at []). Window setup is synchronous (async setup throws), so a plugin reaches active only after its ctx.add(Theme, …) has run. A plugin that contributes its theme can't be counted as settled before the theme is registered.settle() always gets called in the app. PluginRoot is mounted unconditionally in AppBaseProviders (app.tsx:74). The stories and e2e fixtures never settle, which doesn't matter.One behaviour change, which I think is fine: settled only ever goes from false to true. When a plugin reloads mid-session, its theme is briefly withdrawn, so the window flashes oc-2 and the cache is cleared, then the theme re-registers and is cached again. Before this commit a withdrawn theme also showed oc-2, so this isn't a regression. It only matters if the app quits during that window, and the next start then paints base colors once.
I didn't run the component tests or the dev app. The shared checkout is on the older commit (07947db) and I didn't want to switch it. I made no changes; git status only shows the existing bun.lock modification.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…cted theme ThemeProvider still reports the window ready while a registered theme may arrive, so desktop windows show on the cached colors. Once the plugin host has settled, a selected theme no plugin contributed falls back to the default theme, clears its cached colors and keeps the stored choice.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.