Small fixes

This commit is contained in:
crschnick 2023-02-20 10:36:00 +00:00
parent 8bd3288051
commit bd6b04dca0
8 changed files with 27 additions and 75 deletions

View file

@ -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) {

View file

@ -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<Path, IOException> con) {
public static void with(String module, String file, FailableConsumer<Path, IOException> 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<Path, IOException> con) {
String module, String file, ModuleLayer layer, FailableConsumer<Path, IOException> 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<Path, IOException> con) {
private static void withResource(String module, String file, FailableConsumer<Path, IOException> 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<Path, IOException> con) {
String module, String file, FailableConsumer<Path, IOException> con) {
try (var fs = openFileSystem(module)) {
var url = fs.getPath("").getWrappedPath().toUri().toURL();
if (!url.getProtocol().equals("jar")) {

View file

@ -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();

View file

@ -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 -> {

View file

@ -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();
}

View file

@ -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<Path, IOException> con);
List<DataStore> getNamedStores();
String getVersion();

View file

@ -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<Path, IOException> con) {
AppResources.with(module, file, con);
}
@Override
public List<DataStore> getNamedStores() {
return DataStorage.get().getStores().stream()

View file

@ -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;
}
}