forked from BeyondDimension/SteamTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
270 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<SignAssembly>true</SignAssembly> | ||
<DelaySign>false</DelaySign> | ||
<AssemblyOriginatorKeyFile>$(MSBuildProjectDirectory)\..\..\avalonia.snk</AssemblyOriginatorKeyFile> | ||
<!--https://github.com/AvaloniaUI/Avalonia/blob/0.10.10/build/SharedVersion.props#L18--> | ||
<IsTrimmable>true</IsTrimmable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="..\AssemblyInfo.Version.Max.cs"> | ||
<LinkBase>Properties</LinkBase> | ||
</Compile> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Avalonia" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using WebView2BaseType = Avalonia.Controls.Shapes.Rectangle; | ||
|
||
namespace Avalonia.Controls; | ||
|
||
public partial class WebView2 : WebView2BaseType | ||
{ | ||
public static bool IsSupported { get; } | ||
|
||
public static readonly DirectProperty<WebView2, Uri?> SourceProperty = | ||
AvaloniaProperty.RegisterDirect<WebView2, Uri?>( | ||
nameof(Uri), | ||
x => x.source, | ||
(x, y) => x.Source = y); | ||
|
||
Uri? source; | ||
|
||
public Uri? Source | ||
{ | ||
get => source; | ||
set => SetAndRaise(SourceProperty, ref source, value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...ST.Client.Desktop.Avalonia/Application/UI/Views/Controls/UserControl/WebView2Compat.axaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<UserControl | ||
x:Class="System.Application.UI.Views.Controls.WebView2Compat" | ||
xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:resx="using:System.Application.UI.Resx" | ||
xmlns:wv2="clr-namespace:Avalonia.Controls;assembly=Avalonia.WebView2" | ||
d:DesignHeight="450" | ||
d:DesignWidth="800" | ||
mc:Ignorable="d"> | ||
<Panel> | ||
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center"> | ||
<TextBlock x:Name="TbContent" | ||
HorizontalAlignment="Center" | ||
VerticalAlignment="Center" | ||
FontSize="24" /> | ||
<Button x:Name="BtnDownloadAndInstall" | ||
Margin="0,24,0,0" | ||
HorizontalAlignment="Center" | ||
VerticalAlignment="Center" | ||
Content="{ReflectionBinding Path=Res.DownloadAndInstall, | ||
Mode=OneWay, | ||
Source={x:Static resx:R.Current}}" /> | ||
</StackPanel> | ||
<wv2:WebView2 x:Name="WebView2" /> | ||
</Panel> | ||
</UserControl> |
109 changes: 109 additions & 0 deletions
109
...Client.Desktop.Avalonia/Application/UI/Views/Controls/UserControl/WebView2Compat.axaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
using Avalonia; | ||
using Avalonia.Interactivity; | ||
using Avalonia.Controls; | ||
using Avalonia.Markup.Xaml; | ||
using System.Application.UI.Resx; | ||
#if WINDOWS | ||
using Microsoft.Web.WebView2.Core; | ||
#endif | ||
|
||
namespace System.Application.UI.Views.Controls; | ||
|
||
public partial class WebView2Compat : UserControl | ||
{ | ||
public readonly TextBlock TbContent; | ||
public readonly Button BtnDownloadAndInstall; | ||
public readonly WebView2 WebView2; | ||
|
||
public WebView2Compat() | ||
{ | ||
InitializeComponent(); | ||
|
||
TbContent = this.FindControl<TextBlock>("TbContent"); | ||
BtnDownloadAndInstall = this.FindControl<Button>("BtnDownloadAndInstall"); | ||
WebView2 = this.FindControl<WebView2>("WebView2"); | ||
WebView2.IsVisible = false; | ||
#if WINDOWS | ||
WebView2.DOMContentLoaded += WebView2_DOMContentLoaded; | ||
#endif | ||
|
||
var webView2IsSupported = WebView2.IsSupported; | ||
TbContent.Text = webView2IsSupported ? AppResources.Loading : AppResources.YouNeedInstallWebView2Runtime; | ||
if (BtnDownloadAndInstall.IsVisible = !webView2IsSupported) | ||
{ | ||
BtnDownloadAndInstall.Click += BtnDownloadAndInstall_Click; | ||
} | ||
|
||
this.GetPropertyChangedObservable(SourceProperty).Subscribe(OnSourceChanged); | ||
this.GetPropertyChangedObservable(HtmlSourceProperty).Subscribe(OnHtmlSourceChanged); | ||
} | ||
|
||
bool isNotFirstLoad; | ||
|
||
#if WINDOWS | ||
void WebView2_DOMContentLoaded(object? sender, CoreWebView2DOMContentLoadedEventArgs e) | ||
{ | ||
if (!isNotFirstLoad) isNotFirstLoad = true; | ||
WebView2.IsVisible = true; | ||
} | ||
#endif | ||
|
||
void BtnDownloadAndInstall_Click(object? sender, RoutedEventArgs e) | ||
{ | ||
// WebView2AutoInstaller | ||
// https://github.com/ProKn1fe/WebView2.Runtime/blob/62011b09436944143996fdb0039cd2c5dbb5c300/WebView2.Runtime.AutoInstaller/WebView2.Runtime.AutoInstaller/WebView2AutoInstaller.cs | ||
} | ||
|
||
void InitializeComponent() | ||
{ | ||
AvaloniaXamlLoader.Load(this); | ||
} | ||
|
||
public static readonly DirectProperty<WebView2Compat, Uri?> SourceProperty = | ||
AvaloniaProperty.RegisterDirect<WebView2Compat, Uri?>( | ||
nameof(Source), | ||
x => x._Source, | ||
(x, y) => x.Source = y); | ||
|
||
Uri? _Source; | ||
|
||
public Uri? Source | ||
{ | ||
get => _Source; | ||
set => SetAndRaise(SourceProperty, ref _Source, value); | ||
} | ||
|
||
void OnSourceChanged(EventArgs e) | ||
{ | ||
if (!isNotFirstLoad) WebView2.IsVisible = true; | ||
WebView2.Source = Source; | ||
if (!isNotFirstLoad) WebView2.IsVisible = false; | ||
} | ||
|
||
public static readonly DirectProperty<WebView2Compat, string?> HtmlSourceProperty = | ||
AvaloniaProperty.RegisterDirect<WebView2Compat, string?>( | ||
nameof(HtmlSource), | ||
x => x._HtmlSource, | ||
(x, y) => x.HtmlSource = y); | ||
|
||
string? _HtmlSource; | ||
|
||
public string? HtmlSource | ||
{ | ||
get => _HtmlSource; | ||
set => SetAndRaise(HtmlSourceProperty, ref _HtmlSource, value); | ||
} | ||
|
||
void OnHtmlSourceChanged(EventArgs e) | ||
{ | ||
#if WINDOWS | ||
var htmlString = _HtmlSource; | ||
if (!string.IsNullOrWhiteSpace(htmlString)) | ||
{ | ||
if (!isNotFirstLoad) WebView2.IsVisible = true; | ||
WebView2.NavigateToString(htmlString); | ||
if (!isNotFirstLoad) WebView2.IsVisible = false; | ||
} | ||
#endif | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.