This commit is contained in:
crschnick
2025-06-04 15:26:56 +00:00
parent 76b13075dd
commit a481ffd42d
4 changed files with 69 additions and 8 deletions
@@ -7,6 +7,7 @@ import io.xpipe.app.util.CommandSupport;
import io.xpipe.app.util.LocalShell;
import io.xpipe.app.util.Translatable;
import io.xpipe.core.process.CommandBuilder;
import io.xpipe.core.process.CommandControl;
import io.xpipe.core.process.OsType;
import io.xpipe.core.process.ShellControl;
@@ -21,10 +22,13 @@ public interface ExternalApplicationType extends PrefsValue {
public interface MacApplication extends ExternalApplicationType {
default void launch(CommandBuilder builder) throws Exception {
default CommandControl launchCommand(CommandBuilder builder, boolean args) throws Exception {
if (args) {
builder.add(0, "--args");
}
builder.addQuoted(getApplicationName());
builder.add(0, "open", "-a");
LocalShell.getShell().executeSimpleCommand(builder);
return LocalShell.getShell().command(builder);
}
@Override
@@ -95,12 +95,12 @@ public abstract class RealVncClient implements ExternalVncClient {
@Override
public void launch(VncLaunchConfig configuration) throws Exception {
var builder = createBuilder(configuration);
launch(builder);
launchCommand(builder, true).execute();
}
@Override
public String getApplicationName() {
return "RealVNC.app";
return "VNC Viewer";
}
}
}
@@ -0,0 +1,42 @@
package io.xpipe.app.vnc;
import com.fasterxml.jackson.annotation.JsonTypeName;
import io.xpipe.app.prefs.ExternalApplicationType;
import io.xpipe.app.util.LocalShell;
import io.xpipe.core.process.CommandBuilder;
import io.xpipe.core.util.SecretValue;
import lombok.Builder;
import lombok.extern.jackson.Jacksonized;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Optional;
@Builder
@Jacksonized
@JsonTypeName("screenSharing")
public class ScreenSharingVncClient implements ExternalApplicationType.MacApplication, ExternalVncClient {
@Override
public boolean supportsPasswords() {
return true;
}
@Override
public void launch(VncLaunchConfig configuration) throws Exception {
var pw = configuration.retrievePassword();
var credentials = (configuration.retrieveUsername().orElse("") + pw.map(secretValue -> ":" + secretValue.getSecretValue()).orElse(""));
var address = configuration.getHost() + ":" + configuration.getPort();
var args = "vnc://" + credentials + "@" + address;
var command = launchCommand(CommandBuilder.of().add(args), false);
if (pw.isPresent()) {
command.sensitive();
}
command.execute();
}
@Override
public String getApplicationName() {
return "Screen Sharing";
}
}
@@ -8,6 +8,7 @@ import io.xpipe.core.process.CommandBuilder;
import lombok.Builder;
import lombok.extern.jackson.Jacksonized;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Optional;
@@ -104,12 +105,15 @@ public abstract class TigerVncClient implements ExternalVncClient {
@Builder
@Jacksonized
@JsonTypeName("tigerVnc")
public static class MacOs extends TigerVncClient implements ExternalApplicationType.MacApplication {
public static class MacOs extends TigerVncClient implements ExternalApplicationType.InstallLocationType {
@Override
public void launch(VncLaunchConfig configuration) throws Exception {
var loc = findExecutable();
var builder = createBuilder(configuration);
launch(builder);
var open = CommandBuilder.of().add("open", "-a").addFile(loc).add("--args");
builder.add(0, open);
LocalShell.getShell().command(builder).execute();
}
@Override
@@ -118,8 +122,19 @@ public abstract class TigerVncClient implements ExternalVncClient {
}
@Override
public String getApplicationName() {
return "TigerVNC.app";
public String getExecutable() {
return "VNCViewer";
}
@Override
public Optional<Path> determineInstallation() {
try (var appsStream = Files.list(Path.of("/Applications"))) {
var dirs = appsStream.toList();
return dirs.stream().filter(path -> path.toString().startsWith("TigerVNC")).findFirst();
} catch (IOException e) {
ErrorEvent.fromThrowable(e).handle();
return Optional.empty();
}
}
}
}