Various fixes

This commit is contained in:
crschnick 2023-04-23 11:04:39 +00:00
parent b211e10184
commit 56dcf905ef
11 changed files with 98 additions and 25 deletions

View file

@ -99,7 +99,6 @@ public class GuiDsStoreCreator extends MultiStepComp.Step<CompStructure<?>> {
e.applyChanges(newE); e.applyChanges(newE);
if (!DataStorage.get().getStoreEntries().contains(e)) { if (!DataStorage.get().getStoreEntries().contains(e)) {
DataStorage.get().addStoreEntry(e); DataStorage.get().addStoreEntry(e);
ScanAlert.showIfNeeded(e.getStore(), true);
} }
DataStorage.get().refresh(); DataStorage.get().refresh();
}); });

View file

@ -19,6 +19,7 @@ import io.xpipe.app.fxcomps.util.PlatformThread;
import io.xpipe.app.fxcomps.util.SimpleChangeListener; import io.xpipe.app.fxcomps.util.SimpleChangeListener;
import io.xpipe.app.prefs.AppPrefs; import io.xpipe.app.prefs.AppPrefs;
import io.xpipe.app.storage.DataStorage; import io.xpipe.app.storage.DataStorage;
import io.xpipe.app.storage.DataStoreEntry;
import io.xpipe.app.util.DesktopHelper; import io.xpipe.app.util.DesktopHelper;
import io.xpipe.app.util.ThreadHelper; import io.xpipe.app.util.ThreadHelper;
import javafx.beans.binding.Bindings; import javafx.beans.binding.Bindings;
@ -156,6 +157,10 @@ public class StoreEntryComp extends SimpleComp {
event.consume(); event.consume();
ThreadHelper.runFailableAsync(() -> { ThreadHelper.runFailableAsync(() -> {
var found = entry.getDefaultActionProvider().getValue(); var found = entry.getDefaultActionProvider().getValue();
if (entry.getState().getValue().equals(DataStoreEntry.State.COMPLETE_BUT_INVALID) || found == null) {
entry.getEntry().refresh(true);
}
if (found != null) { if (found != null) {
entry.getEntry().updateLastUsed(); entry.getEntry().updateLastUsed();
found.createAction(entry.getEntry().getStore().asNeeded()).execute(); found.createAction(entry.getEntry().getStore().asNeeded()).execute();

View file

@ -65,6 +65,7 @@ public class StoreEntryWrapper implements StorageFilter.Filterable {
} }
public void delete() { public void delete() {
DataStorage.get().deleteChildren(this.entry, true);
DataStorage.get().deleteStoreEntry(this.entry); DataStorage.get().deleteStoreEntry(this.entry);
} }

View file

@ -8,6 +8,7 @@ import io.xpipe.app.fxcomps.SimpleComp;
import io.xpipe.app.storage.DataStorage; import io.xpipe.app.storage.DataStorage;
import io.xpipe.app.util.CustomComboBoxBuilder; import io.xpipe.app.util.CustomComboBoxBuilder;
import io.xpipe.app.util.XPipeDaemon; import io.xpipe.app.util.XPipeDaemon;
import io.xpipe.core.store.DataStore;
import io.xpipe.core.store.ShellStore; import io.xpipe.core.store.ShellStore;
import javafx.beans.property.Property; import javafx.beans.property.Property;
import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.SimpleStringProperty;
@ -22,27 +23,33 @@ import java.util.Optional;
import java.util.function.Predicate; import java.util.function.Predicate;
@AllArgsConstructor @AllArgsConstructor
public class ShellStoreChoiceComp<T extends ShellStore> extends SimpleComp { public class DataStoreChoiceComp<T extends DataStore> extends SimpleComp {
public static ShellStoreChoiceComp<ShellStore> proxy(Property<ShellStore> selected) { public static DataStoreChoiceComp<ShellStore> proxy(Property<ShellStore> selected) {
return new ShellStoreChoiceComp<>(Mode.PROXY_CHOICE, null, selected, ShellStore.class, shellStore -> true); return new DataStoreChoiceComp<>(Mode.PROXY, null, selected, ShellStore.class, shellStore -> true);
} }
public static ShellStoreChoiceComp<ShellStore> host(Property<ShellStore> selected) { public static DataStoreChoiceComp<ShellStore> host(Property<ShellStore> selected) {
return new ShellStoreChoiceComp<>(Mode.HOST_CHOICE, null, selected, ShellStore.class, shellStore -> true); return new DataStoreChoiceComp<>(Mode.HOST, null, selected, ShellStore.class, shellStore -> true);
} }
public static ShellStoreChoiceComp<ShellStore> proxy(ShellStore self, Property<ShellStore> selected) { public static DataStoreChoiceComp<ShellStore> environment(ShellStore self, Property<ShellStore> selected) {
return new ShellStoreChoiceComp<>(Mode.PROXY_CHOICE, self, selected, ShellStore.class, shellStore -> true); return new DataStoreChoiceComp<>(Mode.ENVIRONMENT, self, selected, ShellStore.class, shellStore -> true);
} }
public static ShellStoreChoiceComp<ShellStore> host(ShellStore self, Property<ShellStore> selected) { public static DataStoreChoiceComp<ShellStore> proxy(ShellStore self, Property<ShellStore> selected) {
return new ShellStoreChoiceComp<>(Mode.HOST_CHOICE, self, selected, ShellStore.class, shellStore -> true); return new DataStoreChoiceComp<>(Mode.PROXY, self, selected, ShellStore.class, shellStore -> true);
}
public static DataStoreChoiceComp<ShellStore> host(ShellStore self, Property<ShellStore> selected) {
return new DataStoreChoiceComp<>(Mode.HOST, self, selected, ShellStore.class, shellStore -> true);
} }
public static enum Mode { public static enum Mode {
HOST_CHOICE, HOST,
PROXY_CHOICE ENVIRONMENT,
OTHER,
PROXY
} }
private final Mode mode; private final Mode mode;
@ -60,7 +67,7 @@ public class ShellStoreChoiceComp<T extends ShellStore> extends SimpleComp {
.filter(e -> e.equals(s)) .filter(e -> e.equals(s))
.findAny() .findAny()
.flatMap(store -> { .flatMap(store -> {
if (ShellStore.isLocal(store.asNeeded()) && mode == Mode.PROXY_CHOICE) { if (ShellStore.isLocal(store.asNeeded()) && mode == Mode.PROXY) {
return Optional.of(AppI18n.get("none")); return Optional.of(AppI18n.get("none"));
} }
@ -97,7 +104,7 @@ public class ShellStoreChoiceComp<T extends ShellStore> extends SimpleComp {
continue; continue;
} }
if (!((ShellStore) s).canHaveSubs()) { if (!(mode == Mode.ENVIRONMENT) && !((ShellStore) s).canHaveSubs()) {
continue; continue;
} }

View file

@ -12,6 +12,7 @@ import io.xpipe.core.source.DataSource;
import io.xpipe.core.source.DataSourceId; import io.xpipe.core.source.DataSourceId;
import io.xpipe.core.source.DataSourceReference; import io.xpipe.core.source.DataSourceReference;
import io.xpipe.core.store.DataStore; import io.xpipe.core.store.DataStore;
import io.xpipe.core.store.FixedHierarchyStore;
import lombok.Getter; import lombok.Getter;
import lombok.NonNull; import lombok.NonNull;
@ -95,6 +96,36 @@ public abstract class DataStorage {
return internalCollection; return internalCollection;
} }
public synchronized void refreshChildren(DataStoreEntry e) {
if (!(e.getStore() instanceof FixedHierarchyStore)) {
return;
}
try {
var newChildren = ((FixedHierarchyStore) e.getStore()).listChildren();
deleteChildren(e, true);
newChildren.forEach((key, value) -> {
try {
addStoreEntry(key, value);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
});
} catch (Exception ex) {
ErrorEvent.fromThrowable(ex).handle();
}
}
public synchronized void deleteChildren(DataStoreEntry e, boolean deep) {
getStoreChildren(e,deep).forEach(entry -> {
if (!entry.getConfiguration().isDeletable()) {
return;
}
deleteStoreEntry(entry);
});
}
public synchronized List<DataStoreEntry> getStoreChildren(DataStoreEntry entry, boolean deep) { public synchronized List<DataStoreEntry> getStoreChildren(DataStoreEntry entry, boolean deep) {
var children = new ArrayList<>(getStoreEntries().stream().filter(other -> { var children = new ArrayList<>(getStoreEntries().stream().filter(other -> {
if (!other.getState().isUsable()) { if (!other.getState().isUsable()) {

View file

@ -10,6 +10,7 @@ import io.xpipe.app.ext.DataStoreProvider;
import io.xpipe.app.ext.DataStoreProviders; import io.xpipe.app.ext.DataStoreProviders;
import io.xpipe.app.issue.ErrorEvent; import io.xpipe.app.issue.ErrorEvent;
import io.xpipe.core.store.DataStore; import io.xpipe.core.store.DataStore;
import io.xpipe.core.store.FixedHierarchyStore;
import io.xpipe.core.util.JacksonMapper; import io.xpipe.core.util.JacksonMapper;
import lombok.*; import lombok.*;
import lombok.experimental.NonFinal; import lombok.experimental.NonFinal;
@ -218,6 +219,11 @@ public class DataStoreEntry extends StorageElement {
state = State.VALIDATING; state = State.VALIDATING;
listeners.forEach(l -> l.onUpdate()); listeners.forEach(l -> l.onUpdate());
store.validate(); store.validate();
if (store instanceof FixedHierarchyStore) {
DataStorage.get().refreshChildren(this);
}
state = State.COMPLETE_AND_VALID; state = State.COMPLETE_AND_VALID;
information = getProvider().queryInformationString(getStore(), 50); information = getProvider().queryInformationString(getStore(), 50);
dirty = true; dirty = true;

View file

@ -11,10 +11,14 @@ public class ProcessOutputException extends Exception {
return new ProcessOutputException(message, ex.getExitCode(), ex.getOutput()); return new ProcessOutputException(message, ex.getExitCode(), ex.getOutput());
} }
public static ProcessOutputException of(int exitCode, String output) { public static ProcessOutputException of(int exitCode, String output, String accumulatedError) {
var messageSuffix = output != null && !output.isBlank()?": " + output : ""; var combinedError = (accumulatedError != null ? accumulatedError.trim() + "\n" : "") + (output != null ? output.trim() : "");
var message = exitCode == CommandControl.TIMEOUT_EXIT_CODE ? "Process timed out" + messageSuffix : "Process returned with exit code " + exitCode + messageSuffix; var message = switch (exitCode) {
return new ProcessOutputException(message, exitCode, output); case CommandControl.KILLED_EXIT_CODE -> "Process timed out" + combinedError;
case CommandControl.TIMEOUT_EXIT_CODE -> "Process timed out" + combinedError;
default -> "Process returned with exit code " + combinedError;
};
return new ProcessOutputException(message, exitCode, combinedError);
} }
private final int exitCode; private final int exitCode;

View file

@ -0,0 +1,13 @@
package io.xpipe.core.store;
import io.xpipe.core.process.ShellControl;
public interface DelegateShellStore extends ShellStore {
@Override
default ShellControl createControl() {
return getDelegateHost().create();
}
ShellStore getDelegateHost();
}

View file

@ -0,0 +1,8 @@
package io.xpipe.core.store;
import java.util.Map;
public interface FixedHierarchyStore extends DataStore {
Map<String, DataStore> listChildren() throws Exception;
}

View file

@ -0,0 +1,5 @@
package io.xpipe.core.store;
public interface LeafStore extends DataStore {
}

View file

@ -22,13 +22,7 @@ public class DeleteStoreChildrenAction implements ActionProvider {
@Override @Override
public void execute() throws Exception { public void execute() throws Exception {
DataStorage.get().getStoreChildren(store,true).forEach(entry -> { DataStorage.get().deleteChildren(store, true);
if (!entry.getConfiguration().isDeletable()) {
return;
}
DataStorage.get().deleteStoreEntry(entry);
});
} }
} }