new_version_init

This commit is contained in:
2024-02-13 02:59:40 +01:00
Unverified
parent e36c1404ee
commit 91f9b645bd
352 changed files with 6777 additions and 8326 deletions

View File

@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<RootNamespace>VDownload.GUI.Services.WebView</RootNamespace>
<RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
<UseWinUI>true</UseWinUI>
<UseRidGraph>true</UseRidGraph>
</PropertyGroup>
<ItemGroup>
<None Remove="WebViewWindow.xaml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.4.231219000" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.2428" />
</ItemGroup>
<ItemGroup>
<Page Update="WebViewWindow.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,29 @@
using Microsoft.Web.WebView2.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VDownload.GUI.Services.WebView
{
public interface IWebViewService
{
Task<string> Show(Uri url, Predicate<string> closePredicate, string name);
}
public class WebViewService : IWebViewService
{
#region METHODS
public async Task<string> Show(Uri url, Predicate<string> closePredicate, string name)
{
WebViewWindow window = new WebViewWindow(name);
return await window.Show(url, closePredicate);
}
#endregion
}
}

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<Window
x:Class="VDownload.GUI.Services.WebView.WebViewWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:VDownload.GUI.Services.WebView"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Closed="Window_Closed">
<WebView2 x:Name="WebView" NavigationCompleted="WebView_NavigationCompleted"/>
</Window>

View File

@@ -0,0 +1,89 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using Microsoft.Web.WebView2.Core;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.Foundation.Collections;
namespace VDownload.GUI.Services.WebView
{
public sealed partial class WebViewWindow : Window
{
#region FIEDLS
private readonly Predicate<string> _defaultClosePredicate = args => false;
private bool _isOpened;
private Predicate<string> _closePredicate;
#endregion
#region CONSTRUCTORS
public WebViewWindow(string name)
{
this.InitializeComponent();
this.Title = name;
_isOpened = false;
_closePredicate = _defaultClosePredicate;
}
#endregion
#region PUBLIC METHODS
internal async Task<string> Show(Uri url, Predicate<string> closePredicate)
{
this.WebView.Source = url;
_closePredicate = closePredicate;
this.Activate();
_isOpened = true;
while (_isOpened)
{
await Task.Delay(10);
}
_closePredicate = _defaultClosePredicate;
return this.WebView.Source.ToString();
}
#endregion
#region EVENT HANDLER
private void WebView_NavigationCompleted(WebView2 sender, CoreWebView2NavigationCompletedEventArgs args)
{
if (_closePredicate.Invoke(this.WebView.Source.ToString()))
{
this.Close();
}
}
private void Window_Closed(object sender, WindowEventArgs args)
{
_isOpened = false;
}
#endregion
}
}