Skip to content

Commit 1d64f99

Browse files
committed
IEP-1554: Finalized eim launch and download changes
1 parent 5f7ef32 commit 1d64f99

File tree

9 files changed

+268
-186
lines changed

9 files changed

+268
-186
lines changed

bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/messages.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ IDFBuildConfiguration_ParseCommand=Parse Compile Commands File
1919
IncreasePartitionSizeTitle=Low Application Partition Size
2020
IncreasePartitionSizeMessage=Less than 30% of application partition size is free({0} of {1} bytes), would you like to increase it? Please click <a href={2}>here</a> to check more details.
2121
ToolsInitializationDifferentPathMessageBoxTitle=Different IDF path found in the config file
22-
ToolsInitializationEimMissingMsgBoxTitle=ESP-IDF Not Found
23-
ToolsInitializationEimMissingMsgBoxMessage=ESP-IDF is not found on your system. To use the IDE, install ESP-IDF using <a href="{0}">EIM - GUI Installer</a>. \n\nOnce installed, the IDE will automatically detect ESP-IDF. You can verify and activate it from the ESP-IDF Manager, accessible via the menu: Espressif > ESP-IDF Manager.\n\n
22+
ToolsInitializationEimMissingMsgBoxTitle=ESP-IDF Installation Required
23+
ToolsInitializationEimMissingMsgBoxMessage=ESP-IDF is not currently installed on your system. To proceed, you can download and launch the EIM - GUI Installer directly from this IDE.\n\nWould you like to download and start the EIM installer now?\n\nOnce installation is complete, the IDE will automatically detect ESP-IDF. You can also verify and activate it later from the ESP-IDF Manager (Espressif > ESP-IDF Manager).
2424
ToolsInitializationDifferentPathMessageBoxMessage=A different ESP-IDF path was found in the esp_idf.json.json configuration file. Do you want to install the tools in the new path or the old path? Please click on the appropriate button.\nNew Path: {0}\nOld Path: {1}
2525
ToolsInitializationDifferentPathMessageBoxOptionYes=Yes
2626
ToolsInitializationDifferentPathMessageBoxOptionNo=No

bundles/com.espressif.idf.core/src/com/espressif/idf/core/tools/EimDownloader.java renamed to bundles/com.espressif.idf.core/src/com/espressif/idf/core/tools/EimLoader.java

Lines changed: 137 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package com.espressif.idf.core.tools;
22

3+
import java.io.BufferedReader;
4+
import java.io.File;
35
import java.io.FileInputStream;
6+
import java.io.FileNotFoundException;
47
import java.io.IOException;
58
import java.io.InputStream;
69
import java.io.InputStreamReader;
@@ -11,33 +14,164 @@
1114
import java.nio.file.Path;
1215
import java.nio.file.Paths;
1316
import java.nio.file.StandardCopyOption;
17+
import java.util.List;
1418
import java.util.Optional;
1519
import java.util.zip.ZipEntry;
1620
import java.util.zip.ZipInputStream;
1721

1822
import org.eclipse.core.runtime.IProgressMonitor;
1923
import org.eclipse.core.runtime.Platform;
24+
import org.eclipse.swt.widgets.Display;
25+
import org.eclipse.ui.console.MessageConsoleStream;
2026

27+
import com.espressif.idf.core.IDFEnvironmentVariables;
28+
import com.espressif.idf.core.logging.Logger;
2129
import com.espressif.idf.core.util.StringUtil;
2230
import com.google.gson.JsonArray;
2331
import com.google.gson.JsonObject;
2432
import com.google.gson.JsonParser;
2533

