From adb78fa4b37c6414fb33fe3291392887b1fd51d3 Mon Sep 17 00:00:00 2001 From: Amartya Parijat Date: Fri, 25 Oct 2024 12:31:28 +0200 Subject: [PATCH] Set Edge data directory to workspace on Windows This contributes to adding the workspace address to the display data on workbench initialization as the data directory used by Edge browser. Contributes to https://github.com/eclipse-platform/eclipse.platform.swt/issues/1013 --- .../org/eclipse/ui/internal/Workbench.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java index 8e9a02ca0de..667f5c3ce79 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java @@ -37,6 +37,7 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.URL; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -74,6 +75,7 @@ import org.eclipse.core.runtime.ListenerList; import org.eclipse.core.runtime.MultiStatus; import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Platform.OS; import org.eclipse.core.runtime.SafeRunner; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.SubMonitor; @@ -140,6 +142,7 @@ import org.eclipse.jface.window.IShellProvider; import org.eclipse.jface.window.Window; import org.eclipse.osgi.internal.location.LocationHelper; +import org.eclipse.osgi.service.datalocation.Location; import org.eclipse.osgi.service.runnable.StartupMonitor; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; @@ -292,6 +295,8 @@ public final class Workbench extends EventManager implements IWorkbench, org.ecl public static final String PROP_EXIT_CODE = "eclipse.exitcode"; //$NON-NLS-1$ private static final String CMD_DATA = "-data"; //$NON-NLS-1$ + private static final String EDGE_USER_DATA_FOLDER = "org.eclipse.swt.internal.win32.Edge.userDataFolder"; //$NON-NLS-1$ + private static final class StartupProgressBundleListener implements ServiceListener { private final SubMonitor subMonitor; @@ -451,6 +456,10 @@ public void serviceChanged(ServiceEvent event) { private Workbench(Display display, final WorkbenchAdvisor advisor, MApplication app, IEclipseContext appContext) { this.advisor = Objects.requireNonNull(advisor); this.display = Objects.requireNonNull(display); + if (OS.isWindows()) { + setEdgeDataDirectory(this.display); + } + application = app; e4Context = appContext; @@ -510,6 +519,19 @@ public void eventLoopException(Throwable exception) { new WorkbenchLocationService(IServiceScopes.WORKBENCH_SCOPE, this, null, null, null, null, 0)); } + private static void setEdgeDataDirectory(Display display) { + Location workspaceLocation = Platform.getInstanceLocation(); + if (workspaceLocation == null) { + return; + } + try { + URI workspaceLocationURI = workspaceLocation.getURL().toURI(); + display.setData(EDGE_USER_DATA_FOLDER, Paths.get(workspaceLocationURI).toString()); + } catch (URISyntaxException e) { + WorkbenchPlugin.log("Invalid workspace location to be set for Edge browser.", e); //$NON-NLS-1$ + } + } + /** * Returns the one and only instance of the workbench, if there is one. *