Add WebLoginDialog for Windows Chardonnay
This commit is contained in:
parent
df2936e0b6
commit
4456432116
34 changed files with 704 additions and 47 deletions
|
|
@ -20,6 +20,7 @@ namespace LinuxConfigApp
|
|||
public LinuxInterop() { }
|
||||
public LinuxInterop(params object[] values) { }
|
||||
|
||||
public IWebViewAdapter CreateWebViewAdapter() => null;
|
||||
public void SetFolderIcon(string image, string directory) => throw new PlatformNotSupportedException();
|
||||
public void DeleteFolderIcon(string directory) => throw new PlatformNotSupportedException();
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<!--<TargetFramework>net7.0-macos</TargetFramework>-->
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<PublishReadyToRun>true</PublishReadyToRun>
|
||||
<RuntimeIdentifier>osx-x64</RuntimeIdentifier>
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ namespace MacOSConfigApp
|
|||
public MacOSInterop() { }
|
||||
public MacOSInterop(params object[] values) { }
|
||||
|
||||
public IWebViewAdapter CreateWebViewAdapter() => null;
|
||||
public void SetFolderIcon(string image, string directory)
|
||||
{
|
||||
Process.Start("fileicon", $"set {directory.SurroundWithQuotes()} {image.SurroundWithQuotes()}").WaitForExit();
|
||||
|
|
|
|||
134
Source/LoadByOS/MacOSConfigApp/MacWebViewAdapter.cs
Normal file
134
Source/LoadByOS/MacOSConfigApp/MacWebViewAdapter.cs
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
/* Work-in-progress
|
||||
*
|
||||
*
|
||||
using LibationFileManager;
|
||||
using ObjCRuntime;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WebKit;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace MacOSConfigApp;
|
||||
|
||||
internal class WKNavigationDelegate1 : WKNavigationDelegate
|
||||
{
|
||||
public override void DidStartProvisionalNavigation(WKWebView webView, WKNavigation navigation)
|
||||
{
|
||||
base.DidStartProvisionalNavigation(webView, navigation);
|
||||
}
|
||||
}
|
||||
internal class MacWebViewAdapter : IWebViewAdapter, IDisposable
|
||||
{
|
||||
private readonly WKWebView _webView;
|
||||
public IPlatformHandle2 PlatformHandle { get; }
|
||||
|
||||
public bool CanGoBack => _webView.CanGoBack;
|
||||
|
||||
public bool CanGoForward => _webView.CanGoForward;
|
||||
|
||||
public Uri? Source { get => _webView?.Url; set => throw new NotImplementedException(); }
|
||||
|
||||
public object NativeWebView { get; }
|
||||
|
||||
public event EventHandler<WebViewNavigationEventArgs>? NavigationCompleted;
|
||||
public event EventHandler<WebViewNavigationEventArgs>? NavigationStarted;
|
||||
public event EventHandler? DOMContentLoaded;
|
||||
|
||||
WKNavigationDelegate1 navDelegate;
|
||||
public MacWebViewAdapter()
|
||||
{
|
||||
var frame = new CGRect(0, 0, 500, 800);
|
||||
NativeWebView = _webView = new WKWebView(frame, new WKWebViewConfiguration());
|
||||
_webView.NavigationDelegate = navDelegate = new WKNavigationDelegate1();
|
||||
PlatformHandle = new MacViewHandle(_webView.Handle);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_webView?.Dispose();
|
||||
}
|
||||
|
||||
public bool GoBack()
|
||||
{
|
||||
if (_webView.CanGoBack)
|
||||
{
|
||||
_webView.GoBack();
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
public bool GoForward()
|
||||
{
|
||||
if (_webView.CanGoForward)
|
||||
{
|
||||
_webView.GoForward();
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
public bool HandleKeyDown(uint key, uint keyModifiers)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public void HandleResize(int width, int height, float zoom)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public async Task<string?> InvokeScriptAsync(string scriptName)
|
||||
{
|
||||
var result = await _webView.EvaluateJavaScriptAsync(scriptName);
|
||||
|
||||
return result.ToString();
|
||||
}
|
||||
|
||||
public void Navigate(Uri url)
|
||||
{
|
||||
NSUrl? nsurl = url;
|
||||
if (nsurl is null) return;
|
||||
|
||||
var request = new NSUrlRequest(nsurl);
|
||||
|
||||
_webView.LoadRequest(request);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public Task NavigateToString(string text)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
internal class MacViewHandle : IPlatformHandle2
|
||||
{
|
||||
private NativeHandle? _view;
|
||||
|
||||
public MacViewHandle(NativeHandle view)
|
||||
{
|
||||
_view = view;
|
||||
}
|
||||
|
||||
public nint Handle => _view?.Handle ?? 0;
|
||||
public string HandleDescriptor => "NativeHandle";
|
||||
}
|
||||
|
||||
*/
|
||||
|
|
@ -12,7 +12,10 @@ namespace WindowsConfigApp
|
|||
public WinInterop() { }
|
||||
public WinInterop(params object[] values) { }
|
||||
|
||||
public void SetFolderIcon(string image, string directory)
|
||||
#nullable enable
|
||||
public IWebViewAdapter? CreateWebViewAdapter() => new WindowsWebView2Adapter();
|
||||
#nullable disable
|
||||
public void SetFolderIcon(string image, string directory)
|
||||
{
|
||||
var icon = Image.Load(image).ToIcon();
|
||||
new DirectoryInfo(directory)?.SetIcon(icon, "Music");
|
||||
|
|
@ -50,5 +53,5 @@ namespace WindowsConfigApp
|
|||
|
||||
return Process.Start(psi);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,10 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<EnableWindowsTargeting>true</EnableWindowsTargeting>
|
||||
<TargetFramework>net7.0-windows</TargetFramework>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<EnableWindowsTargeting>true</EnableWindowsTargeting>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<PublishReadyToRun>true</PublishReadyToRun>
|
||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
|
||||
|
|
@ -23,6 +25,10 @@
|
|||
<DebugType>embedded</DebugType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.1722.45" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\LibationUiBase\LibationUiBase.csproj" />
|
||||
</ItemGroup>
|
||||
|
|
|
|||
114
Source/LoadByOS/WindowsConfigApp/WindowsWebView2Adapter.cs
Normal file
114
Source/LoadByOS/WindowsConfigApp/WindowsWebView2Adapter.cs
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
using LibationFileManager;
|
||||
using Microsoft.Web.WebView2.WinForms;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
#nullable enable
|
||||
namespace WindowsConfigApp;
|
||||
|
||||
internal class WindowsWebView2Adapter : IWebViewAdapter, IDisposable
|
||||
{
|
||||
public object NativeWebView { get; }
|
||||
private readonly WebView2 _webView;
|
||||
|
||||
public WindowsWebView2Adapter()
|
||||
{
|
||||
NativeWebView = _webView = new WebView2();
|
||||
PlatformHandle = new WebView2Handle { Handle = _webView.Handle };
|
||||
|
||||
_webView.CoreWebView2InitializationCompleted += _webView_CoreWebView2InitializationCompleted;
|
||||
|
||||
_webView.NavigationStarting += (s, a) =>
|
||||
{
|
||||
NavigationStarted?.Invoke(this, new WebViewNavigationEventArgs { Request = new Uri(a.Uri) });
|
||||
};
|
||||
_webView.NavigationCompleted += (s, a) =>
|
||||
{
|
||||
NavigationCompleted?.Invoke(this, new WebViewNavigationEventArgs { Request = _webView.Source });
|
||||
};
|
||||
}
|
||||
|
||||
private void _webView_CoreWebView2InitializationCompleted(object? sender, Microsoft.Web.WebView2.Core.CoreWebView2InitializationCompletedEventArgs e)
|
||||
{
|
||||
_webView.CoreWebView2.DOMContentLoaded -= CoreWebView2_DOMContentLoaded;
|
||||
_webView.CoreWebView2.DOMContentLoaded += CoreWebView2_DOMContentLoaded;
|
||||
}
|
||||
|
||||
private void CoreWebView2_DOMContentLoaded(object? sender, Microsoft.Web.WebView2.Core.CoreWebView2DOMContentLoadedEventArgs e)
|
||||
=> DOMContentLoaded?.Invoke(this, e);
|
||||
|
||||
public IPlatformHandle2 PlatformHandle { get; }
|
||||
|
||||
public bool CanGoBack => _webView.CanGoBack;
|
||||
|
||||
public bool CanGoForward => _webView.CanGoForward;
|
||||
|
||||
public Uri? Source
|
||||
{
|
||||
get => _webView.Source;
|
||||
set => _webView.Source = value;
|
||||
}
|
||||
|
||||
public event EventHandler<WebViewNavigationEventArgs>? NavigationStarted;
|
||||
public event EventHandler<WebViewNavigationEventArgs>? NavigationCompleted;
|
||||
public event EventHandler? DOMContentLoaded;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_webView.Dispose();
|
||||
}
|
||||
|
||||
public bool GoBack()
|
||||
{
|
||||
_webView.GoBack();
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool GoForward()
|
||||
{
|
||||
_webView.GoForward();
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task<string?> InvokeScriptAsync(string scriptName)
|
||||
{
|
||||
return await _webView.ExecuteScriptAsync(scriptName);
|
||||
}
|
||||
|
||||
public void Navigate(Uri url)
|
||||
{
|
||||
_webView.Source = url;
|
||||
}
|
||||
|
||||
public async Task NavigateToString(string text)
|
||||
{
|
||||
await _webView.EnsureCoreWebView2Async();
|
||||
|
||||
_webView.NavigateToString(text);
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
_webView.Refresh();
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
_webView.Stop();
|
||||
}
|
||||
|
||||
public void HandleResize(int width, int height, float zoom)
|
||||
{
|
||||
}
|
||||
|
||||
public bool HandleKeyDown(uint key, uint keyModifiers)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
internal class WebView2Handle : IPlatformHandle2
|
||||
{
|
||||
public IntPtr Handle { get; init; }
|
||||
public string HandleDescriptor => "HWND";
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue