Skip to content

Commit

Permalink
Move actual logic to event for quicker startup.
Browse files Browse the repository at this point in the history
  • Loading branch information
gmemstr committed Nov 28, 2021
1 parent f3efb79 commit 1064ccb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
21 changes: 12 additions & 9 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@ public partial class MainWindow : Window
public MainWindow()
{
InitializeComponent();
ContentRendered += MainWindow_ContentRendered;
}

// Open url on button click.
private void Button_Click(object sender, RoutedEventArgs e) {
Button button = (Button)sender;
string url = (string)button.Tag;
Process.Start(new ProcessStartInfo(url) { UseShellExecute = true });
}

public void MainWindow_ContentRendered(object sender, EventArgs e) {
(bool, string) result = Nvidia.API.IsNewDriver();
Grid appGrid = (Grid)this.FindName("appGrid");

Expand All @@ -28,7 +38,7 @@ public MainWindow()
gpuName.Text += $" ({guessedGpu})";


if (result.Item1) {
if (!result.Item1) {
// Show new driver available in application window.
textBlock.Text = "New NVIDIA driver found!";
// Create a button with a link.
Expand All @@ -45,16 +55,9 @@ public MainWindow()
Grid.SetColumn(button, 1);
Grid.SetRow(button, 2);
} else {
textBlock.Text = "You're up to date!";
textBlock.Text = "You're up to date!\n(or unknown GPU)";
}
}

// Open url on button click.
private void Button_Click(object sender, RoutedEventArgs e) {
Button button = (Button)sender;
string url = (string)button.Tag;
Process.Start(new ProcessStartInfo(url) { UseShellExecute = true });
}

}
}
3 changes: 3 additions & 0 deletions Nvidia/NvidiaWeb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public static (bool, string) IsNewDriver() {
// Fetch downloadUrl.
HttpResponseMessage response = client.GetAsync(downloadUrl).Result;
string downloadPage = response.Content.ReadAsStringAsync().Result;
if (downloadPage.Contains("No certified downloads were found for this configuration")) {
return (false, "");
}
var web = new HtmlWeb();
var doc = web.Load(downloadPage);

Expand Down

0 comments on commit 1064ccb

Please sign in to comment.