Skip to content

Commit 9b1606f

Browse files
authored
IEP-1754 Run ESP-IDF version detection asynchronously with progress reporting (#1445)
* feat: use Job and virtual threads for refresh * feat: internalizing strings in the ESPIDFMainTablePage
1 parent 6e2de1e commit 9b1606f

3 files changed

Lines changed: 70 additions & 37 deletions

File tree

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,22 @@ public class Messages extends NLS
3838

3939
public static String ESPIDFMainTablePage_ActiveLbl;
4040

41+
public static String ESPIDFMainTablePage_DetectingEspIdfSubTaskName;
42+
4143
public static String ESPIDFMainTablePage_EIMButtonTooltip;
4244

45+
public static String ESPIDFMainTablePage_FailderRefreshMsg;
46+
4347
public static String ESPIDFMainTablePage_MainContentGroupLbl;
4448

4549
public static String ESPIDFMainTablePage_RefreshEnvBtnName;
4650

4751
public static String ESPIDFMainTablePage_RefreshEnvBtnTooltip;
4852

53+
public static String ESPIDFMainTablePage_RefreshingIdfJobName;
54+
55+
public static String ESPIDFMainTablePage_ScanningProcessTaskName;
56+
4957
public static String ESPIDFMainTablePage_SettingUpLbl;
5058

5159
public static String ESPIDFMainTablePage_StatusColumnName;

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/manager/pages/ESPIDFMainTablePage.java

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

77
import java.util.List;
88
import java.util.concurrent.CompletableFuture;
9+
import java.util.concurrent.Executors;
910

11+
import org.eclipse.core.runtime.IProgressMonitor;
12+
import org.eclipse.core.runtime.IStatus;
13+
import org.eclipse.core.runtime.Status;
14+
import org.eclipse.core.runtime.jobs.Job;
1015
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
1116
import org.eclipse.core.runtime.preferences.InstanceScope;
1217
import org.eclipse.jface.layout.TableColumnLayout;
@@ -81,16 +86,14 @@ private record IdfRow(IdfInstalled original, boolean isActive, String version, S
8186
private EimJson eimJson;
8287

8388
private final EimIdfConfiguratinParser configParser;
84-
private final ToolInitializer toolInitializer;
85-
8689
private final IDFConsole idfConsole = new IDFConsole();
8790
private IdfInstalled currentInstallingNode = null;
8891

8992
public ESPIDFMainTablePage(EimJson eimJson)
9093
{
9194
this.eimJson = eimJson;
9295
this.configParser = new EimIdfConfiguratinParser();
93-
this.toolInitializer = new ToolInitializer(InstanceScope.INSTANCE.getNode(UIPlugin.PLUGIN_ID));
96+
new ToolInitializer(InstanceScope.INSTANCE.getNode(UIPlugin.PLUGIN_ID));
9497
}
9598

9699
public Composite createPage(Composite parent)
@@ -423,44 +426,62 @@ public void refreshEditorUI()
423426
if (container == null || container.isDisposed())
424427
return;
425428

426-
CompletableFuture.supplyAsync(() -> {
427-
try
429+
Job refreshJob = new Job(Messages.ESPIDFMainTablePage_RefreshingIdfJobName)
430+
{
431+
@Override
432+
protected IStatus run(IProgressMonitor monitor)
428433
{
429-
var newJson = configParser.getEimJson(true);
430-
if (newJson != null && newJson.getIdfInstalled() != null)
434+
monitor.beginTask(Messages.ESPIDFMainTablePage_ScanningProcessTaskName, IProgressMonitor.UNKNOWN);
435+
436+
try
431437
{
432-
var gitPath = newJson.getGitPath();
433-
return newJson.getIdfInstalled().stream()
434-
.map(idf -> new IdfRow(idf, ToolsUtility.isIdfInstalledActive(idf),
435-
ToolsUtility.getIdfVersion(idf, gitPath), idf.getName(), idf.getPath()))
436-
.toList();
438+
var newJson = configParser.getEimJson(true);
439+
List<IdfRow> rows = List.of();
440+
441+
if (newJson != null && newJson.getIdfInstalled() != null)
442+
{
443+
var gitPath = newJson.getGitPath();
444+
445+
monitor.subTask(Messages.ESPIDFMainTablePage_DetectingEspIdfSubTaskName);
446+
447+
try (var executor = Executors.newVirtualThreadPerTaskExecutor())
448+
{
449+
var futures = newJson.getIdfInstalled().stream().map(idf -> CompletableFuture.supplyAsync(
450+
() -> new IdfRow(idf, ToolsUtility.isIdfInstalledActive(idf),
451+
ToolsUtility.getIdfVersion(idf, gitPath), idf.getName(), idf.getPath()),
452+
executor)).toList();
453+
454+
rows = futures.stream().map(CompletableFuture::join).toList();
455+
}
456+
}
457+
458+
final List<IdfRow> finalRows = rows;
459+
460+
Display.getDefault().asyncExec(() -> {
461+
if (container.isDisposed())
462+
return;
463+
464+
var currentSelection = tableViewer.getSelection();
465+
currentInstallingNode = null;
466+
467+
tableViewer.setInput(finalRows);
468+
tableViewer.setSelection(currentSelection);
469+
updateButtonState();
470+
});
471+
472+
return Status.OK_STATUS;
473+
}
474+
catch (Exception e)
475+
{
476+
Logger.log(e);
477+
return new Status(IStatus.ERROR, UIPlugin.PLUGIN_ID, Messages.ESPIDFMainTablePage_FailderRefreshMsg, e);
478+
} finally
479+
{
480+
monitor.done();
437481
}
438-
return List.<IdfRow>of();
439-
}
440-
catch (Exception e)
441-
{
442-
throw new RuntimeException(e);
443-
}
444-
}).thenAcceptAsync(rows -> {
445-
if (container.isDisposed())
446-
return;
447-
var currentSelection = tableViewer.getSelection();
448-
this.currentInstallingNode = null;
449-
try
450-
{
451-
this.eimJson = configParser.getEimJson(false);
452-
}
453-
catch (Exception e)
454-
{
455-
Logger.log(e.toString());
456482
}
457-
tableViewer.setInput(rows);
458-
tableViewer.setSelection(currentSelection);
459-
updateButtonState();
460-
}, Display.getDefault()::asyncExec).exceptionally(ex -> {
461-
Logger.log(ex.getCause() != null ? ex.getCause().toString() : ex.toString());
462-
return null;
463-
});
483+
};
484+
refreshJob.schedule();
464485
}
465486

466487
public void setupInitialEspIdf()

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@ EimJsonStateChangedMsgDetail=It looks like the ESP-IDF installation was modified
1414
ESPIDFMainTablePage_ActiveBtnName=Activate Selected
1515
ESPIDFMainTablePage_ActiveBtnTooltip=Set this version as the active ESP-IDF
1616
ESPIDFMainTablePage_ActiveLbl=\u2713 Active
17+
ESPIDFMainTablePage_DetectingEspIdfSubTaskName=Detecting ESP-IDF versions...
1718
ESPIDFMainTablePage_EIMButtonTooltip=Open the ESP-IDF Installation Manager (EIM) to install, update, or remove ESP-IDF versions.
19+
ESPIDFMainTablePage_FailderRefreshMsg=Failed to refresh ESP-IDF environments
1820
ESPIDFMainTablePage_MainContentGroupLbl=Installed IDF Versions
1921
ESPIDFMainTablePage_RefreshEnvBtnName=Refresh Environment
2022
ESPIDFMainTablePage_RefreshEnvBtnTooltip=Refresh toolchains, Python virtual environment, and IDE settings for the CURRENTLY ACTIVE version
23+
ESPIDFMainTablePage_RefreshingIdfJobName=Refreshing ESP-IDF Environments
24+
ESPIDFMainTablePage_ScanningProcessTaskName=Scanning configurations...
2125
ESPIDFMainTablePage_SettingUpLbl=Setting up...
2226
ESPIDFMainTablePage_StatusColumnName=Status
2327
ESPIDFMainTablePage_VersionDetectionFailedMsg=Detection Failed

0 commit comments

Comments
 (0)