Skip to content

Commit

Permalink
Various small fixes [release]
Browse files Browse the repository at this point in the history
  • Loading branch information
crschnick committed Mar 6, 2023
1 parent b7fa352 commit 3ec708e
Show file tree
Hide file tree
Showing 20 changed files with 160 additions and 82 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ run {
systemProperty 'io.xpipe.app.writeLogs', "true"
systemProperty 'io.xpipe.app.writeSysOut', "true"
systemProperty 'io.xpipe.app.developerMode', "true"
systemProperty 'io.xpipe.app.logLevel', "trace"
systemProperty 'io.xpipe.app.logLevel', "debug"
systemProperty 'io.xpipe.app.fullVersion', rootProject.fullVersion
// systemProperty "io.xpipe.beacon.port", "21724"
// systemProperty "io.xpipe.beacon.printMessages", "true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private Region getGraphic() {
AppI18n.get("selectStreamStore"), AppI18n.get("openStreamStoreWizard"), graphic);
} else {
return JfxHelper.createNamedEntry(
f.getFileName().toString(), f.getFile().toString(), graphic);
f.getFileName().toString(), f.getPath().toString(), graphic);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ private boolean hasProvider() {

private Region getGraphic() {
var graphic = hasProvider() ? provider.getValue().getDisplayIconFileName() : "file_icon.png";
if (chosenFile.getValue() == null || !(chosenFile.getValue() instanceof FileStore f) || f.getFile() == null) {
if (chosenFile.getValue() == null || !(chosenFile.getValue() instanceof FileStore f) || f.getPath() == null) {
return JfxHelper.createNamedEntry(AppI18n.get("browse"), AppI18n.get("selectFileFromComputer"), graphic);
} else {
return JfxHelper.createNamedEntry(
f.getFileName().toString(), f.getFile().toString(), graphic);
f.getFileName().toString(), f.getPath().toString(), graphic);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected Region createSimple() {

return FileStore.builder()
.fileSystem(machine.get())
.file(fileName.get())
.path(fileName.get())
.build();
},
store)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ public GuiDsStoreCreator(
r.get().setPrefWidth(AppFont.em(36));
r.get().setPrefHeight(AppFont.em(42));
});

this.validator.addListener((observable, oldValue, newValue) -> {
Platform.runLater(() -> {
newValue.validate();
});
});
}

