From 0d6536e7feb6f6dc1ad663a7848cc02cb33df708 Mon Sep 17 00:00:00 2001 From: Terry MacDonald Date: Sat, 30 Oct 2021 19:01:03 +1300 Subject: [PATCH] Splash screen to inform user when program starting This is designed to inform the user that DisplayMagician is starting. Partially fixes #49. --- DisplayMagician/Program.cs | 20 +++++- DisplayMagician/Properties/AssemblyInfo.cs | 4 +- .../UIForms/LoadingForm.Designer.cs | 65 ++++++++++--------- DisplayMagician/UIForms/MainForm.cs | 9 ++- displaymagician/uiforms/displayprofileform.cs | 9 ++- 5 files changed, 69 insertions(+), 38 deletions(-) diff --git a/DisplayMagician/Program.cs b/DisplayMagician/Program.cs index e8fb419..0327aef 100644 --- a/DisplayMagician/Program.cs +++ b/DisplayMagician/Program.cs @@ -19,6 +19,7 @@ using NLog.Config; using System.Collections.Generic; using AutoUpdaterDotNET; using Newtonsoft.Json; +using System.Threading; namespace DisplayMagician { @@ -40,7 +41,7 @@ namespace DisplayMagician { public static bool WaitingForGameToExit = false; public static ProgramSettings AppProgramSettings; public static MainForm AppMainForm; - + public static LoadingForm AppSplashScreen; private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger(); 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"); + //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 Task.Run(() => LoadGamesInBackground()); @@ -716,6 +724,7 @@ namespace DisplayMagician { // Run the program with normal startup AppMainForm = new MainForm(); + //AppMainForm.Load += MainForm_LoadCompleted; 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 private static void RunShortcut(string shortcutUUID) @@ -1006,6 +1023,7 @@ namespace DisplayMagician { return true; + } public static string HotkeyToString(Keys hotkey) diff --git a/DisplayMagician/Properties/AssemblyInfo.cs b/DisplayMagician/Properties/AssemblyInfo.cs index dc9d915..146637e 100644 --- a/DisplayMagician/Properties/AssemblyInfo.cs +++ b/DisplayMagician/Properties/AssemblyInfo.cs @@ -26,8 +26,8 @@ using System.Resources; [assembly: Guid("e4ceaf5e-ad01-4695-b179-31168eb74c48")] // Version information -[assembly: AssemblyVersion("2.1.0.40")] -[assembly: AssemblyFileVersion("2.1.0.40")] +[assembly: AssemblyVersion("2.1.0.54")] +[assembly: AssemblyFileVersion("2.1.0.54")] [assembly: NeutralResourcesLanguageAttribute( "en" )] [assembly: CLSCompliant(true)] diff --git a/DisplayMagician/UIForms/LoadingForm.Designer.cs b/DisplayMagician/UIForms/LoadingForm.Designer.cs index 9f4a125..d2a3374 100644 --- a/DisplayMagician/UIForms/LoadingForm.Designer.cs +++ b/DisplayMagician/UIForms/LoadingForm.Designer.cs @@ -30,61 +30,62 @@ namespace DisplayMagician.UIForms private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(LoadingForm)); - this.lbl_title = new System.Windows.Forms.Label(); - this.lbl_description = new System.Windows.Forms.Label(); + this.lblTitle = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); this.SuspendLayout(); // - // lbl_title + // lblTitle // - this.lbl_title.AutoSize = true; - this.lbl_title.BackColor = System.Drawing.Color.Black; - this.lbl_title.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.lbl_title.ForeColor = System.Drawing.Color.White; - this.lbl_title.Location = new System.Drawing.Point(71, 35); - this.lbl_title.Name = "lbl_title"; - this.lbl_title.Size = new System.Drawing.Size(346, 29); - this.lbl_title.TabIndex = 0; - this.lbl_title.Text = "DisplayMagician is loading..."; - this.lbl_title.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.lblTitle.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.lblTitle.ForeColor = System.Drawing.Color.White; + this.lblTitle.Location = new System.Drawing.Point(36, 26); + this.lblTitle.Name = "lblTitle"; + this.lblTitle.Size = new System.Drawing.Size(347, 30); + this.lblTitle.TabIndex = 2; + this.lblTitle.Text = "DisplayMagician is loading..."; + this.lblTitle.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // - // lbl_description + // label1 // - this.lbl_description.BackColor = System.Drawing.Color.IndianRed; - this.lbl_description.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.lbl_description.ForeColor = System.Drawing.Color.Black; - this.lbl_description.Location = new System.Drawing.Point(71, 64); - this.lbl_description.Name = "lbl_description"; - this.lbl_description.Size = new System.Drawing.Size(346, 28); - this.lbl_description.TabIndex = 1; - this.lbl_description.Text = "but it\'s taking a while! Please wait."; - this.lbl_description.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; + this.label1.BackColor = System.Drawing.Color.WhiteSmoke; + this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label1.Location = new System.Drawing.Point(36, 56); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(347, 48); + this.label1.TabIndex = 3; + this.label1.Text = "If you have installed a lot of games over time or have a lot of games installed n" + + "ow, this may take a while!"; + this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // LoadingForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 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.Controls.Add(this.lbl_description); - this.Controls.Add(this.lbl_title); + this.Controls.Add(this.label1); + this.Controls.Add(this.lblTitle); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MaximizeBox = false; - this.MaximumSize = new System.Drawing.Size(511, 168); + this.MaximumSize = new System.Drawing.Size(434, 168); this.MinimizeBox = false; - this.MinimumSize = new System.Drawing.Size(511, 168); + this.MinimumSize = new System.Drawing.Size(434, 168); this.Name = "LoadingForm"; this.ShowIcon = false; this.ShowInTaskbar = false; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "DisplayMagician is loading...."; + this.UseWaitCursor = true; this.ResumeLayout(false); - this.PerformLayout(); } #endregion - - private System.Windows.Forms.Label lbl_title; - private System.Windows.Forms.Label lbl_description; + private System.Windows.Forms.Label lblTitle; + private System.Windows.Forms.Label label1; } } \ No newline at end of file diff --git a/DisplayMagician/UIForms/MainForm.cs b/DisplayMagician/UIForms/MainForm.cs index a0443d5..932f454 100644 --- a/DisplayMagician/UIForms/MainForm.cs +++ b/DisplayMagician/UIForms/MainForm.cs @@ -140,7 +140,8 @@ namespace DisplayMagician.UIForms ToastContentBuilder tcBuilder = new ToastContentBuilder() .AddToastActivationInfo("notify=minimiseStart&action=open", ToastActivationType.Foreground) .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; // Make sure to use Windows.Data.Xml.Dom var doc = new XmlDocument(); @@ -153,7 +154,7 @@ namespace DisplayMagician.UIForms DesktopNotifications.DesktopNotificationManagerCompat.History.Clear(); // And then show it - DesktopNotifications.DesktopNotificationManagerCompat.CreateToastNotifier().Show(toast); + DesktopNotifications.DesktopNotificationManagerCompat.CreateToastNotifier().Show(toast); } else @@ -173,6 +174,10 @@ namespace DisplayMagician.UIForms 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 (formToOpen is DisplayProfileForm) { diff --git a/displaymagician/uiforms/displayprofileform.cs b/displaymagician/uiforms/displayprofileform.cs index 2bf6413..2d64d8b 100644 --- a/displaymagician/uiforms/displayprofileform.cs +++ b/displaymagician/uiforms/displayprofileform.cs @@ -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 ilv_saved_profiles.ResumeLayout(); } @@ -255,7 +262,7 @@ namespace DisplayMagician.UIForms // Refresh the Profile UI RefreshDisplayProfileUI(); - + }