Skip to content

Commit

Permalink
DriverChecker: Fix download URL sometimes not opening
Browse files Browse the repository at this point in the history
  • Loading branch information
mat1jaczyyy committed Feb 8, 2024
1 parent f0b0139 commit 1f15487
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
11 changes: 5 additions & 6 deletions Apollo/Helpers/DriverChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,13 @@ static MessageWindow CreateDriverError(bool IsOldVersion) {
"computer.\n\n"
) +
"Please install at least version 2.22.0.10 of the driver before using Apollo Studio.",
new string[] {"Download Driver", "OK"}
new string[] {"Download Driver", "OK"},
result => {
if (result == "Download Driver")
App.URL("https://github.com/mat1jaczyyy/apollo-studio/raw/master/Publish/novationusbmidi.exe");
}
);

ret.Completed.Task.ContinueWith(result => {
if (result.Result == "Download Driver")
App.URL("https://github.com/mat1jaczyyy/apollo-studio/raw/master/Publish/novationusbmidi.exe");
});

return ret;
}

Expand Down
14 changes: 11 additions & 3 deletions Apollo/Windows/MessageWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ public class MessageWindow: Window {

Button Default;

public Action<string> OnComplete;
public TaskCompletionSource<string> Completed = new();

void UpdateTopmost(bool value) => Topmost = value;

public MessageWindow() => new InvalidOperationException();

public MessageWindow(string message, string[] options = null) {
public MessageWindow(string message, string[] options = null, Action<string> oncomplete = null) {
InitializeComponent();
#if DEBUG
this.AttachDevTools();
Expand All @@ -44,6 +45,8 @@ public MessageWindow(string message, string[] options = null) {
Buttons.Children.Add(btn);
return btn;
}).ToList().Last(); // ToList required otherwise Last will only resolve Select on the last item

OnComplete = oncomplete;
}

void Loaded(object sender, EventArgs e) {
Expand All @@ -56,7 +59,7 @@ void Loaded(object sender, EventArgs e) {

void Unloaded(object sender, CancelEventArgs e) {
if (!Completed.Task.IsCompleted)
Completed.SetResult((string)Default.Content);
Result((string)Default.Content);

Preferences.AlwaysOnTopChanged -= UpdateTopmost;

Expand All @@ -68,8 +71,13 @@ void Unloaded(object sender, CancelEventArgs e) {
this.Content = null;
}

void Result(string result) {
OnComplete?.Invoke(result);
Completed.SetResult(result);
}

void Complete(object sender, EventArgs e) {
Completed.SetResult((string)((Button)sender).Content);
Result((string)((Button)sender).Content);
Close();
}

Expand Down

0 comments on commit 1f15487

Please sign in to comment.