public static void showEdit(DataStoreEntry e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ protected Region createContent() {
ThreadHelper.runFailableAsync(() -> {
var found = entry.getDefaultActionProvider().getValue();
if (found != null) {
found.getDataStoreCallSite()
found
.createAction(entry.getEntry().getStore().asNeeded())
.execute();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
import io.xpipe.app.prefs.AppPrefs;
import io.xpipe.app.storage.DataStorage;
import io.xpipe.app.storage.DataStoreEntry;
import javafx.beans.Observable;
import javafx.beans.binding.Bindings;
import javafx.beans.property.*;
import javafx.beans.value.ObservableValue;
import lombok.Getter;

import java.time.Duration;
Expand All @@ -31,7 +28,7 @@ public class StoreEntryWrapper implements StorageFilter.Filterable {
private final StringProperty information = new SimpleStringProperty();
private final StringProperty summary = new SimpleStringProperty();
private final Map<ActionProvider, BooleanProperty> actionProviders;
private final ObservableValue<ActionProvider> defaultActionProvider;
private final Property<ActionProvider.DefaultDataStoreCallSite<?>> defaultActionProvider;
private final BooleanProperty editable = new SimpleBooleanProperty();
private final BooleanProperty renamable = new SimpleBooleanProperty();
private final BooleanProperty refreshable = new SimpleBooleanProperty();
Expand All @@ -54,16 +51,7 @@ public StoreEntryWrapper(DataStoreEntry entry) {
.forEach(dataStoreActionProvider -> {
actionProviders.put(dataStoreActionProvider, new SimpleBooleanProperty(true));
});
this.defaultActionProvider = Bindings.createObjectBinding(
() -> {
var found = actionProviders.entrySet().stream()
.filter(e -> e.getValue().get())
.filter(e -> e.getKey().getDataStoreCallSite() != null
&& e.getKey().getDataStoreCallSite().isDefault())
.findFirst();
return found.map(p -> p.getKey()).orElse(null);
},
actionProviders.values().toArray(Observable[]::new));
this.defaultActionProvider = new SimpleObjectProperty<>();
setupListeners();
update();
}
Expand Down Expand Up @@ -126,6 +114,7 @@ public void update() {
actionProviders.keySet().forEach(dataStoreActionProvider -> {
if (!isInStorage()) {
actionProviders.get(dataStoreActionProvider).set(false);
defaultActionProvider.setValue(null);
return;
}

Expand All @@ -138,6 +127,12 @@ public void update() {
return;
}

var defaultProvider = ActionProvider.ALL.stream()
.filter(e -> e.getDefaultDataStoreCallSite() != null
&& e.getDefaultDataStoreCallSite().isApplicable(entry.getStore().asNeeded()))
.findFirst().map(ActionProvider::getDefaultDataStoreCallSite).orElse(null);
this.defaultActionProvider.setValue(defaultProvider);

try {
actionProviders
.get(dataStoreActionProvider)
Expand Down
19 changes: 15 additions & 4 deletions app/src/main/java/io/xpipe/app/ext/ActionProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,26 @@ default LauncherCallSite getLauncherCallSite() {
default DataStoreCallSite<?> getDataStoreCallSite() {
return null;
}
default DefaultDataStoreCallSite<?> getDefaultDataStoreCallSite() {
return null;
}

default DataSourceCallSite<?> getDataSourceCallSite() {
return null;
}


public static interface DefaultDataStoreCallSite<T extends DataStore> {

Action createAction(T store);

Class<T> getApplicableClass();

default boolean isApplicable(T o) {
return true;
}
}

public static interface DataStoreCallSite<T extends DataStore> {

enum ActiveType {
Expand All @@ -85,10 +100,6 @@ enum ActiveType {

Class<T> getApplicableClass();

default boolean isDefault() {
return false;
}

default boolean isMajor() {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ private void setSelected(FileSystemStore fileSystem, String file) {
@Override
protected Region createSimple() {
var fileProperty = new SimpleStringProperty(
selected.getValue() != null ? selected.getValue().getFile() : null);
selected.getValue() != null ? selected.getValue().getPath() : null);
fileProperty.addListener((observable, oldValue, newValue) -> {
setSelected(selected.getValue().getFileSystem(), newValue);
});
selected.addListener((observable, oldValue, newValue) -> {
fileProperty.setValue(newValue.getFile());
fileProperty.setValue(newValue.getPath());
});

var fileSystemChoiceComp = new FileSystemStoreChoiceComp(selected).grow(false, true).styleClass(Styles.LEFT_PILL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ protected Region createSimple() {
fileSystemProperty.addListener((observable, oldValue, newValue) -> {
selected.setValue(FileStore.builder()
.fileSystem(newValue)
.file(selected.getValue() != null ? selected.getValue().getFile() : null)
.path(selected.getValue() != null ? selected.getValue().getPath() : null)
.build());
});

selected.addListener((observable, oldValue, newValue) -> {
fileSystemProperty.setValue(newValue.getFileSystem());
fileSystemProperty.setValue(newValue != null?newValue.getFileSystem():null);
});

var comboBox =
Expand Down
80 changes: 61 additions & 19 deletions app/src/main/java/io/xpipe/app/issue/ErrorHandlerComp.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import io.xpipe.app.core.AppWindowHelper;
import io.xpipe.app.fxcomps.SimpleComp;
import io.xpipe.app.fxcomps.augment.GrowAugment;
import io.xpipe.app.fxcomps.util.PlatformThread;
import io.xpipe.app.util.JfxHelper;
import javafx.application.Platform;
import javafx.geometry.Orientation;
import javafx.scene.control.Label;
import javafx.scene.control.Separator;
Expand All @@ -20,6 +20,8 @@
import org.kordamp.ikonli.javafx.FontIcon;

import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

import static atlantafx.base.theme.Styles.ACCENT;
Expand All @@ -37,27 +39,67 @@ public ErrorHandlerComp(ErrorEvent event, Stage stage) {
}

public static void showAndWait(ErrorEvent event) {
PlatformThread.runLaterIfNeededBlocking(() -> {
synchronized (showing) {
if (!showing.get()) {
showing.set(true);
var window = AppWindowHelper.sideWindow(
AppI18n.get("errorHandler"), w -> new ErrorHandlerComp(event, w), true, null);
window.setOnHidden(e -> {
showing.set(false);
});

// An exception is thrown when show and wait is called
// within an animation or layout processing task
try {
window.showAndWait();
} catch (Throwable t) {
window.show();
t.printStackTrace();
}
if (Platform.isFxApplicationThread()) {
showAndWaitWithPlatformThread(event);
} else {
showAndWaitWithOtherThread(event);
}
}

public static void showAndWaitWithPlatformThread(ErrorEvent event) {
var finishLatch = new CountDownLatch(1);
if (!showing.get()) {
showing.set(true);
var window = AppWindowHelper.sideWindow(
AppI18n.get("errorHandler"), w -> new ErrorHandlerComp(event, w), true, null);
window.setOnHidden(e -> {
showing.set(false);
finishLatch.countDown();
});

// An exception is thrown when show and wait is called
// within an animation or layout processing task, so use show
try {
window.show();
} catch (Throwable t) {
t.printStackTrace();
}
}
}

public static void showAndWaitWithOtherThread(ErrorEvent event) {
var showLatch = new CountDownLatch(1);
var finishLatch = new CountDownLatch(1);
Platform.runLater(() -> {
if (!showing.get()) {
showing.set(true);
var window = AppWindowHelper.sideWindow(
AppI18n.get("errorHandler"), w -> new ErrorHandlerComp(event, w), true, null);
window.setOnHidden(e -> {
showing.set(false);
finishLatch.countDown();
});

// An exception is thrown when show and wait is called
// within an animation or layout processing task, so use show
try {
showLatch.countDown();
window.show();
} catch (Throwable t) {
t.printStackTrace();
}
}
});

try {
// Only wait for a certain time in case we somehow deadlocked the platform thread
if (showLatch.await(5, TimeUnit.SECONDS)) {
finishLatch.await();
} else {
TrackEvent.error("Platform thread in error handler was timed out");
}
} catch (InterruptedException ignored) {
}
}

private Region createActionComp(ErrorAction a) {
Expand Down
29 changes: 16 additions & 13 deletions app/src/main/java/io/xpipe/app/storage/DataStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -367,30 +367,32 @@ public void refreshAsync(StorageElement element, boolean deep) {
});
}

private synchronized void propagateUpdate() {
private void propagateUpdate() {
for (DataStoreEntry dataStoreEntry : getStoreEntries()) {
dataStoreEntry.simpleRefresh();
}

for (var e : sourceEntries) {
for (var e : getSourceEntries()) {
e.simpleRefresh();
}
}

public synchronized void addStoreEntry(@NonNull DataStoreEntry e) {
public void addStoreEntry(@NonNull DataStoreEntry e) {
if (getStoreEntryIfPresent(e.getName()).isPresent()) {
throw new IllegalArgumentException("Store with name " + e.getName() + " already exists");
}

e.setDirectory(getStoresDir().resolve(e.getUuid().toString()));
this.storeEntries.add(e);
synchronized (this) {
e.setDirectory(getStoresDir().resolve(e.getUuid().toString()));
this.storeEntries.add(e);
}
propagateUpdate();
save();

this.listeners.forEach(l -> l.onStoreAdd(e));
}

public synchronized void addStoreEntryIfNotPresent(@NonNull String name, DataStore store) {
public void addStoreEntryIfNotPresent(@NonNull String name, DataStore store) {
if (getStoreEntryIfPresent(store).isPresent()) {
return;
}
Expand All @@ -399,29 +401,30 @@ public synchronized void addStoreEntryIfNotPresent(@NonNull String name, DataSto
addStoreEntry(e);
}

public synchronized DataStoreEntry addStoreEntry(@NonNull String name, DataStore store) {
public DataStoreEntry addStoreEntry(@NonNull String name, DataStore store) {
var e = DataStoreEntry.createNew(UUID.randomUUID(), createUniqueStoreEntryName(name), store);
addStoreEntry(e);
return e;
}

public synchronized void deleteStoreEntry(@NonNull DataStoreEntry store) {
public void deleteStoreEntry(@NonNull DataStoreEntry store) {
if (!store.getConfiguration().isDeletable()) {
throw new UnsupportedOperationException();
}

this.storeEntries.remove(store);
synchronized (this) {
this.storeEntries.remove(store);
}
propagateUpdate();
save();

this.listeners.forEach(l -> l.onStoreRemove(store));
}

public synchronized void addListener(StorageListener l) {
this.listeners.add(l);
}

public synchronized DataSourceCollection createOrGetCollection(String name) {
public DataSourceCollection createOrGetCollection(String name) {
return getCollectionForName(name).orElseGet(() -> {
var col = DataSourceCollection.createNew(name);
addCollection(col);
Expand Down Expand Up @@ -460,8 +463,8 @@ public synchronized void deleteSourceEntry(DataSourceEntry e) {

public abstract void load();

public synchronized void refresh() {
storeEntries.forEach(entry -> {
public void refresh() {
getStoreEntries().forEach(entry -> {
entry.simpleRefresh();
});
save();
Expand Down
Loading

0 comments on commit 3ec708e

Please sign in to comment.