Completed adding "minimise on start" ability

Am able to minimise on start, or run normally
using a simple checkbox on the main form.
Maintains the setting over different runs using
a settings json file stored in the AppData directory.
This commit is contained in:
Terry MacDonald 2020-10-26 17:08:55 +13:00
parent 23930a2a15
commit 5e9135ed30
8 changed files with 243 additions and 29 deletions

View File

@ -88,6 +88,7 @@
<Compile Include="IconFromFile.cs" /> <Compile Include="IconFromFile.cs" />
<Compile Include="IconUtils.cs" /> <Compile Include="IconUtils.cs" />
<Compile Include="ProgressReporter.cs" /> <Compile Include="ProgressReporter.cs" />
<Compile Include="ProgramSettings.cs" />
<Compile Include="ShellIcon.cs" /> <Compile Include="ShellIcon.cs" />
<Compile Include="ShortcutItem.cs" /> <Compile Include="ShortcutItem.cs" />
<Compile Include="ShortcutRepository.cs" /> <Compile Include="ShortcutRepository.cs" />

View File

@ -42,7 +42,7 @@ namespace HeliosPlus {
public static string AppSteamIconFilename = Path.Combine(AppIconPath, @"Steam.ico"); public static string AppSteamIconFilename = Path.Combine(AppIconPath, @"Steam.ico");
public static string AppUplayIconFilename = Path.Combine(AppIconPath, @"Uplay.ico"); public static string AppUplayIconFilename = Path.Combine(AppIconPath, @"Uplay.ico");
public static string AppEpicIconFilename = Path.Combine(AppIconPath, @"Epic.ico"); public static string AppEpicIconFilename = Path.Combine(AppIconPath, @"Epic.ico");
public static ProgramSettings AppProgramSettings;
/// <summary> /// <summary>
/// The main entry point for the application. /// The main entry point for the application.
@ -66,6 +66,8 @@ namespace HeliosPlus {
Application.EnableVisualStyles(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
// Load the program settings
AppProgramSettings = ProgramSettings.LoadSettings();
var app = new CommandLineApplication(); var app = new CommandLineApplication();

View File

@ -0,0 +1,123 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HeliosPlus
{
public class ProgramSettings
{
#region Class Variables
// Common items to the class
private static bool _programSettingsLoaded = false;
// Other constants that are useful
private static string _programSettingsStorageJsonFileName = Path.Combine(Program.AppDataPath, $"Settings_{FileVersion.ToString(2)}.json");
#endregion
#region Instance Variables
private bool _minimiseOnStart = false;
#endregion
#region Class Properties
public bool MinimiseOnStart {
get
{
return _minimiseOnStart;
}
set
{
_minimiseOnStart = value;
// Because a value has changed, we need to save the setting
// to remember it for later.
if (_programSettingsLoaded)
SaveSettings();
}
}
public static Version FileVersion
{
get => new Version(1, 0, 0);
}
#endregion
#region Class Methods
public static ProgramSettings LoadSettings()
{
ProgramSettings programSettings = null;
if (File.Exists(_programSettingsStorageJsonFileName))
{
var json = File.ReadAllText(_programSettingsStorageJsonFileName, Encoding.Unicode);
if (!string.IsNullOrWhiteSpace(json))
{
try
{
programSettings = JsonConvert.DeserializeObject<ProgramSettings>(json, new JsonSerializerSettings
{
MissingMemberHandling = MissingMemberHandling.Ignore,
NullValueHandling = NullValueHandling.Ignore,
DefaultValueHandling = DefaultValueHandling.Include,
TypeNameHandling = TypeNameHandling.Auto
});
}
catch (FileNotFoundException ex)
{
Console.WriteLine($"ProgramSettings/LoadSettings exception 1: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
}
catch (Exception ex)
{
Console.WriteLine($"Unable to load Program Settings JSON file {_programSettingsStorageJsonFileName}: " + ex.Message);
}
}
}
// If there isn't any settings in the file then create a new ProgramSettings object
if (programSettings == null)
programSettings = new ProgramSettings();
_programSettingsLoaded = true;
return programSettings ;
}
public bool SaveSettings()
{
try
{
var json = JsonConvert.SerializeObject(this, Formatting.Indented, new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Include,
DefaultValueHandling = DefaultValueHandling.Populate,
TypeNameHandling = TypeNameHandling.Auto
});
if (!string.IsNullOrWhiteSpace(json))
{
File.WriteAllText(_programSettingsStorageJsonFileName, json, Encoding.Unicode);
return true;
}
}
catch (FileNotFoundException ex)
{
Console.WriteLine($"ProgramSettings/SaveSettings exception 1: {ex.Message}: {ex.StackTrace} - {ex.InnerException}");
}
catch (Exception ex)
{
Console.WriteLine($"Unable to save Program Settings JSON file {_programSettingsStorageJsonFileName}: " + ex.Message);
}
return false;
}
#endregion
}
}

View File

@ -50,6 +50,7 @@
this.shortcutToolStripSeparator = new System.Windows.Forms.ToolStripSeparator(); this.shortcutToolStripSeparator = new System.Windows.Forms.ToolStripSeparator();
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.cb_minimise_notification_area = new System.Windows.Forms.CheckBox();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout();
@ -72,6 +73,7 @@
// //
// splitContainer1.Panel2 // splitContainer1.Panel2
// //
this.splitContainer1.Panel2.Controls.Add(this.cb_minimise_notification_area);
this.splitContainer1.Panel2.Controls.Add(this.lbl_version); this.splitContainer1.Panel2.Controls.Add(this.lbl_version);
this.splitContainer1.Panel2.Controls.Add(this.btn_setup_game_shortcuts); this.splitContainer1.Panel2.Controls.Add(this.btn_setup_game_shortcuts);
this.splitContainer1.Panel2.Controls.Add(this.btn_exit); this.splitContainer1.Panel2.Controls.Add(this.btn_exit);
@ -211,6 +213,14 @@
resources.ApplyResources(this.exitToolStripMenuItem, "exitToolStripMenuItem"); resources.ApplyResources(this.exitToolStripMenuItem, "exitToolStripMenuItem");
this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click); this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
// //
// cb_minimise_notification_area
//
resources.ApplyResources(this.cb_minimise_notification_area, "cb_minimise_notification_area");
this.cb_minimise_notification_area.ForeColor = System.Drawing.Color.White;
this.cb_minimise_notification_area.Name = "cb_minimise_notification_area";
this.cb_minimise_notification_area.UseVisualStyleBackColor = true;
this.cb_minimise_notification_area.CheckedChanged += new System.EventHandler(this.cb_minimise_notification_area_CheckedChanged);
//
// MainForm // MainForm
// //
resources.ApplyResources(this, "$this"); resources.ApplyResources(this, "$this");
@ -255,5 +265,6 @@
private System.Windows.Forms.ToolStripSeparator shortcutToolStripSeparator; private System.Windows.Forms.ToolStripSeparator shortcutToolStripSeparator;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem;
private System.Windows.Forms.CheckBox cb_minimise_notification_area;
} }
} }

