Rework scans

This commit is contained in:
crschnick 2023-05-03 12:24:03 +00:00
parent 114332ff2f
commit 758f721690
7 changed files with 57 additions and 10 deletions

View file

@ -37,6 +37,7 @@ public class ListSelectorComp<T> extends SimpleComp {
}
});
var l = new Label(toString.apply(v), cb);
l.setGraphicTextGap(9);
l.setOnMouseClicked(event -> cb.setSelected(!cb.isSelected()));
vbox.getChildren().add(l);
}

View file

@ -109,7 +109,7 @@ public class GuiDsStoreCreator extends MultiStepComp.Step<CompStructure<?>> {
show(null, null, null, filter, e -> {
try {
DataStorage.get().addStoreEntry(e);
ScanAlert.showIfNeeded(e.getStore(), true);
ScanAlert.show(e.getStore(), true);
} catch (Exception ex) {
ErrorEvent.fromThrowable(ex).handle();
}

View file

@ -35,7 +35,7 @@ public class StoreIntroComp extends SimpleComp {
});
var scanButton = new Button(AppI18n.get("detectConnections"), new FontIcon("mdi2m-magnify"));
scanButton.setOnAction(event -> ScanAlert.showIfNeeded(new LocalStore(), false));
scanButton.setOnAction(event -> ScanAlert.show(new LocalStore(), false));
var scanPane = new StackPane(scanButton);
scanPane.setAlignment(Pos.CENTER);

View file

@ -1,6 +1,8 @@
package io.xpipe.app.ext;
import io.xpipe.core.process.ShellControl;
import io.xpipe.core.store.DataStore;
import io.xpipe.core.store.ShellStore;
import io.xpipe.core.util.ModuleLayerLoader;
import lombok.Value;
import org.apache.commons.lang3.function.FailableRunnable;
@ -27,7 +29,8 @@ public abstract class ScanProvider {
public void init(ModuleLayer layer) {
ALL = ServiceLoader.load(layer, ScanProvider.class).stream()
.map(ServiceLoader.Provider::get)
.sorted(Comparator.comparing(scanProvider -> scanProvider.getClass().getName()))
.sorted(Comparator.comparing(
scanProvider -> scanProvider.getClass().getName()))
.collect(Collectors.toList());
}
@ -46,5 +49,11 @@ public abstract class ScanProvider {
return ALL;
}
public abstract ScanOperation create(DataStore store, boolean automatic);
public ScanOperation create(DataStore store, boolean automatic) {
return null;
}
public ScanOperation create(ShellStore store, ShellControl sc, boolean automatic) throws Exception {
return null;
}
}

View file

@ -8,6 +8,7 @@ import io.xpipe.app.fxcomps.impl.LabelComp;
import io.xpipe.app.fxcomps.impl.VerticalComp;
import io.xpipe.app.issue.ErrorEvent;
import io.xpipe.core.store.DataStore;
import io.xpipe.core.store.ShellStore;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleListProperty;
import javafx.collections.FXCollections;
@ -19,24 +20,53 @@ import java.util.List;
public class ScanAlert {
public static void showIfNeeded(DataStore store, boolean automatic) {
public static void show(DataStore store, boolean automatic) {
if (store instanceof ShellStore) {
showForShellStore(store.asNeeded(), automatic);
} else {
showForOtherStore(store, automatic);
}
}
private static void showForOtherStore(DataStore store, boolean automatic) {
var providers = ScanProvider.getAll();
var applicable = providers.stream()
.map(scanProvider -> scanProvider.create(store, automatic))
.filter(scanOperation -> scanOperation != null)
.toList();
showIfNeeded(applicable);
}
private static void showForShellStore(ShellStore store, boolean automatic) {
try (var sc = store.control().start()) {
var providers = ScanProvider.getAll();
var applicable = new ArrayList<ScanProvider.ScanOperation>();
for (ScanProvider scanProvider : providers) {
ScanProvider.ScanOperation operation = scanProvider.create(store, sc, automatic);
if (operation != null) {
applicable.add(operation);
}
}
showIfNeeded(applicable);
} catch (Exception ex) {
ErrorEvent.fromThrowable(ex);
}
}
private static void showIfNeeded(List<ScanProvider.ScanOperation> applicable) {
if (applicable.size() == 0) {
return;
}
var selected = new SimpleListProperty<ScanProvider.ScanOperation>(
FXCollections.observableList(new ArrayList<>(applicable.stream().filter(scanOperation -> scanOperation.isDefaultSelected()).toList())));
FXCollections.observableList(new ArrayList<>(applicable.stream()
.filter(scanOperation -> scanOperation.isDefaultSelected())
.toList())));
var busy = new SimpleBooleanProperty();
AppWindowHelper.showAlert(
alert -> {
alert.setAlertType(Alert.AlertType.NONE);
alert.setTitle(AppI18n.get("scanAlertTitle"));
alert.setWidth(300);
var content = new VerticalComp(List.of(
new LabelComp(AppI18n.get("scanAlertHeader"))
.apply(struc -> struc.get().setWrapText(true)),
@ -47,6 +77,7 @@ public class ScanAlert {
.apply(struc -> struc.get().setSpacing(15))
.styleClass("window-content")
.createRegion();
content.setPrefWidth(500);
alert.getButtonTypes().add(ButtonType.OK);
alert.getDialogPane().setContent(content);
},

View file

@ -31,8 +31,8 @@ connectionName=Connection name
connectionNameDescription=Give this connection a custom name
openFileTitle=Open file
unknown=Unknown
scanAlertTitle=Connection detection
scanAlertHeader=Select types of connections you want to automatically detect on the host system:
scanAlertTitle=Add connections
scanAlertHeader=Select types of connections you want to automatically add for the host system:
namedHostFeatureUnsupported=$HOST$ does not support this feature
namedHostNotActive=$HOST$ is not active
noInformationAvailable=No information available

View file

@ -42,7 +42,13 @@ public interface ShellStore extends DataStore, StatefulDataStore, LaunchableStor
}
default OsType getOsType() {
return getState("os", OsType.class, null);
return getOrComputeState("os", OsType.class, () -> {
try (var sc = control().start()) {
return sc.getOsType();
} catch (Exception ex) {
throw new RuntimeException(ex);
}
});
}
default Charset getCharset() {