Skip to content

Commit 949f661

Browse files
committed
Use Launcher to open links
1 parent be78986 commit 949f661

File tree

6 files changed

+28
-20
lines changed

6 files changed

+28
-20
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<PropertyGroup>
1313
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
14-
<AvaloniaVersion>11.0.11</AvaloniaVersion>
14+
<AvaloniaVersion>11.1.0</AvaloniaVersion>
1515
<AvaloniaSamplesVersion>11.3.0-beta2</AvaloniaSamplesVersion>
1616
</PropertyGroup>
1717

external/HtmlRenderer/Adapters/RAdapter.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,15 @@ public void SetToClipboard(string text)
257257
SetToClipboardInt(text);
258258
}
259259

260+
/// <summary>
261+
/// Opens the specified URL in the default web browser.
262+
/// </summary>
263+
/// <param name="url">The URL to open.</param>
264+
public void OpenLink(string url)
265+
{
266+
OpenLinkInt(url);
267+
}
268+
260269
/// <summary>
261270
/// Set the given html and plain text data to clipboard.<br/>
262271
/// Not relevant for platforms that don't render HTML on UI element.
@@ -414,6 +423,15 @@ protected virtual void SetToClipboardInt(string text)
414423
throw new NotImplementedException();
415424
}
416425

426+
/// <summary>
427+
/// Opens the specified URL in the default web browser.
428+
/// </summary>
429+
/// <param name="url">The URL to open.</param>
430+
protected virtual void OpenLinkInt(string text)
431+
{
432+
throw new NotImplementedException();
433+
}
434+
417435
/// <summary>
418436
/// Set the given html and plain text data to clipboard.
419437
/// </summary>

external/HtmlRenderer/Core/Handlers/ImageLoadHandler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using System.IO;
1616
using System.Text;
1717
using System.Threading;
18+
using System.Threading.Tasks;
1819
using TheArtOfDev.HtmlRenderer.Adapters;
1920
using TheArtOfDev.HtmlRenderer.Adapters.Entities;
2021
using TheArtOfDev.HtmlRenderer.Core.Entities;
@@ -284,7 +285,7 @@ private void SetImageFromFile(FileInfo source)
284285
if (_htmlContainer.AvoidAsyncImagesLoading)
285286
LoadImageFromFile(source.FullName);
286287
else
287-
ThreadPool.QueueUserWorkItem(state => LoadImageFromFile(source.FullName));
288+
Task.Run(() => LoadImageFromFile(source.FullName));
288289
}
289290
else
290291
{

external/HtmlRenderer/Core/HtmlContainerInt.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -964,9 +964,7 @@ internal void HandleLinkClicked(RControl parent, RPoint location, CssBox link)
964964
}
965965
else
966966
{
967-
var nfo = new ProcessStartInfo(link.HrefLink);
968-
nfo.UseShellExecute = true;
969-
Process.Start(nfo);
967+
_adapter.OpenLink(link.HrefLink);
970968
}
971969
}
972970
}

external/HtmlRenderer/Core/Utils/CommonUtils.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -191,21 +191,6 @@ public static FileInfo TryGetFileInfo(string path)
191191
return null;
192192
}
193193

194-
/// <summary>
195-
/// Get web client response content type.
196-
/// </summary>
197-
/// <param name="client">the web client to get the response content type from</param>
198-
/// <returns>response content type or null</returns>
199-
public static string GetResponseContentType(WebClient client)
200-
{
201-
foreach (string header in client.ResponseHeaders)
202-
{
203-
if (header.Equals("Content-Type", StringComparison.InvariantCultureIgnoreCase))
204-
return client.ResponseHeaders[header];
205-
}
206-
return null;
207-
}
208-
209194
/// <summary>
210195
/// Gets the representation of the online uri on the local disk.
211196
/// </summary>

src/Avalonia.HtmlRenderer/Adapters/AvaloniaAdapter.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@ protected override void SetToClipboardInt(string text)
134134
_ = topLevel?.Clipboard?.SetTextAsync(text);
135135
}
136136

137+
protected override void OpenLinkInt(string link)
138+
{
139+
var topLevel = TryGetTopLevel();
140+
_ = topLevel?.Launcher.LaunchUriAsync(new Uri(link));
141+
}
142+
137143
protected override void SetToClipboardInt(string html, string plainText)
138144
{
139145
var topLevel = TryGetTopLevel();

0 commit comments

Comments
 (0)