View File

@ -27,11 +27,26 @@ namespace HeliosPlus.UIForms
btn_setup_game_shortcuts.Parent = splitContainer1.Panel2; btn_setup_game_shortcuts.Parent = splitContainer1.Panel2;
lbl_version.Text = string.Format(lbl_version.Text, Assembly.GetExecutingAssembly().GetName().Version); lbl_version.Text = string.Format(lbl_version.Text, Assembly.GetExecutingAssembly().GetName().Version);
notifyIcon.Visible = true; notifyIcon.Visible = true;
// Make the form show
allowVisible = true;
// Close the application when the form is closed
allowClose = true;
RefreshNotifyIconMenus(); RefreshNotifyIconMenus();
if (Program.AppProgramSettings.MinimiseOnStart)
{
// Make the form minimised on start
allowVisible = false;
// Hide the application to notification area when the form is closed
allowClose = false;
cb_minimise_notification_area.Checked = true;
}
else
{
// Make the form show to the user on startup
allowVisible = true;
// Really close the application when the form is closed
allowClose = true;
cb_minimise_notification_area.Checked = false;
}
} }
protected override void SetVisibleCore(bool value) protected override void SetVisibleCore(bool value)
@ -149,5 +164,27 @@ namespace HeliosPlus.UIForms
allowClose = true; allowClose = true;
Application.Exit(); Application.Exit();
} }
private void cb_minimise_notification_area_CheckedChanged(object sender, EventArgs e)
{
if (cb_minimise_notification_area.Checked)
{
// Make the form minimised on start
allowVisible = false;
// Hide the application to notification area when the form is closed
allowClose = false;
// Enable the MinimiseOnStart setting
Program.AppProgramSettings.MinimiseOnStart = true;
}
else
{
// Make the form show to the user on startup
allowVisible = true;
// Really close the application when the form is closed
allowClose = true;
// Disable the MinimiseOnStart setting
Program.AppProgramSettings.MinimiseOnStart = false;
}
}
} }
} }

