From 3df5a1f6974e879211c1c68cb7322447cd9388db Mon Sep 17 00:00:00 2001 From: crschnick Date: Mon, 18 Nov 2024 11:36:38 +0000 Subject: [PATCH] Various resilience fixes --- .../file/BrowserFileSystemTabModel.java | 3 +- .../xpipe/app/comp/store/StoreEntryComp.java | 2 ++ .../app/comp/store/StoreEntryWrapper.java | 2 +- .../java/io/xpipe/app/core/AppProperties.java | 4 +++ .../app/core/check/AppUserDirectoryCheck.java | 5 ++-- .../io/xpipe/app/core/mode/OperationMode.java | 1 - .../java/io/xpipe/app/prefs/AppPrefs.java | 28 ++----------------- .../xpipe/core/store/NetworkTunnelStore.java | 4 +-- .../service/CustomServiceStoreProvider.java | 2 +- 9 files changed, 17 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/io/xpipe/app/browser/file/BrowserFileSystemTabModel.java b/app/src/main/java/io/xpipe/app/browser/file/BrowserFileSystemTabModel.java index 864f3a8de..75aa2d88b 100644 --- a/app/src/main/java/io/xpipe/app/browser/file/BrowserFileSystemTabModel.java +++ b/app/src/main/java/io/xpipe/app/browser/file/BrowserFileSystemTabModel.java @@ -113,7 +113,8 @@ public final class BrowserFileSystemTabModel extends BrowserStoreSessionTab { return !getWrapper().getDeletable().get() + && AppPrefs.get().developerMode().getValue() && !AppPrefs.get() .developerDisableGuiRestrictions() .get(); }, getWrapper().getDeletable(), + AppPrefs.get().developerMode(), AppPrefs.get().developerDisableGuiRestrictions())); del.setOnAction(event -> getWrapper().delete()); contextMenu.getItems().add(del); diff --git a/app/src/main/java/io/xpipe/app/comp/store/StoreEntryWrapper.java b/app/src/main/java/io/xpipe/app/comp/store/StoreEntryWrapper.java index 6e2fae963..edd24f9c1 100644 --- a/app/src/main/java/io/xpipe/app/comp/store/StoreEntryWrapper.java +++ b/app/src/main/java/io/xpipe/app/comp/store/StoreEntryWrapper.java @@ -157,7 +157,7 @@ public class StoreEntryWrapper { busy.setValue(entry.getBusyCounter().get() != 0); deletable.setValue(entry.getConfiguration().isDeletable() - || AppPrefs.get().developerDisableGuiRestrictions().getValue()); + || (AppPrefs.get().developerMode().getValue() && AppPrefs.get().developerDisableGuiRestrictions().getValue())); sessionActive.setValue(entry.getStore() instanceof SingletonSessionStore ss && entry.getStore() instanceof ShellStore && ss.isSessionRunning()); diff --git a/app/src/main/java/io/xpipe/app/core/AppProperties.java b/app/src/main/java/io/xpipe/app/core/AppProperties.java index bb1e94d17..df0185083 100644 --- a/app/src/main/java/io/xpipe/app/core/AppProperties.java +++ b/app/src/main/java/io/xpipe/app/core/AppProperties.java @@ -1,5 +1,6 @@ package io.xpipe.app.core; +import io.xpipe.app.core.check.AppUserDirectoryCheck; import io.xpipe.app.issue.ErrorEvent; import io.xpipe.app.issue.TrackEvent; import io.xpipe.app.prefs.AppPrefs; @@ -121,6 +122,9 @@ public class AppProperties { autoAcceptEula = Optional.ofNullable(System.getProperty("io.xpipe.app.acceptEula")) .map(Boolean::parseBoolean) .orElse(false); + + // We require the user dir from here + AppUserDirectoryCheck.check(dataDir); AppCache.setBasePath(dataDir.resolve("cache")); UUID id = AppCache.getNonNull("uuid", UUID.class, null); if (id == null) { diff --git a/app/src/main/java/io/xpipe/app/core/check/AppUserDirectoryCheck.java b/app/src/main/java/io/xpipe/app/core/check/AppUserDirectoryCheck.java index 238e80f4b..45ea7e44d 100644 --- a/app/src/main/java/io/xpipe/app/core/check/AppUserDirectoryCheck.java +++ b/app/src/main/java/io/xpipe/app/core/check/AppUserDirectoryCheck.java @@ -7,12 +7,11 @@ import org.apache.commons.io.FileUtils; import java.io.IOException; import java.nio.file.Files; +import java.nio.file.Path; public class AppUserDirectoryCheck { - public static void check() { - var dataDirectory = AppProperties.get().getDataDir(); - + public static void check(Path dataDirectory) { try { FileUtils.forceMkdir(dataDirectory.toFile()); var testDirectory = dataDirectory.resolve("permissions_check"); diff --git a/app/src/main/java/io/xpipe/app/core/mode/OperationMode.java b/app/src/main/java/io/xpipe/app/core/mode/OperationMode.java index 60743e6a4..7d9dc6eb7 100644 --- a/app/src/main/java/io/xpipe/app/core/mode/OperationMode.java +++ b/app/src/main/java/io/xpipe/app/core/mode/OperationMode.java @@ -115,7 +115,6 @@ public abstract class OperationMode { TrackEvent.info("Initial setup"); AppProperties.init(); - AppUserDirectoryCheck.check(); AppTempCheck.check(); AppLogs.init(); AppDebugModeCheck.printIfNeeded(); diff --git a/app/src/main/java/io/xpipe/app/prefs/AppPrefs.java b/app/src/main/java/io/xpipe/app/prefs/AppPrefs.java index c2653ea71..6f47a2b3a 100644 --- a/app/src/main/java/io/xpipe/app/prefs/AppPrefs.java +++ b/app/src/main/java/io/xpipe/app/prefs/AppPrefs.java @@ -133,12 +133,8 @@ public class AppPrefs { mapLocal(new SimpleBooleanProperty(false), "developerMode", Boolean.class, true); final BooleanProperty developerDisableUpdateVersionCheck = mapLocal(new SimpleBooleanProperty(false), "developerDisableUpdateVersionCheck", Boolean.class, false); - private final ObservableBooleanValue developerDisableUpdateVersionCheckEffective = - bindDeveloperTrue(developerDisableUpdateVersionCheck); final BooleanProperty developerDisableGuiRestrictions = mapLocal(new SimpleBooleanProperty(false), "developerDisableGuiRestrictions", Boolean.class, false); - private final ObservableBooleanValue developerDisableGuiRestrictionsEffective = - bindDeveloperTrue(developerDisableGuiRestrictions); final BooleanProperty developerForceSshTty = mapLocal(new SimpleBooleanProperty(false), "developerForceSshTty", Boolean.class, false); @@ -276,24 +272,6 @@ public class AppPrefs { return developerMode().getValue() && !ModuleHelper.isImage(); } - private ObservableBooleanValue bindDeveloperTrue(ObservableBooleanValue o) { - return Bindings.createBooleanBinding( - () -> { - return developerMode().getValue() && o.get(); - }, - o, - developerMode()); - } - - private ObservableBooleanValue bindDeveloperFalse(ObservableBooleanValue o) { - return Bindings.createBooleanBinding( - () -> { - return !developerMode().getValue() && o.get(); - }, - o, - developerMode()); - } - public ObservableValue externalPasswordManager() { return passwordManager; } @@ -488,15 +466,15 @@ public class AppPrefs { } public ObservableBooleanValue developerDisableUpdateVersionCheck() { - return developerDisableUpdateVersionCheckEffective; + return developerDisableUpdateVersionCheck; } public ObservableBooleanValue developerDisableGuiRestrictions() { - return developerDisableGuiRestrictionsEffective; + return developerDisableGuiRestrictions; } public ObservableBooleanValue developerForceSshTty() { - return bindDeveloperTrue(developerForceSshTty); + return developerForceSshTty; } @SuppressWarnings("unchecked") diff --git a/core/src/main/java/io/xpipe/core/store/NetworkTunnelStore.java b/core/src/main/java/io/xpipe/core/store/NetworkTunnelStore.java index 7307143dd..34997f312 100644 --- a/core/src/main/java/io/xpipe/core/store/NetworkTunnelStore.java +++ b/core/src/main/java/io/xpipe/core/store/NetworkTunnelStore.java @@ -42,7 +42,7 @@ public interface NetworkTunnelStore extends DataStore { } } - default boolean isLocallyTunneable() { + default boolean isLocallyTunnelable() { NetworkTunnelStore current = this; while (true) { if (current.getNetworkParent() == null) { @@ -58,7 +58,7 @@ public interface NetworkTunnelStore extends DataStore { } default NetworkTunnelSession sessionChain(int local, int remotePort, String address) throws Exception { - if (!isLocallyTunneable()) { + if (!isLocallyTunnelable()) { throw new IllegalStateException( "Unable to create tunnel chain as one intermediate system does not support tunneling"); } diff --git a/ext/base/src/main/java/io/xpipe/ext/base/service/CustomServiceStoreProvider.java b/ext/base/src/main/java/io/xpipe/ext/base/service/CustomServiceStoreProvider.java index 18cc84e77..f1270b008 100644 --- a/ext/base/src/main/java/io/xpipe/ext/base/service/CustomServiceStoreProvider.java +++ b/ext/base/src/main/java/io/xpipe/ext/base/service/CustomServiceStoreProvider.java @@ -39,7 +39,7 @@ public class CustomServiceStoreProvider extends AbstractServiceStoreProvider { StoreChoiceComp.other( host, NetworkTunnelStore.class, - n -> n.getStore().isLocallyTunneable(), + n -> n.getStore().isLocallyTunnelable(), StoreViewState.get().getAllConnectionsCategory()), host) .nonNull()