Startup progress reporting

This commit is contained in:
John Lewin 2017-12-17 00:17:21 -08:00
parent 614d29fa7c
commit bdeedd457e
2 changed files with 71 additions and 21 deletions

View file

@ -71,7 +71,7 @@ namespace MatterHackers.MatterControl
public static bool IsLoading { get; private set; } = true;
public static GuiWidget Initialize(SystemWindow systemWindow, Action<string> reporter)
public static GuiWidget Initialize(SystemWindow systemWindow, Action<double, string> 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)

View file

@ -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;
/// <summary>
/// The main entry point for the application.
/// </summary>
@ -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)