diff --git a/MainForm.Designer.cs b/MainForm.Designer.cs index d004b27..4cfa287 100644 --- a/MainForm.Designer.cs +++ b/MainForm.Designer.cs @@ -64,21 +64,26 @@ private void InitializeComponent() label13 = new Label(); label11 = new Label(); tabPage2 = new TabPage(); + label15 = new Label(); linkLabel3 = new LinkLabel(); tabPage3 = new TabPage(); + checkUpdateBtn = new Button(); runMinimized = new CheckBox(); saveState = new CheckBox(); tabPage4 = new TabPage(); panel1 = new Panel(); - label15 = new Label(); + versionLabel = new Label(); label2 = new Label(); linkLabel4 = new LinkLabel(); tinyDrpcNotifyIcon = new NotifyIcon(components); tinyDrpcTrayIconContext = new ContextMenuStrip(components); + anUpdateIsAvailableToDownloadToolStripMenuItem = new ToolStripMenuItem(); showMainWindowToolStripMenuItem = new ToolStripMenuItem(); startDaemonContext = new ToolStripMenuItem(); toolStripSeparator1 = new ToolStripSeparator(); exitContext = new ToolStripMenuItem(); + updateAvailableBtn = new Button(); + checkUpdateOnStartup = new CheckBox(); tabControl1.SuspendLayout(); tabPage1.SuspendLayout(); tabPage2.SuspendLayout(); @@ -418,6 +423,7 @@ private void InitializeComponent() // // tabPage2 // + tabPage2.Controls.Add(label15); tabPage2.Controls.Add(linkLabel3); tabPage2.Controls.Add(label7); tabPage2.Controls.Add(label9); @@ -433,6 +439,15 @@ private void InitializeComponent() tabPage2.Text = "Image"; tabPage2.UseVisualStyleBackColor = true; // + // label15 + // + label15.AutoSize = true; + label15.Location = new Point(6, 291); + label15.Name = "label15"; + label15.Size = new Size(336, 30); + label15.TabIndex = 8; + label15.Text = "Note: Make sure you uploaded your image to the same app id \r\nyou provided in tab Configuration"; + // // linkLabel3 // linkLabel3.ActiveLinkColor = Color.Teal; @@ -449,6 +464,8 @@ private void InitializeComponent() // // tabPage3 // + tabPage3.Controls.Add(checkUpdateOnStartup); + tabPage3.Controls.Add(checkUpdateBtn); tabPage3.Controls.Add(runMinimized); tabPage3.Controls.Add(discordAppId); tabPage3.Controls.Add(linkLabel2); @@ -464,6 +481,16 @@ private void InitializeComponent() tabPage3.Text = "Configuration"; tabPage3.UseVisualStyleBackColor = true; // + // checkUpdateBtn + // + checkUpdateBtn.Location = new Point(6, 149); + checkUpdateBtn.Name = "checkUpdateBtn"; + checkUpdateBtn.Size = new Size(207, 23); + checkUpdateBtn.TabIndex = 11; + checkUpdateBtn.Text = "Check update now"; + checkUpdateBtn.UseVisualStyleBackColor = true; + checkUpdateBtn.Click += checkUpdateBtn_Click; + // // runMinimized // runMinimized.AutoSize = true; @@ -481,16 +508,16 @@ private void InitializeComponent() saveState.AutoSize = true; saveState.Location = new Point(6, 99); saveState.Name = "saveState"; - saveState.Size = new Size(203, 19); + saveState.Size = new Size(207, 19); saveState.TabIndex = 9; - saveState.Text = "Save running state for next statup"; + saveState.Text = "Save running state for next startup"; saveState.UseVisualStyleBackColor = true; saveState.CheckedChanged += saveState_CheckedChanged; // // tabPage4 // tabPage4.Controls.Add(panel1); - tabPage4.Controls.Add(label15); + tabPage4.Controls.Add(versionLabel); tabPage4.Controls.Add(label2); tabPage4.Controls.Add(linkLabel4); tabPage4.Location = new Point(4, 24); @@ -509,14 +536,14 @@ private void InitializeComponent() panel1.Size = new Size(100, 100); panel1.TabIndex = 0; // - // label15 + // versionLabel // - label15.AutoSize = true; - label15.Location = new Point(87, 177); - label15.Name = "label15"; - label15.Size = new Size(192, 15); - label15.TabIndex = 1; - label15.Text = "Version: 1.0 - powered by michioxd"; + versionLabel.AutoSize = true; + versionLabel.Location = new Point(87, 177); + versionLabel.Name = "versionLabel"; + versionLabel.Size = new Size(192, 15); + versionLabel.TabIndex = 1; + versionLabel.Text = "Version: 1.1 - powered by michioxd"; // // label2 // @@ -550,42 +577,81 @@ private void InitializeComponent() // // tinyDrpcTrayIconContext // - tinyDrpcTrayIconContext.Items.AddRange(new ToolStripItem[] { showMainWindowToolStripMenuItem, startDaemonContext, toolStripSeparator1, exitContext }); + tinyDrpcTrayIconContext.Items.AddRange(new ToolStripItem[] { anUpdateIsAvailableToDownloadToolStripMenuItem, showMainWindowToolStripMenuItem, startDaemonContext, toolStripSeparator1, exitContext }); tinyDrpcTrayIconContext.Name = "tinyDrpcTrayIconContext"; - tinyDrpcTrayIconContext.Size = new Size(181, 76); + tinyDrpcTrayIconContext.Size = new Size(266, 98); + // + // anUpdateIsAvailableToDownloadToolStripMenuItem + // + anUpdateIsAvailableToDownloadToolStripMenuItem.Font = new Font("Segoe UI", 9F, FontStyle.Bold, GraphicsUnit.Point, 0); + anUpdateIsAvailableToDownloadToolStripMenuItem.Image = Properties.Resources.update_drivers; + anUpdateIsAvailableToDownloadToolStripMenuItem.Name = "anUpdateIsAvailableToDownloadToolStripMenuItem"; + anUpdateIsAvailableToDownloadToolStripMenuItem.Size = new Size(265, 22); + anUpdateIsAvailableToDownloadToolStripMenuItem.Text = "An update is available to download"; + anUpdateIsAvailableToDownloadToolStripMenuItem.Visible = false; // // showMainWindowToolStripMenuItem // + showMainWindowToolStripMenuItem.Image = Properties.Resources.dialog_more; showMainWindowToolStripMenuItem.Name = "showMainWindowToolStripMenuItem"; - showMainWindowToolStripMenuItem.Size = new Size(180, 22); + showMainWindowToolStripMenuItem.Size = new Size(265, 22); showMainWindowToolStripMenuItem.Text = "Show Main Window"; showMainWindowToolStripMenuItem.Click += showMainWindowToolStripMenuItem_Click; // // startDaemonContext // + startDaemonContext.Image = Properties.Resources.lightning; startDaemonContext.Name = "startDaemonContext"; - startDaemonContext.Size = new Size(180, 22); + startDaemonContext.Size = new Size(265, 22); startDaemonContext.Text = "Start daemon"; startDaemonContext.Click += startDaemonContext_Click; // // toolStripSeparator1 // toolStripSeparator1.Name = "toolStripSeparator1"; - toolStripSeparator1.Size = new Size(177, 6); + toolStripSeparator1.Size = new Size(262, 6); // // exitContext // + exitContext.Image = Properties.Resources.dialog_close; exitContext.Name = "exitContext"; - exitContext.Size = new Size(180, 22); + exitContext.Size = new Size(265, 22); exitContext.Text = "Quit TinyDRPC"; exitContext.Click += exitContext_Click; // + // updateAvailableBtn + // + updateAvailableBtn.AccessibleDescription = "An update is available to download."; + updateAvailableBtn.Image = Properties.Resources.update_drivers; + updateAvailableBtn.ImageAlign = ContentAlignment.MiddleLeft; + updateAvailableBtn.Location = new Point(273, 12); + updateAvailableBtn.Name = "updateAvailableBtn"; + updateAvailableBtn.Size = new Size(120, 25); + updateAvailableBtn.TabIndex = 12; + updateAvailableBtn.Text = " Update available"; + updateAvailableBtn.UseVisualStyleBackColor = true; + updateAvailableBtn.Visible = false; + // + // checkUpdateOnStartup + // + checkUpdateOnStartup.AutoSize = true; + checkUpdateOnStartup.Checked = true; + checkUpdateOnStartup.CheckState = CheckState.Checked; + checkUpdateOnStartup.Location = new Point(6, 124); + checkUpdateOnStartup.Name = "checkUpdateOnStartup"; + checkUpdateOnStartup.Size = new Size(156, 19); + checkUpdateOnStartup.TabIndex = 12; + checkUpdateOnStartup.Text = "Check update on startup"; + checkUpdateOnStartup.UseVisualStyleBackColor = true; + checkUpdateOnStartup.CheckedChanged += checkUpdateOnStartup_CheckedChanged; + // // MainForm // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; BackColor = SystemColors.Window; ClientSize = new Size(404, 513); + Controls.Add(updateAvailableBtn); Controls.Add(tabControl1); Controls.Add(status); Controls.Add(label10); @@ -654,7 +720,7 @@ private void InitializeComponent() private TabPage tabPage4; private LinkLabel linkLabel3; private Panel panel1; - private Label label15; + private Label versionLabel; private Label label2; private LinkLabel linkLabel4; private NotifyIcon tinyDrpcNotifyIcon; @@ -665,5 +731,10 @@ private void InitializeComponent() private ToolStripMenuItem showMainWindowToolStripMenuItem; private CheckBox saveState; private CheckBox runMinimized; + private Button updateAvailableBtn; + private ToolStripMenuItem anUpdateIsAvailableToDownloadToolStripMenuItem; + private Label label15; + private Button checkUpdateBtn; + private CheckBox checkUpdateOnStartup; } } diff --git a/MainForm.cs b/MainForm.cs index b6ee200..aa79fb9 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -3,13 +3,13 @@ using TinyDRPC.Utils; using BlueMystic; using Microsoft.Win32; -using System.Windows.Forms; +using Newtonsoft.Json; namespace TinyDRPC { public partial class MainForm : Form { - + public string CurrentVersion = "1.1"; private DiscordRpcClient? drpc; public MainForm() @@ -17,12 +17,83 @@ public MainForm() InitializeComponent(); } + private class VersionInfo + { + [JsonProperty("latestVersion")] + public string LatestVersion { get; set; } + + [JsonProperty("download")] + public string Download { get; set; } + } + private bool ValidateUrl(string url) { return Uri.TryCreate(url, UriKind.Absolute, out Uri uriResult) && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps); } + private void CheckForUpdate() + { + checkUpdateBtn.Enabled = false; + checkUpdateBtn.Text = "Checking..."; + _ = this.Invoke(new MethodInvoker(async delegate () + { + using var httpClient = new HttpClient(new HttpClientHandler { AllowAutoRedirect = true }); + try + { + string jsonContent = await httpClient.GetStringAsync("https://michioxd.github.io/TinyDRPC/fetchVersion.json"); + var versionInfo = JsonConvert.DeserializeObject(jsonContent); + checkUpdateBtn.Text = "Check update now"; + checkUpdateBtn.Enabled = true; + + if (versionInfo != null) + { + if (string.Compare(CurrentVersion, versionInfo.LatestVersion) < 0) + { + updateAvailableBtn.Visible = true; + updateAvailableBtn.Click += (object sender, EventArgs e) => + { + DialogResult result = MessageBox.Show($"A newer version ({versionInfo.LatestVersion}) is available for download. Do you want to go to browser and download it?", "TinyDRPC Update Available", MessageBoxButtons.YesNo, MessageBoxIcon.Information); + if (result == DialogResult.Yes) + { + new OpenBrowser(versionInfo.Download); + } + }; + anUpdateIsAvailableToDownloadToolStripMenuItem.Visible = true; + anUpdateIsAvailableToDownloadToolStripMenuItem.Click += (object sender, EventArgs e) => + { + DialogResult result = MessageBox.Show($"A newer version ({versionInfo.LatestVersion}) is available for download. Do you want to go to browser and download it?", "TinyDRPC Update Available", MessageBoxButtons.YesNo, MessageBoxIcon.Information); + if (result == DialogResult.Yes) + { + new OpenBrowser(versionInfo.Download); + } + }; + if (tinyDrpcNotifyIcon.Visible == true) + { + tinyDrpcNotifyIcon.BalloonTipIcon = ToolTipIcon.Info; + tinyDrpcNotifyIcon.BalloonTipText = $"A newer version ({versionInfo.LatestVersion}) is available for download. Click this notification to download now!"; + tinyDrpcNotifyIcon.BalloonTipTitle = "An update of TinyRDPC is available to download"; + tinyDrpcNotifyIcon.BalloonTipClicked += (object sender, EventArgs e) => + { + DialogResult result = MessageBox.Show($"A newer version ({versionInfo.LatestVersion}) is available for download. Do you want to go to browser and download it?", "TinyDRPC Update Available", MessageBoxButtons.YesNo, MessageBoxIcon.Information); + if (result == DialogResult.Yes) + { + new OpenBrowser(versionInfo.Download); + } + }; + tinyDrpcNotifyIcon.ShowBalloonTip(5000); + } + } + } + } + catch (HttpRequestException ex) + { + checkUpdateBtn.Text = "Got error during check update"; + checkUpdateBtn.Enabled = true; + } + })); + } + private void MainForm_Load(object sender, EventArgs e) { ConfigurationManager configManager = new ConfigurationManager(); @@ -43,8 +114,10 @@ private void MainForm_Load(object sender, EventArgs e) runOnStartup.CheckState = config.runOnStartup ? CheckState.Checked : CheckState.Unchecked; saveState.CheckState = config.saveRunningState ? CheckState.Checked : CheckState.Unchecked; runMinimized.CheckState = config.runMinimized ? CheckState.Checked : CheckState.Unchecked; + checkUpdateOnStartup.CheckState = config.checkUpdateOnStartup ? CheckState.Checked : CheckState.Unchecked; runMinimized.Enabled = runOnStartup.Checked; + versionLabel.Text = $"Version: {CurrentVersion} - powered by michioxd"; if (config.runMinimized && config.runOnStartup) { @@ -58,6 +131,11 @@ private void MainForm_Load(object sender, EventArgs e) }), null, 50, Timeout.Infinite); } + if (checkUpdateOnStartup.Checked) + { + CheckForUpdate(); + } + if (config.saveRunningState == true && config.lastStateIsRunning == true) { prepareDaemon(); @@ -223,6 +301,15 @@ private void runMinimized_CheckedChanged(object sender, EventArgs e) configManager.SaveConfiguration(config); } + private void checkUpdateOnStartup_CheckedChanged(object sender, EventArgs e) + { + ConfigurationManager configManager = new ConfigurationManager(); + TinyDRPC.Utils.Configuration config = configManager.LoadConfiguration(); + + config.checkUpdateOnStartup = checkUpdateOnStartup.Checked; + configManager.SaveConfiguration(config); + } + private void changeLastRunningState(Boolean state) { ConfigurationManager configManager = new ConfigurationManager(); @@ -382,7 +469,7 @@ private void MainFormOnResize(object sender, EventArgs e) tinyDrpcNotifyIcon.Visible = true; ConfigurationManager configManager = new ConfigurationManager(); TinyDRPC.Utils.Configuration config = configManager.LoadConfiguration(); - if(config.minimizedAtFirst == false) + if (config.minimizedAtFirst == false) { tinyDrpcNotifyIcon.BalloonTipIcon = ToolTipIcon.Info; tinyDrpcNotifyIcon.BalloonTipText = "TinyDRPC is minimized in the system tray; to open the main window, double-click on this icon; you only see this tip once. Enjoy!"; @@ -427,5 +514,12 @@ private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs { new OpenBrowser("https://github.com/michioxd/TinyDRPC/tree/master?tab=readme-ov-file#how-to-get-image-key"); } + + private void checkUpdateBtn_Click(object sender, EventArgs e) + { + CheckForUpdate(); + } + + } } diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs index 5608cfa..060c465 100644 --- a/Properties/Resources.Designer.cs +++ b/Properties/Resources.Designer.cs @@ -60,6 +60,36 @@ internal Resources() { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap dialog_close { + get { + object obj = ResourceManager.GetObject("dialog_close", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap dialog_more { + get { + object obj = ResourceManager.GetObject("dialog_more", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap lightning { + get { + object obj = ResourceManager.GetObject("lightning", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// @@ -69,5 +99,15 @@ internal static System.Drawing.Bitmap tinydrpc_100x100 { return ((System.Drawing.Bitmap)(obj)); } } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap update_drivers { + get { + object obj = ResourceManager.GetObject("update_drivers", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } } } diff --git a/Properties/Resources.resx b/Properties/Resources.resx index 45ff40a..d789876 100644 --- a/Properties/Resources.resx +++ b/Properties/Resources.resx @@ -118,7 +118,19 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + ..\Resources\dialog-close.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\dialog-more.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\lightning.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\Resources\tinydrpc_100x100.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\update_drivers.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file diff --git a/Resources/dialog-close.png b/Resources/dialog-close.png new file mode 100644 index 0000000..5efd283 Binary files /dev/null and b/Resources/dialog-close.png differ diff --git a/Resources/dialog-more.png b/Resources/dialog-more.png new file mode 100644 index 0000000..e601ec5 Binary files /dev/null and b/Resources/dialog-more.png differ diff --git a/Resources/lightning.png b/Resources/lightning.png new file mode 100644 index 0000000..6dbe6e3 Binary files /dev/null and b/Resources/lightning.png differ diff --git a/Resources/update_drivers.png b/Resources/update_drivers.png new file mode 100644 index 0000000..ca3dd73 Binary files /dev/null and b/Resources/update_drivers.png differ diff --git a/TinyDRPC.csproj b/TinyDRPC.csproj index c90b6cf..38d428a 100644 --- a/TinyDRPC.csproj +++ b/TinyDRPC.csproj @@ -16,6 +16,7 @@ tinydrpc_100x100.png https://github.com/michioxd/TinyDRPC README.md + 1.1 diff --git a/TinyDRPC.iss b/TinyDRPC.iss index e342d2c..581692d 100644 --- a/TinyDRPC.iss +++ b/TinyDRPC.iss @@ -5,7 +5,7 @@ #include "CodeDependencies.iss" #define MyAppName "TinyDRPC" -#define MyAppVersion "1.0" +#define MyAppVersion "1.1" #define MyAppPublisher "michioxd" #define MyAppURL "https://github.com/michioxd/TinyDRPC" #define MyAppExeName "TinyDRPC.exe" diff --git a/Utils/Configuration.cs b/Utils/Configuration.cs index 2e577f5..f85cba7 100644 --- a/Utils/Configuration.cs +++ b/Utils/Configuration.cs @@ -22,6 +22,7 @@ public class Configuration public bool lastStateIsRunning { get; set; } public bool runMinimized { get; set; } public bool minimizedAtFirst { get; set; } + public bool checkUpdateOnStartup { get; set; } } public class ConfigurationManager @@ -77,6 +78,7 @@ public void SaveConfiguration(Configuration config) writer.WriteLine($"lastStateIsRunning={(config.lastStateIsRunning ? "1" : "0")}"); writer.WriteLine($"runMinimized={(config.runMinimized ? "1" : "0")}"); writer.WriteLine($"minimizedAtFirst={(config.minimizedAtFirst ? "1" : "0")}"); + writer.WriteLine($"checkUpdateOnStartup={(config.checkUpdateOnStartup ? "1" : "0")}"); } } @@ -135,6 +137,9 @@ private void SetProperty(Configuration config, string key, string value) case "minimizedAtFirst": config.minimizedAtFirst = (value == "1") ? true : false; break; + case "checkUpdateOnStartup": + config.checkUpdateOnStartup = (value == "1") ? true : false; + break; default: throw new Exception($"Unknown key: {key}"); } @@ -160,7 +165,8 @@ private Configuration CreateDefaultConfiguration() saveRunningState = true, lastStateIsRunning = false, runMinimized = true, - minimizedAtFirst = false + minimizedAtFirst = false, + checkUpdateOnStartup = true }; SaveConfiguration(config); return config;