Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

fix(plugins): reload active icon theme when a same-metadata update changes its content (STA-12869) (#36151)

Neil3fcac7243777
diff --git a/src/main/plugins/contributions/plugin-icon-theme-registry.test.ts b/src/main/plugins/contributions/plugin-icon-theme-registry.test.ts
index 33bf20f49e5..c138aa5f9a9 100644
--- a/src/main/plugins/contributions/plugin-icon-theme-registry.test.ts
+++ b/src/main/plugins/contributions/plugin-icon-theme-registry.test.ts
@@ -60,7 +60,8 @@ it('lists metadata and reads a theme only when it is loaded', async () => {
{
id: 'plugin:samples.minimal-icons/minimal',
pluginKey: 'samples.minimal-icons',
- label: 'Minimal'
+ label: 'Minimal',
+ revision: expect.stringMatching(/^[0-9a-f]{32}$/)
}
])
const theme = await registry.load('plugin:samples.minimal-icons/minimal')
@@ -68,6 +69,11 @@ it('lists metadata and reads a theme only when it is loaded', async () => {
expect(theme?.svgs[theme.icons.folder ?? -1]).toContain('currentColor')
expect(theme?.svgs[theme.fileExtensions.ts ?? -1]).toContain('#3178c6')
await expect(registry.load('plugin:samples.other/x')).resolves.toBeNull()
+
+ // An update that changes only SVG bytes keeps id and title but installs a new tree hash.
+ const revision = registry.list()[0]?.revision
+ await registry.reconcile([{ ...plugin, contentHash: 'a'.repeat(64) }], () => true)
+ expect(registry.list()[0]?.revision).not.toBe(revision)
})
it('fails a load whose file is not an SVG document and forgets themes once disabled', async () => {
diff --git a/src/main/plugins/contributions/plugin-icon-theme-registry.ts b/src/main/plugins/contributions/plugin-icon-theme-registry.ts
index 0a2c9f3120e..8b434b3a8a7 100644
--- a/src/main/plugins/contributions/plugin-icon-theme-registry.ts
+++ b/src/main/plugins/contributions/plugin-icon-theme-registry.ts
@@ -1,3 +1,4 @@
+import { createHash } from 'node:crypto'
import type { PluginThemeContribution } from '../../../shared/plugins/contributions/plugin-content-pack-contributions'
import {
PLUGIN_ICON_SVG_MAX_BYTES,
@@ -34,24 +35,34 @@ export class PluginIconThemeRegistry {
this.descriptors = new PluginArtifactPackRegistry({
contentVerifier,
contributions: (plugin) => plugin.manifest.contributes.iconThemes,
- load: async (plugin, contribution) => ({
- id: `plugin:${plugin.pluginKey}/${contribution.id}`,
- pluginKey: plugin.pluginKey,
- label: contribution.title,
- rootDir: plugin.rootDir,
- artifact: parsePluginIconThemeArtifact(
- await readContainedPluginArtifactText(
- plugin.rootDir,
- contribution.path,
- PLUGIN_ICON_THEME_MAX_BYTES
- )
+ load: async (plugin, contribution) => {
+ const text = await readContainedPluginArtifactText(
+ plugin.rootDir,
+ contribution.path,
+ PLUGIN_ICON_THEME_MAX_BYTES
)
- })
+ return {
+ id: `plugin:${plugin.pluginKey}/${contribution.id}`,
+ pluginKey: plugin.pluginKey,
+ label: contribution.title,
+ // Why the tree hash: SVGs load lazily, so it stands in for their bytes across updates.
+ revision: createHash('sha256')
+ .update(plugin.contentHash ?? '')
+ .update('\0')
+ .update(text)
+ .digest('hex')
+ .slice(0, 32),
+ rootDir: plugin.rootDir,
+ artifact: parsePluginIconThemeArtifact(text)
+ }
+ }
})
}
list(): PluginIconThemeMetadata[] {
- return this.descriptors.list().map(({ id, pluginKey, label }) => ({ id, pluginKey, label }))
+ return this.descriptors
+ .list()
+ .map(({ id, pluginKey, label, revision }) => ({ id, pluginKey, label, revision }))
}
error(pluginKey: string): string | null {
@@ -113,6 +124,7 @@ async function materialize(descriptor: IconThemeDescriptor): Promise<PluginIconT
id: descriptor.id,
pluginKey: descriptor.pluginKey,
label: descriptor.label,
+ revision: descriptor.revision,
svgs,
icons: indexOf(artifact.icons),
fileNames: indexOf(artifact.fileNames),
diff --git a/src/renderer/src/store/plugin-icon-themes.test.ts b/src/renderer/src/store/plugin-icon-themes.test.ts
index 447e42621da..d1048c93615 100644
--- a/src/renderer/src/store/plugin-icon-themes.test.ts
+++ b/src/renderer/src/store/plugin-icon-themes.test.ts
@@ -85,3 +85,48 @@ it('drops the previous icons when the next selected theme fails to load', async
await waitFor(() => expect(document.getElementById('orca-plugin-icon-theme')).toBeNull())
expect(store.useActivePluginIconTheme.getState().theme).toBeNull()
})
+
+it('reloads the active icon theme when a same-metadata update changes its content', async () => {
+ const metadata = { id: 'plugin:samples.icons/minimal', pluginKey: 'samples.icons', label: 'A' }
+ let listed: { id: string; pluginKey: string; label: string; revision?: string }[] = [
+ { ...metadata, revision: 'r1' }
+ ]
+ const listeners: ((event: PluginChangeEvent) => void)[] = []
+ const loadIconTheme = vi.fn(async () => ({
+ ...listed[0],
+ svgs: ['<svg xmlns="http://www.w3.org/2000/svg"><path fill="currentColor"/></svg>'],
+ icons: { file: 0 },
+ fileNames: {},
+ fileExtensions: {}
+ }))
+ vi.stubGlobal('api', {
+ plugins: {
+ listIconThemes: async () => listed,
+ loadIconTheme,
+ onChanged: (listener: (event: PluginChangeEvent) => void) => {
+ listeners.push(listener)
+ return () => {}
+ }
+ }
+ })
+ const store = await import('./plugin-icon-themes')
+ renderHook(() => store.usePluginIconThemeActivation(metadata.id))
+ await waitFor(() => expect(loadIconTheme).toHaveBeenCalledTimes(1))
+
+ const refresh = async () => {
+ act(() => listeners.forEach((listener) => listener({ contentPacksChanged: true })))
+ await act(async () => {
+ await store.usePluginIconThemeStore.getState().fetchEntries()
+ })
+ }
+ listed = [
+ { ...metadata, revision: 'r1' },
+ { ...metadata, id: 'plugin:samples.icons/other' }
+ ]
+ await refresh()
+ expect(loadIconTheme).toHaveBeenCalledTimes(1)
+
+ listed = [{ ...metadata, revision: 'r2' }]
+ await refresh()
+ await waitFor(() => expect(loadIconTheme).toHaveBeenCalledTimes(2))
+})
diff --git a/src/renderer/src/store/plugin-icon-themes.ts b/src/renderer/src/store/plugin-icon-themes.ts
index f913e84bf0c..b1fd08841e1 100644
--- a/src/renderer/src/store/plugin-icon-themes.ts
+++ b/src/renderer/src/store/plugin-icon-themes.ts
@@ -75,10 +75,13 @@ function registerIcons(theme: PluginIconThemeRegistration): ActivePluginIconThem
}
}
-/** Loads the selected icon theme whenever the selection or the enabled themes change. */
+/** Loads the selected icon theme whenever the selection or its content changes. */
export function usePluginIconThemeActivation(selectedId: string | null | undefined): void {
const available = usePluginIconThemes()
- const selected = available.find((theme) => theme.id === selectedId)?.id ?? null
+ const selectedTheme = available.find((theme) => theme.id === selectedId)
+ const selected = selectedTheme?.id ?? null
+ const revision = selectedTheme?.revision
+ // Why `revision`, not the list: reload on this theme's content change, not on other themes'.
useEffect(() => {
const generation = ++loadGeneration
const load = window.api?.plugins?.loadIconTheme
@@ -98,5 +101,5 @@ export function usePluginIconThemeActivation(selectedId: string | null | undefin
useActivePluginIconTheme.setState({ theme: theme ? registerIcons(theme) : null })
}
})
- }, [selected, available])
+ }, [selected, revision])
}
diff --git a/src/shared/plugins/artifacts/plugin-icon-theme-artifact.ts b/src/shared/plugins/artifacts/plugin-icon-theme-artifact.ts
index 966c49e9fee..d148260bf8d 100644
--- a/src/shared/plugins/artifacts/plugin-icon-theme-artifact.ts
+++ b/src/shared/plugins/artifacts/plugin-icon-theme-artifact.ts
@@ -123,7 +123,9 @@ const svgIndexSchema = z
const pluginIconThemeMetadataSchema = z.object({
id: pluginContentIdSchema,
pluginKey: z.string(),
- label: z.string()
+ label: z.string(),
+ // Optional: older hosts omit it.
+ revision: z.string().optional()
})
/** Each distinct SVG is sent once; the maps point into `svgs` so rows never repeat image data. */