From cf54cce6608010ac7d6a1007edea9953d796b7fc Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 7 Nov 2016 15:49:31 +0100 Subject: [PATCH] SplashScreenHelper output progress in console for text-only mode This commit makes this changes: - SplashScreenHelper is now local in Base constructor - if SplashScreenHelper is instantiated with a null SplashScreen instance then it outputs progress in console and avoid to make calls to Swing toolkit - The parsing of command line arguments is anticipated so we can determine if we are in command line or GUI mode early and setup objects that produces output to not use graphics toolkits. - In this case the SplashScreenHelper is initialized with a real splashscreen only if we are in GUI mode --- .../cc/arduino/view/SplashScreenHelper.java | 8 +++-- app/src/processing/app/Base.java | 29 ++++++++++++------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/app/src/cc/arduino/view/SplashScreenHelper.java b/app/src/cc/arduino/view/SplashScreenHelper.java index 0e6779026..108c1c8b2 100644 --- a/app/src/cc/arduino/view/SplashScreenHelper.java +++ b/app/src/cc/arduino/view/SplashScreenHelper.java @@ -51,8 +51,12 @@ public class SplashScreenHelper { public SplashScreenHelper(SplashScreen splash) { this.splash = splash; - Toolkit tk = Toolkit.getDefaultToolkit(); - desktopHints = (Map) tk.getDesktopProperty("awt.font.desktophints"); + if (splash != null) { + Toolkit tk = Toolkit.getDefaultToolkit(); + desktopHints = (Map) tk.getDesktopProperty("awt.font.desktophints"); + } else { + desktopHints = null; + } } public void splashText(String text) { diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index a96ac221a..dd87b9613 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -84,7 +84,6 @@ public class Base { private static boolean commandLine; public static volatile Base INSTANCE; - public static SplashScreenHelper splashScreenHelper = new SplashScreenHelper(SplashScreen.getSplashScreen()); public static Map FIND_DIALOG_STATE = new HashMap<>(); private final ContributionInstaller contributionInstaller; private final LibraryInstaller libraryInstaller; @@ -195,9 +194,20 @@ public class Base { BaseNoGui.initPortableFolder(); + // Look for a possible "--preferences-file" parameter and load preferences BaseNoGui.initParameters(args); - splashScreenHelper.splashText(tr("Loading configuration...")); + CommandlineParser parser = new CommandlineParser(args); + parser.parseArgumentsPhase1(); + + SplashScreenHelper splash; + if (parser.isGuiMode()) { + splash = new SplashScreenHelper(SplashScreen.getSplashScreen()); + } else { + splash = new SplashScreenHelper(null); + } + + splash.splashText(tr("Loading configuration...")); BaseNoGui.initVersion(); @@ -224,9 +234,6 @@ public class Base { BaseNoGui.notifier = new GUIUserNotifier(this); - CommandlineParser parser = new CommandlineParser(args); - parser.parseArgumentsPhase1(); - BaseNoGui.checkInstallationFolder(); // If no path is set, get the default sketchbook folder for this platform @@ -241,9 +248,9 @@ public class Base { } } - splashScreenHelper.splashText(tr("Initializing packages...")); + splash.splashText(tr("Initializing packages...")); BaseNoGui.initPackages(); - splashScreenHelper.splashText(tr("Preparing boards...")); + splash.splashText(tr("Preparing boards...")); rebuildBoardsMenu(); rebuildProgrammerMenu(); @@ -372,7 +379,7 @@ public class Base { System.exit(0); } else if (parser.isVerifyOrUploadMode()) { - splashScreenHelper.close(); + splash.close(); // Set verbosity for command line build PreferencesData.set("build.verbose", "" + parser.isDoVerboseBuild()); PreferencesData.set("upload.verbose", "" + parser.isDoVerboseUpload()); @@ -385,10 +392,10 @@ public class Base { Editor editor = editors.get(0); if (parser.isUploadMode()) { - splashScreenHelper.splashText(tr("Verifying and uploading...")); + splash.splashText(tr("Verifying and uploading...")); editor.exportHandler.run(); } else { - splashScreenHelper.splashText(tr("Verifying...")); + splash.splashText(tr("Verifying...")); editor.runHandler.run(); } @@ -400,7 +407,7 @@ public class Base { // No errors exit gracefully System.exit(0); } else if (parser.isGuiMode()) { - splashScreenHelper.splashText(tr("Starting...")); + splash.splashText(tr("Starting...")); installKeyboardInputMap();