Skip to content

Commit dbd74f9

Browse files
committed
fix(launcher_strategies): updated launcher strategies to handle gui param
1 parent 96c923f commit dbd74f9

7 files changed

Lines changed: 55 additions & 15 deletions

File tree

bundles/com.espressif.idf.core/src/com/espressif/idf/core/tools/EimLoader.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,18 @@ private void logError(String message)
116116
*/
117117
public LaunchResult launchEimWithResult(String eimPath) throws IOException
118118
{
119-
LaunchResult result = launchService.launch(eimPath);
119+
return launchEimWithResult(eimPath, new String[0]);
120+
}
121+
122+
/**
123+
* Launches EIM with optional arguments (e.g. "gui") and returns the {@link com.espressif.idf.core.tools.launch.LaunchResult}.
124+
*/
125+
public LaunchResult launchEimWithResult(String eimPath, String... args) throws IOException
126+
{
127+
LaunchResult result = launchService.launch(eimPath, args);
120128
this.lastLaunchResult = result;
121129

122-
logMessage("Launched EIM application: " + eimPath + " (pid=" + result.pid().orElse(-1) + ")\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
130+
logMessage("Launched EIM application: " + eimPath + " " + String.join(" ", args) + " (pid=" + result.pid().orElse(-1) + ")\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
123131
return result;
124132
}
125133

bundles/com.espressif.idf.core/src/com/espressif/idf/core/tools/launch/EimLaunchService.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,23 @@ public EimLaunchService(Display display, MessageConsoleStream standardConsoleStr
3131
}
3232

3333
public LaunchResult launch(String eimPath) throws IOException
34+
{
35+
return launch(eimPath, new String[0]);
36+
}
37+
38+
public LaunchResult launch(String eimPath, String... args) throws IOException
3439
{
3540
if (eimPath == null || eimPath.isBlank())
3641
throw new IOException("EIM path is null/blank"); //$NON-NLS-1$
3742

3843
if (!Files.exists(Paths.get(eimPath)))
3944
throw new IOException("EIM path not found: " + eimPath); //$NON-NLS-1$
4045

41-
return strategy.launch(eimPath);
46+
if (args == null || args.length == 0)
47+
{
48+
return strategy.launch(eimPath);
49+
}
50+
return strategy.launch(eimPath, args);
4251
}
4352

4453
public IStatus waitForExit(LaunchResult launchResult, IProgressMonitor monitor)

bundles/com.espressif.idf.core/src/com/espressif/idf/core/tools/launch/strategies/EimLauncherStrategy.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,7 @@ public interface EimLauncherStrategy
2020
{
2121
LaunchResult launch(String eimPath) throws IOException;
2222

23+
LaunchResult launch(String eimPath, String... args) throws IOException;
24+
2325
IStatus waitForExit(LaunchResult launchResult, IProgressMonitor monitor);
2426
}

bundles/com.espressif.idf.core/src/com/espressif/idf/core/tools/launch/strategies/LinuxEimLauncherStrategy.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,19 @@ public LinuxEimLauncherStrategy(Display display, MessageConsoleStream standardCo
3333

3434
@Override
3535
public LaunchResult launch(String eimPath) throws IOException
36+
{
37+
return launch(eimPath, new String[0]);
38+
}
39+
40+
@Override
41+
public LaunchResult launch(String eimPath, String... args) throws IOException
3642
{
3743
if (!Files.exists(Paths.get(eimPath)))
3844
throw new IOException("EIM path not found: " + eimPath); //$NON-NLS-1$
3945

4046
String quotedPath = ProcessUtils.bashSingleQuote(eimPath);
41-
String bashCmd = "nohup " + quotedPath + " > /dev/null 2>&1 & echo $!"; //$NON-NLS-1$ //$NON-NLS-2$
47+
String argsStr = (args != null && args.length > 0) ? " " + String.join(" ", args) : ""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
48+
String bashCmd = "nohup " + quotedPath + argsStr + " > /dev/null 2>&1 & echo $!"; //$NON-NLS-1$ //$NON-NLS-2$
4249

4350
List<String> command = List.of("bash", "-lc", bashCmd); //$NON-NLS-1$ //$NON-NLS-2$
4451
Process launcher = new ProcessBuilder(command).redirectErrorStream(true).start();

bundles/com.espressif.idf.core/src/com/espressif/idf/core/tools/launch/strategies/MacOsEimLauncherStrategy.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ public final class MacOsEimLauncherStrategy extends AbstractLoggingLauncherStrat
3737
private static final String MACOS_LAUNCH_AND_PID_APPLESCRIPT = """
3838
set appPath to system attribute "APP_PATH"
3939
set bundleId to system attribute "BUNDLE_ID"
40+
set openArgs to system attribute "OPEN_ARGS"
4041
41-
do shell script "open -a " & quoted form of appPath
42+
do shell script "open -a " & quoted form of appPath & openArgs
4243
4344
tell application "System Events"
4445
repeat 300 times
@@ -61,20 +62,29 @@ public MacOsEimLauncherStrategy(Display display, MessageConsoleStream standardCo
6162

6263
@Override
6364
public LaunchResult launch(String eimPath) throws IOException
65+
{
66+
return launch(eimPath, new String[0]);
67+
}
68+
69+
@Override
70+
public LaunchResult launch(String eimPath, String... args) throws IOException
6471
{
6572
if (!isAppBundle(eimPath))
6673
{
67-
return launchCliDirect(eimPath);
74+
return launchCliDirect(eimPath, args);
6875
}
6976

7077
String appBundlePath = deriveAppBundlePath(eimPath);
7178
String execPath = deriveExecPath(eimPath, appBundlePath);
7279
String bundleId = readBundleId(appBundlePath);
7380

81+
String argsForOpen = (args != null && args.length > 0) ? " --args " + String.join(" ", args) : ""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
82+
7483
ProcessBuilder pb = new ProcessBuilder("osascript", "-"); //$NON-NLS-1$ //$NON-NLS-2$
7584
pb.redirectErrorStream(true);
7685
pb.environment().put("APP_PATH", appBundlePath); //$NON-NLS-1$
7786
pb.environment().put("BUNDLE_ID", bundleId); //$NON-NLS-1$
87+
pb.environment().put("OPEN_ARGS", argsForOpen); //$NON-NLS-1$
7888

7989
Process p = pb.start();
8090
try (OutputStream stdin = p.getOutputStream())
@@ -99,24 +109,21 @@ public LaunchResult launch(String eimPath) throws IOException
99109
Logger.log("BUNDLE_ID=" + bundleId); //$NON-NLS-1$
100110
Logger.log("Launcher output was:\n" + out); //$NON-NLS-1$
101111

102-
// If osascript failed or returned no pid, we fall back to execPath polling.
103112
Long pid = ProcessUtils.parseFirstLongLine(out);
104113
if (exit == 0 && pid != null)
105114
{
106115
return LaunchResult.ofPid(pid.longValue(), execPath, out);
107116
}
108117

109-
// Fallback (still "successfully launched" from user perspective):
110-
// - we already attempted "open -a"
111-
// - we can wait for closure using pgrep -f execPath
112118
return LaunchResult.ofNoPid(execPath,
113119
"osascript exit=" + exit + "\n" + out); //$NON-NLS-1$ //$NON-NLS-2$
114120
}
115121

116-
private LaunchResult launchCliDirect(String eimPath) throws IOException
122+
private LaunchResult launchCliDirect(String eimPath, String... args) throws IOException
117123
{
118124
String quotedPath = ProcessUtils.bashSingleQuote(eimPath);
119-
String bashCmd = "nohup " + quotedPath + " > /dev/null 2>&1 & echo $!"; //$NON-NLS-1$ //$NON-NLS-2$
125+
String argsStr = (args != null && args.length > 0) ? " " + String.join(" ", args) : ""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
126+
String bashCmd = "nohup " + quotedPath + argsStr + " > /dev/null 2>&1 & echo $!"; //$NON-NLS-1$ //$NON-NLS-2$
120127

121128
Process launcher = new ProcessBuilder("bash", "-lc", bashCmd) //$NON-NLS-1$ //$NON-NLS-2$
122129
.redirectErrorStream(true).start();

bundles/com.espressif.idf.core/src/com/espressif/idf/core/tools/launch/strategies/WindowsEimLauncherStrategy.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,21 @@ public WindowsEimLauncherStrategy(Display display, MessageConsoleStream standard
3333

3434
@Override
3535
public LaunchResult launch(String eimPath) throws IOException
36+
{
37+
return launch(eimPath, new String[0]);
38+
}
39+
40+
@Override
41+
public LaunchResult launch(String eimPath, String... args) throws IOException
3642
{
3743
if (!Files.exists(Paths.get(eimPath)))
3844
throw new IOException("EIM path not found: " + eimPath); //$NON-NLS-1$
3945

4046
String escapedPathForPowershell = eimPath.replace("'", "''"); //$NON-NLS-1$ //$NON-NLS-2$
47+
String argsStr = (args != null && args.length > 0) ? " -ArgumentList '" + String.join(" ", args) + "'" : ""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
4148
String powershellCmd = String.format(
42-
"Start-Process -FilePath '%s' -PassThru | Select-Object -ExpandProperty Id", //$NON-NLS-1$
43-
escapedPathForPowershell);
49+
"Start-Process -FilePath '%s'%s -PassThru | Select-Object -ExpandProperty Id", //$NON-NLS-1$
50+
escapedPathForPowershell, argsStr);
4451

4552
List<String> command = List.of("powershell.exe", "-Command", powershellCmd); //$NON-NLS-1$ //$NON-NLS-2$
4653
Process launcher = new ProcessBuilder(command).redirectErrorStream(true).start();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static void launch(ToolInitializer toolInitializer, EimLoader eimLoader,
3636
{
3737
if (toolInitializer.isEimGuiCapable(eimPath))
3838
{
39-
LaunchResult launchResult = eimLoader.launchEimWithResult(eimPath);
39+
LaunchResult launchResult = eimLoader.launchEimWithResult(eimPath, "gui"); //$NON-NLS-1$
4040
eimLoader.waitForEimClosure(launchResult, afterEimClosed);
4141
return;
4242
}

0 commit comments

Comments
 (0)