diff --git a/creator-tools/src/main/java/com/skcraft/launcher/creator/Creator.java b/creator-tools/src/main/java/com/skcraft/launcher/creator/Creator.java index 4084396..7c7c828 100644 --- a/creator-tools/src/main/java/com/skcraft/launcher/creator/Creator.java +++ b/creator-tools/src/main/java/com/skcraft/launcher/creator/Creator.java @@ -6,6 +6,8 @@ package com.skcraft.launcher.creator; +import com.google.common.util.concurrent.ListeningExecutorService; +import com.google.common.util.concurrent.MoreExecutors; import com.skcraft.launcher.Launcher; import com.skcraft.launcher.creator.controller.WelcomeController; import com.skcraft.launcher.creator.dialog.WelcomeDialog; @@ -21,11 +23,13 @@ import javax.swing.filechooser.FileSystemView; import java.io.File; import java.util.Iterator; import java.util.List; +import java.util.concurrent.Executors; public class Creator { @Getter private final File dataDir; @Getter private final CreatorConfig config; + @Getter private final ListeningExecutorService executor = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool()); public Creator() { this.dataDir = getAppDataDir(); diff --git a/creator-tools/src/main/java/com/skcraft/launcher/creator/controller/WelcomeController.java b/creator-tools/src/main/java/com/skcraft/launcher/creator/controller/WelcomeController.java index d765076..1ee9156 100644 --- a/creator-tools/src/main/java/com/skcraft/launcher/creator/controller/WelcomeController.java +++ b/creator-tools/src/main/java/com/skcraft/launcher/creator/controller/WelcomeController.java @@ -8,6 +8,9 @@ package com.skcraft.launcher.creator.controller; import com.google.common.base.Optional; import com.google.common.collect.Lists; +import com.google.common.util.concurrent.ListeningExecutorService; +import com.skcraft.concurrency.Deferred; +import com.skcraft.concurrency.Deferreds; import com.skcraft.launcher.creator.Creator; import com.skcraft.launcher.creator.dialog.AboutDialog; import com.skcraft.launcher.creator.dialog.PackManagerFrame; @@ -16,10 +19,12 @@ import com.skcraft.launcher.creator.model.creator.RecentEntry; import com.skcraft.launcher.creator.model.creator.Workspace; import com.skcraft.launcher.creator.model.swing.RecentListModel; import com.skcraft.launcher.creator.swing.WorkspaceDirectoryFilter; +import com.skcraft.launcher.dialog.ProgressDialog; import com.skcraft.launcher.persistence.Persistence; import com.skcraft.launcher.swing.PopupMouseAdapter; import com.skcraft.launcher.swing.SwingHelper; import com.skcraft.launcher.util.MorePaths; +import com.skcraft.launcher.util.SwingExecutor; import javax.swing.*; import java.awt.*; @@ -51,16 +56,17 @@ public class WelcomeController { } private boolean openWorkspace(File dir) { - try { - PackManagerFrame frame = new PackManagerFrame(); + ListeningExecutorService executor = creator.getExecutor(); + PackManagerFrame frame = new PackManagerFrame(); + Deferred deferred = Deferreds.makeDeferred(executor.submit(() -> { PackManagerController controller = new PackManagerController(frame, dir, creator); addRecentEntry(dir); - controller.show(); - return true; - } catch (IOException e) { - SwingHelper.showErrorDialog(dialog, "An unexpected error has occurred.", "Error", e); - return false; - } + return controller; + }), executor) + .handleAsync(PackManagerController::show, ex -> {}, SwingExecutor.INSTANCE); + SwingHelper.addErrorDialogCallback(frame, deferred); + + return true; } private void addRecentEntry(File dir) {