mirror of
https://github.com/xpipe-io/xpipe.git
synced 2026-04-22 23:49:09 -04:00
Rework terminal loading
This commit is contained in:
@@ -19,7 +19,7 @@ public class Main {
|
||||
"""
|
||||
The daemon executable xpiped does not accept any command-line arguments.
|
||||
|
||||
For a reference on what you can do from the CLI, take a look at the xpipe CLI executable instead.
|
||||
For a reference on how to use xpipe from the command-line, take a look at https://docs.xpipe.io/cli.
|
||||
""");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package io.xpipe.app.beacon.impl;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import io.xpipe.app.prefs.AppPrefs;
|
||||
import io.xpipe.app.terminal.TerminalLauncherManager;
|
||||
import io.xpipe.app.terminal.TerminalView;
|
||||
import io.xpipe.beacon.BeaconClientException;
|
||||
import io.xpipe.beacon.BeaconServerException;
|
||||
import io.xpipe.beacon.api.TerminalPrepareExchange;
|
||||
|
||||
public class TerminalPrepareExchangeImpl extends TerminalPrepareExchange {
|
||||
|
||||
@Override
|
||||
public Object handle(HttpExchange exchange, Request msg) throws BeaconClientException, BeaconServerException {
|
||||
TerminalView.get().open(msg.getRequest(), msg.getPid());
|
||||
TerminalLauncherManager.registerPid(msg.getRequest(), msg.getPid());
|
||||
var term = AppPrefs.get().terminalType().getValue();
|
||||
var unicode = true;
|
||||
var escapes = term.supportsEscapes();
|
||||
var finished = TerminalLauncherManager.isCompletedSuccessfully(msg.getRequest());
|
||||
return Response.builder().supportsUnicode(unicode).supportsEscapeSequences(escapes).alreadyFinished(finished).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requiresEnabledApi() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -9,10 +9,10 @@ import io.xpipe.beacon.api.TerminalWaitExchange;
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
|
||||
public class TerminalWaitExchangeImpl extends TerminalWaitExchange {
|
||||
|
||||
@Override
|
||||
public Object handle(HttpExchange exchange, Request msg) throws BeaconClientException, BeaconServerException {
|
||||
TerminalView.get().open(msg.getRequest(), msg.getPid());
|
||||
TerminalLauncherManager.waitExchange(msg.getRequest(), msg.getPid());
|
||||
TerminalLauncherManager.waitExchange(msg.getRequest());
|
||||
return Response.builder().build();
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ public interface AlacrittyTerminalType extends ExternalTerminalType, TrackableTe
|
||||
}
|
||||
|
||||
@Override
|
||||
default boolean supportsColoredTitle() {
|
||||
default boolean useColoredTitle() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,11 @@ public class CmdTerminalType extends ExternalTerminalType.SimplePathType impleme
|
||||
super("app.cmd", "cmd.exe", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsEscapes() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TerminalOpenFormat getOpenFormat() {
|
||||
return TerminalOpenFormat.NEW_WINDOW;
|
||||
@@ -29,7 +34,7 @@ public class CmdTerminalType extends ExternalTerminalType.SimplePathType impleme
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsColoredTitle() {
|
||||
public boolean useColoredTitle() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ public class CustomTerminalType extends ExternalApplicationType implements Exter
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsColoredTitle() {
|
||||
public boolean useColoredTitle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -117,7 +117,7 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsColoredTitle() {
|
||||
public boolean useColoredTitle() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsColoredTitle() {
|
||||
public boolean useColoredTitle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsColoredTitle() {
|
||||
public boolean useColoredTitle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -210,7 +210,7 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsColoredTitle() {
|
||||
public boolean useColoredTitle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -239,7 +239,7 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsColoredTitle() {
|
||||
public boolean useColoredTitle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -264,7 +264,7 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsColoredTitle() {
|
||||
public boolean useColoredTitle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -295,7 +295,7 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsColoredTitle() {
|
||||
public boolean useColoredTitle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -327,7 +327,7 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsColoredTitle() {
|
||||
public boolean useColoredTitle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -359,7 +359,7 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsColoredTitle() {
|
||||
public boolean useColoredTitle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -390,7 +390,7 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsColoredTitle() {
|
||||
public boolean useColoredTitle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -421,7 +421,7 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsColoredTitle() {
|
||||
public boolean useColoredTitle() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -457,7 +457,7 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsColoredTitle() {
|
||||
public boolean useColoredTitle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -489,7 +489,7 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsColoredTitle() {
|
||||
public boolean useColoredTitle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -516,7 +516,7 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsColoredTitle() {
|
||||
public boolean useColoredTitle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -552,7 +552,7 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsColoredTitle() {
|
||||
public boolean useColoredTitle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -679,7 +679,11 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
|
||||
|
||||
boolean isRecommended();
|
||||
|
||||
boolean supportsColoredTitle();
|
||||
boolean useColoredTitle();
|
||||
|
||||
default boolean supportsEscapes() {
|
||||
return true;
|
||||
}
|
||||
|
||||
default boolean shouldClear() {
|
||||
return true;
|
||||
|
||||
@@ -27,7 +27,7 @@ public class GnomeTerminalType extends ExternalTerminalType.PathCheckType implem
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsColoredTitle() {
|
||||
public boolean useColoredTitle() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ public interface KittyTerminalType extends ExternalTerminalType, TrackableTermin
|
||||
}
|
||||
|
||||
@Override
|
||||
default boolean supportsColoredTitle() {
|
||||
default boolean useColoredTitle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ public class MobaXTermTerminalType extends ExternalTerminalType.WindowsType {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsColoredTitle() {
|
||||
public boolean useColoredTitle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,11 @@ import java.util.Base64;
|
||||
|
||||
public class PowerShellTerminalType extends ExternalTerminalType.SimplePathType implements TrackableTerminalType {
|
||||
|
||||
@Override
|
||||
public boolean supportsEscapes() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public PowerShellTerminalType() {
|
||||
super("app.powershell", "powershell", true);
|
||||
}
|
||||
@@ -32,7 +37,7 @@ public class PowerShellTerminalType extends ExternalTerminalType.SimplePathType
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsColoredTitle() {
|
||||
public boolean useColoredTitle() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,11 @@ public class PwshTerminalType extends ExternalTerminalType.SimplePathType implem
|
||||
super("app.pwsh", "pwsh", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsEscapes() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TerminalOpenFormat getOpenFormat() {
|
||||
return TerminalOpenFormat.NEW_WINDOW;
|
||||
@@ -27,7 +32,7 @@ public class PwshTerminalType extends ExternalTerminalType.SimplePathType implem
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsColoredTitle() {
|
||||
public boolean useColoredTitle() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ public class SecureCrtTerminalType extends ExternalTerminalType.WindowsType {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsColoredTitle() {
|
||||
public boolean useColoredTitle() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ public interface TabbyTerminalType extends ExternalTerminalType, TrackableTermin
|
||||
}
|
||||
|
||||
@Override
|
||||
default boolean supportsColoredTitle() {
|
||||
default boolean useColoredTitle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ public class TerminalLauncher {
|
||||
}
|
||||
|
||||
var color = entry != null ? DataStorage.get().getEffectiveColor(entry) : null;
|
||||
var prefix = entry != null && color != null && type.supportsColoredTitle() ? color.getEmoji() + " " : "";
|
||||
var prefix = entry != null && color != null && type.useColoredTitle() ? color.getEmoji() + " " : "";
|
||||
var cleanTitle = (title != null ? title : entry != null ? entry.getName() : "?");
|
||||
var adjustedTitle = prefix + cleanTitle;
|
||||
var log = AppPrefs.get().enableTerminalLogging().get();
|
||||
|
||||
@@ -61,15 +61,18 @@ public class TerminalLauncherManager {
|
||||
return last.waitForCompletion();
|
||||
}
|
||||
|
||||
public static Path waitExchange(UUID request, long pid) throws BeaconClientException, BeaconServerException {
|
||||
public static boolean isCompletedSuccessfully(UUID request) {
|
||||
synchronized (entries) {
|
||||
var req = entries.get(request);
|
||||
return req.getResult() instanceof TerminalLaunchResult.ResultSuccess;
|
||||
}
|
||||
}
|
||||
|
||||
public static void registerPid(UUID request, long pid) throws BeaconClientException {
|
||||
TerminalLaunchRequest req;
|
||||
synchronized (entries) {
|
||||
req = entries.get(request);
|
||||
}
|
||||
if (req == null) {
|
||||
throw new BeaconClientException("Unknown launch request " + request);
|
||||
}
|
||||
|
||||
var byPid = ProcessHandle.of(pid);
|
||||
if (byPid.isEmpty()) {
|
||||
throw new BeaconClientException("Unable to find terminal child process " + pid);
|
||||
@@ -79,6 +82,16 @@ public class TerminalLauncherManager {
|
||||
throw new BeaconClientException("Wrong launch context");
|
||||
}
|
||||
req.setPid(shell.pid());
|
||||
}
|
||||
|
||||
public static Path waitExchange(UUID request) throws BeaconClientException, BeaconServerException {
|
||||
TerminalLaunchRequest req;
|
||||
synchronized (entries) {
|
||||
req = entries.get(request);
|
||||
}
|
||||
if (req == null) {
|
||||
throw new BeaconClientException("Unknown launch request " + request);
|
||||
}
|
||||
|
||||
if (req.isSetupCompleted()) {
|
||||
submitAsync(req.getRequest(), req.getProcessControl(), req.getConfig(), req.getWorkingDirectory());
|
||||
|
||||
@@ -61,7 +61,7 @@ public class TermiusTerminalType implements ExternalTerminalType {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsColoredTitle() {
|
||||
public boolean useColoredTitle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ public class WarpTerminalType extends ExternalTerminalType.MacOsType {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsColoredTitle() {
|
||||
public boolean useColoredTitle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ public interface WaveTerminalType extends ExternalTerminalType, TrackableTermina
|
||||
}
|
||||
|
||||
@Override
|
||||
default boolean supportsColoredTitle() {
|
||||
default boolean useColoredTitle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ public interface WezTerminalType extends ExternalTerminalType, TrackableTerminal
|
||||
}
|
||||
|
||||
@Override
|
||||
default boolean supportsColoredTitle() {
|
||||
default boolean useColoredTitle() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -124,7 +124,7 @@ public interface WindowsTerminalType extends ExternalTerminalType, TrackableTerm
|
||||
}
|
||||
|
||||
@Override
|
||||
default boolean supportsColoredTitle() {
|
||||
default boolean useColoredTitle() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ public class XShellTerminalType extends ExternalTerminalType.WindowsType {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsColoredTitle() {
|
||||
public boolean useColoredTitle() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -148,6 +148,7 @@ open module io.xpipe.app {
|
||||
FsScriptExchangeImpl,
|
||||
FsWriteExchangeImpl,
|
||||
AskpassExchangeImpl,
|
||||
TerminalPrepareExchangeImpl,
|
||||
TerminalWaitExchangeImpl,
|
||||
TerminalLaunchExchangeImpl,
|
||||
SshLaunchExchangeImpl,
|
||||
|
||||
@@ -14,7 +14,7 @@ public class TerminalLaunchExchange extends BeaconInterface<TerminalLaunchExchan
|
||||
|
||||
@Override
|
||||
public String getPath() {
|
||||
return "/terminalLaunch";
|
||||
return "/terminal/launch";
|
||||
}
|
||||
|
||||
@Jacksonized
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package io.xpipe.beacon.api;
|
||||
|
||||
import io.xpipe.beacon.BeaconInterface;
|
||||
import lombok.Builder;
|
||||
import lombok.NonNull;
|
||||
import lombok.Value;
|
||||
import lombok.extern.jackson.Jacksonized;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class TerminalPrepareExchange extends BeaconInterface<TerminalPrepareExchange.Request> {
|
||||
|
||||
@Override
|
||||
public String getPath() {
|
||||
return "/terminal/prepare";
|
||||
}
|
||||
|
||||
@Jacksonized
|
||||
@Builder
|
||||
@Value
|
||||
public static class Request {
|
||||
@NonNull
|
||||
UUID request;
|
||||
|
||||
long pid;
|
||||
}
|
||||
|
||||
@Jacksonized
|
||||
@Builder
|
||||
@Value
|
||||
public static class Response {
|
||||
boolean supportsUnicode;
|
||||
boolean supportsEscapeSequences;
|
||||
boolean alreadyFinished;
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ public class TerminalWaitExchange extends BeaconInterface<TerminalWaitExchange.R
|
||||
|
||||
@Override
|
||||
public String getPath() {
|
||||
return "/terminalWait";
|
||||
return "/terminal/wait";
|
||||
}
|
||||
|
||||
@Jacksonized
|
||||
@@ -22,8 +22,6 @@ public class TerminalWaitExchange extends BeaconInterface<TerminalWaitExchange.R
|
||||
public static class Request {
|
||||
@NonNull
|
||||
UUID request;
|
||||
|
||||
long pid;
|
||||
}
|
||||
|
||||
@Jacksonized
|
||||
|
||||
@@ -46,6 +46,7 @@ open module io.xpipe.beacon {
|
||||
ConnectionToggleExchange,
|
||||
ConnectionRefreshExchange,
|
||||
AskpassExchange,
|
||||
TerminalPrepareExchange,
|
||||
TerminalWaitExchange,
|
||||
TerminalLaunchExchange,
|
||||
SshLaunchExchange,
|
||||
|
||||
Reference in New Issue
Block a user