From cf41bc37f6d37eccf00367de90aa70fcaf31007d Mon Sep 17 00:00:00 2001 From: Guerra24 Date: Sun, 10 Nov 2024 14:52:23 -0600 Subject: [PATCH] Better fit to content webview --- LRReader.Shared/LRReader.Shared.csproj | 3 +- LRReader.Shared/Services/Api.cs | 3 +- LRReader.Shared/Services/Updates.cs | 3 +- LRReader.Shared/packages.lock.json | 20 ------- LRReader.UWP/Extensions/Extensions.cs | 53 +++++++++++++++++-- LRReader.UWP/LRReader.UWP.csproj | 4 +- .../Views/Dialogs/MarkdownDialog.xaml | 4 +- .../Views/Dialogs/MarkdownDialog.xaml.cs | 2 +- LRReader.UWP/packages.lock.json | 10 ---- 9 files changed, 56 insertions(+), 46 deletions(-) diff --git a/LRReader.Shared/LRReader.Shared.csproj b/LRReader.Shared/LRReader.Shared.csproj index e3de92f..6aa52b7 100644 --- a/LRReader.Shared/LRReader.Shared.csproj +++ b/LRReader.Shared/LRReader.Shared.csproj @@ -3,7 +3,7 @@ netstandard2.1;uap10.0.17763 enable - 10.0 + 11.0 true 6.2.14 10.0.22621.0 @@ -27,7 +27,6 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - diff --git a/LRReader.Shared/Services/Api.cs b/LRReader.Shared/Services/Api.cs index 857569d..960d0c7 100644 --- a/LRReader.Shared/Services/Api.cs +++ b/LRReader.Shared/Services/Api.cs @@ -3,7 +3,6 @@ using Microsoft.AppCenter.Crashes; #endif using RestSharp; -using RestSharp.Serializers.NewtonsoftJson; using System; using System.Text; using System.Threading.Tasks; @@ -33,7 +32,7 @@ public bool RefreshSettings(ServerProfile profile) return false; var options = new RestClientOptions(profile.ServerAddress) { UserAgent = "LRReader" }; Client?.Dispose(); - Client = new RestClient(options, configureSerialization: s => s.UseNewtonsoftJson(), useClientFactory: true); + Client = new RestClient(options, useClientFactory: true); if (!string.IsNullOrEmpty(profile.ServerApiKey)) { var base64Key = Convert.ToBase64String(Encoding.UTF8.GetBytes(profile.ServerApiKey)); diff --git a/LRReader.Shared/Services/Updates.cs b/LRReader.Shared/Services/Updates.cs index 9123da1..cf3b6a5 100644 --- a/LRReader.Shared/Services/Updates.cs +++ b/LRReader.Shared/Services/Updates.cs @@ -3,7 +3,6 @@ using System.Threading.Tasks; using LRReader.Shared.Models; using RestSharp; -using RestSharp.Serializers.NewtonsoftJson; namespace LRReader.Shared.Services { @@ -29,7 +28,7 @@ public UpdatesService(PlatformService platform, ISettingsStorageService settings var uri = new Uri("https://api.guerra24.net/"); #endif var options = new RestClientOptions(uri) { UserAgent = "LRReader" }; - client = new RestClient(options, configureSerialization: s => s.UseNewtonsoftJson()); + client = new RestClient(options); } public abstract Task CheckForUpdates(); diff --git a/LRReader.Shared/packages.lock.json b/LRReader.Shared/packages.lock.json index 2997cb6..e8c4c54 100644 --- a/LRReader.Shared/packages.lock.json +++ b/LRReader.Shared/packages.lock.json @@ -93,16 +93,6 @@ "System.Text.Json": "8.0.4" } }, - "RestSharp.Serializers.NewtonsoftJson": { - "type": "Direct", - "requested": "[112.1.0, )", - "resolved": "112.1.0", - "contentHash": "d/Ro5KeCKw2p0XVQrAKG0CUiG6VO4YeXLxIm5sHj8fwaIk2IlrtMOKoJJprsEUyJfq1Z9Qv8E1yN2rPFPuRVzw==", - "dependencies": { - "Newtonsoft.Json": "13.0.3", - "RestSharp": "112.1.0" - } - }, "SixLabors.ImageSharp": { "type": "Direct", "requested": "[2.1.9, )", @@ -546,16 +536,6 @@ "System.Text.Json": "8.0.4" } }, - "RestSharp.Serializers.NewtonsoftJson": { - "type": "Direct", - "requested": "[112.1.0, )", - "resolved": "112.1.0", - "contentHash": "d/Ro5KeCKw2p0XVQrAKG0CUiG6VO4YeXLxIm5sHj8fwaIk2IlrtMOKoJJprsEUyJfq1Z9Qv8E1yN2rPFPuRVzw==", - "dependencies": { - "Newtonsoft.Json": "13.0.3", - "RestSharp": "112.1.0" - } - }, "SixLabors.ImageSharp": { "type": "Direct", "requested": "[2.1.9, )", diff --git a/LRReader.UWP/Extensions/Extensions.cs b/LRReader.UWP/Extensions/Extensions.cs index f559713..46628e5 100644 --- a/LRReader.UWP/Extensions/Extensions.cs +++ b/LRReader.UWP/Extensions/Extensions.cs @@ -117,15 +117,14 @@ public static class WebViewExt private static readonly MarkdownPipeline pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build(); - public static void SetMarkdown(WebView webView, string markdown) + public static void SetMarkdown(this WebView webView, string markdown) { webView.SetValue(MarkdownProperty, markdown); if (!(bool)webView.GetValue(MarkdownReadyProperty)) { - webView.NavigationCompleted += async (sender, args) => + webView.ScriptNotify += (sender, args) => { - var heightString = await webView.InvokeScriptAsync("eval", new[] { "document.body.scrollHeight.toString()" }); - if (int.TryParse(heightString, out var height)) + if (double.TryParse(args.Value, out var height)) webView.Height = height; }; webView.SetValue(MarkdownReadyProperty, true); @@ -139,7 +138,51 @@ public static void SetMarkdownBase(this WebView webView, string markdown) var color = (Color)Application.Current.Resources["TextFillColorPrimary"]; var selectedColor = (Color)Application.Current.Resources["TextOnAccentFillColorSelectedText"]; var selectedBg = (Color)Application.Current.Resources["SystemAccentColor"]; - webView.NavigateToString($"md{Markdown.ToHtml(markdown, pipeline)}"); + webView.NavigateToString($$""" + + + + + + md + + + + + {{Markdown.ToHtml(markdown, pipeline)}} + + + """); webView.NavigationStarting += (sender, args) => { args.Cancel = true; diff --git a/LRReader.UWP/LRReader.UWP.csproj b/LRReader.UWP/LRReader.UWP.csproj index 12c0389..d12fc04 100644 --- a/LRReader.UWP/LRReader.UWP.csproj +++ b/LRReader.UWP/LRReader.UWP.csproj @@ -11,7 +11,7 @@ LRReader.UWP en UAP - 10.0.26100.0 + 10.0.22621.0 10.0.17763.0 14 512 @@ -30,7 +30,7 @@ http://timestamp.digicert.com Resources\MiddleClickScrolling-CursorType.res enable - 10.0 + 11.0 true diff --git a/LRReader.UWP/Views/Dialogs/MarkdownDialog.xaml b/LRReader.UWP/Views/Dialogs/MarkdownDialog.xaml index cb91ceb..21dc731 100644 --- a/LRReader.UWP/Views/Dialogs/MarkdownDialog.xaml +++ b/LRReader.UWP/Views/Dialogs/MarkdownDialog.xaml @@ -23,7 +23,7 @@ MinHeight="{ThemeResource ContentDialogMinHeight}" MaxWidth="670" MaxHeight="{ThemeResource ContentDialogMaxHeight}" - HorizontalAlignment="Stretch" VerticalAlignment="Stretch" + HorizontalAlignment="Stretch" VerticalAlignment="Center" Background="{TemplateBinding Background}" BackgroundSizing="InnerBorderEdge" BorderBrush="{TemplateBinding BorderBrush}" @@ -267,5 +267,5 @@ - + diff --git a/LRReader.UWP/Views/Dialogs/MarkdownDialog.xaml.cs b/LRReader.UWP/Views/Dialogs/MarkdownDialog.xaml.cs index a7b0243..c011862 100644 --- a/LRReader.UWP/Views/Dialogs/MarkdownDialog.xaml.cs +++ b/LRReader.UWP/Views/Dialogs/MarkdownDialog.xaml.cs @@ -10,7 +10,7 @@ public MarkdownDialog(string title, string text) { this.InitializeComponent(); this.Title = title; - WebView.SetMarkdownBase(text); + WebView.SetMarkdown(text); } } } diff --git a/LRReader.UWP/packages.lock.json b/LRReader.UWP/packages.lock.json index 4e3d917..a68d98e 100644 --- a/LRReader.UWP/packages.lock.json +++ b/LRReader.UWP/packages.lock.json @@ -400,15 +400,6 @@ "System.Text.Json": "8.0.4" } }, - "RestSharp.Serializers.NewtonsoftJson": { - "type": "Transitive", - "resolved": "112.1.0", - "contentHash": "d/Ro5KeCKw2p0XVQrAKG0CUiG6VO4YeXLxIm5sHj8fwaIk2IlrtMOKoJJprsEUyJfq1Z9Qv8E1yN2rPFPuRVzw==", - "dependencies": { - "Newtonsoft.Json": "13.0.3", - "RestSharp": "112.1.0" - } - }, "runtime.win10-arm.Microsoft.Net.Native.Compiler": { "type": "Transitive", "resolved": "2.2.12-rel-31116-00", @@ -628,7 +619,6 @@ "NReco.Logging.File": "[1.2.1, )", "Newtonsoft.Json": "[13.0.3, )", "RestSharp": "[112.1.0, )", - "RestSharp.Serializers.NewtonsoftJson": "[112.1.0, )", "SixLabors.ImageSharp": "[2.1.9, )" } }