@@ -15,6 +15,7 @@ import com.intellij.openapi.application.ApplicationManager
1515import com.intellij.openapi.diagnostic.Logger
1616import com.intellij.openapi.util.Disposer
1717import com.intellij.util.messages.MessageBusConnection
18+ import com.sina.weibo.agent.core.ServiceProxyRegistry
1819import java.io.File
1920import java.io.IOException
2021import java.io.InputStream
@@ -64,7 +65,7 @@ class ThemeManager : Disposable {
6465
6566 // JSON serialization
6667 private val gson = Gson ()
67-
68+
6869 /* *
6970 * Initialize theme manager
7071 * @param resourceRoot Theme resource root directory
@@ -404,53 +405,55 @@ class ThemeManager : Disposable {
404405 val themeFile = themeResourceDir?.resolve(themeFileName)?.toFile()
405406 val vscodeThemeFile = themeResourceDir?.resolve(vscodeThemeName)?.toFile()
406407
407- if (themeFile?.exists() == true && vscodeThemeFile?.exists() == true ) {
408- // Read theme file content
409- val themeContent = themeFile.readText()
410-
411- // Parse theme content
412- val parsed = parseThemeString(themeContent)
413-
414- // Handle include field, similar to getTheme.ts logic
415- var finalTheme = parsed
416- if (parsed.has(" include" )) {
417- val includeFileName = parsed.get(" include" ).asString
418- val includePath = themeResourceDir?.resolve(includeFileName)
419-
420- if (includePath != null && includePath.exists()) {
421- try {
422- val includeContent = includePath.toFile().readText()
423- val includeTheme = parseThemeString(includeContent)
424- finalTheme = mergeJsonObjects(finalTheme, includeTheme)
425- } catch (e: Exception ) {
426- logger.error(" Error processing include theme: $includeFileName " , e)
427- }
408+ val cssExists = vscodeThemeFile?.exists() == true
409+ if (! cssExists) {
410+ logger.warn(" VSCode theme style file does not exist: $vscodeThemeName " )
411+ return
412+ }
413+
414+ // Read theme file content if it exists; otherwise proceed with an empty theme
415+ val themeContent = if (themeFile?.exists() == true ) themeFile.readText() else " "
416+
417+ // Parse theme content when non-blank; otherwise start from an empty JsonObject
418+ val parsed = if (themeContent.isNotBlank()) parseThemeString(themeContent) else JsonObject ()
419+
420+ // Handle include field, similar to getTheme.ts logic
421+ var finalTheme = parsed
422+ if (parsed.has(" include" )) {
423+ val includeFileName = parsed.get(" include" ).asString
424+ val includePath = themeResourceDir?.resolve(includeFileName)
425+
426+ if (includePath != null && includePath.exists()) {
427+ try {
428+ val includeContent = includePath.toFile().readText()
429+ val includeTheme = parseThemeString(includeContent)
430+ finalTheme = mergeJsonObjects(finalTheme, includeTheme)
431+ } catch (e: Exception ) {
432+ logger.error(" Error processing include theme: $includeFileName " , e)
428433 }
429434 }
430-
431- // Convert theme
432- val converted = convertTheme(finalTheme)
433-
434- // Read VSCode theme style file
435- themeStyleContent = loadVscodeThemeStyle(vscodeThemeFile)
436-
437- // Add style content to converted theme object
438- if (themeStyleContent != null ) {
439- converted.addProperty(" cssContent" , themeStyleContent)
440- }
441-
442- // Update cache
443- val oldConfig = currentThemeConfig
444- currentThemeConfig = converted
445-
446- logger.info(" Loaded and converted theme configuration: $themeFileName " )
447-
448- // Notify listeners when configuration changes
449- if (oldConfig?.toString() != converted.toString()) {
450- notifyThemeChangeListeners()
451- }
452- } else {
453- logger.warn(" Theme configuration file does not exist: $themeFileName " )
435+ }
436+
437+ // Convert theme (works even if finalTheme is empty)
438+ val converted = convertTheme(finalTheme)
439+
440+ // Read VSCode theme style file
441+ themeStyleContent = vscodeThemeFile?.let { loadVscodeThemeStyle(it) }
442+
443+ // Add style content to converted theme object
444+ if (themeStyleContent != null ) {
445+ converted.addProperty(" cssContent" , themeStyleContent)
446+ }
447+
448+ // Update cache
449+ val oldConfig = currentThemeConfig
450+ currentThemeConfig = converted
451+
452+ logger.info(" Loaded and converted theme configuration: $themeFileName (theme exists: ${themeFile?.exists() == true } , css exists: $cssExists )" )
453+
454+ // Notify listeners when configuration changes
455+ if (oldConfig?.toString() != converted.toString()) {
456+ notifyThemeChangeListeners()
454457 }
455458 } catch (e: IOException ) {
456459 logger.error(" Error reading theme configuration" , e)
@@ -570,14 +573,18 @@ class ThemeManager : Disposable {
570573
571574 if (themeDir.notExists()) {
572575 // Try second path: integrations/theme/default-themes
573- themeDir = Paths .get (resourceRoot, " integrations " , " theme " , " default-themes " )
576+ themeDir = getDefaultThemeResourceDir (resourceRoot);
574577 if (themeDir.notExists()) {
575578 return null
576579 }
577580 }
578581
579582 return themeDir
580583 }
584+
585+ fun getDefaultThemeResourceDir (resourceRoot : String ): Path {
586+ return Paths .get(resourceRoot, " integrations" , " theme" , " default-themes" )
587+ }
581588
582589 /* *
583590 * Get theme manager instance
0 commit comments