From bdeedd457efa8a9bf2e91c3ad849327347c8b752 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Sun, 17 Dec 2017 00:17:21 -0800 Subject: [PATCH] Startup progress reporting --- MatterControlApplication.cs | 19 +++++----- Program.cs | 73 +++++++++++++++++++++++++++++++------ 2 files changed, 71 insertions(+), 21 deletions(-) diff --git a/MatterControlApplication.cs b/MatterControlApplication.cs index 90adb46cf..bf24bda6a 100644 --- a/MatterControlApplication.cs +++ b/MatterControlApplication.cs @@ -71,7 +71,7 @@ namespace MatterHackers.MatterControl public static bool IsLoading { get; private set; } = true; - public static GuiWidget Initialize(SystemWindow systemWindow, Action reporter) + public static GuiWidget Initialize(SystemWindow systemWindow, Action reporter) { if (AggContext.OperatingSystem == OSType.Mac && AggContext.StaticData == null) { @@ -84,7 +84,7 @@ namespace MatterHackers.MatterControl // Initialize a standard file system backed StaticData provider if (AggContext.StaticData == null) // it may already be initialized by tests { - reporter?.Invoke( "StaticData"); + reporter?.Invoke(0.01, "StaticData"); AggContext.StaticData = new MatterHackers.Agg.FileSystemStaticData(); } @@ -118,22 +118,22 @@ namespace MatterHackers.MatterControl } } - reporter?.Invoke("ApplicationController"); + reporter?.Invoke(0.05, "ApplicationController"); var na = ApplicationController.Instance; // Set the default theme colors - reporter?.Invoke("LoadOemOrDefaultTheme"); + reporter?.Invoke(0.1, "LoadOemOrDefaultTheme"); ApplicationController.LoadOemOrDefaultTheme(); // Accessing any property on ProfileManager will run the static constructor and spin up the ProfileManager instance - reporter?.Invoke("ProfileManager"); + reporter?.Invoke(0.2, "ProfileManager"); bool na2 = ProfileManager.Instance.IsGuestProfile; - reporter?.Invoke("MainView"); - ApplicationController.Instance.MainView = new DesktopView(); + reporter?.Invoke(0.3, "MainView"); + ApplicationController.Instance.MainView = new WidescreenPanel(); // now that we are all set up lets load our plugins and allow them their chance to set things up - reporter?.Invoke("Plugins"); + reporter?.Invoke(0.8, "Plugins"); FindAndInstantiatePlugins(systemWindow); if (ApplicationController.Instance.PluginsLoaded != null) { @@ -151,6 +151,7 @@ namespace MatterHackers.MatterControl } } + reporter?.Invoke(0.9, "AfterLoad"); AfterLoad(); return ApplicationController.Instance.MainView; @@ -164,7 +165,7 @@ namespace MatterHackers.MatterControl // TODO: Calling UserChanged seems wrong. Load the right user before we spin up controls, rather than after // Pushing this after load fixes that empty printer list - ApplicationController.Instance.UserChanged(); + /////////////////////ApplicationController.Instance.UserChanged(); bool showAuthWindow = PrinterSetup.ShouldShowAuthPanel?.Invoke() ?? false; if (showAuthWindow) diff --git a/Program.cs b/Program.cs index 68148cb3d..8924bbf17 100644 --- a/Program.cs +++ b/Program.cs @@ -3,7 +3,9 @@ using System.Diagnostics; using System.Globalization; using System.IO; using System.Threading; +using System.Threading.Tasks; using MatterHackers.Agg; +using MatterHackers.Agg.Font; using MatterHackers.Agg.Platform; using MatterHackers.Agg.UI; using MatterHackers.MatterControl.DataStorage; @@ -18,6 +20,14 @@ namespace MatterHackers.MatterControl private static int raygunNotificationCount = 0; + private static string lastSection = ""; + + private static RaygunClient _raygunClient = GetCorrectClient(); + private static Stopwatch timer; + private static ProgressBar progressBar; + private static TextWidget statusText; + private static FlowLayoutWidget progressPanel; + /// /// The main entry point for the application. /// @@ -44,7 +54,7 @@ namespace MatterHackers.MatterControl AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); } - var timer = Stopwatch.StartNew(); + timer = Stopwatch.StartNew(); // Get startup bounds from MatterControl and construct system window //var systemWindow = new DesktopMainWindow(400, 200) @@ -55,36 +65,77 @@ namespace MatterHackers.MatterControl BackgroundColor = Color.DarkGray }; + progressPanel = new FlowLayoutWidget(FlowDirection.TopToBottom) + { + HAnchor = HAnchor.Center, + VAnchor = VAnchor.Center, + MinimumSize = new VectorMath.Vector2(400, 100), + }; + systemWindow.AddChild(progressPanel); + + progressPanel.AddChild(statusText = new TextWidget("XXXXXXXXXXXXX", textColor: new Color("#bbb")) + { + MinimumSize = new VectorMath.Vector2(200, 30) + }); + + progressPanel.AddChild(progressBar = new ProgressBar() + { + FillColor = new Color("#3D4B72"), + BorderColor = new Color("#777"), + Height = 11, + Width = 300, + HAnchor = HAnchor.Absolute, + VAnchor = VAnchor.Absolute + }); + AppContext.RootSystemWindow = systemWindow; // Hook SystemWindow load and spin up MatterControl once we've hit first draw systemWindow.Load += (s, e) => { - UiThread.RunOnIdle(() => + ReportStartupProgress(0.1, "First draw->RunOnIdle"); + + //UiThread.RunOnIdle(() => + Task.Run(() => { + ReportStartupProgress(0.5, "Datastore"); Datastore.Instance.Initialize(); - var mainView = MatterControlApplication.Initialize(systemWindow, ReportStartupProgress); - - Console.WriteLine("Time to MatterControlApplication.Instance init: " + timer.Elapsed.TotalSeconds); + ReportStartupProgress(0.15, "MatterControlApplication.Initialize"); + var mainView = MatterControlApplication.Initialize(systemWindow, (progress0To1, status) => + { + ReportStartupProgress(0.2 + progress0To1 * 0.7, status); + }); + ReportStartupProgress(0.9, "AddChild->MainView"); systemWindow.RemoveAllChildren(); - systemWindow.AddChild(mainView); - Console.WriteLine("Time to MatterControlApplication Layout: " + timer.Elapsed.TotalSeconds); + ReportStartupProgress(1, "X9x"); + + systemWindow.BackgroundColor = Color.Transparent; + systemWindow.Invalidate(); + + ReportStartupProgress(1.1, "X9x"); }); }; // Block indefinitely + ReportStartupProgress(0, "ShowAsSystemWindow"); systemWindow.ShowAsSystemWindow(); } - private static void ReportStartupProgress(string status) + private static void ReportStartupProgress(double progress0To1, string section) { - Console.WriteLine(status); - } + statusText.Text = section; + progressBar.RatioComplete = progress0To1; + progressPanel.Invalidate(); + Console.WriteLine($"Time to '{lastSection}': {timer.ElapsedMilliseconds}"); + timer.Restart(); + + lastSection = section; + } private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e) { @@ -106,8 +157,6 @@ namespace MatterHackers.MatterControl #endif } - private static RaygunClient _raygunClient = GetCorrectClient(); - private static RaygunClient GetCorrectClient() { if (AggContext.OperatingSystem == OSType.Mac)