mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-11-25 00:50:31 +00:00
More fixes
This commit is contained in:
parent
55b7021a18
commit
5b6550ca98
9 changed files with 160 additions and 130 deletions
|
@ -3,7 +3,7 @@ package io.xpipe.app.terminal;
|
|||
import io.xpipe.app.util.LocalShell;
|
||||
import io.xpipe.core.process.CommandBuilder;
|
||||
|
||||
public interface AlacrittyTerminalType extends ExternalTerminalType {
|
||||
public interface AlacrittyTerminalType extends ExternalTerminalType, DockableTerminalType {
|
||||
|
||||
ExternalTerminalType ALACRITTY_WINDOWS = new Windows();
|
||||
ExternalTerminalType ALACRITTY_LINUX = new Linux();
|
||||
|
|
38
app/src/main/java/io/xpipe/app/terminal/CmdTerminalType.java
Normal file
38
app/src/main/java/io/xpipe/app/terminal/CmdTerminalType.java
Normal file
|
@ -0,0 +1,38 @@
|
|||
package io.xpipe.app.terminal;
|
||||
|
||||
import io.xpipe.core.process.CommandBuilder;
|
||||
import io.xpipe.core.process.ShellDialects;
|
||||
|
||||
public class CmdTerminalType extends ExternalTerminalType.SimplePathType implements DockableTerminalType {
|
||||
|
||||
public CmdTerminalType() {super("app.cmd", "cmd.exe", true);}
|
||||
|
||||
@Override
|
||||
public int getProcessHierarchyOffset() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsTabs() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRecommended() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsColoredTitle() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CommandBuilder toCommand(LaunchConfiguration configuration) {
|
||||
if (configuration.getScriptDialect().equals(ShellDialects.CMD)) {
|
||||
return CommandBuilder.of().add("/c").addFile(configuration.getScriptFile());
|
||||
}
|
||||
|
||||
return CommandBuilder.of().add("/c").add(configuration.getDialectLaunchCommand());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package io.xpipe.app.terminal;
|
||||
|
||||
public interface DockableTerminalType {
|
||||
|
||||
public default int getProcessHierarchyOffset() {
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -23,7 +23,6 @@ import lombok.Value;
|
|||
import lombok.With;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
|
@ -398,109 +397,12 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
|
|||
}
|
||||
};
|
||||
|
||||
ExternalTerminalType CMD = new SimplePathType("app.cmd", "cmd.exe", true) {
|
||||
ExternalTerminalType CMD = new CmdTerminalType();
|
||||
|
||||
@Override
|
||||
public boolean supportsTabs() {
|
||||
return false;
|
||||
}
|
||||
ExternalTerminalType POWERSHELL = new PowerShellTerminalType();
|
||||
|
||||
@Override
|
||||
public boolean isRecommended() {
|
||||
return false;
|
||||
}
|
||||
ExternalTerminalType PWSH = new PwshTerminalType();
|
||||
|
||||
@Override
|
||||
public boolean supportsColoredTitle() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CommandBuilder toCommand(LaunchConfiguration configuration) {
|
||||
if (configuration.getScriptDialect().equals(ShellDialects.CMD)) {
|
||||
return CommandBuilder.of().add("/c").addFile(configuration.getScriptFile());
|
||||
}
|
||||
|
||||
return CommandBuilder.of().add("/c").add(configuration.getDialectLaunchCommand());
|
||||
}
|
||||
};
|
||||
|
||||
ExternalTerminalType POWERSHELL = new SimplePathType("app.powershell", "powershell", true) {
|
||||
|
||||
@Override
|
||||
public boolean supportsTabs() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRecommended() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsColoredTitle() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CommandBuilder toCommand(LaunchConfiguration configuration) {
|
||||
if (configuration.getScriptDialect().equals(ShellDialects.POWERSHELL)) {
|
||||
return CommandBuilder.of()
|
||||
.add("-ExecutionPolicy", "Bypass")
|
||||
.add("-File")
|
||||
.addFile(configuration.getScriptFile());
|
||||
}
|
||||
|
||||
return CommandBuilder.of()
|
||||
.add("-ExecutionPolicy", "Bypass")
|
||||
.add("-EncodedCommand")
|
||||
.add(sc -> {
|
||||
var base64 = Base64.getEncoder()
|
||||
.encodeToString(configuration
|
||||
.getDialectLaunchCommand()
|
||||
.buildBase(sc)
|
||||
.getBytes(StandardCharsets.UTF_16LE));
|
||||
return "\"" + base64 + "\"";
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
ExternalTerminalType PWSH = new SimplePathType("app.pwsh", "pwsh", true) {
|
||||
|
||||
@Override
|
||||
public String getWebsite() {
|
||||
return "https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell?view=powershell-7.4";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsTabs() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRecommended() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsColoredTitle() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CommandBuilder toCommand(LaunchConfiguration configuration) {
|
||||
return CommandBuilder.of()
|
||||
.add("-ExecutionPolicy", "Bypass")
|
||||
.add("-EncodedCommand")
|
||||
.add(sc -> {
|
||||
// Fix for https://github.com/PowerShell/PowerShell/issues/18530#issuecomment-1325691850
|
||||
var c = "$env:PSModulePath=\"\";"
|
||||
+ configuration.getDialectLaunchCommand().buildBase(sc);
|
||||
var base64 = Base64.getEncoder().encodeToString(c.getBytes(StandardCharsets.UTF_16LE));
|
||||
return "\"" + base64 + "\"";
|
||||
});
|
||||
}
|
||||
};
|
||||
ExternalTerminalType GNOME_TERMINAL = new PathCheckType("app.gnomeTerminal", "gnome-terminal", true) {
|
||||
@Override
|
||||
public String getWebsite() {
|
||||
|
@ -1214,4 +1116,5 @@ public interface ExternalTerminalType extends PrefsChoiceValue {
|
|||
|
||||
protected abstract CommandBuilder toCommand(LaunchConfiguration configuration) throws Exception;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
package io.xpipe.app.terminal;
|
||||
|
||||
import io.xpipe.core.process.CommandBuilder;
|
||||
import io.xpipe.core.process.ShellDialects;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
|
||||
public class PowerShellTerminalType extends ExternalTerminalType.SimplePathType implements DockableTerminalType {
|
||||
|
||||
public PowerShellTerminalType() {super("app.powershell", "powershell", true);}
|
||||
|
||||
@Override
|
||||
public boolean supportsTabs() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRecommended() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsColoredTitle() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CommandBuilder toCommand(LaunchConfiguration configuration) {
|
||||
if (configuration.getScriptDialect().equals(ShellDialects.POWERSHELL)) {
|
||||
return CommandBuilder.of().add("-ExecutionPolicy", "Bypass").add("-File").addFile(configuration.getScriptFile());
|
||||
}
|
||||
|
||||
return CommandBuilder.of().add("-ExecutionPolicy", "Bypass").add("-EncodedCommand").add(sc -> {
|
||||
var base64 = Base64.getEncoder().encodeToString(
|
||||
configuration.getDialectLaunchCommand().buildBase(sc).getBytes(StandardCharsets.UTF_16LE));
|
||||
return "\"" + base64 + "\"";
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package io.xpipe.app.terminal;
|
||||
|
||||
import io.xpipe.core.process.CommandBuilder;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
|
||||
public class PwshTerminalType extends ExternalTerminalType.SimplePathType implements DockableTerminalType {
|
||||
|
||||
public PwshTerminalType() {super("app.pwsh", "pwsh", true);}
|
||||
|
||||
@Override
|
||||
public String getWebsite() {
|
||||
return "https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell?view=powershell-7.4";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsTabs() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRecommended() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsColoredTitle() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CommandBuilder toCommand(LaunchConfiguration configuration) {
|
||||
return CommandBuilder.of().add("-ExecutionPolicy", "Bypass").add("-EncodedCommand").add(sc -> {
|
||||
// Fix for https://github.com/PowerShell/PowerShell/issues/18530#issuecomment-1325691850
|
||||
var c = "$env:PSModulePath=\"\";" + configuration.getDialectLaunchCommand().buildBase(sc);
|
||||
var base64 = Base64.getEncoder().encodeToString(c.getBytes(StandardCharsets.UTF_16LE));
|
||||
return "\"" + base64 + "\"";
|
||||
});
|
||||
}
|
||||
}
|
|
@ -9,7 +9,7 @@ import io.xpipe.core.process.TerminalInitFunction;
|
|||
import java.nio.file.Path;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface TabbyTerminalType extends ExternalTerminalType {
|
||||
public interface TabbyTerminalType extends ExternalTerminalType, DockableTerminalType {
|
||||
|
||||
ExternalTerminalType TABBY_WINDOWS = new Windows();
|
||||
ExternalTerminalType TABBY_MAC_OS = new MacOs();
|
||||
|
|
|
@ -8,7 +8,7 @@ import io.xpipe.core.store.FileNames;
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public interface WindowsTerminalType extends ExternalTerminalType {
|
||||
public interface WindowsTerminalType extends ExternalTerminalType, DockableTerminalType {
|
||||
|
||||
ExternalTerminalType WINDOWS_TERMINAL = new Standard();
|
||||
ExternalTerminalType WINDOWS_TERMINAL_PREVIEW = new Preview();
|
||||
|
|
|
@ -4,6 +4,7 @@ import io.xpipe.app.core.AppLayoutModel;
|
|||
import io.xpipe.app.core.window.NativeWinWindowControl;
|
||||
import io.xpipe.app.issue.TrackEvent;
|
||||
import io.xpipe.app.prefs.AppPrefs;
|
||||
import io.xpipe.app.terminal.DockableTerminalType;
|
||||
import io.xpipe.app.terminal.ExternalTerminalType;
|
||||
import io.xpipe.core.process.OsType;
|
||||
import javafx.application.Platform;
|
||||
|
@ -14,6 +15,7 @@ import lombok.experimental.FieldDefaults;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class TerminalView {
|
||||
|
||||
|
@ -79,7 +81,6 @@ public class TerminalView {
|
|||
@Override
|
||||
public void show() {
|
||||
this.control.show();
|
||||
front();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -90,6 +91,7 @@ public class TerminalView {
|
|||
@Override
|
||||
public void front() {
|
||||
this.control.alwaysInFront();
|
||||
this.control.removeBorders();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -143,7 +145,7 @@ public class TerminalView {
|
|||
return;
|
||||
}
|
||||
|
||||
var terminal = isTerminalShell() ? shell : shell.get().parent();
|
||||
var terminal = getTerminalProcess(shell.get());
|
||||
if (terminal.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
@ -152,16 +154,14 @@ public class TerminalView {
|
|||
sessions.add(session);
|
||||
|
||||
var instance = terminalInstances.stream().filter(i -> i.terminal.equals(terminal.get())).findFirst();
|
||||
if (instance.isPresent()) {
|
||||
return;
|
||||
if (instance.isEmpty()) {
|
||||
var control = NativeWinWindowControl.byPid(terminal.get().pid());
|
||||
if (control.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
terminalInstances.add(new WindowsTerminalInstance(terminal.get(), control.get()));
|
||||
}
|
||||
|
||||
var control = NativeWinWindowControl.byPid(terminal.get().pid());
|
||||
if (control.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
terminalInstances.add(new WindowsTerminalInstance(terminal.get(), control.get()));
|
||||
|
||||
TrackEvent.withTrace("Terminal instance opened")
|
||||
.tag("terminalPid", terminal.get().pid())
|
||||
.tag("viewEnabled", isEnabled())
|
||||
|
@ -176,13 +176,18 @@ public class TerminalView {
|
|||
});
|
||||
}
|
||||
|
||||
private boolean isTerminalShell() {
|
||||
private Optional<ProcessHandle> getTerminalProcess(ProcessHandle shell) {
|
||||
var t = AppPrefs.get().terminalType().getValue();
|
||||
if (t.equals(ExternalTerminalType.CMD) || t.equals(ExternalTerminalType.POWERSHELL) || t.equals(ExternalTerminalType.PWSH)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
if (!(t instanceof DockableTerminalType dockableTerminalType)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
var off = dockableTerminalType.getProcessHierarchyOffset();
|
||||
var current = Optional.of(shell);
|
||||
for (int i = 0; i < 1 + off; i++) {
|
||||
current = current.flatMap(processHandle -> processHandle.parent());
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
public synchronized void tick() {
|
||||
|
@ -235,10 +240,6 @@ public class TerminalView {
|
|||
}
|
||||
|
||||
public synchronized void onWindowActivate() {
|
||||
if (!viewActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
TrackEvent.withTrace("Terminal view focus gained")
|
||||
.handle();
|
||||
terminalInstances.forEach(terminalInstance -> {
|
||||
|
@ -248,14 +249,15 @@ public class TerminalView {
|
|||
}
|
||||
|
||||
terminalInstance.show();
|
||||
if (viewActive) {
|
||||
terminalInstance.front();
|
||||
} else {
|
||||
terminalInstance.back();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public synchronized void onWindowMinimize() {
|
||||
if (!viewActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
TrackEvent.withTrace("Terminal view minimized")
|
||||
.handle();
|
||||
|
||||
|
@ -307,9 +309,7 @@ public class TerminalView {
|
|||
TrackEvent.withTrace("Terminal view resized")
|
||||
.tag("rect", viewBounds)
|
||||
.handle();
|
||||
if (viewActive) {
|
||||
updatePositions();
|
||||
}
|
||||
updatePositions();
|
||||
}
|
||||
|
||||
public void clickView() {
|
||||
|
|
Loading…
Reference in a new issue