Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion com.microsoft.copilot.eclipse.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ Bundle-Activator: com.microsoft.copilot.eclipse.ui.CopilotUi
Bundle-RequiredExecutionEnvironment: JavaSE-17
Automatic-Module-Name: com.microsoft.copilot.eclipse.ui
Bundle-ActivationPolicy: lazy
Import-Package: org.osgi.framework;version="[1.10.0,2.0.0)"
Import-Package: org.eclipse.e4.ui.css.swt.theme,
org.osgi.framework;version="[1.10.0,2.0.0)"
Require-Bundle: com.microsoft.copilot.eclipse.core;bundle-version="0.19.0",
com.microsoft.copilot.eclipse.terminal.api;bundle-version="0.19.0",
org.eclipse.ui.ide;bundle-version="3.22.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.e4.ui.css.swt.theme.ITheme;
import org.eclipse.e4.ui.css.swt.theme.IThemeEngine;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.e4.ui.services.IStylingEngine;
import org.eclipse.e4.ui.workbench.modeling.EPartService;
Expand Down Expand Up @@ -88,7 +89,6 @@
import org.eclipse.ui.part.IShowInTarget;
import org.eclipse.ui.part.ShowInContext;
import org.eclipse.ui.texteditor.ITextEditor;
import org.osgi.service.prefs.Preferences;

import com.microsoft.copilot.eclipse.core.CopilotCore;
import com.microsoft.copilot.eclipse.core.utils.PlatformUtils;
Expand Down Expand Up @@ -505,10 +505,15 @@ public static void applyChatFont(Control control) {
* @return true if dark theme is active, false otherwise
*/
public static boolean isDarkTheme() {
Preferences preferences = InstanceScope.INSTANCE.getNode("org.eclipse.e4.ui.css.swt.theme");
String themeCssUri = preferences.get("themeid", "");
if (themeCssUri.toLowerCase().contains("dark")) {
return true;
IThemeEngine engine = PlatformUI.getWorkbench().getService(IThemeEngine.class);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding extra (not needed) dependency, you can use Platform.getPreferencesService(). Original problem was that only workspace scope was considered, preference service, if properly used, can consider other scopes as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem I encountered with this is method is that all scopes don't have a value to return. If I do for example:
Preferences preferences1 = InstanceScope.INSTANCE.getNode("org.eclipse.e4.ui.css.swt.theme");
String themeCssUri2 = preferences1.get("themeid", "");
Preferences preferences2 = ConfigurationScope.INSTANCE.getNode("org.eclipse.e4.ui.css.swt.theme");
String themeCssUri3 = preferences2.get("themeid", "");
Preferences preferences3 = DefaultScope.INSTANCE.getNode("org.eclipse.e4.ui.css.swt.theme");
String themeCssUri4 = preferences3.get("themeid", "");
IPreferencesService service = Platform.getPreferencesService();
String themeId = service.getString("org.eclipse.e4.ui.css.swt.theme", "currentThemeId", null, null);
String themeId2 = service.getString("org.eclipse.e4.ui.css.swt.theme", "currentThemeId", null, new IScopeContext[] { InstanceScope.INSTANCE });
String themeId3 = service.getString("org.eclipse.e4.ui.css.swt.theme", "currentThemeId", null, new IScopeContext[] { ConfigurationScope.INSTANCE });
String themeId4 = service.getString("org.eclipse.e4.ui.css.swt.theme", "currentThemeId", null, new IScopeContext[] {DefaultScope.INSTANCE });

All of the scopes return null (the default value if using the platform.getpreferencesservice) or "" (if using the Instancescope method). When I checked with copilot, it seems that the e4 service applies the preference through a different mechanism, so that's why we can't read the preference.

If the preference is saved in that file I mentioned before (such as manually setting/re-setting the preference), then the old code works fine. But if that file/preference isn't saved, then none of the default preference retreival methods are able to see the theme being applied.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iloveeclipse Will the newly introduced dependency a concern for you?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will the newly introduced dependency a concern for you?

Every added dependency always adds extra work in the future :-)

But if that file/preference isn't saved, then none of the default preference retreival methods are able to see the theme being applied.

I see. I would say this is a bug in Platform UI, you should report it here: https://github.com/eclipse-platform/eclipse.platform.ui/issues. A client doesn't need to have hard dependency to org.eclipse.e4.ui.css.swt.theme bundle just to know whether some preference is set or not.

So your solution seem to be the only possible today.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jomillerOpen could you file an issue as @iloveeclipse suggested?

My feeling is that: If the upstream fixes this immediately, then we can assume that we can get the truth via Platform.getPreferencesService(). Users will get the fix automatically as long as they upgrade the Eclipse IDE.

If the upstream has no plan to fix it immediately, I'm ok to have this workaround right now.

Let's see their response first. WDYT?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened a new bug for them: eclipse-platform/eclipse.platform.ui#4168

if (engine != null) {
ITheme activeTheme = engine.getActiveTheme();
if (activeTheme != null) {
String themeCssUri = activeTheme.getId();
if (themeCssUri != null && themeCssUri.toLowerCase().contains("dark")) {
return true;
}
}
}
return false;
}
Expand Down