From 1c24b914b38d95ebc931c2692548896a47006408 Mon Sep 17 00:00:00 2001 From: Andrew Zambazos Date: Wed, 21 Jan 2026 10:59:21 +1300 Subject: [PATCH] Update theme-manager.js --- theme-manager.js | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/theme-manager.js b/theme-manager.js index 7885e27..5a22c31 100644 --- a/theme-manager.js +++ b/theme-manager.js @@ -5,24 +5,55 @@ const fs = require('fs'); const path = require('path'); +const { app } = require('electron'); class ThemeManager { constructor() { this.themesDir = path.join(__dirname, 'themes'); - this.userThemesDir = path.join(this.themesDir, 'user'); - this.downloadedThemesDir = path.join(this.themesDir, 'downloaded'); + this.userDataThemesDir = path.join(app.getPath('userData'), 'themes'); + this.userThemesDir = path.join(this.userDataThemesDir, 'user'); + this.downloadedThemesDir = path.join(this.userDataThemesDir, 'downloaded'); + this.legacyUserThemesDir = path.join(this.themesDir, 'user'); + this.legacyDownloadedThemesDir = path.join(this.themesDir, 'downloaded'); this.ensureDirectories(); + this.migrateLegacyThemes(); } ensureDirectories() { - [this.userThemesDir, this.downloadedThemesDir].forEach(dir => { + [this.userDataThemesDir, this.userThemesDir, this.downloadedThemesDir].forEach(dir => { if (!fs.existsSync(dir)) { fs.mkdirSync(dir, { recursive: true }); } }); } + migrateLegacyThemes() { + this.migrateDirectoryIfNeeded(this.legacyUserThemesDir, this.userThemesDir); + this.migrateDirectoryIfNeeded(this.legacyDownloadedThemesDir, this.downloadedThemesDir); + } + + migrateDirectoryIfNeeded(fromDir, toDir) { + try { + if (!fs.existsSync(fromDir)) return; + if (!fs.existsSync(toDir)) fs.mkdirSync(toDir, { recursive: true }); + + const toFiles = fs.readdirSync(toDir).filter(file => file.endsWith('.json')); + if (toFiles.length > 0) return; + + const fromFiles = fs.readdirSync(fromDir).filter(file => file.endsWith('.json')); + fromFiles.forEach(file => { + const sourcePath = path.join(fromDir, file); + const destinationPath = path.join(toDir, file); + if (!fs.existsSync(destinationPath)) { + fs.copyFileSync(sourcePath, destinationPath); + } + }); + } catch (error) { + console.warn('[Themes] Failed to migrate legacy themes:', error); + } + } + /** * Get all available themes * @returns {Object} Object containing default, user, and downloaded themes