From 12e4ccb995f7e8a1140c71f72f097d0ff4e136c7 Mon Sep 17 00:00:00 2001 From: crschnick Date: Thu, 22 Feb 2024 05:21:24 +0000 Subject: [PATCH] Various fixes --- .../io/xpipe/app/browser/OpenFileSystemModel.java | 15 +++++++++++---- .../main/java/io/xpipe/app/issue/ErrorEvent.java | 4 ++++ .../main/java/io/xpipe/app/util/LocalShell.java | 4 ++-- .../java/io/xpipe/core/process/ShellControl.java | 2 +- .../io/xpipe/core/store/ConnectionFileSystem.java | 2 +- .../main/java/io/xpipe/core/store/FileSystem.java | 2 +- 6 files changed, 20 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/xpipe/app/browser/OpenFileSystemModel.java b/app/src/main/java/io/xpipe/app/browser/OpenFileSystemModel.java index 6ec8f60fa..449a4bf8a 100644 --- a/app/src/main/java/io/xpipe/app/browser/OpenFileSystemModel.java +++ b/app/src/main/java/io/xpipe/app/browser/OpenFileSystemModel.java @@ -67,13 +67,15 @@ public final class OpenFileSystemModel { && fileSystem.getShell().get().getLock().isLocked()); } - private void startIfNeeded() { + private void startIfNeeded() throws Exception { if (fileSystem == null) { return; } var s = fileSystem.getShell(); - s.ifPresent(ShellControl::start); + if (s.isPresent()) { + s.get().start(); + } } public void withShell(FailableConsumer c, boolean refresh) { @@ -151,8 +153,13 @@ public final class OpenFileSystemModel { return Optional.empty(); } - // Start shell in case we exited - startIfNeeded(); + try { + // Start shell in case we exited + startIfNeeded(); + } catch (Exception ex) { + ErrorEvent.fromThrowable(ex).handle(); + return Optional.ofNullable(currentPath.get()); + } // Fix common issues with paths var adjustedPath = FileSystemHelper.adjustPath(this, path); diff --git a/app/src/main/java/io/xpipe/app/issue/ErrorEvent.java b/app/src/main/java/io/xpipe/app/issue/ErrorEvent.java index 46c1924b8..ea2845a5b 100644 --- a/app/src/main/java/io/xpipe/app/issue/ErrorEvent.java +++ b/app/src/main/java/io/xpipe/app/issue/ErrorEvent.java @@ -85,6 +85,10 @@ public class ErrorEvent { return t; } + public static void preconfigure(ErrorEventBuilder event) { + EVENT_BASES.put(event.throwable, event); + } + public void attachUserReport(String email, String text) { this.email = email; userReport = text; diff --git a/app/src/main/java/io/xpipe/app/util/LocalShell.java b/app/src/main/java/io/xpipe/app/util/LocalShell.java index ba8f78193..480f36448 100644 --- a/app/src/main/java/io/xpipe/app/util/LocalShell.java +++ b/app/src/main/java/io/xpipe/app/util/LocalShell.java @@ -13,12 +13,12 @@ public class LocalShell { private static ShellControl local; private static ShellControl localPowershell; - public static void init() { + public static void init() throws Exception { local = ProcessControlProvider.get().createLocalProcessControl(false).start(); localCache = new ShellControlCache(local); } - public static ShellControl getLocalPowershell() { + public static ShellControl getLocalPowershell() throws Exception { if (localPowershell == null) { localPowershell = ProcessControlProvider.get() .createLocalProcessControl(true) diff --git a/core/src/main/java/io/xpipe/core/process/ShellControl.java b/core/src/main/java/io/xpipe/core/process/ShellControl.java index 53c352c35..79ba1974b 100644 --- a/core/src/main/java/io/xpipe/core/process/ShellControl.java +++ b/core/src/main/java/io/xpipe/core/process/ShellControl.java @@ -76,7 +76,7 @@ public interface ShellControl extends ProcessControl { ShellControl withExceptionConverter(ExceptionConverter converter); @Override - ShellControl start(); + ShellControl start() throws Exception; ShellControl withErrorFormatter(Function formatter); diff --git a/core/src/main/java/io/xpipe/core/store/ConnectionFileSystem.java b/core/src/main/java/io/xpipe/core/store/ConnectionFileSystem.java index b44d4a076..8b1273763 100644 --- a/core/src/main/java/io/xpipe/core/store/ConnectionFileSystem.java +++ b/core/src/main/java/io/xpipe/core/store/ConnectionFileSystem.java @@ -36,7 +36,7 @@ public class ConnectionFileSystem implements FileSystem { } @Override - public FileSystem open() { + public FileSystem open() throws Exception { shellControl.start(); return this; } diff --git a/core/src/main/java/io/xpipe/core/store/FileSystem.java b/core/src/main/java/io/xpipe/core/store/FileSystem.java index da6fdcaab..b6daad8c5 100644 --- a/core/src/main/java/io/xpipe/core/store/FileSystem.java +++ b/core/src/main/java/io/xpipe/core/store/FileSystem.java @@ -21,7 +21,7 @@ public interface FileSystem extends Closeable, AutoCloseable { Optional getShell(); - FileSystem open(); + FileSystem open() throws Exception; InputStream openInput(String file) throws Exception;