From dd542d6758c42a19d6486996280bc4be085ffa1d Mon Sep 17 00:00:00 2001 From: crschnick Date: Sun, 22 Sep 2024 16:26:21 +0000 Subject: [PATCH] Improve shell control bookkeeping --- .../java/io/xpipe/app/browser/file/LocalFileSystem.java | 7 +++++++ .../io/xpipe/app/browser/fs/OpenFileSystemModel.java | 9 +++++---- .../xpipe/app/browser/session/BrowserSessionModel.java | 2 +- app/src/main/java/io/xpipe/app/core/mode/BaseMode.java | 6 +++++- app/src/main/java/io/xpipe/app/core/mode/GuiMode.java | 6 ++++++ .../java/io/xpipe/app/ext/ProcessControlProvider.java | 2 ++ .../io/xpipe/app/storage/DataStorageSyncHandler.java | 2 ++ 7 files changed, 28 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/xpipe/app/browser/file/LocalFileSystem.java b/app/src/main/java/io/xpipe/app/browser/file/LocalFileSystem.java index d35985d87..48b74d368 100644 --- a/app/src/main/java/io/xpipe/app/browser/file/LocalFileSystem.java +++ b/app/src/main/java/io/xpipe/app/browser/file/LocalFileSystem.java @@ -19,6 +19,13 @@ public class LocalFileSystem { } } + public static void reset() throws Exception { + if (localFileSystem != null) { + localFileSystem.close(); + localFileSystem = null; + } + } + public static FileEntry getLocalFileEntry(Path file) throws Exception { if (localFileSystem == null) { throw new IllegalStateException(); diff --git a/app/src/main/java/io/xpipe/app/browser/fs/OpenFileSystemModel.java b/app/src/main/java/io/xpipe/app/browser/fs/OpenFileSystemModel.java index ed3792239..3e6399089 100644 --- a/app/src/main/java/io/xpipe/app/browser/fs/OpenFileSystemModel.java +++ b/app/src/main/java/io/xpipe/app/browser/fs/OpenFileSystemModel.java @@ -72,10 +72,11 @@ public final class OpenFileSystemModel extends BrowserSessionTab(sessionEntries)) { // Don't close busy connections gracefully // as we otherwise might lock up - if (o.canImmediatelyClose()) { + if (!o.canImmediatelyClose()) { continue; } diff --git a/app/src/main/java/io/xpipe/app/core/mode/BaseMode.java b/app/src/main/java/io/xpipe/app/core/mode/BaseMode.java index 46475ae44..5e22ae223 100644 --- a/app/src/main/java/io/xpipe/app/core/mode/BaseMode.java +++ b/app/src/main/java/io/xpipe/app/core/mode/BaseMode.java @@ -8,6 +8,7 @@ import io.xpipe.app.core.*; import io.xpipe.app.core.check.*; import io.xpipe.app.ext.ActionProvider; import io.xpipe.app.ext.DataStoreProviders; +import io.xpipe.app.ext.ProcessControlProvider; import io.xpipe.app.issue.TrackEvent; import io.xpipe.app.prefs.AppPrefs; import io.xpipe.app.resources.AppResources; @@ -74,7 +75,7 @@ public class BaseMode extends OperationMode { public void onSwitchFrom() {} @Override - public void finalTeardown() { + public void finalTeardown() throws Exception { TrackEvent.info("Background mode shutdown started"); BrowserSessionModel.DEFAULT.reset(); SshLocalBridge.reset(); @@ -82,6 +83,9 @@ public class BaseMode extends OperationMode { DataStoreProviders.reset(); DataStorage.reset(); AppPrefs.reset(); + DataStorageSyncHandler.getInstance().reset(); + LocalShell.reset(); + ProcessControlProvider.get().reset(); AppResources.reset(); AppExtensionManager.reset(); AppDataLock.unlock(); diff --git a/app/src/main/java/io/xpipe/app/core/mode/GuiMode.java b/app/src/main/java/io/xpipe/app/core/mode/GuiMode.java index ad26c5d96..fef22244d 100644 --- a/app/src/main/java/io/xpipe/app/core/mode/GuiMode.java +++ b/app/src/main/java/io/xpipe/app/core/mode/GuiMode.java @@ -63,4 +63,10 @@ public class GuiMode extends PlatformMode { UpdateChangelogAlert.showIfNeeded(); } + + @Override + public void finalTeardown() throws Throwable { + LocalFileSystem.reset(); + super.finalTeardown(); + } } diff --git a/app/src/main/java/io/xpipe/app/ext/ProcessControlProvider.java b/app/src/main/java/io/xpipe/app/ext/ProcessControlProvider.java index 868be499c..99c6468d6 100644 --- a/app/src/main/java/io/xpipe/app/ext/ProcessControlProvider.java +++ b/app/src/main/java/io/xpipe/app/ext/ProcessControlProvider.java @@ -23,6 +23,8 @@ public abstract class ProcessControlProvider { return INSTANCE; } + public abstract void reset(); + public abstract ShellControl withDefaultScripts(ShellControl pc); public abstract ShellControl sub( diff --git a/app/src/main/java/io/xpipe/app/storage/DataStorageSyncHandler.java b/app/src/main/java/io/xpipe/app/storage/DataStorageSyncHandler.java index 6661ee5e2..86e3b5513 100644 --- a/app/src/main/java/io/xpipe/app/storage/DataStorageSyncHandler.java +++ b/app/src/main/java/io/xpipe/app/storage/DataStorageSyncHandler.java @@ -10,6 +10,8 @@ public interface DataStorageSyncHandler { return (DataStorageSyncHandler) ProcessControlProvider.get().getGitStorageHandler(); } + void reset() throws Exception; + boolean validateConnection(); boolean supportsSync();