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

View file

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

View file

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

View file

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