From 78bc9e4f61aaf478518f17f0f4d5f6c61bb818c2 Mon Sep 17 00:00:00 2001 From: GregF Date: Sat, 7 Dec 2024 18:19:24 +0000 Subject: [PATCH] Add logic for detecting a blocked website --- .../Services/PluginDownloadService.cs | 1 - .../ViewModel/Windows/MainWindowViewModel.cs | 18 ++++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Saradomin/Infrastructure/Services/PluginDownloadService.cs b/Saradomin/Infrastructure/Services/PluginDownloadService.cs index 8111684..551bda9 100644 --- a/Saradomin/Infrastructure/Services/PluginDownloadService.cs +++ b/Saradomin/Infrastructure/Services/PluginDownloadService.cs @@ -106,7 +106,6 @@ namespace Saradomin.Infrastructure.Services } catch (HttpRequestException e) { - NotificationBox.DisplayNotification("Error!", $"Plugin service unavailable: {e.Message}"); return new List(); } } diff --git a/Saradomin/ViewModel/Windows/MainWindowViewModel.cs b/Saradomin/ViewModel/Windows/MainWindowViewModel.cs index 201a5c3..49c29df 100644 --- a/Saradomin/ViewModel/Windows/MainWindowViewModel.cs +++ b/Saradomin/ViewModel/Windows/MainWindowViewModel.cs @@ -70,13 +70,20 @@ namespace Saradomin.ViewModel.Windows await ExecuteLaunchSequence(); } + private HtmlNode ConnectionErrorMessage(HtmlDocument doc, string msg) + { + var failMessage = "

Not Available


This content is unavailable, likely due to a "; + doc.LoadHtml(failMessage + msg + ""); + return doc.DocumentNode; + } + public async void MainViewLoaded(MainViewLoadedMessage _) { using (var httpClient = new HttpClient()) { HtmlNode node; var doc = new HtmlDocument(); - + try { var response = @@ -86,10 +93,13 @@ namespace Saradomin.ViewModel.Windows } catch (HttpRequestException) { - doc.LoadHtml("

Not Available


This content is unavailable, likely due to a lack of an internet connection."); - node = doc.DocumentNode; + node = ConnectionErrorMessage(doc, "lack of an internet connection."); + } + if (node == null) + { + // If 2009scape is blocked + node = ConnectionErrorMessage(doc, "blocked internet connection. The stable server should still work."); } - var renderer = new HtmlRenderer(node); HtmlInlines = renderer.Render(); }