From bd6b04dca0727a6d64ebcab0480ef1d2a89f17e6 Mon Sep 17 00:00:00 2001 From: crschnick Date: Mon, 20 Feb 2023 10:36:00 +0000 Subject: [PATCH] Small fixes --- .../xpipe/app/core/AppExtensionManager.java | 39 +++++++------------ .../java/io/xpipe/app/core/AppResources.java | 10 ++--- .../java/io/xpipe/app/core/mode/BaseMode.java | 2 +- .../xpipe/app/issue/TerminalErrorHandler.java | 4 +- .../java/io/xpipe/app/update/AppUpdater.java | 28 ++----------- .../java/io/xpipe/app/util/XPipeDaemon.java | 5 --- .../xpipe/app/util/XPipeDaemonProvider.java | 9 ----- .../java/io/xpipe/core/util/Deobfuscator.java | 5 +-- 8 files changed, 27 insertions(+), 75 deletions(-) diff --git a/app/src/main/java/io/xpipe/app/core/AppExtensionManager.java b/app/src/main/java/io/xpipe/app/core/AppExtensionManager.java index 650be8c9a..7dae310b2 100644 --- a/app/src/main/java/io/xpipe/app/core/AppExtensionManager.java +++ b/app/src/main/java/io/xpipe/app/core/AppExtensionManager.java @@ -28,7 +28,7 @@ public class AppExtensionManager { private ModuleLayer baseLayer = ModuleLayer.boot(); private ModuleLayer extendedLayer; - public static void init() throws Exception { + public static void init(boolean loadProviders) { if (INSTANCE != null) { return; } @@ -37,7 +37,10 @@ public class AppExtensionManager { INSTANCE.determineExtensionDirectories(); INSTANCE.loadBasicExtension(); INSTANCE.loadExtensions(); - INSTANCE.loadContent(); + + if (loadProviders) { + INSTANCE.loadContent(); + } } private void loadBasicExtension() { @@ -50,21 +53,6 @@ public class AppExtensionManager { loadedExtensions.add(baseModule.get()); } - public static ModuleLayer initBare() { - if (INSTANCE != null) { - return INSTANCE.extendedLayer; - } - - INSTANCE = new AppExtensionManager(); - INSTANCE.determineExtensionDirectories(); - INSTANCE.loadBasicExtension(); - var proc = INSTANCE.loadExtension("proc", INSTANCE.baseLayer).orElseThrow(); - var procx = INSTANCE.loadExtension("procx", proc.getModule().getLayer()).orElseThrow(); - INSTANCE.leafModuleLayers.add(procx.getModule().getLayer()); - INSTANCE.extendedLayer = procx.getModule().getLayer(); - return INSTANCE.extendedLayer; - } - private void determineExtensionDirectories() { if (!AppProperties.get().isImage()) { extensionBaseDirectories.add(Path.of(System.getProperty("user.dir")).resolve("app").resolve("build").resolve("ext_dev")); @@ -131,7 +119,7 @@ public class AppExtensionManager { return ext != null ? base.resolve(ext) : base; } - private void loadExtensions() throws IOException { + private void loadExtensions() { for (Path extensionBaseDirectory : extensionBaseDirectories) { loadExtensionBaseDirectory(extensionBaseDirectory); } @@ -148,7 +136,7 @@ public class AppExtensionManager { } } - private void loadContent() throws IOException { + private void loadContent() { addNativeLibrariesToPath(); XPipeServiceProviders.load(extendedLayer); MessageExchangeImpls.loadAll(); @@ -297,13 +285,16 @@ public class AppExtensionManager { .findFirst(); } - private void addNativeLibrariesToPath() throws IOException { + private void addNativeLibrariesToPath() { var libsDir = AppProperties.get().isImage() ? XPipeInstallation.getLocalDynamicLibraryDirectory() : Path.of("lib"); - if (Files.exists(libsDir)) { - // FileUtils.deleteDirectory(libsDir.toFile()); - } else { - Files.createDirectories(libsDir); + if (!Files.exists(libsDir)) { + try { + Files.createDirectories(libsDir); + } catch (IOException e) { + ErrorEvent.fromThrowable(e).handle(); + return; + } } for (var ext : loadedExtensions) { diff --git a/app/src/main/java/io/xpipe/app/core/AppResources.java b/app/src/main/java/io/xpipe/app/core/AppResources.java index f35376e2b..46478048b 100644 --- a/app/src/main/java/io/xpipe/app/core/AppResources.java +++ b/app/src/main/java/io/xpipe/app/core/AppResources.java @@ -1,8 +1,8 @@ package io.xpipe.app.core; import io.xpipe.app.issue.ErrorEvent; -import io.xpipe.core.charsetter.Charsetter; import io.xpipe.modulefs.ModuleFileSystem; +import org.apache.commons.lang3.function.FailableConsumer; import java.io.IOException; import java.net.JarURLConnection; @@ -39,7 +39,7 @@ public class AppResources { } } - public static void with(String module, String file, Charsetter.FailableConsumer con) { + public static void with(String module, String file, FailableConsumer con) { if (AppProperties.get() != null && !AppProperties.get().isImage() && AppProperties.get().isDeveloperMode()) { @@ -53,7 +53,7 @@ public class AppResources { } public static void withResource( - String module, String file, ModuleLayer layer, Charsetter.FailableConsumer con) { + String module, String file, ModuleLayer layer, FailableConsumer con) { try (var fs = FileSystems.newFileSystem(URI.create("module:/" + module), Map.of("layer", layer))) { var f = fs.getPath(module.replace('.', '/') + "/resources/" + file); con.accept(f); @@ -62,7 +62,7 @@ public class AppResources { } } - private static void withResource(String module, String file, Charsetter.FailableConsumer con) { + private static void withResource(String module, String file, FailableConsumer con) { try (var fs = openFileSystem(module)) { var f = fs.getPath(module.replace('.', '/') + "/resources/" + file); con.accept(f); @@ -72,7 +72,7 @@ public class AppResources { } private static boolean withLocalDevResource( - String module, String file, Charsetter.FailableConsumer con) { + String module, String file, FailableConsumer con) { try (var fs = openFileSystem(module)) { var url = fs.getPath("").getWrappedPath().toUri().toURL(); if (!url.getProtocol().equals("jar")) { 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 6fec93a8a..52e150d42 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 @@ -33,7 +33,7 @@ public class BaseMode extends OperationMode { @Override public void initialSetup() throws Exception { TrackEvent.info("mode", "Initializing base mode components ..."); - AppExtensionManager.init(); + AppExtensionManager.init(true); JacksonMapper.initModularized(AppExtensionManager.getInstance().getExtendedLayer()); AppPrefs.init(); AppCharsets.init(); diff --git a/app/src/main/java/io/xpipe/app/issue/TerminalErrorHandler.java b/app/src/main/java/io/xpipe/app/issue/TerminalErrorHandler.java index 8897a65ef..1d416983f 100644 --- a/app/src/main/java/io/xpipe/app/issue/TerminalErrorHandler.java +++ b/app/src/main/java/io/xpipe/app/issue/TerminalErrorHandler.java @@ -58,7 +58,7 @@ public class TerminalErrorHandler implements ErrorHandler { try { AppProperties.init(); - AppExtensionManager.initBare(); + AppExtensionManager.init(false); AppI18n.init(); AppStyle.init(); ErrorHandlerComp.showAndWait(event); @@ -86,7 +86,7 @@ public class TerminalErrorHandler implements ErrorHandler { private static void handleProbableUpdate() { try { - AppUpdater.initBare(); + AppUpdater.initFallback(); var rel = AppUpdater.get().checkForUpdate(true); if (rel.isUpdate()) { var update = AppWindowHelper.showBlockingAlert(alert -> { diff --git a/app/src/main/java/io/xpipe/app/update/AppUpdater.java b/app/src/main/java/io/xpipe/app/update/AppUpdater.java index b8bf8085f..3c2cb0498 100644 --- a/app/src/main/java/io/xpipe/app/update/AppUpdater.java +++ b/app/src/main/java/io/xpipe/app/update/AppUpdater.java @@ -81,38 +81,16 @@ public class AppUpdater { TrackEvent.builder().category("installer").type("info").message(msg).handle(); } - public static void executeUpdateOnStartupIfNeeded() { - try { - AppProperties.init(); - DownloadedUpdate downloaded = AppCache.get("downloadedUpdate", DownloadedUpdate.class, () -> null); - if (downloaded != null) { - if (!downloaded.getSourceVersion().equals(AppProperties.get().getVersion())) { - return; - } - - initBare(); - if (INSTANCE.shouldPerformUpdate()) { - INSTANCE.executeUpdateAndClose(); - } - } - } catch (Throwable t) { - ErrorEvent.fromThrowable(t).handle(); - } - } - public static AppUpdater get() { return INSTANCE; } - public static void initBare() { + public static void initFallback() { AppProperties.init(); XPipeSession.init(AppProperties.get().getBuildUuid()); - var layer = AppExtensionManager.initBare(); - if (layer == null) { - return; - } - ProcessControlProvider.init(layer); + AppExtensionManager.init(false); + ProcessControlProvider.init(AppExtensionManager.getInstance().getExtendedLayer()); INSTANCE = new AppUpdater(); } diff --git a/app/src/main/java/io/xpipe/app/util/XPipeDaemon.java b/app/src/main/java/io/xpipe/app/util/XPipeDaemon.java index 0540451ef..3f273e178 100644 --- a/app/src/main/java/io/xpipe/app/util/XPipeDaemon.java +++ b/app/src/main/java/io/xpipe/app/util/XPipeDaemon.java @@ -3,7 +3,6 @@ package io.xpipe.app.util; import io.xpipe.app.ext.DataSourceProvider; import io.xpipe.app.ext.DataStoreProvider; import io.xpipe.app.fxcomps.Comp; -import io.xpipe.core.charsetter.Charsetter; import io.xpipe.core.source.DataSource; import io.xpipe.core.source.DataSourceType; import io.xpipe.core.store.DataStore; @@ -11,8 +10,6 @@ import javafx.beans.property.Property; import javafx.beans.value.ObservableValue; import javafx.scene.image.Image; -import java.io.IOException; -import java.nio.file.Path; import java.util.List; import java.util.Optional; import java.util.ServiceLoader; @@ -28,8 +25,6 @@ public interface XPipeDaemon { return ServiceLoader.load(XPipeDaemon.class).findFirst(); } - void withResource(String module, String file, Charsetter.FailableConsumer con); - List getNamedStores(); String getVersion(); diff --git a/app/src/main/java/io/xpipe/app/util/XPipeDaemonProvider.java b/app/src/main/java/io/xpipe/app/util/XPipeDaemonProvider.java index 5a107a19a..fae54b11a 100644 --- a/app/src/main/java/io/xpipe/app/util/XPipeDaemonProvider.java +++ b/app/src/main/java/io/xpipe/app/util/XPipeDaemonProvider.java @@ -6,14 +6,12 @@ import io.xpipe.app.comp.source.store.DsStreamStoreChoiceComp; import io.xpipe.app.comp.source.store.NamedStoreChoiceComp; import io.xpipe.app.core.AppImages; import io.xpipe.app.core.AppProperties; -import io.xpipe.app.core.AppResources; import io.xpipe.app.ext.DataSourceProvider; import io.xpipe.app.ext.DataStoreProvider; import io.xpipe.app.fxcomps.Comp; import io.xpipe.app.storage.DataStorage; import io.xpipe.app.storage.DataStoreEntry; import io.xpipe.app.update.AppDownloads; -import io.xpipe.core.charsetter.Charsetter; import io.xpipe.core.source.DataSource; import io.xpipe.core.source.DataSourceId; import io.xpipe.core.source.DataSourceReference; @@ -23,19 +21,12 @@ import javafx.beans.property.Property; import javafx.beans.value.ObservableValue; import javafx.scene.image.Image; -import java.io.IOException; -import java.nio.file.Path; import java.util.List; import java.util.Optional; import java.util.function.Predicate; public class XPipeDaemonProvider implements XPipeDaemon { - @Override - public void withResource(String module, String file, Charsetter.FailableConsumer con) { - AppResources.with(module, file, con); - } - @Override public List getNamedStores() { return DataStorage.get().getStores().stream() diff --git a/core/src/main/java/io/xpipe/core/util/Deobfuscator.java b/core/src/main/java/io/xpipe/core/util/Deobfuscator.java index 606226cd8..804975f44 100644 --- a/core/src/main/java/io/xpipe/core/util/Deobfuscator.java +++ b/core/src/main/java/io/xpipe/core/util/Deobfuscator.java @@ -3,7 +3,6 @@ package io.xpipe.core.util; import io.xpipe.core.charsetter.NewLine; import io.xpipe.core.process.OsType; import io.xpipe.core.process.ShellDialects; -import io.xpipe.core.store.ShellStore; import java.io.PrintWriter; import java.io.StringWriter; @@ -106,8 +105,6 @@ public class Deobfuscator { } var t = ShellDialects.getPlatformDefault(); - return ShellStore.local() - .create() - .executeBooleanSimpleCommand(t.getWhichCommand("retrace." + t.getScriptFileEnding())); + return true; } }