From 8e5550c61db5fb462edfaeec35e0e2a41c8be9d7 Mon Sep 17 00:00:00 2001 From: crschnick Date: Tue, 27 Feb 2024 04:38:45 +0000 Subject: [PATCH] Rework git init order --- .../java/io/xpipe/app/core/mode/BaseMode.java | 11 +++++-- .../java/io/xpipe/app/prefs/AppPrefs.java | 29 ++++++++++++++----- .../xpipe/app/storage/GitStorageHandler.java | 6 ++-- .../io/xpipe/app/storage/StandardStorage.java | 11 ------- .../core/process/ProcessControlProvider.java | 2 +- 5 files changed, 34 insertions(+), 25 deletions(-) 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 058881daf..fd0bb1391 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 @@ -10,10 +10,12 @@ import io.xpipe.app.ext.ActionProvider; import io.xpipe.app.issue.TrackEvent; import io.xpipe.app.prefs.AppPrefs; import io.xpipe.app.storage.DataStorage; +import io.xpipe.app.storage.GitStorageHandler; import io.xpipe.app.update.XPipeDistributionType; import io.xpipe.app.util.FileBridge; import io.xpipe.app.util.LicenseProvider; import io.xpipe.app.util.LocalShell; +import io.xpipe.app.util.UnlockAlert; import io.xpipe.core.util.JacksonMapper; public class BaseMode extends OperationMode { @@ -44,16 +46,19 @@ public class BaseMode extends OperationMode { JacksonMapper.initModularized(AppExtensionManager.getInstance().getExtendedLayer()); AppI18n.init(); LicenseProvider.get().init(); - AppPrefs.init(); + AppPrefs.initLocal(); AppCertutilCheck.check(); AppAvCheck.check(); LocalShell.init(); XPipeDistributionType.init(); AppShellCheck.check(); AppPrefs.setDefaults(); - // Initialize socket server before storage - // as we should be prepared for git askpass commands + // Initialize socket server as we should be prepared for git askpass commands AppSocketServer.init(); + GitStorageHandler.getInstance().init(); + GitStorageHandler.getInstance().setupRepositoryAndPull(); + AppPrefs.initSharedRemote(); + UnlockAlert.showIfNeeded(); DataStorage.init(); AppFileWatcher.init(); FileBridge.init(); diff --git a/app/src/main/java/io/xpipe/app/prefs/AppPrefs.java b/app/src/main/java/io/xpipe/app/prefs/AppPrefs.java index 1f5d0ddba..e11ed5b58 100644 --- a/app/src/main/java/io/xpipe/app/prefs/AppPrefs.java +++ b/app/src/main/java/io/xpipe/app/prefs/AppPrefs.java @@ -153,11 +153,14 @@ public class AppPrefs { categories.get(selected >= 0 && selected < categories.size() ? selected : 0)); } - public static void init() { + public static void initLocal() { INSTANCE = new AppPrefs(); PrefsProvider.getAll().forEach(prov -> prov.addPrefs(INSTANCE.extensionHandler)); - INSTANCE.load(); + INSTANCE.loadLocal(); + } + public static void initSharedRemote() { + INSTANCE.loadSharedRemote(); INSTANCE.encryptAllVaultData.addListener((observableValue, aBoolean, t1) -> { if (DataStorage.get() != null) { DataStorage.get().forceRewrite(); @@ -417,16 +420,28 @@ public class AppPrefs { .orElseThrow(); } - public void load() { + private void loadLocal() { for (Mapping value : mapping) { + if (value.isVaultSpecific()) { + continue; + } + + loadValue(globalStorageHandler, value); + } + } + + private void loadSharedRemote() { + for (Mapping value : mapping) { + if (!value.isVaultSpecific()) { + continue; + } + var def = value.getProperty().getValue(); - AppPrefsStorageHandler handler = value.isVaultSpecific() ? vaultStorageHandler : globalStorageHandler; - var r = loadValue(handler, value); + var r = loadValue(vaultStorageHandler, value); // This can be used to facilitate backwards compatibility - // Overdose is not really needed as many moved properties have changed anyways var isDefault = Objects.equals(r, def); - if (isDefault && value.isVaultSpecific()) { + if (isDefault) { loadValue(globalStorageHandler, value); } } diff --git a/app/src/main/java/io/xpipe/app/storage/GitStorageHandler.java b/app/src/main/java/io/xpipe/app/storage/GitStorageHandler.java index b739540a1..3b02096e4 100644 --- a/app/src/main/java/io/xpipe/app/storage/GitStorageHandler.java +++ b/app/src/main/java/io/xpipe/app/storage/GitStorageHandler.java @@ -7,14 +7,14 @@ import java.nio.file.Path; public interface GitStorageHandler { static GitStorageHandler getInstance() { - return (GitStorageHandler) ProcessControlProvider.get().createStorageHandler(); + return (GitStorageHandler) ProcessControlProvider.get().getGitStorageHandler(); } boolean supportsShare(); - void init(Path dir); + void init(); - void beforeStorageLoad(); + void setupRepositoryAndPull(); void afterStorageLoad(); diff --git a/app/src/main/java/io/xpipe/app/storage/StandardStorage.java b/app/src/main/java/io/xpipe/app/storage/StandardStorage.java index 51cf04a96..315ecbd5c 100644 --- a/app/src/main/java/io/xpipe/app/storage/StandardStorage.java +++ b/app/src/main/java/io/xpipe/app/storage/StandardStorage.java @@ -3,7 +3,6 @@ package io.xpipe.app.storage; import io.xpipe.app.issue.ErrorEvent; import io.xpipe.app.issue.TrackEvent; import io.xpipe.app.prefs.AppPrefs; -import io.xpipe.app.util.UnlockAlert; import io.xpipe.core.process.OsType; import io.xpipe.core.store.LocalStore; import lombok.Getter; @@ -52,16 +51,6 @@ public class StandardStorage extends DataStorage { ErrorEvent.fromThrowable(e).terminal(true).build().handle(); } - this.gitStorageHandler.init(dir); - this.gitStorageHandler.beforeStorageLoad(); - - try { - // This can fail if the necessary platform initialization fails - UnlockAlert.showIfNeeded(); - } catch (Exception e) { - ErrorEvent.fromThrowable(e).terminal(true).build().handle(); - } - try { initSystemInfo(); } catch (Exception e) { diff --git a/core/src/main/java/io/xpipe/core/process/ProcessControlProvider.java b/core/src/main/java/io/xpipe/core/process/ProcessControlProvider.java index 9e126d8d3..dd7f2a515 100644 --- a/core/src/main/java/io/xpipe/core/process/ProcessControlProvider.java +++ b/core/src/main/java/io/xpipe/core/process/ProcessControlProvider.java @@ -28,7 +28,7 @@ public abstract class ProcessControlProvider { public abstract ShellControl createLocalProcessControl(boolean stoppable); - public abstract Object createStorageHandler(); + public abstract Object getGitStorageHandler(); public abstract ShellDialect getEffectiveLocalDialect();