mirror of
https://github.com/xpipe-io/xpipe.git
synced 2026-08-13 04:51:03 +00:00
Introduce API for daemon modes
This commit is contained in:
@@ -4,13 +4,17 @@ import java.util.ServiceLoader;
|
||||
|
||||
public abstract class SecretProvider {
|
||||
|
||||
private static final SecretProvider INSTANCE = ServiceLoader.load(ModuleLayer.boot(), SecretProvider.class).findFirst().orElseThrow();
|
||||
private static SecretProvider INSTANCE;
|
||||
|
||||
public abstract byte[] encrypt(byte[] c);
|
||||
|
||||
public abstract byte[] decrypt(byte[] c);
|
||||
|
||||
public static SecretProvider get() {
|
||||
if (INSTANCE == null) {
|
||||
INSTANCE = ServiceLoader.load(ModuleLayer.boot(), SecretProvider.class).findFirst().orElseThrow();
|
||||
}
|
||||
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package io.xpipe.core.util;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public enum XPipeDaemonMode {
|
||||
@JsonProperty("background")
|
||||
BACKGROUND("background", List.of("base", "background")),
|
||||
|
||||
@JsonProperty("tray")
|
||||
TRAY("tray", List.of("tray", "taskbar")),
|
||||
|
||||
@JsonProperty("gui")
|
||||
GUI("gui", List.of("gui", "desktop", "interface"));
|
||||
|
||||
public static XPipeDaemonMode get(String name) {
|
||||
return Arrays.stream(XPipeDaemonMode.values())
|
||||
.filter(xPipeDaemonMode ->
|
||||
xPipeDaemonMode.getNameAlternatives().contains(name.toLowerCase(Locale.ROOT)))
|
||||
.findAny()
|
||||
.orElseThrow(() -> new IllegalArgumentException("Unknown mode: " + name + ". Possible values: "
|
||||
+ Arrays.stream(values())
|
||||
.map(XPipeDaemonMode::getDisplayName)
|
||||
.collect(Collectors.joining(", "))));
|
||||
}
|
||||
|
||||
@Getter
|
||||
private final String displayName;
|
||||
|
||||
@Getter
|
||||
private final List<String> nameAlternatives;
|
||||
|
||||
XPipeDaemonMode(String displayName, List<String> nameAlternatives) {
|
||||
this.displayName = displayName;
|
||||
this.nameAlternatives = nameAlternatives;
|
||||
}
|
||||
}
|
||||
@@ -11,15 +11,15 @@ import java.util.List;
|
||||
|
||||
public class XPipeInstallation {
|
||||
|
||||
public static String createExternalAsyncLaunchCommand(String installationBase, String arguments) {
|
||||
public static String createExternalAsyncLaunchCommand(String installationBase, XPipeDaemonMode mode, String arguments) {
|
||||
var suffix = (arguments != null ? " " + arguments : "");
|
||||
if (OsType.getLocal().equals(OsType.LINUX)) {
|
||||
return "nohup \"" + installationBase + "/app/bin/xpiped\" --external" + suffix + " & disown";
|
||||
return "nohup \"" + installationBase + "/app/bin/xpiped\" --mode " + mode.getDisplayName() + suffix + " & disown";
|
||||
} else if (OsType.getLocal().equals(OsType.MAC)) {
|
||||
return "open \"" + installationBase + "\" --args --external" + suffix;
|
||||
return "open \"" + installationBase + "\" --args --mode " + mode.getDisplayName() + suffix;
|
||||
}
|
||||
|
||||
return "\"" + FileNames.join(installationBase, XPipeInstallation.getDaemonExecutablePath(OsType.getLocal())) + "\" --external" + suffix;
|
||||
return "\"" + FileNames.join(installationBase, XPipeInstallation.getDaemonExecutablePath(OsType.getLocal())) + "\" --mode " + mode.getDisplayName() + suffix;
|
||||
}
|
||||
|
||||
public static String createExternalLaunchCommand(String command, String arguments) {
|
||||
|
||||
Reference in New Issue
Block a user