feat(web): import themes from local .vsix extension packages #8419
Closedipanasenko(GitHub profile, opens in a new tab)wants to merge 34 commits into
main fromrefs/pull/8419/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
- apps/desktop/src/ipc/methods/window.ts line 375OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -349,13 +356,20 @@356+ ],349357 multiple: true,350358 });351359 if (paths.length === 0) {352360 return null;353361 }354362 return yield* Effect.forEach(paths, (filePath) => {355363 const name = path.basename(filePath);364+ const isPackage = name.toLowerCase().endsWith(".vsix");356365 return Effect.gen(function* () {357366 const info = yield* fileSystem.stat(filePath);358367 const size = Number(info.size);359- if (size > PICKED_THEME_FILE_MAX_BYTES) {368+ const limit = isPackage ? PICKED_THEME_PACKAGE_MAX_BYTES : PICKED_THEME_FILE_MAX_BYTES;369+ if (size > limit) {360370 return { name, size, text: "" } satisfies PickedThemeFile;361371 }372+ // A package is binary, so it crosses the bridge base64-encoded; the373+ // renderer unzips it and never looks at `text`.374+ if (isPackage) {375+ const bytes = yield* fileSystem.readFile(filePath);
github-actions[bot](GitHub profile, opens in a new tab) removed labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
- apps/web/src/components/settings/ThemeImportDialog.tsx line 620OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -487,3 +614,7 @@487614 <ThemeJsonEditor id="theme-json-editor" onChange={setJson} value={json} />488615 </div>489616 );617+ if (pendingPackage) {618+ return (619+ <div className="space-y-3">620+ <div className="rounded-xl border border-border/70 bg-muted/20 p-3">
- apps/desktop/src/ipc/methods/window.ts lines 457 to 462Resolvedby ipanasenko(GitHub profile, opens in a new tab)@@ -356,6 +396,20 @@396+ const isPackage = name.toLowerCase().endsWith(".vsix");356397 return Effect.gen(function* () {357398 const info = yield* fileSystem.stat(filePath);358399 const size = Number(info.size);359- if (size > PICKED_THEME_FILE_MAX_BYTES) {400+ const limit = isPackage ? PICKED_THEME_PACKAGE_MAX_BYTES : PICKED_THEME_FILE_MAX_BYTES;401+ if (size > limit) {360402 return { name, size, text: "" } satisfies PickedThemeFile;361403 }404+ // A package is binary, so it crosses the bridge base64-encoded; the405+ // renderer unzips it and never looks at `text`.406+ if (isPackage) {407+ const bytes = yield* readCappedFile(fileSystem, filePath, limit);408+ if (Option.isNone(bytes)) {409+ // Grew past the cap after stat; report a size the renderer410+ // rejects as oversized.411+ return { name, size: limit + 1, text: "" } satisfies PickedThemeFile;412+ }413+ const contentBase64 = Buffer.from(bytes.value).toString("base64");414+ return { name, size, text: "", contentBase64 } satisfies PickedThemeFile;415+ }
- apps/web/src/components/settings/ThemeImportDialog.tsx line 167Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -140,5 +154,13 @@140154 );141155 }142156143-/** What the import pipeline needs from a file; DOM File satisfies it. */144-type ImportableThemeFile = { name: string; size: number; text: () => Promise<string> };157+/** What the import pipeline needs from a file; DOM File satisfies it.158+ * `bytes` is only read for extension packages, which are binary. */159+type ImportableThemeFile = {160+ name: string;161+ size: number;162+ text: () => Promise<string>;163+ bytes?: () => Promise<Uint8Array>;164+};165+166+function decodeBase64(value: string): Uint8Array {
- apps/web/src/components/settings/ThemeImportDialog.tsx line 191OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -144,0 +171,21 @@171+function importableThemeFile(file: File): ImportableThemeFile {172+ return {173+ name: file.name,174+ size: file.size,175+ text: () => file.text(),176+ bytes: async () => new Uint8Array(await file.arrayBuffer()),177+ };178+}179+180+/** An extension package waiting on an update-or-cancel decision because its181+ * collection is already installed. */182+type PendingThemePackage = {183+ label: string;184+ collectionId: string;185+ themes: ReadonlyArray<ThemeDefinition>;186+ installedCollection: ReadonlyArray<ThemeDefinition>;187+};188+189+function ThemeConflictNotice({ title, children }: { title: ReactNode; children: ReactNode }) {190+ return (191+ <Alert className="border-border/70 bg-muted/20 px-3 py-3 dark:bg-muted/20">
- docs/user/appearance.md lines 34 to 38Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -23,5 +23,8 @@2323 ## Custom themes24242525 On web and desktop, choose **Create theme** to adjust a palette, or import a T3 Code or VS Code26-theme. The theme editor's color picker lets you select an area of the app to find the color to27-change. Export your theme as JSON to share it.26+theme. Import accepts theme `.json` files and VS Code theme extensions as `.vsix` packages, so a27+theme you bought or built yourself installs without a registry. Every color theme in a package28+installs together, and importing the same package again offers to update it in place. The theme29+editor's color picker lets you select an area of the app to find the color to change. Export your30+theme as JSON to share it.
- apps/desktop/src/ipc/methods/window.ts lines 388 to 389OutdatedResolvedby ipanasenko(GitHub profile, opens in a new tab)@@ -379,6 +382,8 @@379382 }),380383 });381384382-/** Theme files are a few KB; anything larger returns empty text and lets the383- * renderer reject it by size without the contents ever crossing the bridge. */384-const PICKED_THEME_FILE_MAX_BYTES = 256 * 1024;385+/** Reads at most `limit` bytes. The cap is enforced while reading, not by a386+ * prior stat, so a file that grows between the size check and the read can387+ * never pull more than the cap into memory. Returns None past the limit. */388+const readCappedFile = (389+ fileSystem: FileSystem.FileSystem,
- apps/web/src/components/settings/ThemeImportDialog.tsx line 401Resolvedby ipanasenko(GitHub profile, opens in a new tab)@@ -266,3 +377,21 @@377+ else installThemePackage(pending);378+ } catch (cause) {379+ if (requestId !== importRequestRef.current) return;380+ setError(381+ cause instanceof Error ? cause.message : "That extension package could not be imported.",382+ );383+ } finally {384+ if (requestId === importRequestRef.current) setIsReading(false);385+ }386+ },387+ [installThemePackage],388+ );389+266390 const readThemeFiles = useCallback(267391 (files: ReadonlyArray<ImportableThemeFile>) => {268392 if (files.length === 0) return;393+ if (files.some((file) => isThemePackageName(file.name))) {394+ // A package expands into a whole collection with its own update395+ // prompt, so it imports on its own rather than inside a batch.396+ if (files.length > 1) {397+ setError("Import one .vsix extension package at a time.");
- apps/web/src/openVsxThemes.ts lines 112 to 112Resolvedby ipanasenko(GitHub profile, opens in a new tab)@@ -190,4 +109,4 @@190109 const id = `${namespace}.${extensionName}`;191110 return {192111 id,193- collectionId: openVsxCollectionId(id),112+ collectionId: themeCollectionId("open-vsx", id.toLowerCase()),
juliusmarminge closed this
Sign in to join this conversation.
Note
Reviews paused#
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
reviews.auto_review.auto_pause_after_reviewed_commitssetting.Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto trigger a single review.Use the checkboxes below for quick actions:
📝 Walkthrough
Walkthrough#
The PR adds local VSIX theme package importing. Desktop IPC transfers capped binary contents, shared code validates and parses VSIX archives, and the settings dialog installs or replaces imported collections. Open VSX imports now use the shared package pipeline.
Changes#
VSIX theme package import
packages/contracts/src/ipc.ts,apps/desktop/src/ipc/methods/window.ts,apps/desktop/src/ipc/methods/window.test.tsapps/web/src/vsixThemePackage.ts,apps/web/src/vsixThemePackage.test.tsapps/web/src/components/settings/ThemeImportDialog.tsx,apps/web/src/components/settings/ThemeImportDialog.test.tsapps/web/src/openVsxThemes.tsdocs/user/appearance.mdPriority: ➖ Normal
Estimated code review effort: 4 (Complex) | ~45 minutes
Change: Feature
Suggested reviewers:
stienswout,juliusmarmingeSequence Diagram(s)#
Merge Risk: 🔵 Low · up to
648c6The updated appearance documentation still needs the required Markdown formatter run before merge. This is a bounded documentation-quality and repository-policy concern.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
✅ Passed checks (4 passed)
Full details: Docstring Coverage
Explanation
Docstring coverage is 20.51% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 39 functions across 8 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Comment `@coderabbitai help` to get the list of available commands.