Skip to content

Commit

Permalink
Various resilience fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
crschnick committed Nov 18, 2024
1 parent e763715 commit 3df5a1f
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ public void close() {
}

var current = getCurrentDirectory();
if (DataStorage.get().getStoreEntries().contains(getEntry().get())
// We might close this after storage shutdown
if (DataStorage.get() != null && DataStorage.get().getStoreEntries().contains(getEntry().get())
&& savedState != null
&& current != null) {
savedState.cd(current.getPath(), false);
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/io/xpipe/app/comp/store/StoreEntryComp.java
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,13 @@ protected ContextMenu createContextMenu() {
.bind(Bindings.createBooleanBinding(
() -> {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public synchronized void update() {

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());
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/io/xpipe/app/core/AppProperties.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -121,6 +122,9 @@ public 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@

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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ private static void setup(String[] args) {

TrackEvent.info("Initial setup");
AppProperties.init();
AppUserDirectoryCheck.check();
AppTempCheck.check();
AppLogs.init();
AppDebugModeCheck.printIfNeeded();
Expand Down
28 changes: 3 additions & 25 deletions app/src/main/java/io/xpipe/app/prefs/AppPrefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -276,24 +272,6 @@ public boolean isDevelopmentEnvironment() {
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> externalPasswordManager() {
return passwordManager;
}
Expand Down Expand Up @@ -488,15 +466,15 @@ public ObservableBooleanValue saveWindowLocation() {
}

public ObservableBooleanValue developerDisableUpdateVersionCheck() {
return developerDisableUpdateVersionCheckEffective;
return developerDisableUpdateVersionCheck;
}

public ObservableBooleanValue developerDisableGuiRestrictions() {
return developerDisableGuiRestrictionsEffective;
return developerDisableGuiRestrictions;
}

public ObservableBooleanValue developerForceSshTty() {
return bindDeveloperTrue(developerForceSshTty);
return developerForceSshTty;
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ default boolean requiresTunnel() {
}
}

default boolean isLocallyTunneable() {
default boolean isLocallyTunnelable() {
NetworkTunnelStore current = this;
while (true) {
if (current.getNetworkParent() == null) {
Expand All @@ -58,7 +58,7 @@ default boolean isLocallyTunneable() {
}

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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public GuiDialog guiDialog(DataStoreEntry entry, Property<DataStore> store) {
StoreChoiceComp.other(
host,
NetworkTunnelStore.class,
n -> n.getStore().isLocallyTunneable(),
n -> n.getStore().isLocallyTunnelable(),
StoreViewState.get().getAllConnectionsCategory()),
host)
.nonNull()
Expand Down

0 comments on commit 3df5a1f

Please sign in to comment.