Properly init direct terminal launcher for updates

This commit is contained in:
crschnick 2024-03-28 15:52:07 +00:00
parent d8b9571de8
commit e9b0a19509
4 changed files with 22 additions and 24 deletions

View file

@ -12,7 +12,6 @@ import io.xpipe.app.util.OptionsBuilder;
import io.xpipe.app.util.TerminalLauncher; import io.xpipe.app.util.TerminalLauncher;
import io.xpipe.core.process.OsType; import io.xpipe.core.process.OsType;
import io.xpipe.core.store.FileNames; import io.xpipe.core.store.FileNames;
import io.xpipe.core.store.LocalStore;
import io.xpipe.core.util.XPipeInstallation; import io.xpipe.core.util.XPipeInstallation;
public class TroubleshootCategory extends AppPrefsCategory { public class TroubleshootCategory extends AppPrefsCategory {
@ -42,14 +41,11 @@ public class TroubleshootCategory extends AppPrefsCategory {
.addComp( .addComp(
new TileButtonComp("launchDebugMode", "launchDebugModeDescription", "mdmz-refresh", e -> { new TileButtonComp("launchDebugMode", "launchDebugModeDescription", "mdmz-refresh", e -> {
OperationMode.executeAfterShutdown(() -> { OperationMode.executeAfterShutdown(() -> {
try (var sc = new LocalStore().control().start()) {
var script = FileNames.join( var script = FileNames.join(
XPipeInstallation.getCurrentInstallationBasePath() XPipeInstallation.getCurrentInstallationBasePath()
.toString(), .toString(),
XPipeInstallation.getDaemonDebugScriptPath(OsType.getLocal())); XPipeInstallation.getDaemonDebugScriptPath(OsType.getLocal()));
var runScript = sc.getShellDialect().runScriptCommand(sc, script); TerminalLauncher.openDirect("XPipe Debug", sc -> sc.getShellDialect().runScriptCommand(sc, script));
TerminalLauncher.openDirect("XPipe Debug", sc, runScript);
}
}); });
e.consume(); e.consume();
}) })

View file

@ -135,7 +135,7 @@ public class AppInstaller {
exec || read -rsp "Update failed ..."$'\\n' -n 1 key exec || read -rsp "Update failed ..."$'\\n' -n 1 key
""", """,
file, file, name); file, file, name);
TerminalLauncher.openDirect("XPipe Updater", LocalShell.getShell(), command); TerminalLauncher.openDirect("XPipe Updater", sc -> command);
} }
@Override @Override
@ -161,7 +161,7 @@ public class AppInstaller {
exec || read -rsp "Update failed ..."$'\\n' -n 1 key exec || read -rsp "Update failed ..."$'\\n' -n 1 key
""", """,
file, file, name); file, file, name);
TerminalLauncher.openDirect("XPipe Updater", LocalShell.getShell(), command); TerminalLauncher.openDirect("XPipe Updater", sc -> command);
} }
@Override @Override
@ -187,7 +187,7 @@ public class AppInstaller {
exec || echo "Update failed ..." && read -rs -k 1 key exec || echo "Update failed ..." && read -rs -k 1 key
""", """,
file, file, name); file, file, name);
TerminalLauncher.openDirect("XPipe Updater", LocalShell.getShell(), command); TerminalLauncher.openDirect("XPipe Updater", sc -> command);
} }
@Override @Override

View file

@ -10,22 +10,26 @@ import io.xpipe.core.process.ProcessControl;
import io.xpipe.core.process.ProcessControlProvider; import io.xpipe.core.process.ProcessControlProvider;
import io.xpipe.core.process.ShellControl; import io.xpipe.core.process.ShellControl;
import io.xpipe.core.process.TerminalInitScriptConfig; import io.xpipe.core.process.TerminalInitScriptConfig;
import io.xpipe.core.util.FailableFunction;
import java.io.IOException; import java.io.IOException;
import java.util.List;
import java.util.UUID; import java.util.UUID;
public class TerminalLauncher { public class TerminalLauncher {
public static void openDirect(String title, ShellControl shellControl, String command) throws Exception { public static void openDirect(String title, FailableFunction<ShellControl,String, Exception> command) throws Exception {
try (var sc = LocalShell.getShell().start()) {
var type = AppPrefs.get().terminalType().getValue(); var type = AppPrefs.get().terminalType().getValue();
if (type == null) { if (type == null) {
throw ErrorEvent.expected(new IllegalStateException(AppI18n.get("noTerminalSet"))); throw ErrorEvent.expected(new IllegalStateException(AppI18n.get("noTerminalSet")));
} }
var script = ScriptHelper.createLocalExecScript(command); var script = ScriptHelper.constructTerminalInitFile(sc.getShellDialect(), sc, ignored -> null, List.of(),
var config = new ExternalTerminalType.LaunchConfiguration( command.apply(sc), new TerminalInitScriptConfig(title, type.shouldClear() && AppPrefs.get().clearTerminalOnInit().get()));
null, title, title, script, shellControl.getShellDialect()); var config = new ExternalTerminalType.LaunchConfiguration(null, title, title, script, sc.getShellDialect());
type.launch(config); type.launch(config);
} }
}
public static void open(String title, ProcessControl cc) throws Exception { public static void open(String title, ProcessControl cc) throws Exception {
open(null, title, null, cc); open(null, title, null, cc);
@ -43,8 +47,7 @@ public class TerminalLauncher {
var adjustedTitle = prefix + cleanTitle; var adjustedTitle = prefix + cleanTitle;
var terminalConfig = new TerminalInitScriptConfig( var terminalConfig = new TerminalInitScriptConfig(
adjustedTitle, adjustedTitle,
type.shouldClear() && AppPrefs.get().clearTerminalOnInit().get(), type.shouldClear() && AppPrefs.get().clearTerminalOnInit().get());
color != null);
var request = UUID.randomUUID(); var request = UUID.randomUUID();
var d = ProcessControlProvider.get().getEffectiveLocalDialect(); var d = ProcessControlProvider.get().getEffectiveLocalDialect();

View file

@ -7,9 +7,8 @@ public class TerminalInitScriptConfig {
String displayName; String displayName;
boolean clearScreen; boolean clearScreen;
boolean hasColor;
public static TerminalInitScriptConfig ofName(String name) { public static TerminalInitScriptConfig ofName(String name) {
return new TerminalInitScriptConfig(name, true, false); return new TerminalInitScriptConfig(name, true);
} }
} }