Added CheckUpdateAsync method

This commit is contained in:
Jaex 2022-01-13 02:59:56 +03:00
parent ac77d58b5b
commit 4210b7390e
5 changed files with 31 additions and 15 deletions

View file

@ -25,6 +25,7 @@ You should have received a copy of the GNU General Public License
using System;
using System.Net;
using System.Threading.Tasks;
using System.Web;
using System.Windows.Forms;
@ -84,6 +85,11 @@ public void RefreshStatus()
public abstract void CheckUpdate();
public Task CheckUpdateAsync()
{
return Task.Run(CheckUpdate);
}
public void DownloadUpdate()
{
DebugHelper.WriteLine("Updating ShareX from version {0} to {1}", CurrentVersion, LatestVersion);

View file

@ -24,7 +24,7 @@ You should have received a copy of the GNU General Public License
#endregion License Information (GPL v3)
using ShareX.HelpersLib.Properties;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ShareX.HelpersLib
@ -40,7 +40,7 @@ public UpdateCheckerLabel()
InitializeComponent();
}
public void CheckUpdate(UpdateChecker updateChecker)
public async Task CheckUpdate(UpdateChecker updateChecker)
{
if (!IsBusy)
{
@ -54,9 +54,7 @@ public void CheckUpdate(UpdateChecker updateChecker)
pbLoading.Visible = true;
lblCheckingUpdates.Visible = true;
Thread thread = new Thread(CheckingUpdate);
thread.IsBackground = true;
thread.Start();
await CheckingUpdate();
}
}
@ -72,9 +70,9 @@ public void UpdateLoadingImage()
}
}
private void CheckingUpdate()
private async Task CheckingUpdate()
{
updateChecker.CheckUpdate();
await updateChecker.CheckUpdateAsync();
try
{

View file

@ -34,6 +34,7 @@ namespace ShareX
public partial class AboutForm : Form
{
private EasterEggAboutAnimation easterEgg;
private bool checkUpdate;
public AboutForm()
{
@ -54,9 +55,7 @@ public AboutForm()
if (!SystemOptions.DisableUpdateCheck)
{
uclUpdate.UpdateLoadingImage();
UpdateChecker updateChecker = Program.UpdateManager.CreateUpdateChecker();
uclUpdate.CheckUpdate(updateChecker);
checkUpdate = true;
}
else
{
@ -119,9 +118,15 @@ public AboutForm()
easterEgg = new EasterEggAboutAnimation(cLogo, this);
}
private void AboutForm_Shown(object sender, EventArgs e)
private async void AboutForm_Shown(object sender, EventArgs e)
{
this.ForceActivate();
if (checkUpdate)
{
UpdateChecker updateChecker = Program.UpdateManager.CreateUpdateChecker();
await uclUpdate.CheckUpdate(updateChecker);
}
}
private void pbLogo_MouseDown(object sender, MouseEventArgs e)

View file

@ -448,12 +448,19 @@ private void cbCheckPreReleaseUpdates_CheckedChanged(object sender, EventArgs e)
Program.Settings.CheckPreReleaseUpdates = cbCheckPreReleaseUpdates.Checked;
}
private void btnCheckDevBuild_Click(object sender, EventArgs e)
private async void btnCheckDevBuild_Click(object sender, EventArgs e)
{
btnCheckDevBuild.Enabled = false;
if (MessageBox.Show(Resources.ApplicationSettingsForm_btnCheckDevBuild_Click_DevBuilds_Warning, "ShareX",
MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
{
TaskHelpers.DownloadAppVeyorBuild();
await TaskHelpers.DownloadAppVeyorBuild();
}
if (!IsDisposed)
{
btnCheckDevBuild.Enabled = true;
}
}

View file

@ -1775,7 +1775,7 @@ public static void ToggleActionsToolbar()
}
}
public static void DownloadAppVeyorBuild()
public static async Task DownloadAppVeyorBuild()
{
AppVeyorUpdateChecker updateChecker = new AppVeyorUpdateChecker()
{
@ -1785,7 +1785,7 @@ public static void DownloadAppVeyorBuild()
Branch = "develop"
};
updateChecker.CheckUpdate();
await updateChecker.CheckUpdateAsync();
if (updateChecker.Status == UpdateStatus.UpdateAvailable)
{