()
| 256 | */ |
| 257 | let ipcRegistered = false |
| 258 | export 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 | } |
no test coverage detected