Skip to content

Commit 49f8cdf

Browse files
committed
IEP-1516: Automatic update to IDE with filewatcher (#1210)
* automatic refresh added * switched to message dialog * improved null checks * file watcher added first
1 parent e378e21 commit 49f8cdf

File tree

5 files changed

+123
-16
lines changed

5 files changed

+123
-16
lines changed

bundles/com.espressif.idf.core/src/com/espressif/idf/core/tools/watcher/EimJsonWatchService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ public void run()
129129
try
130130
{
131131
watchService.close();
132+
Logger.log("File Watch Service close"); //$NON-NLS-1$
132133
}
133134
catch (IOException e)
134135
{

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/EspressifToolStartup.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import java.text.MessageFormat;
88

9-
import org.eclipse.jface.dialogs.MessageDialog;
109
import org.eclipse.swt.SWT;
1110
import org.eclipse.swt.widgets.Display;
1211
import org.eclipse.swt.widgets.MessageBox;
@@ -41,13 +40,17 @@
4140
*/
4241
public class EspressifToolStartup implements IStartup
4342
{
43+
private EimJsonUiChangeHandler eimJsonUiChangeHandler;
4444
@Override
4545
public void earlyStartup()
4646
{
4747
Preferences preferences = org.eclipse.core.runtime.preferences.InstanceScope.INSTANCE
4848
.getNode(UIPlugin.PLUGIN_ID);
4949
ToolInitializer toolInitializer = new ToolInitializer(preferences);
50-
50+
EimJsonStateChecker stateChecker = new EimJsonStateChecker(preferences);
51+
eimJsonUiChangeHandler = new EimJsonUiChangeHandler(preferences);
52+
stateChecker.updateLastSeenTimestamp();
53+
EimJsonWatchService.getInstance().addEimJsonChangeListener(eimJsonUiChangeHandler);
5154
if (!toolInitializer.isEimInstalled())
5255
{
5356
notifyMissingTools();
@@ -65,23 +68,16 @@ public void earlyStartup()
6568
promptUserToOpenToolManager(eimJson);
6669
}
6770

68-
EimJsonStateChecker stateChecker = new EimJsonStateChecker(preferences);
6971
if (stateChecker.wasModifiedSinceLastRun())
7072
{
7173
showEimJsonStateChangeNotification();
7274
}
73-
74-
stateChecker.updateLastSeenTimestamp();
75-
EimJsonWatchService.getInstance().addEimJsonChangeListener(new EimJsonUiChangeHandler(preferences));
7675
}
7776

7877
private void showEimJsonStateChangeNotification()
7978
{
80-
Display.getDefault().asyncExec(() -> {
81-
MessageDialog.openInformation(Display.getDefault().getActiveShell(),
82-
com.espressif.idf.ui.tools.Messages.EimJsonChangedMsgTitle,
83-
com.espressif.idf.ui.tools.Messages.EimJsonStateChangedMsgDetail);
84-
});
79+
int response = eimJsonUiChangeHandler.displayMessageToUser();
80+
eimJsonUiChangeHandler.handleUserResponse(response);
8581
}
8682

8783
private void notifyMissingTools()

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/Messages.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ public class Messages extends NLS
3030
public static String EimJsonChangedMsgDetail;
3131
public static String EimJsonStateChangedMsgDetail;
3232

33+
public static String MsgYes;
34+
public static String MsgNo;
35+
3336
static
3437
{
3538
// initialize resource bundle

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/messages.properties

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ EspIdfManagerReloadBtnToolTip=Reload from disk
77
IDFToolsHandler_ToolsManagerConsole=Espressif IDF Tools Console
88
IDFGuideLinkLabel_Text=Select the version of ESP-IDF you want to use. Click the radio button in Active column next to the version you want. For help in choosing the correct version, visit <a>ESP-IDF Version Guide</a>.
99
EimJsonChangedMsgTitle=ESP-IDF Installation Changed
10-
EimJsonChangedMsgDetail=It looks like the ESP-IDF tools are modified. The Espressif IDE cannot guarantee the consistency. Kindly refresh the installation via ESP-IDF Manager.
10+
EimJsonChangedMsgDetail=It seems that the ESP-IDF tools have been modified. If you just installed ESP-IDF we recommend refereshing via ESP-IDF Manager . Would you like to proceed with the update?
1111
EimJsonStateChangedMsgDetail=It looks like the ESP-IDF installation was modified since last start. The Espressif IDE cannot guarantee the consistency. Kindly refresh the installation via ESP-IDF Manager.
12-
12+
MsgYes=Yes
13+
MsgNo=No

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/watcher/EimJsonUiChangeHandler.java

Lines changed: 109 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,31 @@
44
*******************************************************************************/
55
package com.espressif.idf.ui.tools.watcher;
66

7+
import java.io.IOException;
78
import java.nio.file.Path;
89

910
import org.eclipse.jface.dialogs.MessageDialog;
1011
import org.eclipse.swt.widgets.Display;
12+
import org.eclipse.swt.widgets.Shell;
13+
import org.eclipse.ui.IWorkbenchWindow;
14+
import org.eclipse.ui.PartInitException;
15+
import org.eclipse.ui.console.MessageConsoleStream;
16+
import org.eclipse.ui.ide.IDE;
1117
import org.osgi.service.prefs.Preferences;
1218

19+
import com.espressif.idf.core.logging.Logger;
20+
import com.espressif.idf.core.tools.EimIdfConfiguratinParser;
21+
import com.espressif.idf.core.tools.SetupToolsInIde;
22+
import com.espressif.idf.core.tools.vo.EimJson;
1323
import com.espressif.idf.core.tools.watcher.EimJsonChangeListener;
1424
import com.espressif.idf.core.tools.watcher.EimJsonStateChecker;
25+
import com.espressif.idf.ui.IDFConsole;
26+
import com.espressif.idf.ui.handlers.EclipseHandler;
1527
import com.espressif.idf.ui.tools.Messages;
28+
import com.espressif.idf.ui.tools.SetupToolsJobListener;
29+
import com.espressif.idf.ui.tools.manager.ESPIDFManagerEditor;
30+
import com.espressif.idf.ui.tools.manager.EimEditorInput;
31+
import com.espressif.idf.ui.tools.manager.pages.ESPIDFMainTablePage;
1632

1733
/**
1834
* eim_idf.json file ui change handler to notify user for changes.
@@ -23,6 +39,7 @@
2339
public class EimJsonUiChangeHandler implements EimJsonChangeListener
2440
{
2541
private Preferences preferences;
42+
private EimJson eimJson;
2643

2744
public EimJsonUiChangeHandler(Preferences preferences)
2845
{
@@ -32,13 +49,102 @@ public EimJsonUiChangeHandler(Preferences preferences)
3249
@Override
3350
public void onJsonFileChanged(Path file)
3451
{
35-
Display.getDefault().asyncExec(() -> {
36-
MessageDialog.openWarning(Display.getDefault().getActiveShell(), Messages.EimJsonChangedMsgTitle,
37-
Messages.EimJsonChangedMsgDetail);
52+
int response = displayMessageToUser();
53+
handleUserResponse(response);
54+
}
55+
56+
public int displayMessageToUser()
57+
{
58+
final int[] response = new int[] { -1 };
59+
Display display = Display.getDefault();
60+
display.syncExec(() -> {
61+
Shell shell = display.getActiveShell();
62+
if (shell == null)
63+
{
64+
shell = new Shell(display);
65+
}
66+
MessageDialog messageDialog = new MessageDialog(shell, Messages.EimJsonChangedMsgTitle, null,
67+
Messages.EimJsonChangedMsgDetail, MessageDialog.WARNING, 0,
68+
new String[] { Messages.MsgYes, Messages.MsgNo });
69+
response[0] = messageDialog.open();
3870
});
3971

72+
return response[0];
73+
}
74+
75+
public void handleUserResponse(int response)
76+
{
77+
if (response == 0)
78+
{
79+
try
80+
{
81+
loadEimJson();
82+
if (eimJson.getIdfInstalled().size() == 1)
83+
{
84+
// only one entry in eimJson so we can simply refresh the IDE environment with that.
85+
setupToolsInIde();
86+
}
87+
else
88+
{
89+
// multiple entries in json so launch manager for user to handle this
90+
launchEspIdfManager();
91+
}
92+
}
93+
catch (
94+
IOException
95+
| PartInitException e)
96+
{
97+
Logger.log(e);
98+
}
99+
}
100+
40101
EimJsonStateChecker checker = new EimJsonStateChecker(preferences);
41102
checker.updateLastSeenTimestamp();
42103
}
43104

105+
private void loadEimJson() throws IOException
106+
{
107+
EimIdfConfiguratinParser eimIdfConfiguratinParser = new EimIdfConfiguratinParser();
108+
eimJson = eimIdfConfiguratinParser.getEimJson(true);
109+
}
110+
111+
private void setupToolsInIde()
112+
{
113+
SetupToolsInIde setupToolsInIde = new SetupToolsInIde(eimJson.getIdfInstalled().get(0), eimJson,
114+
getConsoleStream(true), getConsoleStream(false));
115+
SetupToolsJobListener toolsActivationJobListener = new SetupToolsJobListener(ESPIDFMainTablePage.getInstance(eimJson),
116+
setupToolsInIde);
117+
setupToolsInIde.addJobChangeListener(toolsActivationJobListener);
118+
setupToolsInIde.schedule();
119+
}
120+
121+
private void launchEspIdfManager() throws PartInitException
122+
{
123+
Display.getDefault().asyncExec(() -> {
124+
IWorkbenchWindow activeww = EclipseHandler.getActiveWorkbenchWindow();
125+
if (activeww == null || activeww.getActivePage() == null)
126+
{
127+
Logger.log("Cannot open ESP-IDF Manager. No active workbench window or active page.");
128+
return;
129+
}
130+
131+
try
132+
{
133+
IDE.openEditor(activeww.getActivePage(), new EimEditorInput(eimJson), ESPIDFManagerEditor.EDITOR_ID,
134+
true);
135+
}
136+
catch (PartInitException e)
137+
{
138+
Logger.log("Failed to open ESP-IDF Manager Editor.");
139+
Logger.log(e);
140+
}
141+
});
142+
143+
}
144+
145+
private MessageConsoleStream getConsoleStream(boolean errorStream)
146+
{
147+
IDFConsole idfConsole = new IDFConsole();
148+
return idfConsole.getConsoleStream(Messages.IDFToolsHandler_ToolsManagerConsole, null, errorStream, true);
149+
}
44150
}

0 commit comments

Comments
 (0)