From 1363389b60a4d5a429811a43bcce2fec27fb3a78 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sun, 16 Oct 2016 15:46:42 +0800 Subject: [PATCH] preload data files --- source/net/filebot/Main.java | 70 ++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 30 deletions(-) diff --git a/source/net/filebot/Main.java b/source/net/filebot/Main.java index 867b169b..1223006f 100644 --- a/source/net/filebot/Main.java +++ b/source/net/filebot/Main.java @@ -44,6 +44,7 @@ import net.filebot.cli.ArgumentBean; import net.filebot.cli.ArgumentProcessor; import net.filebot.format.ExpressionFormat; import net.filebot.mac.MacAppUtilities; +import net.filebot.media.MediaDetection; import net.filebot.ui.FileBotMenuBar; import net.filebot.ui.GettingStartedStage; import net.filebot.ui.MainFrame; @@ -136,36 +137,8 @@ public class Main { SwingEventBus.getInstance().post(new FileTransferable(files)); } - // wait for UI to startup completely before loading more classes - Thread.sleep(2000); - - // preload media.types (when loaded during DnD it will freeze the UI for a few hundred milliseconds) - MediaTypes.getDefault(); - - // JavaFX is used for ProgressMonitor and GettingStartedDialog - try { - initJavaFX(); - } catch (Throwable e) { - log.log(Level.SEVERE, "Failed to initialize JavaFX. Please install JavaFX.", e); - } - - // check if application help should be shown - if (!"skip".equals(System.getProperty("application.help"))) { - try { - checkGettingStarted(); - } catch (Throwable e) { - debug.log(Level.WARNING, "Failed to show Getting Started help", e); - } - } - - // check for application updates - if (!"skip".equals(System.getProperty("application.update"))) { - try { - checkUpdate(); - } catch (Throwable e) { - debug.log(Level.WARNING, "Failed to check for updates", e); - } - } + // run background tasks + new Thread(Main::onStart).start(); } catch (CmdLineException e) { // illegal arguments => print CLI error message System.err.println(e.getMessage()); @@ -182,6 +155,43 @@ public class Main { } } + private static void onStart() { + // preload media.types (when loaded during DnD it will freeze the UI for a few hundred milliseconds) + MediaTypes.getDefault(); + + // check if application help should be shown + if (!"skip".equals(System.getProperty("application.help"))) { + try { + checkGettingStarted(); + } catch (Throwable e) { + debug.log(Level.WARNING, "Failed to show Getting Started help", e); + } + } + + // check for application updates + if (!"skip".equals(System.getProperty("application.update"))) { + try { + checkUpdate(); + } catch (Throwable e) { + debug.log(Level.WARNING, "Failed to check for updates", e); + } + } + + // JavaFX is used for ProgressMonitor and GettingStartedDialog + try { + initJavaFX(); + } catch (Throwable e) { + log.log(Level.SEVERE, "Failed to initialize JavaFX. Please install JavaFX.", e); + } + + // preload data files + try { + MediaDetection.warmupCachedResources(); + } catch (Throwable e) { + debug.log(Level.WARNING, "Failed cache resources", e); + } + } + private static void startUserInterface(ArgumentBean args) { // use native LaF an all platforms (use platform-independent laf for standalone jar deployment) try {