Skip to content

Commit ac763a4

Browse files
committed
Fixes #2085: Only warn once per workspace
1 parent e8921f7 commit ac763a4

1 file changed

Lines changed: 24 additions & 8 deletions

File tree

  • org.eclipse.wildwebdeveloper.embedder.node/src/org/eclipse/wildwebdeveloper/embedder/node

org.eclipse.wildwebdeveloper.embedder.node/src/org/eclipse/wildwebdeveloper/embedder/node/NodeJSManager.java

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,19 @@
3131
import org.eclipse.core.runtime.IPath;
3232
import org.eclipse.core.runtime.Path;
3333
import org.eclipse.core.runtime.Platform;
34+
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
35+
import org.eclipse.core.runtime.preferences.InstanceScope;
3436
import org.eclipse.jface.dialogs.MessageDialog;
3537
import org.eclipse.osgi.service.datalocation.Location;
3638
import org.eclipse.swt.widgets.Display;
39+
import org.osgi.service.prefs.BackingStoreException;
3740

3841
public class NodeJSManager {
3942
public static final String NODE_ROOT_DIRECTORY = ".node";
4043

4144
private static final String MACOS_DSCL_SHELL_PREFIX = "UserShell: ";
45+
private static final String ALREADY_WARNED_NODEJS_MISSING = "alreadyWarnedNodeJsMissing";
4246

43-
private static boolean alreadyWarned;
4447
private static Properties cachedNodeJsInfoProperties;
4548
private static final Object EXPAND_LOCK = new Object();
4649

@@ -100,10 +103,9 @@ public static File getNodeJsLocation() {
100103
if (res != null) {
101104
validateNodeVersion(res);
102105
return res;
103-
} else if (!alreadyWarned) {
104-
warnNodeJSMissing();
105-
alreadyWarned = true;
106106
}
107+
warnNodeJSMissing();
108+
107109
return null;
108110
}
109111

@@ -332,20 +334,34 @@ private static void validateNodeVersion(File nodeJsLocation) {
332334
}
333335

334336
private static void warnNodeJSMissing() {
335-
if (!alreadyWarned) {
337+
if (!hasAlreadyWarnedNodeJsMissing()) {
336338
Display.getDefault().asyncExec(() -> MessageDialog.openWarning(Display.getCurrent().getActiveShell(),
337339
"Missing node.js", "Could not find node.js. This will result in editors missing key features.\n"
338340
+ "Please make sure node.js is installed and that your PATH environment variable contains the location to the `node` executable."));
341+
setAlreadyWarnedNodeJsMissing();
339342
}
340-
alreadyWarned = true;
341343
}
342344

343345
private static void warnNodeJSVersionCouldNotBeDetermined() {
344-
if (!alreadyWarned) {
346+
if (!hasAlreadyWarnedNodeJsMissing()) {
345347
Display.getDefault().asyncExec(() -> MessageDialog.openWarning(Display.getCurrent().getActiveShell(),
346348
"Node.js version could not be determined",
347349
"Node.js version could not be determined. Please make sure a recent version of node.js is installed, editors may be missing key features otherwise.\n"));
350+
setAlreadyWarnedNodeJsMissing();
348351
}
349-
alreadyWarned = true;
352+
}
353+
354+
private static boolean hasAlreadyWarnedNodeJsMissing() {
355+
return Platform.getPreferencesService().getBoolean(Activator.PLUGIN_ID, ALREADY_WARNED_NODEJS_MISSING, false, null);
356+
}
357+
358+
private static void setAlreadyWarnedNodeJsMissing() {
359+
try {
360+
IEclipsePreferences workspacePreferences = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
361+
workspacePreferences.putBoolean(ALREADY_WARNED_NODEJS_MISSING, true);
362+
workspacePreferences.flush();
363+
} catch (BackingStoreException e) {
364+
ILog.get().error(e.getMessage(), e);
365+
}
350366
}
351367
}

0 commit comments

Comments
 (0)