View File

@ -10725,6 +10725,42 @@
<data name="&gt;&gt;splitContainer1.Panel1.ZOrder" xml:space="preserve"> <data name="&gt;&gt;splitContainer1.Panel1.ZOrder" xml:space="preserve">
<value>0</value> <value>0</value>
</data> </data>
<data name="cb_minimise_notification_area.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Bottom, Left, Right</value>
</data>
<data name="cb_minimise_notification_area.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
</data>
<data name="cb_minimise_notification_area.Font" type="System.Drawing.Font, System.Drawing">
<value>Microsoft Sans Serif, 9.75pt</value>
</data>
<data name="cb_minimise_notification_area.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
<value>NoControl</value>
</data>
<data name="cb_minimise_notification_area.Location" type="System.Drawing.Point, System.Drawing">
<value>245, 352</value>
</data>
<data name="cb_minimise_notification_area.Size" type="System.Drawing.Size, System.Drawing">
<value>296, 20</value>
</data>
<data name="cb_minimise_notification_area.TabIndex" type="System.Int32, mscorlib">
<value>5</value>
</data>
<data name="cb_minimise_notification_area.Text" xml:space="preserve">
<value>Start HeliosPlus minimised in notification area</value>
</data>
<data name="&gt;&gt;cb_minimise_notification_area.Name" xml:space="preserve">
<value>cb_minimise_notification_area</value>
</data>
<data name="&gt;&gt;cb_minimise_notification_area.Type" xml:space="preserve">
<value>System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;cb_minimise_notification_area.Parent" xml:space="preserve">
<value>splitContainer1.Panel2</value>
</data>
<data name="&gt;&gt;cb_minimise_notification_area.ZOrder" xml:space="preserve">
<value>0</value>
</data>
<data name="lbl_version.AutoSize" type="System.Boolean, mscorlib"> <data name="lbl_version.AutoSize" type="System.Boolean, mscorlib">
<value>True</value> <value>True</value>
</data> </data>
@ -10732,7 +10768,7 @@
<value>Microsoft Sans Serif, 9.75pt</value> <value>Microsoft Sans Serif, 9.75pt</value>
</data> </data>
<data name="lbl_version.Location" type="System.Drawing.Point, System.Drawing"> <data name="lbl_version.Location" type="System.Drawing.Point, System.Drawing">
<value>12, 355</value> <value>12, 353</value>
</data> </data>
<data name="lbl_version.Size" type="System.Drawing.Size, System.Drawing"> <data name="lbl_version.Size" type="System.Drawing.Size, System.Drawing">
<value>25, 16</value> <value>25, 16</value>
@ -10756,7 +10792,7 @@
<value>splitContainer1.Panel2</value> <value>splitContainer1.Panel2</value>
</data> </data>
<data name="&gt;&gt;lbl_version.ZOrder" xml:space="preserve"> <data name="&gt;&gt;lbl_version.ZOrder" xml:space="preserve">
<value>0</value> <value>1</value>
</data> </data>
<data name="btn_setup_game_shortcuts.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms"> <data name="btn_setup_game_shortcuts.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>None</value> <value>None</value>
@ -10768,7 +10804,7 @@
<value>Microsoft Sans Serif, 21.75pt</value> <value>Microsoft Sans Serif, 21.75pt</value>
</data> </data>
<data name="btn_setup_game_shortcuts.Location" type="System.Drawing.Point, System.Drawing"> <data name="btn_setup_game_shortcuts.Location" type="System.Drawing.Point, System.Drawing">
<value>212, 180</value> <value>212, 182</value>
</data> </data>
<data name="btn_setup_game_shortcuts.Size" type="System.Drawing.Size, System.Drawing"> <data name="btn_setup_game_shortcuts.Size" type="System.Drawing.Size, System.Drawing">
<value>360, 50</value> <value>360, 50</value>
@ -10789,7 +10825,7 @@
<value>splitContainer1.Panel2</value> <value>splitContainer1.Panel2</value>
</data> </data>
<data name="&gt;&gt;btn_setup_game_shortcuts.ZOrder" xml:space="preserve"> <data name="&gt;&gt;btn_setup_game_shortcuts.ZOrder" xml:space="preserve">
<value>1</value> <value>2</value>
</data> </data>
<data name="btn_exit.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms"> <data name="btn_exit.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Bottom, Right</value> <value>Bottom, Right</value>
@ -10797,8 +10833,11 @@
<data name="btn_exit.FlatStyle" type="System.Windows.Forms.FlatStyle, System.Windows.Forms"> <data name="btn_exit.FlatStyle" type="System.Windows.Forms.FlatStyle, System.Windows.Forms">
<value>Flat</value> <value>Flat</value>
</data> </data>
<data name="btn_exit.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
<value>NoControl</value>
</data>
<data name="btn_exit.Location" type="System.Drawing.Point, System.Drawing"> <data name="btn_exit.Location" type="System.Drawing.Point, System.Drawing">
<value>698, 347</value> <value>698, 350</value>
</data> </data>
<data name="btn_exit.Size" type="System.Drawing.Size, System.Drawing"> <data name="btn_exit.Size" type="System.Drawing.Size, System.Drawing">
<value>75, 23</value> <value>75, 23</value>
@ -10819,7 +10858,7 @@
<value>splitContainer1.Panel2</value> <value>splitContainer1.Panel2</value>
</data> </data>
<data name="&gt;&gt;btn_exit.ZOrder" xml:space="preserve"> <data name="&gt;&gt;btn_exit.ZOrder" xml:space="preserve">
<value>2</value> <value>3</value>
</data> </data>
<data name="pb_game_shortcut.Dock" type="System.Windows.Forms.DockStyle, System.Windows.Forms"> <data name="pb_game_shortcut.Dock" type="System.Windows.Forms.DockStyle, System.Windows.Forms">
<value>Fill</value> <value>Fill</value>
@ -63104,7 +63143,7 @@
<value>splitContainer1.Panel2</value> <value>splitContainer1.Panel2</value>
</data> </data>
<data name="&gt;&gt;pb_game_shortcut.ZOrder" xml:space="preserve"> <data name="&gt;&gt;pb_game_shortcut.ZOrder" xml:space="preserve">
<value>3</value> <value>4</value>
</data> </data>
<data name="&gt;&gt;splitContainer1.Panel2.Name" xml:space="preserve"> <data name="&gt;&gt;splitContainer1.Panel2.Name" xml:space="preserve">
<value>splitContainer1.Panel2</value> <value>splitContainer1.Panel2</value>

