Skip to content

Commit

Permalink
Merge pull request #2825 from X9VoiD/fix-updater-2
Browse files Browse the repository at this point in the history
Actually prevent multiple invocations to Updater's Install button
  • Loading branch information
X9VoiD committed Jul 3, 2023
2 parents 334d22e + 9fc97db commit 55c3dc5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
6 changes: 5 additions & 1 deletion OpenTabletDriver.UX/Windows/Updater/UpdaterWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Eto.Drawing;
using Eto.Forms;
using OpenTabletDriver.Desktop.Interop;
using OpenTabletDriver.Interop;
using OpenTabletDriver.Plugin;
using OpenTabletDriver.UX.Controls;
Expand Down Expand Up @@ -36,6 +36,7 @@ public UpdaterWindow()
_ = InitializeAsync();
}

private int _isUpdateRequested;
private TaskCompletionSource<bool> _updateAvailable = new();
public Task<bool> HasUpdates() => _updateAvailable.Task;

Expand Down Expand Up @@ -74,6 +75,9 @@ private async Task InitializeAsync()

private void Update(object sender, EventArgs e) => Application.Instance.AsyncInvoke(async () =>
{
if (Interlocked.Exchange(ref _isUpdateRequested, 1) != 0)
return;
// Disallow multiple invocations
(sender as Control)!.Enabled = false;
Expand Down
14 changes: 9 additions & 5 deletions OpenTabletDriver.UX/Windows/WindowSingleton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@ namespace OpenTabletDriver.UX.Windows
{
public class WindowSingleton<T> where T : Window, new()
{
private readonly object sync = new();
private T window;

public T GetWindow()
{
if (window == null)
lock (sync)
{
window = new T();
window.Closed += HandleWindowClosed;
}
if (window == null)
{
window = new T();
window.Closed += HandleWindowClosed;
}

return window;
return window;
}
}

public void Show()
Expand Down

0 comments on commit 55c3dc5

Please sign in to comment.