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

View file

@ -65,6 +65,7 @@ public class StoreEntryWrapper implements StorageFilter.Filterable {
}
public void delete() {
DataStorage.get().deleteChildren(this.entry, true);
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.util.CustomComboBoxBuilder;
import io.xpipe.app.util.XPipeDaemon;
import io.xpipe.core.store.DataStore;
import io.xpipe.core.store.ShellStore;
import javafx.beans.property.Property;
import javafx.beans.property.SimpleStringProperty;
@ -22,27 +23,33 @@ import java.util.Optional;
import java.util.function.Predicate;
@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) {
return new ShellStoreChoiceComp<>(Mode.PROXY_CHOICE, null, selected, ShellStore.class, shellStore -> true);
public static DataStoreChoiceComp<ShellStore> proxy(Property<ShellStore> selected) {
return new DataStoreChoiceComp<>(Mode.PROXY, null, selected, ShellStore.class, shellStore -> true);
}
public static ShellStoreChoiceComp<ShellStore> host(Property<ShellStore> selected) {
return new ShellStoreChoiceComp<>(Mode.HOST_CHOICE, null, selected, ShellStore.class, shellStore -> true);
public static DataStoreChoiceComp<ShellStore> host(Property<ShellStore> selected) {
return new DataStoreChoiceComp<>(Mode.HOST, null, selected, ShellStore.class, shellStore -> true);
}
public static ShellStoreChoiceComp<ShellStore> proxy(ShellStore self, Property<ShellStore> selected) {
return new ShellStoreChoiceComp<>(Mode.PROXY_CHOICE, self, selected, ShellStore.class, shellStore -> true);
public static DataStoreChoiceComp<ShellStore> environment(ShellStore self, Property<ShellStore> selected) {
return new DataStoreChoiceComp<>(Mode.ENVIRONMENT, self, selected, ShellStore.class, shellStore -> true);
}
public static ShellStoreChoiceComp<ShellStore> host(ShellStore self, Property<ShellStore> selected) {
return new ShellStoreChoiceComp<>(Mode.HOST_CHOICE, self, selected, ShellStore.class, shellStore -> true);
public static DataStoreChoiceComp<ShellStore> proxy(ShellStore self, Property<ShellStore> selected) {
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 {
HOST_CHOICE,
PROXY_CHOICE
HOST,
ENVIRONMENT,
OTHER,
PROXY
}
private final Mode mode;
@ -60,7 +67,7 @@ public class ShellStoreChoiceComp<T extends ShellStore> extends SimpleComp {
.filter(e -> e.equals(s))
.findAny()
.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"));
}
@ -97,7 +104,7 @@ public class ShellStoreChoiceComp<T extends ShellStore> extends SimpleComp {
continue;
}
if (!((ShellStore) s).canHaveSubs()) {
if (!(mode == Mode.ENVIRONMENT) && !((ShellStore) s).canHaveSubs()) {
continue;
}

View file

@ -12,6 +12,7 @@ import io.xpipe.core.source.DataSource;
import io.xpipe.core.source.DataSourceId;
import io.xpipe.core.source.DataSourceReference;
import io.xpipe.core.store.DataStore;
import io.xpipe.core.store.FixedHierarchyStore;
import lombok.Getter;
import lombok.NonNull;
@ -95,6 +96,36 @@ public abstract class DataStorage {
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) {
var children = new ArrayList<>(getStoreEntries().stream().filter(other -> {
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.issue.ErrorEvent;
import io.xpipe.core.store.DataStore;
import io.xpipe.core.store.FixedHierarchyStore;
import io.xpipe.core.util.JacksonMapper;
import lombok.*;
import lombok.experimental.NonFinal;
@ -218,6 +219,11 @@ public class DataStoreEntry extends StorageElement {
state = State.VALIDATING;
listeners.forEach(l -> l.onUpdate());
store.validate();
if (store instanceof FixedHierarchyStore) {
DataStorage.get().refreshChildren(this);
}
state = State.COMPLETE_AND_VALID;
information = getProvider().queryInformationString(getStore(), 50);
dirty = true;

View file

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

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
public void execute() throws Exception {
DataStorage.get().getStoreChildren(store,true).forEach(entry -> {
if (!entry.getConfiguration().isDeletable()) {
return;
}
DataStorage.get().deleteStoreEntry(entry);
});
DataStorage.get().deleteChildren(store, true);
}
}