Rework lxd connections

This commit is contained in:
crschnick 2023-07-04 05:42:00 +00:00
parent 75e85f3764
commit a097ae7a41
5 changed files with 14 additions and 12 deletions

View file

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

View file

@ -123,7 +123,9 @@ public class GuiDsStoreCreator extends MultiStepComp.Step<CompStructure<?>> {
e -> {
try {
DataStorage.get().addStoreEntry(e);
ScanAlert.showAsync(e, true);
if (e.getProvider().shouldHaveSubShells()) {
ScanAlert.showAsync(e);
}
} catch (Exception ex) {
ErrorEvent.fromThrowable(ex).handle();
}

View file

@ -49,11 +49,11 @@ public abstract class ScanProvider {
return ALL;
}
public ScanOperation create(DataStore store, boolean automatic) {
public ScanOperation create(DataStore store) {
return null;
}
public ScanOperation create(DataStoreEntry entry, ShellControl sc, boolean automatic) throws Exception {
public ScanOperation create(DataStoreEntry entry, ShellControl sc) throws Exception {
return null;
}
}

View file

@ -29,34 +29,34 @@ import java.util.function.Supplier;
public class ScanAlert {
public static void showAsync(DataStoreEntry entry, boolean automatic) {
public static void showAsync(DataStoreEntry entry) {
ThreadHelper.runAsync(() -> {
if (entry.getStore() instanceof ShellStore) {
showForShellStore(entry, automatic);
showForShellStore(entry);
} else {
showForOtherStore(entry, automatic);
showForOtherStore(entry);
}
});
}
private static void showForOtherStore(DataStoreEntry entry, boolean automatic) {
private static void showForOtherStore(DataStoreEntry entry) {
showIfNeeded(() -> {
var providers = ScanProvider.getAll();
var applicable = providers.stream()
.map(scanProvider -> scanProvider.create(entry.getStore(), automatic))
.map(scanProvider -> scanProvider.create(entry.getStore()))
.filter(scanOperation -> scanOperation != null)
.toList();
return applicable;
});
}
private static void showForShellStore(DataStoreEntry entry, boolean automatic) {
private static void showForShellStore(DataStoreEntry entry) {
showIfNeeded(() -> {
try (var sc = ((ShellStore) entry.getStore()).control().start()) {
var providers = ScanProvider.getAll();
var applicable = new ArrayList<ScanProvider.ScanOperation>();
for (ScanProvider scanProvider : providers) {
ScanProvider.ScanOperation operation = scanProvider.create(entry, sc, automatic);
ScanProvider.ScanOperation operation = scanProvider.create(entry, sc);
if (operation != null) {
applicable.add(operation);
}

View file

@ -24,7 +24,7 @@ public class ScanAction implements ActionProvider {
@Override
public void execute() {
ScanAlert.showAsync(entry, false);
ScanAlert.showAsync(entry);
}
}