Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

Commit bf35c06

Browse files
committed
1.1
1 parent fbc5376 commit bf35c06

File tree

11 files changed

+247
-23
lines changed

11 files changed

+247
-23
lines changed

MainForm.Designer.cs

Lines changed: 89 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MainForm.cs

Lines changed: 97 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,97 @@
33
using TinyDRPC.Utils;
44
using BlueMystic;
55
using Microsoft.Win32;
6-
using System.Windows.Forms;
6+
using Newtonsoft.Json;
77

88
namespace TinyDRPC
99
{
1010
public partial class MainForm : Form
1111
{
12-
12+
public string CurrentVersion = "1.1";
1313
private DiscordRpcClient? drpc;
1414

1515
public MainForm()
1616
{
1717
InitializeComponent();
1818
}
1919

20+
private class VersionInfo
21+
{
22+
[JsonProperty("latestVersion")]
23+
public string LatestVersion { get; set; }
24+
25+
[JsonProperty("download")]
26+
public string Download { get; set; }
27+
}
28+
2029
private bool ValidateUrl(string url)
2130
{
2231
return Uri.TryCreate(url, UriKind.Absolute, out Uri uriResult)
2332
&& (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);
2433
}
2534

35+
private void CheckForUpdate()
36+
{
37+
checkUpdateBtn.Enabled = false;
38+
checkUpdateBtn.Text = "Checking...";
39+
_ = this.Invoke(new MethodInvoker(async delegate ()
40+
{
41+
using var httpClient = new HttpClient(new HttpClientHandler { AllowAutoRedirect = true });
42+
try
43+
{
44+
string jsonContent = await httpClient.GetStringAsync("https://michioxd.github.io/TinyDRPC/fetchVersion.json");
45+
var versionInfo = JsonConvert.DeserializeObject<VersionInfo>(jsonContent);
46+
checkUpdateBtn.Text = "Check update now";
47+
checkUpdateBtn.Enabled = true;
48+
49+
if (versionInfo != null)
50+
{
51+
if (string.Compare(CurrentVersion, versionInfo.LatestVersion) < 0)
52+
{
53+
updateAvailableBtn.Visible = true;
54+
updateAvailableBtn.Click += (object sender, EventArgs e) =>
55+
{
56+
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);
57+
if (result == DialogResult.Yes)
58+
{
59+
new OpenBrowser(versionInfo.Download);
60+
}
61+
};
62+
anUpdateIsAvailableToDownloadToolStripMenuItem.Visible = true;
63+
anUpdateIsAvailableToDownloadToolStripMenuItem.Click += (object sender, EventArgs e) =>
64+
{
65+
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);
66+
if (result == DialogResult.Yes)
67+
{
68+
new OpenBrowser(versionInfo.Download);
69+
}
70+
};
71+
if (tinyDrpcNotifyIcon.Visible == true)
72+
{
73+
tinyDrpcNotifyIcon.BalloonTipIcon = ToolTipIcon.Info;
74+
tinyDrpcNotifyIcon.BalloonTipText = $"A newer version ({versionInfo.LatestVersion}) is available for download. Click this notification to download now!";
75+
tinyDrpcNotifyIcon.BalloonTipTitle = "An update of TinyRDPC is available to download";
76+
tinyDrpcNotifyIcon.BalloonTipClicked += (object sender, EventArgs e) =>
77+
{
78+
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);
79+
if (result == DialogResult.Yes)
80+
{
81+
new OpenBrowser(versionInfo.Download);
82+
}
83+
};
84+
tinyDrpcNotifyIcon.ShowBalloonTip(5000);
85+
}
86+
}
87+
}
88+
}
89+
catch (HttpRequestException ex)
90+
{
91+
checkUpdateBtn.Text = "Got error during check update";
92+
checkUpdateBtn.Enabled = true;
93+
}
94+
}));
95+
}
96+
2697
private void MainForm_Load(object sender, EventArgs e)
2798
{
2899
ConfigurationManager configManager = new ConfigurationManager();
@@ -43,8 +114,10 @@ private void MainForm_Load(object sender, EventArgs e)
43114
runOnStartup.CheckState = config.runOnStartup ? CheckState.Checked : CheckState.Unchecked;
44115
saveState.CheckState = config.saveRunningState ? CheckState.Checked : CheckState.Unchecked;
45116
runMinimized.CheckState = config.runMinimized ? CheckState.Checked : CheckState.Unchecked;
117+
checkUpdateOnStartup.CheckState = config.checkUpdateOnStartup ? CheckState.Checked : CheckState.Unchecked;
46118

47119
runMinimized.Enabled = runOnStartup.Checked;
120+
versionLabel.Text = $"Version: {CurrentVersion} - powered by michioxd";
48121

49122
if (config.runMinimized && config.runOnStartup)
50123
{
@@ -58,6 +131,11 @@ private void MainForm_Load(object sender, EventArgs e)
58131
}), null, 50, Timeout.Infinite);
59132
}
60133

134+
if (checkUpdateOnStartup.Checked)
135+
{
136+
CheckForUpdate();
137+
}
138+
61139
if (config.saveRunningState == true && config.lastStateIsRunning == true)
62140
{
63141
prepareDaemon();
@@ -223,6 +301,15 @@ private void runMinimized_CheckedChanged(object sender, EventArgs e)
223301
configManager.SaveConfiguration(config);
224302
}
225303

304+
private void checkUpdateOnStartup_CheckedChanged(object sender, EventArgs e)
305+
{
306+
ConfigurationManager configManager = new ConfigurationManager();
307+
TinyDRPC.Utils.Configuration config = configManager.LoadConfiguration();
308+
309+
config.checkUpdateOnStartup = checkUpdateOnStartup.Checked;
310+
configManager.SaveConfiguration(config);
311+
}
312+
226313
private void changeLastRunningState(Boolean state)
227314
{
228315
ConfigurationManager configManager = new ConfigurationManager();
@@ -382,7 +469,7 @@ private void MainFormOnResize(object sender, EventArgs e)
382469
tinyDrpcNotifyIcon.Visible = true;
383470
ConfigurationManager configManager = new ConfigurationManager();
384471
TinyDRPC.Utils.Configuration config = configManager.LoadConfiguration();
385-
if(config.minimizedAtFirst == false)
472+
if (config.minimizedAtFirst == false)
386473
{
387474
tinyDrpcNotifyIcon.BalloonTipIcon = ToolTipIcon.Info;
388475
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
427514
{
428515
new OpenBrowser("https://github.com/michioxd/TinyDRPC/tree/master?tab=readme-ov-file#how-to-get-image-key");
429516
}
517+
518+
private void checkUpdateBtn_Click(object sender, EventArgs e)
519+
{
520+
CheckForUpdate();
521+
}
522+
523+
430524
}
431525
}

0 commit comments

Comments
 (0)