This commit is contained in:
crschnick 2024-06-25 07:56:30 +00:00
parent dacd24a8e5
commit 06a7ef27b5
19 changed files with 143 additions and 109 deletions

View file

@ -163,16 +163,20 @@ public class AppBeaconServer {
if (notFoundHtml == null) {
AppResources.with(AppResources.XPIPE_MODULE, "misc/api.md", file -> {
var md = Files.readString(file);
md = md.replaceAll(Pattern.quote( """
md = md.replaceAll(
Pattern.quote(
"""
> 400 Response
```json
{
"message": "string"
}
```
"""), "");
notFoundHtml = MarkdownHelper.toHtml(md,
"""),
"");
notFoundHtml = MarkdownHelper.toHtml(
md,
head -> {
return head + "\n" + "<link rel=\"stylesheet\" href=\"markdown.css\">"
+ "\n" + "<link rel=\"stylesheet\" href=\"github-dark.min.css\">"

View file

@ -1,11 +1,12 @@
package io.xpipe.app.beacon.impl;
import com.sun.net.httpserver.HttpExchange;
import io.xpipe.app.storage.DataStorage;
import io.xpipe.beacon.BeaconClientException;
import io.xpipe.beacon.api.ConnectionInfoExchange;
import io.xpipe.core.store.StorePath;
import com.sun.net.httpserver.HttpExchange;
import java.util.ArrayList;
import java.util.UUID;
@ -15,7 +16,9 @@ public class ConnectionInfoExchangeImpl extends ConnectionInfoExchange {
public Object handle(HttpExchange exchange, Request msg) throws BeaconClientException {
var list = new ArrayList<InfoResponse>();
for (UUID uuid : msg.getConnections()) {
var e = DataStorage.get().getStoreEntryIfPresent(uuid).orElseThrow(() -> new BeaconClientException("Unknown connection: " + uuid));
var e = DataStorage.get()
.getStoreEntryIfPresent(uuid)
.orElseThrow(() -> new BeaconClientException("Unknown connection: " + uuid));
var names = DataStorage.get()
.getStorePath(DataStorage.get()
@ -24,9 +27,17 @@ public class ConnectionInfoExchangeImpl extends ConnectionInfoExchange {
.getNames();
var cat = new StorePath(names.subList(1, names.size()));
var apply = InfoResponse.builder().lastModified(e.getLastModified()).lastUsed(e.getLastUsed()).connection(e.getCategoryUuid()).category(cat).name(
DataStorage.get().getStorePath(e)).rawData(e.getStore()).usageCategory(e.getProvider().getUsageCategory()).type(
e.getProvider().getId()).state(e.getStorePersistentState()).build();
var apply = InfoResponse.builder()
.lastModified(e.getLastModified())
.lastUsed(e.getLastUsed())
.connection(e.getCategoryUuid())
.category(cat)
.name(DataStorage.get().getStorePath(e))
.rawData(e.getStore())
.usageCategory(e.getProvider().getUsageCategory())
.type(e.getProvider().getId())
.state(e.getStorePersistentState())
.build();
list.add(apply);
}
return Response.builder().infos(list).build();

View file

@ -1,10 +1,11 @@
package io.xpipe.app.beacon.impl;
import com.sun.net.httpserver.HttpExchange;
import io.xpipe.app.storage.DataStorage;
import io.xpipe.app.storage.DataStoreEntry;
import io.xpipe.beacon.api.ConnectionQueryExchange;
import com.sun.net.httpserver.HttpExchange;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
@ -13,7 +14,8 @@ public class ConnectionQueryExchangeImpl extends ConnectionQueryExchange {
@Override
public Object handle(HttpExchange exchange, Request msg) {
var catMatcher = Pattern.compile(toRegex("all connections/" + msg.getCategoryFilter().toLowerCase()));
var catMatcher = Pattern.compile(
toRegex("all connections/" + msg.getCategoryFilter().toLowerCase()));
var conMatcher = Pattern.compile(toRegex(msg.getConnectionFilter().toLowerCase()));
var typeMatcher = Pattern.compile(toRegex(msg.getTypeFilter().toLowerCase()));
@ -49,7 +51,9 @@ public class ConnectionQueryExchangeImpl extends ConnectionQueryExchange {
found.add(storeEntry);
}
return Response.builder().found(found.stream().map(entry -> entry.getUuid()).toList()).build();
return Response.builder()
.found(found.stream().map(entry -> entry.getUuid()).toList())
.build();
}
private String toRegex(String pattern) {

View file

@ -31,7 +31,8 @@ public class FsReadExchangeImpl extends FsReadExchange {
var file = BlobManager.get().newBlobFile();
try (var in = fs.openInput(msg.getPath().toString())) {
var fixedIn = new FixedSizeInputStream(new BufferedInputStream(in), size);
try (var fileOut = Files.newOutputStream(file.resolve(msg.getPath().getFileName()))) {
try (var fileOut =
Files.newOutputStream(file.resolve(msg.getPath().getFileName()))) {
fixedIn.transferTo(fileOut);
}
in.transferTo(OutputStream.nullOutputStream());

View file

@ -1,16 +1,18 @@
package io.xpipe.app.browser;
import atlantafx.base.theme.Styles;
import io.xpipe.app.comp.store.StoreCategoryWrapper;
import io.xpipe.app.comp.store.StoreViewState;
import io.xpipe.app.fxcomps.SimpleComp;
import io.xpipe.app.fxcomps.impl.FilterComp;
import io.xpipe.app.fxcomps.impl.HorizontalComp;
import io.xpipe.app.util.DataStoreCategoryChoiceComp;
import javafx.beans.property.Property;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.scene.layout.Region;
import atlantafx.base.theme.Styles;
import lombok.Getter;
import java.util.List;
@ -29,9 +31,7 @@ public final class BrowserBookmarkHeaderComp extends SimpleComp {
StoreViewState.get().getActiveCategory(),
this.category)
.styleClass(Styles.LEFT_PILL);
var filter = new FilterComp(this.filter)
.styleClass(Styles.RIGHT_PILL)
.hgrow();
var filter = new FilterComp(this.filter).styleClass(Styles.RIGHT_PILL).hgrow();
var top = new HorizontalComp(List.of(category, filter))
.apply(struc -> struc.get().setFillHeight(true))

View file

@ -50,17 +50,20 @@ public class BrowserSelectionListComp extends SimpleComp {
@Override
protected Region createSimple() {
var c = new ListBoxViewComp<>(list, list, entry -> {
return Comp.of(() -> {
var image = PrettyImageHelper.ofFixedSizeSquare(entry.getIcon(), 24)
.createRegion();
var l = new Label(null, image);
l.setTextOverrun(OverrunStyle.CENTER_ELLIPSIS);
l.textProperty().bind(PlatformThread.sync(nameTransformation.apply(entry)));
return l;
});
},
false)
var c = new ListBoxViewComp<>(
list,
list,
entry -> {
return Comp.of(() -> {
var image = PrettyImageHelper.ofFixedSizeSquare(entry.getIcon(), 24)
.createRegion();
var l = new Label(null, image);
l.setTextOverrun(OverrunStyle.CENTER_ELLIPSIS);
l.textProperty().bind(PlatformThread.sync(nameTransformation.apply(entry)));
return l;
});
},
false)
.styleClass("selected-file-list");
return c.createRegion();
}

View file

@ -97,19 +97,23 @@ public class BrowserWelcomeComp extends SimpleComp {
var storeList = new VBox();
storeList.setSpacing(8);
var listBox = new ListBoxViewComp<>(list, list, e -> {
var disable = new SimpleBooleanProperty();
var entryButton = entryButton(e, disable);
var dirButton = dirButton(e, disable);
return new HorizontalComp(List.of(entryButton, dirButton)).apply(struc -> {
((Region) struc.get().getChildren().get(0))
.prefHeightProperty()
.bind(struc.get().heightProperty());
((Region) struc.get().getChildren().get(1))
.prefHeightProperty()
.bind(struc.get().heightProperty());
});
}, true)
var listBox = new ListBoxViewComp<>(
list,
list,
e -> {
var disable = new SimpleBooleanProperty();
var entryButton = entryButton(e, disable);
var dirButton = dirButton(e, disable);
return new HorizontalComp(List.of(entryButton, dirButton)).apply(struc -> {
((Region) struc.get().getChildren().get(0))
.prefHeightProperty()
.bind(struc.get().heightProperty());
((Region) struc.get().getChildren().get(1))
.prefHeightProperty()
.bind(struc.get().heightProperty());
});
},
true)
.apply(struc -> {
VBox vBox = (VBox) struc.get().getContent();
vBox.setSpacing(10);

View file

@ -5,6 +5,7 @@ import io.xpipe.app.fxcomps.CompStructure;
import io.xpipe.app.fxcomps.SimpleCompStructure;
import io.xpipe.app.fxcomps.util.DerivedObservableList;
import io.xpipe.app.fxcomps.util.PlatformThread;
import javafx.application.Platform;
import javafx.beans.binding.Bindings;
import javafx.collections.ListChangeListener;
@ -32,7 +33,8 @@ public class ListBoxViewComp<T> extends Comp<CompStructure<ScrollPane>> {
private final int limit = Integer.MAX_VALUE;
private final boolean scrollBar;
public ListBoxViewComp(ObservableList<T> shown, ObservableList<T> all, Function<T, Comp<?>> compFunction, boolean scrollBar) {
public ListBoxViewComp(
ObservableList<T> shown, ObservableList<T> all, Function<T, Comp<?>> compFunction, boolean scrollBar) {
this.shown = PlatformThread.sync(shown);
this.all = PlatformThread.sync(all);
this.compFunction = compFunction;
@ -64,10 +66,13 @@ public class ListBoxViewComp<T> extends Comp<CompStructure<ScrollPane>> {
scroll.skinProperty().subscribe(newValue -> {
if (newValue != null) {
ScrollBar bar = (ScrollBar) scroll.lookup(".scroll-bar:vertical");
bar.opacityProperty().bind(Bindings.createDoubleBinding(() -> {
var v = bar.getVisibleAmount();
return v < 1.0 ? 1.0 : 0.0;
}, bar.visibleAmountProperty()));
bar.opacityProperty()
.bind(Bindings.createDoubleBinding(
() -> {
var v = bar.getVisibleAmount();
return v < 1.0 ? 1.0 : 0.0;
},
bar.visibleAmountProperty()));
}
});
} else {

View file

@ -28,29 +28,22 @@ public class StoreCreationMenu {
menu.getItems().add(category("addHost", "mdi2h-home-plus", DataStoreCreationCategory.HOST, "ssh"));
menu.getItems()
.add(category("addDesktop", "mdi2c-camera-plus", DataStoreCreationCategory.DESKTOP, null));
menu.getItems().add(category("addDesktop", "mdi2c-camera-plus", DataStoreCreationCategory.DESKTOP, null));
menu.getItems().add(category("addShell", "mdi2t-text-box-multiple", DataStoreCreationCategory.SHELL, null));
menu.getItems()
.add(category("addShell", "mdi2t-text-box-multiple", DataStoreCreationCategory.SHELL, null));
.add(category("addScript", "mdi2s-script-text-outline", DataStoreCreationCategory.SCRIPT, "script"));
menu.getItems().add(category("addService", "mdi2c-cloud-braces", DataStoreCreationCategory.SERVICE, null));
menu.getItems()
.add(category(
"addScript", "mdi2s-script-text-outline", DataStoreCreationCategory.SCRIPT, "script"));
.add(category("addTunnel", "mdi2v-vector-polyline-plus", DataStoreCreationCategory.TUNNEL, null));
menu.getItems()
.add(category("addService", "mdi2c-cloud-braces", DataStoreCreationCategory.SERVICE, null));
.add(category("addCommand", "mdi2c-code-greater-than", DataStoreCreationCategory.COMMAND, "cmd"));
menu.getItems()
.add(category(
"addTunnel", "mdi2v-vector-polyline-plus", DataStoreCreationCategory.TUNNEL, null));
menu.getItems()
.add(category(
"addCommand", "mdi2c-code-greater-than", DataStoreCreationCategory.COMMAND, "cmd"));
menu.getItems()
.add(category("addDatabase", "mdi2d-database-plus", DataStoreCreationCategory.DATABASE, null));
menu.getItems().add(category("addDatabase", "mdi2d-database-plus", DataStoreCreationCategory.DATABASE, null));
}
private static MenuItem category(

View file

@ -4,6 +4,7 @@ import io.xpipe.app.comp.base.ListBoxViewComp;
import io.xpipe.app.comp.base.MultiContentComp;
import io.xpipe.app.fxcomps.Comp;
import io.xpipe.app.fxcomps.SimpleComp;
import javafx.beans.binding.Bindings;
import javafx.beans.value.ObservableValue;
import javafx.scene.layout.Region;
@ -14,18 +15,18 @@ public class StoreEntryListComp extends SimpleComp {
private Comp<?> createList() {
var content = new ListBoxViewComp<>(
StoreViewState.get()
.getCurrentTopLevelSection()
.getShownChildren()
.getList(),
StoreViewState.get()
.getCurrentTopLevelSection()
.getAllChildren()
.getList(),
(StoreSection e) -> {
var custom = StoreSection.customSection(e, true).hgrow();
return custom;
},
StoreViewState.get()
.getCurrentTopLevelSection()
.getShownChildren()
.getList(),
StoreViewState.get()
.getCurrentTopLevelSection()
.getAllChildren()
.getList(),
(StoreSection e) -> {
var custom = StoreSection.customSection(e, true).hgrow();
return custom;
},
true);
return content.styleClass("store-list-comp");
}

View file

@ -134,10 +134,12 @@ public class StoreSectionComp extends Comp<CompStructure<VBox>> {
section.getWrapper().getExpanded(),
section.getAllChildren().getList());
var content = new ListBoxViewComp<>(
listSections.getList(), section.getAllChildren().getList(), (StoreSection e) -> {
listSections.getList(),
section.getAllChildren().getList(),
(StoreSection e) -> {
return StoreSection.customSection(e, false).apply(GrowAugment.create(true, false));
},
false)
false)
.minHeight(0)
.hgrow();
@ -151,8 +153,7 @@ public class StoreSectionComp extends Comp<CompStructure<VBox>> {
var full = new VerticalComp(List.of(
topEntryList,
Comp.separator().hide(expanded.not()),
content
.styleClass("children-content")
content.styleClass("children-content")
.hide(Bindings.or(
Bindings.not(section.getWrapper().getExpanded()),
Bindings.size(section.getShownChildren().getList())

View file

@ -9,6 +9,7 @@ import io.xpipe.app.fxcomps.impl.IconButtonComp;
import io.xpipe.app.fxcomps.impl.PrettyImageHelper;
import io.xpipe.app.fxcomps.impl.VerticalComp;
import io.xpipe.app.storage.DataStoreColor;
import javafx.beans.binding.Bindings;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
@ -133,15 +134,16 @@ public class StoreSectionMiniComp extends Comp<CompStructure<VBox>> {
section.getAllChildren().getList())
: section.getShownChildren();
var content = new ListBoxViewComp<>(
listSections.getList(), section.getAllChildren().getList(), (StoreSection e) -> {
listSections.getList(),
section.getAllChildren().getList(),
(StoreSection e) -> {
return new StoreSectionMiniComp(e, this.augment, this.action);
},
section.getWrapper() == null)
section.getWrapper() == null)
.minHeight(0)
.hgrow();
list.add(content
.styleClass("children-content")
list.add(content.styleClass("children-content")
.hide(Bindings.or(
Bindings.not(expanded),
Bindings.size(section.getAllChildren().getList()).isEqualTo(0))));

View file

@ -2,6 +2,7 @@ package io.xpipe.app.core.window;
import io.xpipe.app.core.App;
import io.xpipe.core.process.OsType;
import javafx.geometry.Rectangle2D;
import javafx.stage.Screen;
import javafx.stage.Stage;

View file

@ -136,7 +136,7 @@ public interface DataStoreProvider {
default DataStoreUsageCategory getUsageCategory() {
var cc = getCreationCategory();
if (cc == DataStoreCreationCategory.SHELL || cc == DataStoreCreationCategory.HOST) {
if (cc == DataStoreCreationCategory.SHELL || cc == DataStoreCreationCategory.HOST) {
return DataStoreUsageCategory.SHELL;
}
@ -233,5 +233,4 @@ public interface DataStoreProvider {
}
List<Class<?>> getStoreClasses();
}

View file

@ -36,21 +36,24 @@ public class DataStoreListChoiceComp<T extends DataStore> extends SimpleComp {
@Override
protected Region createSimple() {
var list = new ListBoxViewComp<>(selectedList, selectedList, t -> {
if (t == null) {
return null;
}
var list = new ListBoxViewComp<>(
selectedList,
selectedList,
t -> {
if (t == null) {
return null;
}
var label = new LabelComp(t.get().getName()).apply(struc -> struc.get()
.setGraphic(PrettyImageHelper.ofFixedSizeSquare(
t.get().getProvider().getDisplayIconFileName(t.getStore()), 16)
.createRegion()));
var delete = new IconButtonComp("mdal-delete_outline", () -> {
selectedList.remove(t);
});
return new HorizontalComp(List.of(label, Comp.hspacer(), delete)).styleClass("entry");
},
true)
var label = new LabelComp(t.get().getName()).apply(struc -> struc.get()
.setGraphic(PrettyImageHelper.ofFixedSizeSquare(
t.get().getProvider().getDisplayIconFileName(t.getStore()), 16)
.createRegion()));
var delete = new IconButtonComp("mdal-delete_outline", () -> {
selectedList.remove(t);
});
return new HorizontalComp(List.of(label, Comp.hspacer(), delete)).styleClass("entry");
},
true)
.padding(new Insets(0))
.apply(struc -> struc.get().setMinHeight(0))
.apply(struc -> ((VBox) struc.get().getContent()).setSpacing(5));

View file

@ -113,7 +113,8 @@ public class StoreCategoryComp extends SimpleComp {
var l = category.getChildren()
.sorted(Comparator.comparing(storeCategoryWrapper ->
storeCategoryWrapper.nameProperty().getValue().toLowerCase(Locale.ROOT)));
var children = new ListBoxViewComp<>(l, l, storeCategoryWrapper -> new StoreCategoryComp(storeCategoryWrapper), false);
var children =
new ListBoxViewComp<>(l, l, storeCategoryWrapper -> new StoreCategoryComp(storeCategoryWrapper), false);
var emptyBinding = Bindings.isEmpty(category.getChildren());
var v = new VerticalComp(List.of(categoryButton, children.hide(emptyBinding)));

View file

@ -2,6 +2,7 @@ package io.xpipe.beacon.api;
import io.xpipe.beacon.BeaconInterface;
import io.xpipe.core.store.StorePath;
import lombok.Builder;
import lombok.NonNull;
import lombok.Value;
@ -34,7 +35,6 @@ public class ConnectionInfoExchange extends BeaconInterface<ConnectionInfoExchan
List<@NonNull InfoResponse> infos;
}
@Jacksonized
@Builder
@Value

View file

@ -1,6 +1,7 @@
package io.xpipe.beacon.api;
import io.xpipe.beacon.BeaconInterface;
import lombok.Builder;
import lombok.NonNull;
import lombok.Value;

View file

@ -6,7 +6,7 @@ info:
You can get started by either using this page as an API reference or alternatively import the OpenAPI definition file into your API client of choice:
<a download href="/openapi.yaml" style="font-size: 20px">OpenAPI .yaml specification</a>
The XPipe application will start up an HTTP server that can be used to send requests.
Note that this server is HTTP-only for now as it runs only on localhost. HTTPS requests are not accepted.
@ -44,7 +44,7 @@ paths:
Note that for development you can also turn off the required authentication in the XPipe settings menu, allowing you to send unauthenticated requests.
operationId: handshake
security: []
security: [ ]
requestBody:
required: true
content:
@ -104,7 +104,7 @@ paths:
examples:
standard:
summary: Matched connections
value: { "found": [ "f0ec68aa-63f5-405c-b178-9a4454556d6b"] }
value: { "found": [ "f0ec68aa-63f5-405c-b178-9a4454556d6b" ] }
'400':
$ref: '#/components/responses/BadRequest'
'401':
@ -130,7 +130,7 @@ paths:
examples:
simple:
summary: Standard
value: { "connections": ["f0ec68aa-63f5-405c-b178-9a4454556d6b"] }
value: { "connections": [ "f0ec68aa-63f5-405c-b178-9a4454556d6b" ] }
responses:
'200':
description: The query was successful. The body contains the detailed connection information.
@ -141,10 +141,10 @@ paths:
examples:
standard:
summary: Connection information
value: { "infos": [ { "connection": "f0ec68aa-63f5-405c-b178-9a4454556d6b", "category": ["default"] ,
"name": ["local machine"], "type": "local", "rawData" : {}, "usageCategory" : "shell",
"lastUsed" : "2024-05-31T11:53:02.408504600Z", "lastModified" : "2024-06-23T21:15:25.608097Z",
"state": {} } ] }
value: { "infos": [ { "connection": "f0ec68aa-63f5-405c-b178-9a4454556d6b", "category": [ "default" ] ,
"name": [ "local machine" ], "type": "local", "rawData": { }, "usageCategory": "shell",
"lastUsed": "2024-05-31T11:53:02.408504600Z", "lastModified": "2024-06-23T21:15:25.608097Z",
"state": { } } ] }
'400':
$ref: '#/components/responses/BadRequest'
'401':
@ -738,4 +738,4 @@ components:
scheme: bearer
description: The bearer token used is the session token that you receive from the handshake exchange.
security:
- bearerAuth: []
- bearerAuth: [ ]