Splash screen to inform user when program starting

This is designed to inform the user that DisplayMagician is starting. Partially fixes #49.
This commit is contained in:
Terry MacDonald 2021-10-30 19:01:03 +13:00
parent bb524749b5
commit 0d6536e7fe
5 changed files with 69 additions and 38 deletions

View File

@ -19,6 +19,7 @@ using NLog.Config;
using System.Collections.Generic; using System.Collections.Generic;
using AutoUpdaterDotNET; using AutoUpdaterDotNET;
using Newtonsoft.Json; using Newtonsoft.Json;
using System.Threading;
namespace DisplayMagician { namespace DisplayMagician {
@ -40,7 +41,7 @@ namespace DisplayMagician {
public static bool WaitingForGameToExit = false; public static bool WaitingForGameToExit = false;
public static ProgramSettings AppProgramSettings; public static ProgramSettings AppProgramSettings;
public static MainForm AppMainForm; public static MainForm AppMainForm;
public static LoadingForm AppSplashScreen;
private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger(); private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
private static SharedLogger sharedLogger; private static SharedLogger sharedLogger;
@ -593,6 +594,13 @@ namespace DisplayMagician {
logger.Debug($"Try to load all the Games in the background to avoid locking the UI"); logger.Debug($"Try to load all the Games in the background to avoid locking the UI");
//Show Splash Form
AppSplashScreen = new LoadingForm();
var splashThread = new Thread(new ThreadStart(
() => Application.Run(AppSplashScreen)));
splashThread.SetApartmentState(ApartmentState.STA);
splashThread.Start();
// Try to load all the games in parallel to this process // Try to load all the games in parallel to this process
Task.Run(() => LoadGamesInBackground()); Task.Run(() => LoadGamesInBackground());
@ -716,6 +724,7 @@ namespace DisplayMagician {
// Run the program with normal startup // Run the program with normal startup
AppMainForm = new MainForm(); AppMainForm = new MainForm();
//AppMainForm.Load += MainForm_LoadCompleted;
Application.Run(AppMainForm); Application.Run(AppMainForm);
} }
@ -732,6 +741,14 @@ namespace DisplayMagician {
} }
private static void MainForm_LoadCompleted(object sender, EventArgs e)
{
if (AppSplashScreen != null && !AppSplashScreen.Disposing && !AppSplashScreen.IsDisposed)
AppSplashScreen.Invoke(new Action(() => AppSplashScreen.Close()));
AppMainForm.TopMost = true;
AppMainForm.Activate();
AppMainForm.TopMost = false;
}
// ReSharper disable once CyclomaticComplexity // ReSharper disable once CyclomaticComplexity
private static void RunShortcut(string shortcutUUID) private static void RunShortcut(string shortcutUUID)
@ -1006,6 +1023,7 @@ namespace DisplayMagician {
return true; return true;
} }
public static string HotkeyToString(Keys hotkey) public static string HotkeyToString(Keys hotkey)

View File

@ -26,8 +26,8 @@ using System.Resources;
[assembly: Guid("e4ceaf5e-ad01-4695-b179-31168eb74c48")] [assembly: Guid("e4ceaf5e-ad01-4695-b179-31168eb74c48")]
// Version information // Version information
[assembly: AssemblyVersion("2.1.0.40")] [assembly: AssemblyVersion("2.1.0.54")]
[assembly: AssemblyFileVersion("2.1.0.40")] [assembly: AssemblyFileVersion("2.1.0.54")]
[assembly: NeutralResourcesLanguageAttribute( "en" )] [assembly: NeutralResourcesLanguageAttribute( "en" )]
[assembly: CLSCompliant(true)] [assembly: CLSCompliant(true)]

View File

@ -30,61 +30,62 @@ namespace DisplayMagician.UIForms
private void InitializeComponent() private void InitializeComponent()
{ {
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(LoadingForm)); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(LoadingForm));
this.lbl_title = new System.Windows.Forms.Label(); this.lblTitle = new System.Windows.Forms.Label();
this.lbl_description = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout(); this.SuspendLayout();
// //
// lbl_title // lblTitle
// //
this.lbl_title.AutoSize = true; this.lblTitle.BackColor = System.Drawing.Color.Black;
this.lbl_title.BackColor = System.Drawing.Color.Black; this.lblTitle.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lbl_title.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lblTitle.ForeColor = System.Drawing.Color.White;
this.lbl_title.ForeColor = System.Drawing.Color.White; this.lblTitle.Location = new System.Drawing.Point(36, 26);
this.lbl_title.Location = new System.Drawing.Point(71, 35); this.lblTitle.Name = "lblTitle";
this.lbl_title.Name = "lbl_title"; this.lblTitle.Size = new System.Drawing.Size(347, 30);
this.lbl_title.Size = new System.Drawing.Size(346, 29); this.lblTitle.TabIndex = 2;
this.lbl_title.TabIndex = 0; this.lblTitle.Text = "DisplayMagician is loading...";
this.lbl_title.Text = "DisplayMagician is loading..."; this.lblTitle.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.lbl_title.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
// //
// lbl_description // label1
// //
this.lbl_description.BackColor = System.Drawing.Color.IndianRed; this.label1.BackColor = System.Drawing.Color.WhiteSmoke;
this.lbl_description.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lbl_description.ForeColor = System.Drawing.Color.Black; this.label1.Location = new System.Drawing.Point(36, 56);
this.lbl_description.Location = new System.Drawing.Point(71, 64); this.label1.Name = "label1";
this.lbl_description.Name = "lbl_description"; this.label1.Size = new System.Drawing.Size(347, 48);
this.lbl_description.Size = new System.Drawing.Size(346, 28); this.label1.TabIndex = 3;
this.lbl_description.TabIndex = 1; this.label1.Text = "If you have installed a lot of games over time or have a lot of games installed n" +
this.lbl_description.Text = "but it\'s taking a while! Please wait."; "ow, this may take a while!";
this.lbl_description.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
// //
// LoadingForm // LoadingForm
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage"))); this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
this.ClientSize = new System.Drawing.Size(495, 129); this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
this.ClientSize = new System.Drawing.Size(418, 129);
this.ControlBox = false; this.ControlBox = false;
this.Controls.Add(this.lbl_description); this.Controls.Add(this.label1);
this.Controls.Add(this.lbl_title); this.Controls.Add(this.lblTitle);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false; this.MaximizeBox = false;
this.MaximumSize = new System.Drawing.Size(511, 168); this.MaximumSize = new System.Drawing.Size(434, 168);
this.MinimizeBox = false; this.MinimizeBox = false;
this.MinimumSize = new System.Drawing.Size(511, 168); this.MinimumSize = new System.Drawing.Size(434, 168);
this.Name = "LoadingForm"; this.Name = "LoadingForm";
this.ShowIcon = false; this.ShowIcon = false;
this.ShowInTaskbar = false; this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "DisplayMagician is loading...."; this.Text = "DisplayMagician is loading....";
this.UseWaitCursor = true;
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout();
} }
#endregion #endregion
private System.Windows.Forms.Label lblTitle;
private System.Windows.Forms.Label lbl_title; private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label lbl_description;
} }
} }

