Skip to content

Commit

Permalink
Fixed reupload timer not ticking properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Plenyx committed Aug 16, 2024
1 parent 932a328 commit 0238f49
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 47 deletions.
14 changes: 0 additions & 14 deletions Forms/FormMain.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 18 additions & 23 deletions Forms/FormMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,18 @@ private int LastLogPullCounter
{ "%channel%", "" },
};
private bool bypassCloseToTray = false;
private readonly System.Timers.Timer timerFailedLogsReupload = new()
{
Enabled = false,
Interval = 900000,
AutoReset = false,
};
private readonly System.Timers.Timer timerCheckUpdate = new()
{
Enabled = false,
Interval = 5400000,
AutoReset = false,
};

// constants
private const int minFileSize = 8192;
Expand Down Expand Up @@ -360,6 +372,8 @@ internal FormMain()
logSessionLink.checkBoxOnlySuccess.CheckedChanged += logSessionLink.CheckBoxOnlySuccess_CheckedChanged;
logSessionLink.checkBoxSaveToFile.CheckedChanged += logSessionLink.CheckBoxSaveToFile_CheckedChanged;
discordWebhooksLink.checkBoxShortenThousands.CheckedChanged += discordWebhooksLink.CheckBoxShortenThousands_CheckedChanged;
timerFailedLogsReupload.Elapsed += TimerFailedLogsReupload_Elapsed;
timerCheckUpdate.Elapsed += TimerCheckUpdate_Elapsed;
ApplicationSettings.Current.Save();
}
catch (Exception e)
Expand Down Expand Up @@ -558,7 +572,6 @@ protected async Task NewReleaseCheckAsync(bool appStartup = false, bool quietFai
{
AddToText(">>> Could not verify the version release.");
}
timerCheckUpdate.Enabled = true;
timerCheckUpdate.Start();
return;
}
Expand All @@ -568,7 +581,6 @@ protected async Task NewReleaseCheckAsync(bool appStartup = false, bool quietFai
{
AddToText(">>> The uploader is up to date.");
}
timerCheckUpdate.Enabled = true;
timerCheckUpdate.Start();
return;
}
Expand Down Expand Up @@ -947,9 +959,7 @@ internal async Task HandleQuickLogUploadRetry(string file, Dictionary<string, st
AddToText($">:> Upload retry failed 4 times for {Path.GetFileName(file)}, will try again during log reupload timer.");
LogReuploader.FailedLogs.Add(file);
LogReuploader.SaveFailedLogs();
timerFailedLogsReupload.Enabled = true;
timerFailedLogsReupload.Stop();
timerFailedLogsReupload.Start();
EnsureReuploadTimerStart();
}
else
{
Expand Down Expand Up @@ -1679,16 +1689,14 @@ private void ButtonReset_Click(object sender, EventArgs e)
ExitApp();
}

private void TimerCheckUpdate_Tick(object sender, EventArgs e)
private void TimerCheckUpdate_Elapsed(object sender, EventArgs e)
{
timerCheckUpdate.Stop();
timerCheckUpdate.Enabled = false;
_ = NewReleaseCheckAsync(false, true);
}

private async void TimerFailedLogsReupload_Tick(object sender, EventArgs e)
private void TimerFailedLogsReupload_Elapsed(object sender, EventArgs e)
{
await HandleReuploadTimerStop();
_ = HandleLogReuploads();
}

private void EnsureReuploadTimerStart()
Expand All @@ -1697,22 +1705,9 @@ private void EnsureReuploadTimerStart()
{
return;
}
timerFailedLogsReupload.Enabled = true;
timerFailedLogsReupload.Stop();
timerFailedLogsReupload.Start();
}

private async Task HandleReuploadTimerStop()
{
if (!timerFailedLogsReupload.Enabled)
{
return;
}
timerFailedLogsReupload.Enabled = false;
timerFailedLogsReupload.Stop();
await HandleLogReuploads();
}

private async Task HandleLogReuploads()
{
if (LogReuploader.FailedLogs.Count == 0)
Expand Down
14 changes: 4 additions & 10 deletions Forms/FormMain.resx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Microsoft ResX Schema
Version 2.0
Expand Down Expand Up @@ -48,7 +48,7 @@
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
Expand Down Expand Up @@ -118,18 +118,12 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="notifyIconTray.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
<value>15, 29</value>
</metadata>
<metadata name="contextMenuStripIcon.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>165, 25</value>
</metadata>
<metadata name="timerCheckUpdate.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>370, 25</value>
</metadata>
<metadata name="toolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>553, 25</value>
</metadata>
<metadata name="timerFailedLogsReupload.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>661, 25</value>
<value>373, 28</value>
</metadata>
</root>

0 comments on commit 0238f49

Please sign in to comment.