Skip to content

Commit c595346

Browse files
travkin79Copilot
andcommitted
Fix dark theme detection using IThemeEngine API
Replace preference-based theme detection with the proper IThemeEngine service API. The previous approach read the theme ID from preferences which could be stale or unavailable. The new approach queries the active theme directly via IThemeEngine.getActiveTheme(). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 0563df1 commit c595346

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

com.microsoft.copilot.eclipse.ui/META-INF/MANIFEST.MF

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,6 @@ Require-Bundle: com.microsoft.copilot.eclipse.core;bundle-version="0.19.0",
7171
org.eclipse.jdt.debug;resolution:=optional,
7272
org.commonmark;bundle-version="0.24.0",
7373
org.commonmark-gfm-tables;bundle-version="0.24.0",
74-
org.commonmark-task-list-items;bundle-version="0.24.0"
74+
org.commonmark-task-list-items;bundle-version="0.24.0",
7575
org.commonmark-gfm-strikethrough;bundle-version="0.24.0",
76+
org.eclipse.e4.ui.css.swt.theme;bundle-version="0.14.500"

com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/utils/UiUtils.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
import org.eclipse.core.filesystem.IFileStore;
3636
import org.eclipse.core.resources.IFile;
3737
import org.eclipse.core.resources.IResource;
38-
import org.eclipse.core.runtime.preferences.InstanceScope;
38+
import org.eclipse.e4.ui.css.swt.theme.ITheme;
39+
import org.eclipse.e4.ui.css.swt.theme.IThemeEngine;
3940
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
4041
import org.eclipse.e4.ui.services.IStylingEngine;
4142
import org.eclipse.e4.ui.workbench.modeling.EPartService;
@@ -88,7 +89,6 @@
8889
import org.eclipse.ui.part.IShowInTarget;
8990
import org.eclipse.ui.part.ShowInContext;
9091
import org.eclipse.ui.texteditor.ITextEditor;
91-
import org.osgi.service.prefs.Preferences;
9292

9393
import com.microsoft.copilot.eclipse.core.CopilotCore;
9494
import com.microsoft.copilot.eclipse.core.utils.PlatformUtils;
@@ -505,10 +505,17 @@ public static void applyChatFont(Control control) {
505505
* @return true if dark theme is active, false otherwise
506506
*/
507507
public static boolean isDarkTheme() {
508-
Preferences preferences = InstanceScope.INSTANCE.getNode("org.eclipse.e4.ui.css.swt.theme");
509-
String themeCssUri = preferences.get("themeid", "");
510-
if (themeCssUri.toLowerCase().contains("dark")) {
511-
return true;
508+
IStylingEngine stylingEngine = PlatformUI.getWorkbench().getService(IStylingEngine.class);
509+
if (stylingEngine != null) {
510+
IThemeEngine themeEngine =
511+
(IThemeEngine) PlatformUI.getWorkbench().getService(IThemeEngine.class);
512+
if (themeEngine != null) {
513+
ITheme activeTheme = themeEngine.getActiveTheme();
514+
if (activeTheme != null) {
515+
String themeId = activeTheme.getId();
516+
return themeId.toLowerCase().contains("dark");
517+
}
518+
}
512519
}
513520
return false;
514521
}

0 commit comments

Comments
 (0)