View File

@ -140,7 +140,8 @@ namespace DisplayMagician.UIForms
ToastContentBuilder tcBuilder = new ToastContentBuilder() ToastContentBuilder tcBuilder = new ToastContentBuilder()
.AddToastActivationInfo("notify=minimiseStart&action=open", ToastActivationType.Foreground) .AddToastActivationInfo("notify=minimiseStart&action=open", ToastActivationType.Foreground)
.AddText("DisplayMagician is minimised", hintMaxLines: 1) .AddText("DisplayMagician is minimised", hintMaxLines: 1)
.AddButton("Open", ToastActivationType.Background, "notify=minimiseStart&action=open"); .AddButton("Open", ToastActivationType.Background, "notify=minimiseStart&action=open")
.SetToastDuration(ToastDuration.Short);
ToastContent toastContent = tcBuilder.Content; ToastContent toastContent = tcBuilder.Content;
// Make sure to use Windows.Data.Xml.Dom // Make sure to use Windows.Data.Xml.Dom
var doc = new XmlDocument(); var doc = new XmlDocument();
@ -173,6 +174,10 @@ namespace DisplayMagician.UIForms
cb_minimise_notification_area.Checked = false; cb_minimise_notification_area.Checked = false;
} }
// Shut down the splash screen
if (Program.AppSplashScreen != null && !Program.AppSplashScreen.Disposing && !Program.AppSplashScreen.IsDisposed)
Program.AppSplashScreen.Invoke(new Action(() => Program.AppSplashScreen.Close()));
// If we've been handed a Form of some kind, then open it straight away // If we've been handed a Form of some kind, then open it straight away
if (formToOpen is DisplayProfileForm) if (formToOpen is DisplayProfileForm)
{ {

View File

@ -223,6 +223,13 @@ namespace DisplayMagician.UIForms
} }
// Also refresh the right-click menu (if we have a main form loaded)
if (Program.AppMainForm is Form)
{
Program.AppMainForm.RefreshNotifyIconMenus();
}
// Restart updating the saved_profiles listview // Restart updating the saved_profiles listview
ilv_saved_profiles.ResumeLayout(); ilv_saved_profiles.ResumeLayout();
} }