|
31 | 31 | import org.eclipse.core.runtime.IPath; |
32 | 32 | import org.eclipse.core.runtime.Path; |
33 | 33 | import org.eclipse.core.runtime.Platform; |
| 34 | +import org.eclipse.core.runtime.preferences.IEclipsePreferences; |
| 35 | +import org.eclipse.core.runtime.preferences.InstanceScope; |
34 | 36 | import org.eclipse.jface.dialogs.MessageDialog; |
35 | 37 | import org.eclipse.osgi.service.datalocation.Location; |
36 | 38 | import org.eclipse.swt.widgets.Display; |
| 39 | +import org.osgi.service.prefs.BackingStoreException; |
37 | 40 |
|
38 | 41 | public class NodeJSManager { |
39 | 42 | public static final String NODE_ROOT_DIRECTORY = ".node"; |
40 | 43 |
|
41 | 44 | private static final String MACOS_DSCL_SHELL_PREFIX = "UserShell: "; |
| 45 | + private static final String ALREADY_WARNED_NODEJS_MISSING = "alreadyWarnedNodeJsMissing"; |
42 | 46 |
|
43 | | - private static boolean alreadyWarned; |
44 | 47 | private static Properties cachedNodeJsInfoProperties; |
45 | 48 | private static final Object EXPAND_LOCK = new Object(); |
46 | 49 |
|
@@ -100,10 +103,9 @@ public static File getNodeJsLocation() { |
100 | 103 | if (res != null) { |
101 | 104 | validateNodeVersion(res); |
102 | 105 | return res; |
103 | | - } else if (!alreadyWarned) { |
104 | | - warnNodeJSMissing(); |
105 | | - alreadyWarned = true; |
106 | 106 | } |
| 107 | + warnNodeJSMissing(); |
| 108 | + |
107 | 109 | return null; |
108 | 110 | } |
109 | 111 |
|
@@ -332,20 +334,34 @@ private static void validateNodeVersion(File nodeJsLocation) { |
332 | 334 | } |
333 | 335 |
|
334 | 336 | private static void warnNodeJSMissing() { |
335 | | - if (!alreadyWarned) { |
| 337 | + if (!hasAlreadyWarnedNodeJsMissing()) { |
336 | 338 | Display.getDefault().asyncExec(() -> MessageDialog.openWarning(Display.getCurrent().getActiveShell(), |
337 | 339 | "Missing node.js", "Could not find node.js. This will result in editors missing key features.\n" |
338 | 340 | + "Please make sure node.js is installed and that your PATH environment variable contains the location to the `node` executable.")); |
| 341 | + setAlreadyWarnedNodeJsMissing(); |
339 | 342 | } |
340 | | - alreadyWarned = true; |
341 | 343 | } |
342 | 344 |
|
343 | 345 | private static void warnNodeJSVersionCouldNotBeDetermined() { |
344 | | - if (!alreadyWarned) { |
| 346 | + if (!hasAlreadyWarnedNodeJsMissing()) { |
345 | 347 | Display.getDefault().asyncExec(() -> MessageDialog.openWarning(Display.getCurrent().getActiveShell(), |
346 | 348 | "Node.js version could not be determined", |
347 | 349 | "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(); |
348 | 351 | } |
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 | + } |
350 | 366 | } |
351 | 367 | } |
0 commit comments