From 45dc04c5a7caadb724f554756cf2f2ad4cef7a9b Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Thu, 9 Aug 2018 11:26:35 -0700 Subject: [PATCH] Added ui.min_show_seconds config. This defines the minimum amount of time for which the UI will be shown before automatically hiding itself. It defaults to 5 seconds (the old hard coded value), which was chosen to ensure that users did not see a random window flash up on the screen and then immediately disappear before they could see what it was or meant, thereby confusing them. --- .../threerings/getdown/data/Application.java | 63 ++++++++++++------- .../threerings/getdown/launcher/Getdown.java | 12 ++-- 2 files changed, 46 insertions(+), 29 deletions(-) diff --git a/src/main/java/com/threerings/getdown/data/Application.java b/src/main/java/com/threerings/getdown/data/Application.java index 6732677..d22cc92 100644 --- a/src/main/java/com/threerings/getdown/data/Application.java +++ b/src/main/java/com/threerings/getdown/data/Application.java @@ -153,6 +153,11 @@ public class Application /** Whether progress text should be hidden or not. */ public boolean hideProgressText; + /** The minimum number of seconds to display the GUI. This is to prevent the GUI from + * flashing up on the screen and immediately disappearing, which can be confusing to the + * user. */ + public int minShowSeconds = 5; + /** The global percentages for each step. A step may have more than one, and * the lowest reasonable one is used if a step is revisited. */ public Map> stepPercentages = @@ -168,7 +173,7 @@ public class Application ", shadow=" + textShadow + ", err=" + installError + ", nrect=" + patchNotes + ", notes=" + patchNotesUrl + ", stepPercentages=" + stepPercentages + ", parect=" + playAgain + ", paimage=" + playAgainImage + - ", hideProgressText" + hideProgressText + "]"; + ", hideProgressText" + hideProgressText + ", minShow=" + minShowSeconds + "]"; } /** Initializer */ @@ -719,6 +724,7 @@ public class Application ui.progress = parseRect(cdata, "ui.progress", ui.progress); ui.progressText = parseColor(cdata, "ui.progress_text", ui.progressText); ui.hideProgressText = Boolean.parseBoolean((String)cdata.get("ui.hide_progress_text")); + ui.minShowSeconds = parseInt(cdata, "ui.min_show_seconds", ui.minShowSeconds); ui.progressBar = parseColor(cdata, "ui.progress_bar", ui.progressBar); ui.status = parseRect(cdata, "ui.status", ui.status); ui.statusText = parseColor(cdata, "ui.status_text", ui.statusText); @@ -1679,6 +1685,27 @@ public class Application return new Resource(path, getRemoteURL(path), getLocalPath(path), attrs); } + /** Helper function to add all values in {@code values} (if non-null) to {@code target}. */ + protected static void addAll (String[] values, List target) { + if (values != null) { + for (String value : values) { + target.add(value); + } + } + } + + /** + * Make an immutable List from the specified int array. + */ + public static List intsToList (int[] values) + { + List list = new ArrayList<>(values.length); + for (int val : values) { + list.add(val); + } + return Collections.unmodifiableList(list); + } + /** Used to parse resources with the specified name. */ protected void parseResources (Map cdata, String name, EnumSet attrs, List list) @@ -1704,27 +1731,6 @@ public class Application return (rect == null) ? def : rect; } - /** Helper function to add all values in {@code values} (if non-null) to {@code target}. */ - protected static void addAll (String[] values, List target) { - if (values != null) { - for (String value : values) { - target.add(value); - } - } - } - - /** - * Make an immutable List from the specified int array. - */ - public static List intsToList (int[] values) - { - List list = new ArrayList<>(values.length); - for (int val : values) { - list.add(val); - } - return Collections.unmodifiableList(list); - } - /** * Takes a comma-separated String of four integers and returns a rectangle using those ints as * the its x, y, width, and height. @@ -1736,11 +1742,22 @@ public class Application if (v != null && v.length == 4) { return new Rectangle(v[0], v[1], v[2], v[3]); } - log.warning("Ignoring invalid '" + name + "' config '" + value + "'."); + log.warning("Ignoring invalid rect '" + name + "' config '" + value + "'."); } return null; } + /** Used to parse int specifications from the config file. */ + protected int parseInt (Map cdata, String name, int def) { + String value = (String)cdata.get(name); + try { + return value == null ? def : Integer.parseInt(value); + } catch (Exception e) { + log.warning("Ignoring invalid int '" + name + "' config '" + value + "',"); + return def; + } + } + /** Used to parse color specifications from the config file. */ protected Color parseColor (Map cdata, String name, Color def) { diff --git a/src/main/java/com/threerings/getdown/launcher/Getdown.java b/src/main/java/com/threerings/getdown/launcher/Getdown.java index f20846e..e7be647 100644 --- a/src/main/java/com/threerings/getdown/launcher/Getdown.java +++ b/src/main/java/com/threerings/getdown/launcher/Getdown.java @@ -850,13 +850,14 @@ public abstract class Getdown extends Thread } } - // if we have a UI open and we haven't been around for at least 5 seconds, don't stick - // a fork in ourselves straight away but give our lovely user a chance to see what - // we're doing + // if we have a UI open and we haven't been around for at least 5 seconds (the default + // for min_show_seconds), don't stick a fork in ourselves straight away but give our + // lovely user a chance to see what we're doing long uptime = System.currentTimeMillis() - _startup; - if (_container != null && uptime < MIN_EXIST_TIME) { + long minshow = _ifc.minShowSeconds * 1000L; + if (_container != null && uptime < minshow) { try { - Thread.sleep(MIN_EXIST_TIME - uptime); + Thread.sleep(minshow - uptime); } catch (Exception e) { } } @@ -1263,7 +1264,6 @@ public abstract class Getdown extends Thread protected int _uiDisplayPercent; protected static final int MAX_LOOPS = 5; - protected static final long MIN_EXIST_TIME = 5000L; protected static final long FALLBACK_CHECK_TIME = 1000L; protected static final long PLAY_AGAIN_TIME = 3000L; protected static final String PROXY_REGISTRY =