26-
public class EimDownloader
34+
public class EimLoader
2735
{
2836
private static final String URL_JSON = "https://dl.espressif.com/dl/eim/eim_unified_release.json"; //$NON-NLS-1$
2937
private static final Path DOWNLOAD_DIR = Paths.get(System.getProperty("java.io.tmpdir"), "eim_gui"); //$NON-NLS-1$ //$NON-NLS-2$
3038

3139
private String os;
3240
private String arch;
33-
DownloadListener listener;
41+
private DownloadListener listener;
42+
private MessageConsoleStream standardConsoleStream;
43+
private MessageConsoleStream errorConsoleStream;
44+
private Display display;
3445

35-
public EimDownloader(DownloadListener listener)
46+
public EimLoader(DownloadListener listener, MessageConsoleStream standardConsoleStream, MessageConsoleStream errorConsoleStream, Display display)
3647
{
3748
os = Platform.getOS();
3849
arch = Platform.getOSArch();
3950
this.listener = listener;
51+
this.standardConsoleStream = standardConsoleStream;
52+
this.errorConsoleStream = errorConsoleStream;
53+
this.display = display;
4054
}
55+
56+
private void logMessage(String message)
57+
{
58+
display.asyncExec(()->{
59+
try
60+
{
61+
standardConsoleStream.write(message);
62+
}
63+
catch (IOException e)
64+
{
65+
Logger.log(e);
66+
logError(e.getMessage());
67+
}
68+
});
69+
70+
Logger.log(message);
71+
}
72+
73+
private void logError(String message)
74+
{
75+
display.asyncExec(()->{
76+
try
77+
{
78+
errorConsoleStream.write(message);
79+
}
80+
catch (IOException e)
81+
{
82+
Logger.log(e);
83+
}
84+
});
85+
86+
Logger.log(message);
87+
}
88+
89+
public Process launchEim(String eimPath) throws IOException
90+
{
91+
if (!Files.exists(Paths.get(eimPath)))
92+
throw new FileNotFoundException("EIM path not found: " + eimPath); //$NON-NLS-1$
93+
94+
String os = Platform.getOS();
95+
List<String> command;
96+
97+
if (os.equals(Platform.OS_WIN32))
98+
{
99+
command = List.of("cmd.exe", "/c", eimPath.toString()); //$NON-NLS-1$ //$NON-NLS-2$
100+
}
101+
else if (os.equals(Platform.OS_MACOSX))
102+
{
103+
command = List.of("open", "-a", eimPath.toString()); //$NON-NLS-1$//$NON-NLS-2$
104+
}
105+
else if (os.equals(Platform.OS_LINUX))
106+
{
107+
command = List.of("bash", "-c", "\"" + eimPath.toString() + "\""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
108+
}
109+
else
110+
{
111+
throw new UnsupportedOperationException("Unsupported OS: " + os); //$NON-NLS-1$
112+
}
113+
114+
Process process = new ProcessBuilder(command).redirectErrorStream(true).start();
115+
116+
logMessage("Launched EIM application: " + eimPath + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
117+
118+
return process;
119+
}
120+
121+
public Process installAndLaunchDmg(Path dmgPath) throws IOException, InterruptedException
122+
{
123+
logMessage("Mounting DMG...\n"); //$NON-NLS-1$
124+
ProcessBuilder mountBuilder = new ProcessBuilder("hdiutil", "attach", dmgPath.toString()); //$NON-NLS-1$ //$NON-NLS-2$
125+
Process mountProcess = mountBuilder.start();
126+
127+
String volumePath = null;
128+
try (BufferedReader reader = new BufferedReader(new InputStreamReader(mountProcess.getInputStream())))
129+
{
130+
String line;
131+
while ((line = reader.readLine()) != null)
132+
{
133+
if (line.contains("/Volumes/")) //$NON-NLS-1$
134+
{
135+
String[] parts = line.split("\t"); //$NON-NLS-1$
136+
for (String part : parts)
137+
{
138+
if (part.startsWith("/Volumes/")) //$NON-NLS-1$
139+
{
140+
volumePath = part.trim();
141+
break;
142+
}
143+
}
144+
}
145+
}
146+
}
147+
148+
if (volumePath == null)
149+
throw new IOException("Failed to mount DMG: Volume path not found."); //$NON-NLS-1$
150+
151+
File[] apps = new File(volumePath).listFiles((dir, name) -> name.endsWith(".app")); //$NON-NLS-1$
152+
if (apps == null || apps.length == 0)
153+
throw new FileNotFoundException("No .app found inside DMG."); //$NON-NLS-1$
154+
155+
File appBundle = apps[0];
156+
Path targetAppPath = Paths.get("/Applications", appBundle.getName()); //$NON-NLS-1$
157+
158+
logMessage("Copying app to /Applications...\n"); //$NON-NLS-1$
159+
160+
// Copy to /Applications
161+
ProcessBuilder copyBuilder = new ProcessBuilder("cp", "-R", appBundle.getAbsolutePath(), //$NON-NLS-1$ //$NON-NLS-2$
162+
targetAppPath.toString());
163+
copyBuilder.inheritIO().start().waitFor();
164+
165+
logMessage("Unmounting DMG...\n"); //$NON-NLS-1$
166+
new ProcessBuilder("hdiutil", "detach", volumePath).start().waitFor(); //$NON-NLS-1$ //$NON-NLS-2$
167+
168+
logMessage("Launching app from /Applications...\n"); //$NON-NLS-1$
169+
170+
Process openProcess = new ProcessBuilder("open", "-W", "-a", targetAppPath.toString()).start(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
171+
new IDFEnvironmentVariables().addEnvVariable(IDFEnvironmentVariables.EIM_PATH, targetAppPath.toString());
172+
return openProcess;
173+
}
174+
41175

42176
public void downloadEim(IProgressMonitor monitor)
43177
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public static void withPausedListeners(Runnable task)
8989

9090
try
9191
{
92-
task.run();
92+
task.run();
9393
}
9494
catch (Exception e)
9595
{

0 commit comments

Comments
 (0)