diff --git a/app/src/main/java/io/xpipe/app/browser/BrowserComp.java b/app/src/main/java/io/xpipe/app/browser/BrowserComp.java index 429a8a6e4..5e28faaae 100644 --- a/app/src/main/java/io/xpipe/app/browser/BrowserComp.java +++ b/app/src/main/java/io/xpipe/app/browser/BrowserComp.java @@ -3,9 +3,6 @@ package io.xpipe.app.browser; import atlantafx.base.controls.RingProgressIndicator; import atlantafx.base.controls.Spacer; import atlantafx.base.theme.Styles; -import io.xpipe.app.browser.icon.BrowserIconDirectoryType; -import io.xpipe.app.browser.icon.BrowserIconFileType; -import io.xpipe.app.browser.icon.FileIconManager; import io.xpipe.app.comp.base.MultiContentComp; import io.xpipe.app.comp.base.SideSplitPaneComp; import io.xpipe.app.core.AppLayoutModel; @@ -18,7 +15,6 @@ import io.xpipe.app.fxcomps.util.BindingsHelper; import io.xpipe.app.fxcomps.util.PlatformThread; import io.xpipe.app.storage.DataStorage; import io.xpipe.app.util.BooleanScope; -import io.xpipe.app.util.ThreadHelper; import javafx.application.Platform; import javafx.beans.binding.Bindings; import javafx.beans.property.SimpleBooleanProperty; @@ -51,12 +47,6 @@ public class BrowserComp extends SimpleComp { @Override protected Region createSimple() { - BrowserIconFileType.loadDefinitions(); - BrowserIconDirectoryType.loadDefinitions(); - ThreadHelper.runAsync(() -> { - FileIconManager.loadIfNecessary(); - }); - var bookmarksList = new BrowserBookmarkComp(model).vgrow(); var localDownloadStage = new BrowserTransferComp(model.getLocalTransfersStage()) .hide(PlatformThread.sync(Bindings.createBooleanBinding( diff --git a/app/src/main/java/io/xpipe/app/browser/BrowserEntry.java b/app/src/main/java/io/xpipe/app/browser/BrowserEntry.java index 253f684ce..9fdb6cd7a 100644 --- a/app/src/main/java/io/xpipe/app/browser/BrowserEntry.java +++ b/app/src/main/java/io/xpipe/app/browser/BrowserEntry.java @@ -29,7 +29,7 @@ public class BrowserEntry { return null; } - for (var f : BrowserIconFileType.ALL) { + for (var f : BrowserIconFileType.getAll()) { if (f.matches(rawFileEntry)) { return f; } @@ -43,7 +43,7 @@ public class BrowserEntry { return null; } - for (var f : BrowserIconDirectoryType.ALL) { + for (var f : BrowserIconDirectoryType.getAll()) { if (f.matches(rawFileEntry)) { return f; } diff --git a/app/src/main/java/io/xpipe/app/browser/BrowserModel.java b/app/src/main/java/io/xpipe/app/browser/BrowserModel.java index 82d47c21c..51b3d8be4 100644 --- a/app/src/main/java/io/xpipe/app/browser/BrowserModel.java +++ b/app/src/main/java/io/xpipe/app/browser/BrowserModel.java @@ -1,5 +1,8 @@ package io.xpipe.app.browser; +import io.xpipe.app.browser.icon.BrowserIconDirectoryType; +import io.xpipe.app.browser.icon.BrowserIconFileType; +import io.xpipe.app.browser.icon.FileIconManager; import io.xpipe.app.fxcomps.util.BindingsHelper; import io.xpipe.app.storage.DataStorage; import io.xpipe.app.storage.DataStoreEntryRef; @@ -139,6 +142,13 @@ public class BrowserModel { return; } + // Only load icons when a file system is opened + ThreadHelper.runAsync(() -> { + BrowserIconFileType.loadDefinitions(); + BrowserIconDirectoryType.loadDefinitions(); + FileIconManager.loadIfNecessary(); + }); + ThreadHelper.runFailableAsync(() -> { OpenFileSystemModel model; diff --git a/app/src/main/java/io/xpipe/app/browser/icon/BrowserIconDirectoryType.java b/app/src/main/java/io/xpipe/app/browser/icon/BrowserIconDirectoryType.java index 565b1baa5..1c87b296b 100644 --- a/app/src/main/java/io/xpipe/app/browser/icon/BrowserIconDirectoryType.java +++ b/app/src/main/java/io/xpipe/app/browser/icon/BrowserIconDirectoryType.java @@ -15,18 +15,18 @@ import java.util.List; import java.util.Set; import java.util.stream.Collectors; -public interface BrowserIconDirectoryType { +public abstract class BrowserIconDirectoryType { - List ALL = new ArrayList<>(); + private static final List ALL = new ArrayList<>(); - static BrowserIconDirectoryType byId(String id) { + public synchronized static BrowserIconDirectoryType byId(String id) { return ALL.stream() .filter(fileType -> fileType.getId().equals(id)) .findAny() .orElseThrow(); } - static void loadDefinitions() { + public synchronized static void loadDefinitions() { ALL.add(new BrowserIconDirectoryType() { @Override @@ -74,13 +74,17 @@ public interface BrowserIconDirectoryType { }); } - String getId(); + public static synchronized List getAll() { + return ALL; + } - boolean matches(FileSystem.FileEntry entry); + public abstract String getId(); - String getIcon(FileSystem.FileEntry entry, boolean open); + public abstract boolean matches(FileSystem.FileEntry entry); - class Simple implements BrowserIconDirectoryType { + public abstract String getIcon(FileSystem.FileEntry entry, boolean open); + + public static class Simple extends BrowserIconDirectoryType { @Getter private final String id; diff --git a/app/src/main/java/io/xpipe/app/browser/icon/BrowserIconFileType.java b/app/src/main/java/io/xpipe/app/browser/icon/BrowserIconFileType.java index 171ead239..58be92326 100644 --- a/app/src/main/java/io/xpipe/app/browser/icon/BrowserIconFileType.java +++ b/app/src/main/java/io/xpipe/app/browser/icon/BrowserIconFileType.java @@ -12,18 +12,18 @@ import java.nio.file.Files; import java.util.*; import java.util.stream.Collectors; -public interface BrowserIconFileType { +public abstract class BrowserIconFileType { - List ALL = new ArrayList<>(); + private static final List ALL = new ArrayList<>(); - static BrowserIconFileType byId(String id) { + public synchronized static BrowserIconFileType byId(String id) { return ALL.stream() .filter(fileType -> fileType.getId().equals(id)) .findAny() .orElseThrow(); } - static void loadDefinitions() { + public synchronized static void loadDefinitions() { AppResources.with(AppResources.XPIPE_MODULE, "file_list.txt", path -> { try (var reader = new BufferedReader(new InputStreamReader(Files.newInputStream(path), StandardCharsets.UTF_8))) { @@ -53,14 +53,18 @@ public interface BrowserIconFileType { }); } - String getId(); + public static synchronized List getAll() { + return ALL; + } - boolean matches(FileSystem.FileEntry entry); + public abstract String getId(); - String getIcon(); + public abstract boolean matches(FileSystem.FileEntry entry); + + public abstract String getIcon(); @Getter - class Simple implements BrowserIconFileType { + public static class Simple extends BrowserIconFileType { private final String id; private final IconVariant icon; diff --git a/app/src/main/java/io/xpipe/app/browser/icon/FileIconManager.java b/app/src/main/java/io/xpipe/app/browser/icon/FileIconManager.java index 6af408cf1..32904253c 100644 --- a/app/src/main/java/io/xpipe/app/browser/icon/FileIconManager.java +++ b/app/src/main/java/io/xpipe/app/browser/icon/FileIconManager.java @@ -16,24 +16,22 @@ public class FileIconManager { } } - public static String getFileIcon(FileSystem.FileEntry entry, boolean open) { + public static synchronized String getFileIcon(FileSystem.FileEntry entry, boolean open) { if (entry == null) { return null; } - loadIfNecessary(); - var r = entry.resolved(); if (r.getKind() != FileKind.DIRECTORY) { - for (var f : BrowserIconFileType.ALL) { + for (var f : BrowserIconFileType.getAll()) { if (f.matches(r)) { - return getIconPath(f.getIcon()); + return f.getIcon(); } } } else { - for (var f : BrowserIconDirectoryType.ALL) { + for (var f : BrowserIconDirectoryType.getAll()) { if (f.matches(r)) { - return getIconPath(f.getIcon(r, open)); + return f.getIcon(r, open); } } } @@ -42,8 +40,4 @@ public class FileIconManager { ? (open ? "default_folder_opened.svg" : "default_folder.svg") : "default_file.svg"; } - - private static String getIconPath(String name) { - return name; - } }