mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-11-25 09:00:26 +00:00
Small fixes
This commit is contained in:
parent
d6cccd1d5a
commit
aa07f88e1d
9 changed files with 80 additions and 34 deletions
|
@ -171,15 +171,15 @@ public abstract class BeaconConnection implements AutoCloseable {
|
|||
|
||||
private BeaconException unwrapException(Exception exception) {
|
||||
if (exception instanceof ServerException s) {
|
||||
return new BeaconException("An internal server error occurred", s.getCause());
|
||||
return new BeaconException("An internal server error occurred", s);
|
||||
}
|
||||
|
||||
if (exception instanceof ClientException s) {
|
||||
return new BeaconException("A client error occurred", s.getCause());
|
||||
return new BeaconException("A client error occurred", s);
|
||||
}
|
||||
|
||||
if (exception instanceof ConnectorException s) {
|
||||
return new BeaconException("A beacon connection error occurred", s.getCause());
|
||||
return new BeaconException("A beacon connection error occurred", s);
|
||||
}
|
||||
|
||||
return new BeaconException("An unexpected error occurred", exception);
|
||||
|
|
|
@ -63,7 +63,7 @@ public class BeaconServer {
|
|||
System.out.println("Starting daemon: " + command);
|
||||
}
|
||||
|
||||
new Thread(
|
||||
var out = new Thread(
|
||||
null,
|
||||
() -> {
|
||||
try {
|
||||
|
@ -79,10 +79,11 @@ public class BeaconServer {
|
|||
ioe.printStackTrace();
|
||||
}
|
||||
},
|
||||
"daemon sysout")
|
||||
.start();
|
||||
"daemon sysout");
|
||||
out.setDaemon(true);
|
||||
out.start();
|
||||
|
||||
new Thread(
|
||||
var err = new Thread(
|
||||
null,
|
||||
() -> {
|
||||
try {
|
||||
|
@ -98,8 +99,9 @@ public class BeaconServer {
|
|||
ioe.printStackTrace();
|
||||
}
|
||||
},
|
||||
"daemon syserr")
|
||||
.start();
|
||||
"daemon syserr");
|
||||
err.setDaemon(true);
|
||||
err.start();
|
||||
}
|
||||
|
||||
public static boolean tryStop(BeaconClient client) throws Exception {
|
||||
|
|
|
@ -11,7 +11,7 @@ import lombok.NonNull;
|
|||
import lombok.Value;
|
||||
import lombok.extern.jackson.Jacksonized;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
/**
|
||||
* Queries general information about a data source.
|
||||
|
@ -50,7 +50,7 @@ public class QueryDataSourceExchange implements MessageExchange {
|
|||
String provider;
|
||||
|
||||
@NonNull
|
||||
Map<String, String> config;
|
||||
LinkedHashMap<String, String> config;
|
||||
|
||||
DataSource<?> internalSource;
|
||||
}
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
package io.xpipe.core.dialog;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Value;
|
||||
import lombok.extern.jackson.Jacksonized;
|
||||
|
||||
@Value
|
||||
@Builder
|
||||
@Jacksonized
|
||||
@AllArgsConstructor
|
||||
@AllArgsConstructor(onConstructor_ = @JsonCreator)
|
||||
public class Choice {
|
||||
|
||||
/**
|
||||
|
|
|
@ -30,6 +30,13 @@ public abstract class Dialog {
|
|||
protected Object eval;
|
||||
private Supplier<?> evaluation;
|
||||
|
||||
/**
|
||||
* Removes all completion listeners. Intended for internal use only.
|
||||
*/
|
||||
public void clearCompletion() {
|
||||
completion.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an empty dialogue. This dialogue completes immediately and does not handle any questions or answers.
|
||||
*/
|
||||
|
|
52
core/src/main/java/io/xpipe/core/dialog/DialogMapper.java
Normal file
52
core/src/main/java/io/xpipe/core/dialog/DialogMapper.java
Normal file
|
@ -0,0 +1,52 @@
|
|||
package io.xpipe.core.dialog;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
public class DialogMapper {
|
||||
|
||||
private final Dialog dialog;
|
||||
private final LinkedHashMap<String, String> map = new LinkedHashMap<>();
|
||||
|
||||
public DialogMapper(Dialog dialog) {
|
||||
this.dialog = dialog;
|
||||
dialog.clearCompletion();
|
||||
}
|
||||
|
||||
public LinkedHashMap<String, String> handle() throws Exception {
|
||||
var element = dialog.start();
|
||||
handle(element);
|
||||
return map;
|
||||
}
|
||||
|
||||
private void handle(DialogElement element) throws Exception {
|
||||
String response = null;
|
||||
if (element instanceof ChoiceElement c) {
|
||||
response = handleChoice(c);
|
||||
}
|
||||
|
||||
if (element instanceof BaseQueryElement q) {
|
||||
response = handleQuery(q);
|
||||
}
|
||||
|
||||
var newElement = dialog.next(response);
|
||||
if (element.equals(newElement)) {
|
||||
throw new IllegalStateException(
|
||||
"Loop for key " + newElement.toDisplayString());
|
||||
}
|
||||
|
||||
element = newElement;
|
||||
if (element != null) {
|
||||
handle(element);
|
||||
}
|
||||
}
|
||||
|
||||
private String handleQuery(BaseQueryElement q) {
|
||||
map.put(q.getDescription(), q.getValue());
|
||||
return q.getValue();
|
||||
}
|
||||
|
||||
private String handleChoice(ChoiceElement c) {
|
||||
map.put(c.getDescription(), c.getElements().get(c.getSelected()).getDescription());
|
||||
return String.valueOf(c.getSelected() + 1);
|
||||
}
|
||||
}
|
|
@ -11,6 +11,11 @@ import java.util.List;
|
|||
|
||||
public interface StandardShellStore extends MachineFileStore, ShellStore {
|
||||
|
||||
public default ProcessControl prepareLocalCommand(List<SecretValue> input, List<String> cmd, Integer timeout)
|
||||
throws Exception {
|
||||
return prepareCommand(input, cmd, timeout, determineType().determineCharset(this));
|
||||
}
|
||||
|
||||
public default boolean isLocal() {
|
||||
return false;
|
||||
}
|
||||
|
@ -19,7 +24,7 @@ public interface StandardShellStore extends MachineFileStore, ShellStore {
|
|||
return determineType().getNewLine();
|
||||
}
|
||||
|
||||
public abstract ShellType determineType() throws Exception;
|
||||
ShellType determineType() throws Exception;
|
||||
|
||||
public default String querySystemName() throws Exception {
|
||||
var result = prepareCommand(
|
||||
|
|
|
@ -20,8 +20,6 @@ import io.xpipe.core.dialog.BaseQueryElement;
|
|||
import io.xpipe.core.dialog.BusyElement;
|
||||
import io.xpipe.core.dialog.ChoiceElement;
|
||||
import io.xpipe.core.dialog.HeaderElement;
|
||||
import io.xpipe.core.impl.TextSource;
|
||||
import io.xpipe.core.impl.XpbtSource;
|
||||
import io.xpipe.core.source.DataSource;
|
||||
import io.xpipe.core.source.DataSourceInfo;
|
||||
import io.xpipe.core.source.DataSourceReference;
|
||||
|
@ -36,14 +34,10 @@ public class CoreJacksonModule extends SimpleModule {
|
|||
@Override
|
||||
public void setupModule(SetupContext context) {
|
||||
context.registerSubtypes(
|
||||
new NamedType(TextSource.class),
|
||||
new NamedType(XpbtSource.class),
|
||||
new NamedType(FileStore.class),
|
||||
new NamedType(StdinDataStore.class),
|
||||
new NamedType(StdoutDataStore.class),
|
||||
new NamedType(LocalDirectoryDataStore.class),
|
||||
new NamedType(CollectionEntryDataStore.class),
|
||||
new NamedType(InMemoryStore.class),
|
||||
new NamedType(LocalStore.class),
|
||||
new NamedType(NamedStore.class),
|
||||
new NamedType(ValueType.class),
|
||||
|
|
|
@ -75,17 +75,6 @@ public class FancyTooltipAugment<S extends CompStructure<?>> implements Augment<
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hide() {
|
||||
Window owner = getOwnerWindow();
|
||||
if (owner == null || owner.isFocused()) {
|
||||
try {
|
||||
super.hide();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show(Node ownerNode, double anchorX, double anchorY) {
|
||||
Window owner = getOwnerWindow();
|
||||
|
|
Loading…
Reference in a new issue