MCPcopy Index your code
hub / github.com/21st-dev/1code / registerThemeScannerIPC

Function registerThemeScannerIPC

src/main/lib/vscode-theme-scanner.ts:258–295  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

256 */
257let ipcRegistered = false
258export function registerThemeScannerIPC(): void {
259 if (ipcRegistered) {
260 return
261 }
262 ipcRegistered = true
263
264 ipcMain.handle("vscode:scan-themes", async () => {
265 try {
266 const themes = await scanVSCodeThemes()
267 return themes
268 } catch (error) {
269 console.error("Error scanning VS Code themes:", error)
270 throw error
271 }
272 })
273
274 ipcMain.handle("vscode:load-theme", async (_, themePath: string) => {
275 try {
276 // Security: Validate path is within allowed directories
277 const normalizedPath = path.normalize(themePath)
278 const isAllowedPath = EXTENSION_PATHS.some(({ path: allowedDir }) => {
279 const normalizedAllowed = path.normalize(allowedDir)
280 // Ensure we check with path separator to avoid partial matches
281 return normalizedPath.startsWith(normalizedAllowed + path.sep) ||
282 normalizedPath.startsWith(normalizedAllowed)
283 })
284
285 if (!isAllowedPath) {
286 throw new Error("Theme path is not within allowed directories")
287 }
288
289 return await loadThemeFromPath(normalizedPath)
290 } catch (error) {
291 console.error("Error loading VS Code theme:", error)
292 throw error
293 }
294 })
295}

Callers 1

registerIpcHandlersFunction · 0.90

Calls 2

scanVSCodeThemesFunction · 0.85
loadThemeFromPathFunction · 0.85

Tested by

no test coverage detected