From 3b402be81c50701a9d341d584eb4c62f4071ca4e Mon Sep 17 00:00:00 2001 From: Sergey Suchkov Date: Sun, 3 Apr 2022 02:31:55 +0700 Subject: [PATCH 1/2] Add Dark mode, remove Apply button on SettingsForm --- Taskplay/Icons/BackwardDark.ico | Bin 0 -> 15086 bytes Taskplay/Icons/ForwardDark.ico | Bin 0 -> 15086 bytes Taskplay/Icons/PauseDark.ico | Bin 0 -> 15086 bytes Taskplay/Icons/PlayDark.ico | Bin 0 -> 15086 bytes Taskplay/Icons/StopDark.ico | Bin 0 -> 15086 bytes Taskplay/Program.cs | 32 ++++++++++--- Taskplay/Properties/AssemblyInfo.cs | 4 +- Taskplay/Properties/Resources.Designer.cs | 52 +++++++++++++++++++++- Taskplay/Properties/Resources.resx | 15 +++++++ Taskplay/SettingsForm.Designer.cs | 52 +++++++++++----------- Taskplay/SettingsForm.cs | 21 ++++++--- Taskplay/Taskplay.csproj | 5 +++ 12 files changed, 140 insertions(+), 41 deletions(-) create mode 100644 Taskplay/Icons/BackwardDark.ico create mode 100644 Taskplay/Icons/ForwardDark.ico create mode 100644 Taskplay/Icons/PauseDark.ico create mode 100644 Taskplay/Icons/PlayDark.ico create mode 100644 Taskplay/Icons/StopDark.ico diff --git a/Taskplay/Icons/BackwardDark.ico b/Taskplay/Icons/BackwardDark.ico new file mode 100644 index 0000000000000000000000000000000000000000..a030c8b13eb146479dacfc38b610df46db0cfbed GIT binary patch literal 15086 zcmeHNziSjh6rRI~NQy+|iWDISDku_2qg*2hLcl*jDtSklPuu!nD zun1SB5KAiy3$d`U5)ly#vC!|!-IK>;&&=%Y&JUcxm)X7S%=_N=-oBlE7h^hRpIKZq z7<=aWoH1vNF}>dS{24xfgwNL2Cg;bES??Ni0@vVAm@)nwgE6@7@cbA%=lIp{_d5-t zi*<FPjRgDDFWW} zm3dL@2dlaNv;GUnv$OvI`?@LXL+3R)fU)GG!3nWGng7XbPAk3KoPMZm4F0v5&9=M2;Fqa;8YwPI*B-lLl-j%?&8#; zh)5~o(4mub$SfH;6bVK2^J(&x+^bKhTg?-He2>Wo@iQYd@s z$yufDD5ZM6dHp@^zs0?kl|{X;)PrTEuAvPcp~w6_3Z>BQ()l?~>-ZWB1}%@c2wBSj zOI_|c)ceLg{kdF!Lz~~gXQM60oB|`DZ9J2{EYtdPTw({f0qFhYI!}L&aRfXAOfGr* z3zt2NaSJFaU-}D|rwcAc<=gfz%il(SJD6)3`%Terw9u32+bomxXY0SFoTNJA=3nuX z)IRgR7pw6!ebvC9s)_as9HXG&_7=Tj9b$lKIH4VSOW)L7e3{a z#}9z{RdW3QB%i(*LjNN-^ZrR)&vPssH*N?H z&M6$^pWHss$g#q6J7ir50@B-j`%-^P5&Y>#)oWn7|efuMzDqB>^Ut;PI{9gf8 z*un>Y&f^H6Ehw)Gxbh)i{KXcGi!pE)XgipPZ~mOe4EO|$fGdEFEkf|uZSfBLZv$m* z5t6^yVi)}R9$sdx56xd}F$I6Fdqv}-F8sw72bcrby*7|1F6zWzY{6X1_|CJBsw01y z2iLtf8Fr{Mf6jxpV2-t4Mk9GgR+!EvdjXK{2Hi6jo&l7NFK9BAFCFb`>>U<0o zeNWMIrhe@!e=;X-1C$rr`3cvd7|*Yc7dq#@w*%;QcXeHr|4hI)#`D`%@csbAdVU`J t?-#E8I`25H{Xef)lD*Y4o57<_#AN^M3aVc^KA9P_vWyekgepjC!;j&F_u^Q>HGOJo3H3! zUz3c*9+qfj zwY81Yem#aCdo2AObK4qR)V^+5gW4j0Yu95OYrTFRuD|^pF#a)r`M-k1E4AJ0TaCqLvT!;AMNKjgf9ygT(#Q$yv6Zn9GjZ@`?>DiwMpkLat>e7qI;Yd=Q!{5i7p49d1^Eo zV+nHBv#+t#s0CI#6y9k0=F3(|_uVfIbOCK_g;-x&HF3u|9GIlkjtCJAcPSAOA>`RC8^#wG+Ctu^*x3N&Zu0aigd>nM#*S_gcY}|#Y`I?k{ z>DUM5>kJI?x%a#O#eQDnpI7|lnSXiJpU=eg3gl6L^ICuMT7R|wcmPrBS#NC#^Zs!C zQ9eC_I)rKOdyd)9bN~4PU+;s@IvRHz=CP}MszBU6%620@cHJ8T`914C1-D4u9r$;j z;zD_!qRhFn=ER5rtrMqWv>TN=-9)?YH))N}W6kp&2VLj=gl)J9+9MTd{gi&YZq=T8 z9W*Bs;5#;1wC~k#e(1N8C76a$kEwq8<;M?DOfA597}b~x(rWfKiO8VfxLF zHu@jJ6&R(t2&-Ry?87T)K^?Nl&tW#A=(oA}hW6)h8}iQYIQq?xUG%TR91I($w7&Pz zFF&;Qy@zF}L0US4`t{XsbD@~ph6R|&(2u0_%Ma!E9&ADrvdE1j_1j!1rrNLyY1gSV z^qU`wsW%`SlMoccKF8D4Z!z^1?W(tmsY=3rq^;lPLb;*+?HXu5jHRz39HuY}bV_Pk;7(?RnF6z%?D@BP~v`YRB2OtL($-}vvKbqS^+i#5o{-(LN? zzO#Bb!F!*6vuZ2-T7$Nsh`%4rqPqpEhoc@V{pM7fi~Rd(KcC8D#mN0~o(9Yle-A1j HIgY>|(qr`Z literal 0 HcmV?d00001 diff --git a/Taskplay/Icons/StopDark.ico b/Taskplay/Icons/StopDark.ico new file mode 100644 index 0000000000000000000000000000000000000000..d98cf2203e47c75341139ac6c036d8b74aa49a4b GIT binary patch literal 15086 zcmeI2F;2rk6htS2E=`0)MdKn!l#!5-%T!z-7f4CVg{Zj*2jL_zKZZz&Q1rDMvbOXr zeOtTv-@6&ljGc9)nXa^0$j44E*V2=ut{d9#?tgRNYW35;m!5B>2j}=BR}B3=NY1;N z53y@|*Z2KwB=P8Zye1=ZkLMk=U&)AE>JKphzdHWZ^7ojJ7is_cKd`0#c5Jafc3v)?Vo&fc@Kd2vq0&tU-m@Gq;YY##c{X)inq z{h`0CuCjUP5B-I=WTLhIw0{1~U_?%iOW(` GetDarkModeState(); + + static readonly Action restartAction = (b) => Application.Restart(); + /// /// The main entry point for the application. /// @@ -33,19 +37,19 @@ static void Main() contextMenu.MenuItems.Add(contextItemSettings); contextMenu.MenuItems.Add(contextItemExit); //Setup nextIcon - nextIcon.Icon = Properties.Resources.Forward; + nextIcon.Icon = IsDarkModeOn ? Properties.Resources.ForwardDark : Properties.Resources.Forward; nextIcon.Text = "Next"; nextIcon.Visible = true; nextIcon.MouseClick += new MouseEventHandler(nextIcon_MouseClick); nextIcon.ContextMenu = contextMenu; //Setup playIcon - playIcon.Icon = Properties.Resources.Play; + playIcon.Icon = IsDarkModeOn ? Properties.Resources.PlayDark : Properties.Resources.Play; playIcon.Text = "Play / Pause"; playIcon.Visible = true; playIcon.MouseClick += new MouseEventHandler(playIcon_MouseClick); playIcon.ContextMenu = contextMenu; //Setup previousIcon - previousIcon.Icon = Properties.Resources.Backward; + previousIcon.Icon = IsDarkModeOn ? Properties.Resources.BackwardDark : Properties.Resources.Backward; previousIcon.Text = "Previous"; previousIcon.Visible = true; previousIcon.MouseClick += new MouseEventHandler(previousIcon_MouseClick); @@ -79,13 +83,13 @@ private static void playIcon_MouseClick(object sender, MouseEventArgs e) if (_isMusicPlaying == false) { // Start playing music and show the pause-icon - playIcon.Icon = Properties.Resources.Pause; + playIcon.Icon = IsDarkModeOn ? Properties.Resources.PauseDark : Properties.Resources.Pause; _isMusicPlaying = true; } else { // Pause the music and display the Play-icon - playIcon.Icon = Properties.Resources.Play; + playIcon.Icon = IsDarkModeOn ? Properties.Resources.PlayDark : Properties.Resources.Play; _isMusicPlaying = false; } } @@ -108,7 +112,8 @@ private static void nextIcon_MouseClick(object sender, MouseEventArgs e) private static void contextMenuSettings_Click(object sender, System.EventArgs e) { //Show Settings form - new SettingsForm().ShowDialog(); + var settingsForm = new SettingsForm(IsDarkModeOn, restartAction); + settingsForm.ShowDialog(); } private static void contextMenuExit_Click(object sender, System.EventArgs e) @@ -117,6 +122,21 @@ private static void contextMenuExit_Click(object sender, System.EventArgs e) Application.Exit(); } + private static bool GetDarkModeState() + { + var subKey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(@"SOFTWARE\Taskplay"); + + var keyValue = subKey.GetValue("DarkMode"); + + if (keyValue == null) + { + subKey.SetValue("DarkMode", 0); + return false; + } + + return (int)keyValue == 1; + } + [DllImport("user32.dll", SetLastError = true)] public static extern void keybd_event(byte virtualKey, byte scanCode, uint flags, IntPtr extraInfo); } diff --git a/Taskplay/Properties/AssemblyInfo.cs b/Taskplay/Properties/AssemblyInfo.cs index 07f48be..177a9e9 100644 --- a/Taskplay/Properties/AssemblyInfo.cs +++ b/Taskplay/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("1.0.1.0")] +[assembly: AssemblyFileVersion("1.0.1.0")] diff --git a/Taskplay/Properties/Resources.Designer.cs b/Taskplay/Properties/Resources.Designer.cs index 73157ae..09d48f6 100644 --- a/Taskplay/Properties/Resources.Designer.cs +++ b/Taskplay/Properties/Resources.Designer.cs @@ -19,7 +19,7 @@ namespace Taskplay.Properties { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { @@ -70,6 +70,16 @@ internal static System.Drawing.Icon Backward { } } + /// + /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). + /// + internal static System.Drawing.Icon BackwardDark { + get { + object obj = ResourceManager.GetObject("BackwardDark", resourceCulture); + return ((System.Drawing.Icon)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). /// @@ -80,6 +90,16 @@ internal static System.Drawing.Icon Forward { } } + /// + /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). + /// + internal static System.Drawing.Icon ForwardDark { + get { + object obj = ResourceManager.GetObject("ForwardDark", resourceCulture); + return ((System.Drawing.Icon)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). /// @@ -90,6 +110,16 @@ internal static System.Drawing.Icon Pause { } } + /// + /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). + /// + internal static System.Drawing.Icon PauseDark { + get { + object obj = ResourceManager.GetObject("PauseDark", resourceCulture); + return ((System.Drawing.Icon)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). /// @@ -100,6 +130,16 @@ internal static System.Drawing.Icon Play { } } + /// + /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). + /// + internal static System.Drawing.Icon PlayDark { + get { + object obj = ResourceManager.GetObject("PlayDark", resourceCulture); + return ((System.Drawing.Icon)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). /// @@ -109,5 +149,15 @@ internal static System.Drawing.Icon Stop { return ((System.Drawing.Icon)(obj)); } } + + /// + /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). + /// + internal static System.Drawing.Icon StopDark { + get { + object obj = ResourceManager.GetObject("StopDark", resourceCulture); + return ((System.Drawing.Icon)(obj)); + } + } } } diff --git a/Taskplay/Properties/Resources.resx b/Taskplay/Properties/Resources.resx index 0a4d049..fc7fe00 100644 --- a/Taskplay/Properties/Resources.resx +++ b/Taskplay/Properties/Resources.resx @@ -133,4 +133,19 @@ ..\icons\stop.ico;System.Drawing.Icon, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Icons\BackwardDark.ico;System.Drawing.Icon, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Icons\ForwardDark.ico;System.Drawing.Icon, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Icons\PauseDark.ico;System.Drawing.Icon, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Icons\PlayDark.ico;System.Drawing.Icon, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Icons\StopDark.ico;System.Drawing.Icon, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file diff --git a/Taskplay/SettingsForm.Designer.cs b/Taskplay/SettingsForm.Designer.cs index 921d87e..6848285 100644 --- a/Taskplay/SettingsForm.Designer.cs +++ b/Taskplay/SettingsForm.Designer.cs @@ -31,6 +31,7 @@ private void InitializeComponent() System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SettingsForm)); this.tabControl = new System.Windows.Forms.TabControl(); this.tabPageGeneral = new System.Windows.Forms.TabPage(); + this.checkBoxDarkMode = new System.Windows.Forms.CheckBox(); this.checkBoxAutorun = new System.Windows.Forms.CheckBox(); this.tabPageAbout = new System.Windows.Forms.TabPage(); this.linkLabelGitHub = new System.Windows.Forms.LinkLabel(); @@ -38,7 +39,6 @@ private void InitializeComponent() this.labelSuggestions = new System.Windows.Forms.Label(); this.labelVersion = new System.Windows.Forms.Label(); this.labelTaskplay = new System.Windows.Forms.Label(); - this.buttonApply = new System.Windows.Forms.Button(); this.buttonCancel = new System.Windows.Forms.Button(); this.buttonOK = new System.Windows.Forms.Button(); this.tabControl.SuspendLayout(); @@ -60,21 +60,32 @@ private void InitializeComponent() // // tabPageGeneral // + this.tabPageGeneral.Controls.Add(this.checkBoxDarkMode); this.tabPageGeneral.Controls.Add(this.checkBoxAutorun); - this.tabPageGeneral.Location = new System.Drawing.Point(4, 22); + this.tabPageGeneral.Location = new System.Drawing.Point(4, 32); this.tabPageGeneral.Name = "tabPageGeneral"; this.tabPageGeneral.Padding = new System.Windows.Forms.Padding(3); - this.tabPageGeneral.Size = new System.Drawing.Size(297, 156); + this.tabPageGeneral.Size = new System.Drawing.Size(297, 146); this.tabPageGeneral.TabIndex = 0; this.tabPageGeneral.Text = "General"; this.tabPageGeneral.UseVisualStyleBackColor = true; // + // checkBoxDarkMode + // + this.checkBoxDarkMode.AutoSize = true; + this.checkBoxDarkMode.Location = new System.Drawing.Point(6, 39); + this.checkBoxDarkMode.Name = "checkBoxDarkMode"; + this.checkBoxDarkMode.Size = new System.Drawing.Size(120, 27); + this.checkBoxDarkMode.TabIndex = 1; + this.checkBoxDarkMode.Text = "Dark mode"; + this.checkBoxDarkMode.UseVisualStyleBackColor = true; + // // checkBoxAutorun // this.checkBoxAutorun.AutoSize = true; this.checkBoxAutorun.Location = new System.Drawing.Point(6, 6); this.checkBoxAutorun.Name = "checkBoxAutorun"; - this.checkBoxAutorun.Size = new System.Drawing.Size(173, 17); + this.checkBoxAutorun.Size = new System.Drawing.Size(249, 27); this.checkBoxAutorun.TabIndex = 0; this.checkBoxAutorun.Text = "Start Taskplay with Windows"; this.checkBoxAutorun.UseVisualStyleBackColor = true; @@ -86,10 +97,10 @@ private void InitializeComponent() this.tabPageAbout.Controls.Add(this.labelSuggestions); this.tabPageAbout.Controls.Add(this.labelVersion); this.tabPageAbout.Controls.Add(this.labelTaskplay); - this.tabPageAbout.Location = new System.Drawing.Point(4, 22); + this.tabPageAbout.Location = new System.Drawing.Point(4, 32); this.tabPageAbout.Name = "tabPageAbout"; this.tabPageAbout.Padding = new System.Windows.Forms.Padding(3); - this.tabPageAbout.Size = new System.Drawing.Size(297, 156); + this.tabPageAbout.Size = new System.Drawing.Size(297, 146); this.tabPageAbout.TabIndex = 1; this.tabPageAbout.Text = "About"; this.tabPageAbout.UseVisualStyleBackColor = true; @@ -101,7 +112,7 @@ private void InitializeComponent() this.linkLabelGitHub.LinkBehavior = System.Windows.Forms.LinkBehavior.NeverUnderline; this.linkLabelGitHub.Location = new System.Drawing.Point(214, 134); this.linkLabelGitHub.Name = "linkLabelGitHub"; - this.linkLabelGitHub.Size = new System.Drawing.Size(44, 13); + this.linkLabelGitHub.Size = new System.Drawing.Size(64, 23); this.linkLabelGitHub.TabIndex = 8; this.linkLabelGitHub.TabStop = true; this.linkLabelGitHub.Text = "GitHub"; @@ -113,7 +124,7 @@ private void InitializeComponent() this.labelContribute.AutoSize = true; this.labelContribute.Location = new System.Drawing.Point(6, 134); this.labelContribute.Name = "labelContribute"; - this.labelContribute.Size = new System.Drawing.Size(215, 13); + this.labelContribute.Size = new System.Drawing.Size(318, 23); this.labelContribute.TabIndex = 7; this.labelContribute.Text = "Feel free to contribute to the project on "; // @@ -123,7 +134,7 @@ private void InitializeComponent() this.labelSuggestions.AutoSize = true; this.labelSuggestions.Location = new System.Drawing.Point(6, 117); this.labelSuggestions.Name = "labelSuggestions"; - this.labelSuggestions.Size = new System.Drawing.Size(183, 13); + this.labelSuggestions.Size = new System.Drawing.Size(268, 23); this.labelSuggestions.TabIndex = 5; this.labelSuggestions.Text = "Got a suggestion or found a bug?"; // @@ -132,7 +143,7 @@ private void InitializeComponent() this.labelVersion.AutoSize = true; this.labelVersion.Location = new System.Drawing.Point(6, 24); this.labelVersion.Name = "labelVersion"; - this.labelVersion.Size = new System.Drawing.Size(60, 13); + this.labelVersion.Size = new System.Drawing.Size(90, 23); this.labelVersion.TabIndex = 4; this.labelVersion.Text = "Version {0}"; // @@ -141,24 +152,14 @@ private void InitializeComponent() this.labelTaskplay.AutoSize = true; this.labelTaskplay.Location = new System.Drawing.Point(6, 7); this.labelTaskplay.Name = "labelTaskplay"; - this.labelTaskplay.Size = new System.Drawing.Size(49, 13); + this.labelTaskplay.Size = new System.Drawing.Size(72, 23); this.labelTaskplay.TabIndex = 2; this.labelTaskplay.Text = "Taskplay"; // - // buttonApply - // - this.buttonApply.Location = new System.Drawing.Point(235, 192); - this.buttonApply.Name = "buttonApply"; - this.buttonApply.Size = new System.Drawing.Size(75, 23); - this.buttonApply.TabIndex = 1; - this.buttonApply.Text = "Apply"; - this.buttonApply.UseVisualStyleBackColor = true; - this.buttonApply.Click += new System.EventHandler(this.buttonApply_Click); - // // buttonCancel // this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.buttonCancel.Location = new System.Drawing.Point(154, 192); + this.buttonCancel.Location = new System.Drawing.Point(228, 192); this.buttonCancel.Name = "buttonCancel"; this.buttonCancel.Size = new System.Drawing.Size(75, 23); this.buttonCancel.TabIndex = 2; @@ -168,7 +169,7 @@ private void InitializeComponent() // // buttonOK // - this.buttonOK.Location = new System.Drawing.Point(73, 192); + this.buttonOK.Location = new System.Drawing.Point(147, 192); this.buttonOK.Name = "buttonOK"; this.buttonOK.Size = new System.Drawing.Size(75, 23); this.buttonOK.TabIndex = 3; @@ -179,13 +180,12 @@ private void InitializeComponent() // SettingsForm // this.AcceptButton = this.buttonOK; - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 23F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.CancelButton = this.buttonCancel; this.ClientSize = new System.Drawing.Size(315, 220); this.Controls.Add(this.buttonOK); this.Controls.Add(this.buttonCancel); - this.Controls.Add(this.buttonApply); this.Controls.Add(this.tabControl); this.Font = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; @@ -215,8 +215,8 @@ private void InitializeComponent() private System.Windows.Forms.Label labelSuggestions; private System.Windows.Forms.Label labelVersion; private System.Windows.Forms.LinkLabel linkLabelGitHub; - private System.Windows.Forms.Button buttonApply; private System.Windows.Forms.Button buttonCancel; private System.Windows.Forms.Button buttonOK; + private System.Windows.Forms.CheckBox checkBoxDarkMode; } } \ No newline at end of file diff --git a/Taskplay/SettingsForm.cs b/Taskplay/SettingsForm.cs index b63883e..b25d138 100644 --- a/Taskplay/SettingsForm.cs +++ b/Taskplay/SettingsForm.cs @@ -6,16 +6,23 @@ namespace Taskplay public partial class SettingsForm : Form { Microsoft.Win32.RegistryKey autorun; - public SettingsForm() + private readonly bool isDarkModeOn; + private readonly Action restartAction; + private bool isRestartNeeded = false; + + public SettingsForm(bool isDarkModeOn, Action restartAction) { InitializeComponent(); autorun = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true); + this.isDarkModeOn = isDarkModeOn; + this.restartAction = restartAction; } private void SettingsForm_Load(object sender, EventArgs e) { labelVersion.Text = String.Format("Version {0}", Application.ProductVersion); checkBoxAutorun.Checked = (autorun.GetValue("Taskplay") != null); + checkBoxDarkMode.Checked = isDarkModeOn; } private void SaveSettings() @@ -24,6 +31,11 @@ private void SaveSettings() autorun.SetValue("Taskplay", Application.ExecutablePath); else autorun.DeleteValue("Taskplay", false); + + var subKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Taskplay", true); + subKey.SetValue("DarkMode", checkBoxDarkMode.Checked ? 1 : 0); + + isRestartNeeded = checkBoxDarkMode.Checked != isDarkModeOn; } private void linkLabelGitHub_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) @@ -31,11 +43,6 @@ private void linkLabelGitHub_LinkClicked(object sender, LinkLabelLinkClickedEven System.Diagnostics.Process.Start("https://github.com/evilpro/Taskplay"); } - private void buttonApply_Click(object sender, EventArgs e) - { - SaveSettings(); - } - private void buttonCancel_Click(object sender, EventArgs e) { Close(); @@ -45,6 +52,8 @@ private void buttonOK_Click(object sender, EventArgs e) { SaveSettings(); Close(); + if (isRestartNeeded) + restartAction(true); } } } diff --git a/Taskplay/Taskplay.csproj b/Taskplay/Taskplay.csproj index c6e8235..5d19468 100644 --- a/Taskplay/Taskplay.csproj +++ b/Taskplay/Taskplay.csproj @@ -116,10 +116,15 @@ + + + + + \ No newline at end of file From 727b9d446356b350b086164c210c595e88ff6d52 Mon Sep 17 00:00:00 2001 From: Sergey Suchkov Date: Sun, 3 Apr 2022 03:08:36 +0700 Subject: [PATCH 2/2] Add an option to hide Next and Previous buttons --- Taskplay/Program.cs | 15 ++++++++------- Taskplay/SettingsForm.Designer.cs | 13 +++++++++++++ Taskplay/SettingsForm.cs | 14 ++++++++++---- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/Taskplay/Program.cs b/Taskplay/Program.cs index 3ca5ba2..94cbf4f 100644 --- a/Taskplay/Program.cs +++ b/Taskplay/Program.cs @@ -8,7 +8,8 @@ static class Program { static bool _isMusicPlaying = false; // Bool to keep in check if the user is playing music - static bool IsDarkModeOn => GetDarkModeState(); + static bool IsDarkModeOn => GetSettingState("DarkMode"); + static bool AreChangeSongButtonsShown => GetSettingState("ShowChangeSongButtons"); static readonly Action restartAction = (b) => Application.Restart(); @@ -39,7 +40,7 @@ static void Main() //Setup nextIcon nextIcon.Icon = IsDarkModeOn ? Properties.Resources.ForwardDark : Properties.Resources.Forward; nextIcon.Text = "Next"; - nextIcon.Visible = true; + nextIcon.Visible = AreChangeSongButtonsShown; nextIcon.MouseClick += new MouseEventHandler(nextIcon_MouseClick); nextIcon.ContextMenu = contextMenu; //Setup playIcon @@ -51,7 +52,7 @@ static void Main() //Setup previousIcon previousIcon.Icon = IsDarkModeOn ? Properties.Resources.BackwardDark : Properties.Resources.Backward; previousIcon.Text = "Previous"; - previousIcon.Visible = true; + previousIcon.Visible = AreChangeSongButtonsShown; previousIcon.MouseClick += new MouseEventHandler(previousIcon_MouseClick); previousIcon.ContextMenu = contextMenu; @@ -112,7 +113,7 @@ private static void nextIcon_MouseClick(object sender, MouseEventArgs e) private static void contextMenuSettings_Click(object sender, System.EventArgs e) { //Show Settings form - var settingsForm = new SettingsForm(IsDarkModeOn, restartAction); + var settingsForm = new SettingsForm(IsDarkModeOn, AreChangeSongButtonsShown, restartAction); settingsForm.ShowDialog(); } @@ -122,15 +123,15 @@ private static void contextMenuExit_Click(object sender, System.EventArgs e) Application.Exit(); } - private static bool GetDarkModeState() + private static bool GetSettingState(string settingName) { var subKey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(@"SOFTWARE\Taskplay"); - var keyValue = subKey.GetValue("DarkMode"); + var keyValue = subKey.GetValue(settingName); if (keyValue == null) { - subKey.SetValue("DarkMode", 0); + subKey.SetValue(settingName, 0); return false; } diff --git a/Taskplay/SettingsForm.Designer.cs b/Taskplay/SettingsForm.Designer.cs index 6848285..59633fa 100644 --- a/Taskplay/SettingsForm.Designer.cs +++ b/Taskplay/SettingsForm.Designer.cs @@ -41,6 +41,7 @@ private void InitializeComponent() this.labelTaskplay = new System.Windows.Forms.Label(); this.buttonCancel = new System.Windows.Forms.Button(); this.buttonOK = new System.Windows.Forms.Button(); + this.checkBoxShowSongChangeButtons = new System.Windows.Forms.CheckBox(); this.tabControl.SuspendLayout(); this.tabPageGeneral.SuspendLayout(); this.tabPageAbout.SuspendLayout(); @@ -60,6 +61,7 @@ private void InitializeComponent() // // tabPageGeneral // + this.tabPageGeneral.Controls.Add(this.checkBoxShowSongChangeButtons); this.tabPageGeneral.Controls.Add(this.checkBoxDarkMode); this.tabPageGeneral.Controls.Add(this.checkBoxAutorun); this.tabPageGeneral.Location = new System.Drawing.Point(4, 32); @@ -177,6 +179,16 @@ private void InitializeComponent() this.buttonOK.UseVisualStyleBackColor = true; this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click); // + // checkBoxShowSongChangeButtons + // + this.checkBoxShowSongChangeButtons.AutoSize = true; + this.checkBoxShowSongChangeButtons.Location = new System.Drawing.Point(6, 72); + this.checkBoxShowSongChangeButtons.Name = "checkBoxShowSongChangeButtons"; + this.checkBoxShowSongChangeButtons.Size = new System.Drawing.Size(259, 27); + this.checkBoxShowSongChangeButtons.TabIndex = 4; + this.checkBoxShowSongChangeButtons.Text = "Show song changing buttons"; + this.checkBoxShowSongChangeButtons.UseVisualStyleBackColor = true; + // // SettingsForm // this.AcceptButton = this.buttonOK; @@ -218,5 +230,6 @@ private void InitializeComponent() private System.Windows.Forms.Button buttonCancel; private System.Windows.Forms.Button buttonOK; private System.Windows.Forms.CheckBox checkBoxDarkMode; + private System.Windows.Forms.CheckBox checkBoxShowSongChangeButtons; } } \ No newline at end of file diff --git a/Taskplay/SettingsForm.cs b/Taskplay/SettingsForm.cs index b25d138..9b595f8 100644 --- a/Taskplay/SettingsForm.cs +++ b/Taskplay/SettingsForm.cs @@ -6,16 +6,20 @@ namespace Taskplay public partial class SettingsForm : Form { Microsoft.Win32.RegistryKey autorun; + Microsoft.Win32.RegistryKey settings; private readonly bool isDarkModeOn; + private readonly bool areChangeSongButtonsShown; private readonly Action restartAction; private bool isRestartNeeded = false; - public SettingsForm(bool isDarkModeOn, Action restartAction) + public SettingsForm(bool isDarkModeOn, bool areChangeSongButtonsShown, Action restartAction) { InitializeComponent(); autorun = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true); + settings = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(@"SOFTWARE\Taskplay"); this.isDarkModeOn = isDarkModeOn; this.restartAction = restartAction; + this.areChangeSongButtonsShown = areChangeSongButtonsShown; } private void SettingsForm_Load(object sender, EventArgs e) @@ -23,6 +27,7 @@ private void SettingsForm_Load(object sender, EventArgs e) labelVersion.Text = String.Format("Version {0}", Application.ProductVersion); checkBoxAutorun.Checked = (autorun.GetValue("Taskplay") != null); checkBoxDarkMode.Checked = isDarkModeOn; + checkBoxShowSongChangeButtons.Checked = areChangeSongButtonsShown; } private void SaveSettings() @@ -32,10 +37,11 @@ private void SaveSettings() else autorun.DeleteValue("Taskplay", false); - var subKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Taskplay", true); - subKey.SetValue("DarkMode", checkBoxDarkMode.Checked ? 1 : 0); + settings.SetValue("DarkMode", checkBoxDarkMode.Checked ? 1 : 0); + settings.SetValue("ShowChangeSongButtons", checkBoxShowSongChangeButtons.Checked ? 1 : 0); - isRestartNeeded = checkBoxDarkMode.Checked != isDarkModeOn; + isRestartNeeded = checkBoxDarkMode.Checked != isDarkModeOn + || checkBoxShowSongChangeButtons.Checked != areChangeSongButtonsShown; } private void linkLabelGitHub_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)