View File

@ -42,7 +42,6 @@ namespace HeliosPlus.UIForms
this.lbl_profile_shown_subtitle = new System.Windows.Forms.Label(); this.lbl_profile_shown_subtitle = new System.Windows.Forms.Label();
this.lbl_profile_shown = new System.Windows.Forms.Label(); this.lbl_profile_shown = new System.Windows.Forms.Label();
this.ilv_saved_profiles = new Manina.Windows.Forms.ImageListView(); this.ilv_saved_profiles = new Manina.Windows.Forms.ImageListView();
this.dv_profile = new HeliosPlus.Shared.UserControls.DisplayView();
this.tabp_before = new System.Windows.Forms.TabPage(); this.tabp_before = new System.Windows.Forms.TabPage();
this.pnl_start_program4 = new System.Windows.Forms.Panel(); this.pnl_start_program4 = new System.Windows.Forms.Panel();
this.cb_start_program4 = new System.Windows.Forms.CheckBox(); this.cb_start_program4 = new System.Windows.Forms.CheckBox();
@ -113,6 +112,7 @@ namespace HeliosPlus.UIForms
this.lbl_title = new System.Windows.Forms.Label(); this.lbl_title = new System.Windows.Forms.Label();
this.lbl_shortcut_name = new System.Windows.Forms.Label(); this.lbl_shortcut_name = new System.Windows.Forms.Label();
this.cb_autosuggest = new System.Windows.Forms.CheckBox(); this.cb_autosuggest = new System.Windows.Forms.CheckBox();
this.dv_profile = new HeliosPlus.Shared.UserControls.DisplayView();
this.tabc_shortcut.SuspendLayout(); this.tabc_shortcut.SuspendLayout();
this.tabp_display.SuspendLayout(); this.tabp_display.SuspendLayout();
this.tabp_before.SuspendLayout(); this.tabp_before.SuspendLayout();
@ -253,21 +253,6 @@ namespace HeliosPlus.UIForms
this.ilv_saved_profiles.View = Manina.Windows.Forms.View.HorizontalStrip; this.ilv_saved_profiles.View = Manina.Windows.Forms.View.HorizontalStrip;
this.ilv_saved_profiles.ItemClick += new Manina.Windows.Forms.ItemClickEventHandler(this.ilv_saved_profiles_ItemClick); this.ilv_saved_profiles.ItemClick += new Manina.Windows.Forms.ItemClickEventHandler(this.ilv_saved_profiles_ItemClick);
// //
// dv_profile
//
this.dv_profile.BackColor = System.Drawing.Color.DimGray;
this.dv_profile.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.dv_profile.Font = new System.Drawing.Font("Consolas", 50F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.dv_profile.ForeColor = System.Drawing.Color.MidnightBlue;
this.dv_profile.Location = new System.Drawing.Point(0, 0);
this.dv_profile.Margin = new System.Windows.Forms.Padding(18);
this.dv_profile.Name = "dv_profile";
this.dv_profile.PaddingX = 100;
this.dv_profile.PaddingY = 100;
this.dv_profile.Profile = null;
this.dv_profile.Size = new System.Drawing.Size(1082, 467);
this.dv_profile.TabIndex = 23;
//
// tabp_before // tabp_before
// //
this.tabp_before.BackColor = System.Drawing.Color.Black; this.tabp_before.BackColor = System.Drawing.Color.Black;
@ -1085,6 +1070,21 @@ namespace HeliosPlus.UIForms
this.cb_autosuggest.UseVisualStyleBackColor = true; this.cb_autosuggest.UseVisualStyleBackColor = true;
this.cb_autosuggest.CheckedChanged += new System.EventHandler(this.cb_autosuggest_CheckedChanged); this.cb_autosuggest.CheckedChanged += new System.EventHandler(this.cb_autosuggest_CheckedChanged);
// //
// dv_profile
//
this.dv_profile.BackColor = System.Drawing.Color.DimGray;
this.dv_profile.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.dv_profile.Font = new System.Drawing.Font("Consolas", 50F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.dv_profile.ForeColor = System.Drawing.Color.MidnightBlue;
this.dv_profile.Location = new System.Drawing.Point(0, 0);
this.dv_profile.Margin = new System.Windows.Forms.Padding(18);
this.dv_profile.Name = "dv_profile";
this.dv_profile.PaddingX = 100;
this.dv_profile.PaddingY = 100;
this.dv_profile.Profile = null;
this.dv_profile.Size = new System.Drawing.Size(1082, 467);
this.dv_profile.TabIndex = 23;
//
// ShortcutForm // ShortcutForm
// //
this.AcceptButton = this.btn_save; this.AcceptButton = this.btn_save;

View File

@ -1418,5 +1418,6 @@ namespace HeliosPlus.UIForms
txt_start_program_args4.Visible = false; txt_start_program_args4.Visible = false;
} }
} }
} }
} }