Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actually prevent multiple invocations to Updater's Install button #2825

Merged
merged 2 commits into from Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion OpenTabletDriver.UX/Windows/Updater/UpdaterWindow.cs
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
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