├── .github ├── ISSUE_TEMPLATE │ ├── bug-report.md │ └── question.md └── workflows │ └── CI.yml ├── .gitignore ├── .gitmodules ├── Avalonia.WebView2.slnx ├── LICENSE ├── README.md ├── ref ├── CefGlue.Avalonia.props └── Microsoft.Web.WebView2 │ ├── LICENSE.txt │ ├── NOTICE.txt │ ├── lib │ ├── net462 │ │ ├── Microsoft.Web.WebView2.Core.dll │ │ └── Microsoft.Web.WebView2.Core.xml │ └── netcoreapp3.0 │ │ ├── Microsoft.Web.WebView2.Core.dll │ │ └── Microsoft.Web.WebView2.Core.xml │ └── runtimes │ ├── win-arm64 │ └── native │ │ └── WebView2Loader.dll │ ├── win-x64 │ └── native │ │ └── WebView2Loader.dll │ └── win-x86 │ └── native │ └── WebView2Loader.dll ├── res └── screenshots │ ├── Avalonia.WebView2.Sample.Win11.webp │ └── Avalonia.WebView2.Sample.Win7.webp └── src ├── .editorconfig ├── Avalonia.Ref ├── AssemblyInfo.Version.Max.cs ├── Avalonia.Desktop │ ├── AppBuilderDesktopExtensions.cs │ └── Avalonia.Desktop.csproj ├── Avalonia.Native │ ├── Avalonia.Native.csproj │ └── AvaloniaNativePlatformExtensions.cs ├── Avalonia.X11 │ ├── Avalonia.X11.csproj │ └── AvaloniaX11PlatformExtensions.cs └── avalonia.snk ├── Avalonia.WebView2.Sample.Mobile.Android ├── Avalonia.WebView2.Sample.Mobile.Android.csproj ├── Icon.png ├── MainActivity.cs ├── Properties │ └── AndroidManifest.xml └── Resources │ ├── AboutResources.txt │ ├── drawable-night-v31 │ └── avalonia_anim.xml │ ├── drawable-v31 │ └── avalonia_anim.xml │ ├── drawable │ └── splash_screen.xml │ ├── values-night │ └── colors.xml │ ├── values-v31 │ └── styles.xml │ └── values │ ├── colors.xml │ └── styles.xml ├── Avalonia.WebView2.Sample.Mobile.iOS ├── AppDelegate.cs ├── Avalonia.WebView2.Sample.Mobile.iOS.csproj ├── Entitlements.plist ├── Info.plist ├── Main.cs └── Resources │ └── LaunchScreen.xib ├── Avalonia.WebView2.Sample.Mobile ├── App.axaml ├── App.axaml.cs ├── Assets │ └── avalonia-logo.ico ├── Avalonia.WebView2.Sample.Mobile.csproj ├── ViewLocator.cs ├── ViewModels │ ├── MainViewModel.cs │ └── ViewModelBase.cs └── Views │ ├── MainView.axaml │ ├── MainView.axaml.cs │ ├── MainWindow.axaml │ └── MainWindow.axaml.cs ├── Avalonia.WebView2.Sample ├── App.xaml ├── App.xaml.cs ├── Avalonia.WebView2.Sample.csproj ├── BCL │ ├── MS │ │ ├── Internal │ │ │ └── PresentationCore │ │ │ │ ├── SR.cs │ │ │ │ └── SRID.cs │ │ └── Win32 │ │ │ ├── ExternDll.cs │ │ │ └── UnsafeNativeMethodsCLR.cs │ └── System │ │ └── Windows │ │ └── MessageBox.cs ├── Common8 │ └── DomainPattern.cs ├── MainWindow.xaml ├── MainWindow.xaml.cs ├── Program.cs ├── Properties │ ├── PublishProfiles │ │ └── win-x64.pubxml │ └── app.manifest ├── WebView2Compat.xaml └── WebView2Compat.xaml.cs ├── Avalonia.WebView2 ├── Avalonia.WebView2.csproj ├── Compat │ └── IsExternalInit.cs ├── Controls │ ├── CoreWebView2CreationProperties.cs │ ├── StorageService │ │ ├── IStorageService.cs │ │ ├── StorageItemOperate.cs │ │ ├── StorageItemType.cs │ │ ├── StorageItemValue.Date.cs │ │ ├── StorageItemValue.JavaScriptStringEncode.cs │ │ ├── StorageItemValue.ToJavaScriptString.cs │ │ └── StorageItemValue.cs │ ├── WebView2.Disposable.cs │ ├── WebView2.Methods.cs │ ├── WebView2.Properties │ │ ├── AllowExternalDrop.cs │ │ ├── CanGoBack.cs │ │ ├── CanGoForward.cs │ │ ├── Cookies.cs │ │ ├── CreationProperties.cs │ │ ├── DefaultBackgroundColor.cs │ │ ├── HtmlSource.cs │ │ ├── Source.cs │ │ ├── Storages.cs │ │ ├── UserAgent.cs │ │ └── ZoomFactor.cs │ ├── WebView2.Script.cs │ ├── WebView2.VisualTree.cs │ └── WebView2.cs ├── Input │ └── WebView2KeyEventArgs.cs ├── NativeMethods.txt └── Platforms │ ├── CefGlue │ └── Controls │ │ ├── WebView2.AvaloniaCefBrowser.EventHandlers.Subscribe.cs │ │ ├── WebView2.AvaloniaCefBrowser.EventHandlers.cs │ │ ├── WebView2.AvaloniaCefBrowser.Events.cs │ │ └── WebView2.cs │ ├── CefNet │ └── WebView2.cs │ ├── Droid │ └── Controls │ │ └── WebView2.cs │ ├── EdgeWebView2 │ ├── CefNet.Avalonia │ │ └── Internal │ │ │ ├── GlobalHooks.cs │ │ │ └── WindowsHwndSource.cs │ ├── Controls │ │ ├── WebView2.CoreWebView2.EventHandlers.Subscribe.cs │ │ ├── WebView2.CoreWebView2.EventHandlers.cs │ │ ├── WebView2.CoreWebView2.Events.cs │ │ ├── WebView2.CoreWebView2.cs │ │ ├── WebView2.CoreWebView2Controller.cs │ │ ├── WebView2.Focus.cs │ │ ├── WebView2.ISupportInitialize.cs │ │ ├── WebView2.KeyPressed.cs │ │ ├── WebView2.SizeChanged.cs │ │ ├── WebView2.WndProc.cs │ │ └── WebView2.cs │ ├── ImplicitInitGate.cs │ ├── Input │ │ ├── KeyInterop.cs │ │ └── WebView2KeyEventArgs.cs │ └── Interop │ │ ├── IHwndHost.cs │ │ ├── NativeMethods.Paint.cs │ │ ├── NativeMethods.Win32Window.cs │ │ └── NativeMethods.cs │ ├── iOS │ └── Controls │ │ └── WebView2.cs │ └── macOS │ └── Controls │ └── WebView2.cs ├── CefGlue.Avalonia ├── CefGlue.Avalonia.csproj └── README.md ├── Directory.Build.props ├── Directory.Packages.props ├── GeneratePackage.props ├── Microsoft.Maui.WebView ├── Core │ ├── Core │ │ ├── IElement.cs │ │ ├── ITransform.cs │ │ ├── IView.cs │ │ └── IWebView.cs │ ├── Graphics │ │ ├── Color.cs │ │ ├── Colors.cs │ │ ├── IShadow.cs │ │ ├── IShape.cs │ │ └── Paint.cs │ ├── Handlers │ │ └── IElementHandler.cs │ ├── IMauiContext.cs │ └── Primitives │ │ ├── FlowDirection.cs │ │ ├── LayoutAlignment.cs │ │ ├── SemanticHeadingLevel.cs │ │ └── Semantics.cs ├── Microsoft.Maui.WebView.projitems ├── Microsoft.Maui.WebView.shproj └── README.md ├── Version.props └── WebView2.NativeAssets.Win32 ├── README.md ├── WebView2.NativeAssets.Win32.bat └── WebView2.NativeAssets.Win32.nuspec /.github/ISSUE_TEMPLATE/bug-report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "Bug Report \U0001F41B" 3 | about: 创建 Bug 报告以帮助我们改进 / Create a report to help us improve 4 | title: "\U0001F41B[BUG] 请输入标题(Please enter a title)" 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | 18 | 19 | ### 🐛 描述(Description) 20 | 24 | 25 | 26 | ### 📷 复现步骤(Steps to Reproduce) 27 | 28 | 34 | 1. 35 | 2. 36 | 3. 37 | 38 | ### 📄 日志信息(Log Information) 39 | 47 | 48 | ### 🚑 基本信息(Basic Information) 49 | 50 | - 库版本(Library Version): 51 | - 系统版本号(OS Version): 52 | 53 | ### 🖼 截图(Screenshots) 54 | 55 | 59 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "Question \U0001F9D0" 3 | about: 对库使用的疑问或需要帮助 / Questions about the use of the library or need help 4 | title: "\U0001F9D0[Question] 请输入标题(Please enter a title)" 5 | labels: question 6 | assignees: '' 7 | 8 | --- 9 | 10 | 16 | 17 | ### 🧐 问题描述(Description) 18 | 19 | 23 | 24 | ### 🚑 其他信息(Other Information) 25 | 26 | 30 | 31 | - 库版本(Library Version): 32 | - 系统版本号(OS Version): 33 | -------------------------------------------------------------------------------- /.github/workflows/CI.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | push: 4 | branches: 5 | - main 6 | tags: 7 | - "*" 8 | pull_request: 9 | workflow_dispatch: 10 | 11 | jobs: 12 | test: 13 | name: Test 14 | runs-on: ${{ matrix.os }} 15 | strategy: 16 | matrix: 17 | os: [ windows-latest ] 18 | 19 | steps: 20 | - name: Checkout repository 21 | uses: actions/checkout@v3 22 | with: 23 | fetch-depth: 0 24 | submodules: recursive 25 | 26 | - name: Setup .NET 27 | uses: actions/setup-dotnet@v2 28 | with: 29 | dotnet-version: 7.0.x 30 | 31 | - name: Verify dotnet info 32 | run: dotnet --info 33 | 34 | - name: Test 35 | shell: pwsh 36 | run: dotnet test -c Release 37 | 38 | build: 39 | name: Build 40 | needs: [ test ] 41 | if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') }} 42 | runs-on: windows-latest 43 | strategy: 44 | matrix: 45 | include: 46 | - ProjectName: "Avalonia.WebView2" 47 | PackageId: "WebView2.Avalonia" 48 | 49 | steps: 50 | - name: Checkout repository 51 | uses: actions/checkout@v3 52 | with: 53 | fetch-depth: 0 54 | submodules: recursive 55 | 56 | - name: Setup .NET 57 | uses: actions/setup-dotnet@v2 58 | with: 59 | dotnet-version: 7.0.x 60 | 61 | - name: Verify dotnet info 62 | run: dotnet --info 63 | 64 | - name: Build 65 | shell: pwsh 66 | run: dotnet build -c Release src\${{ matrix.ProjectName }}\${{ matrix.ProjectName }}.csproj 67 | 68 | - name: Run NativeAssets Bat 69 | shell: pwsh 70 | run: cmd.exe /c src\WebView2.NativeAssets.Win32.bat 71 | 72 | - name: Push nuget packages 73 | shell: pwsh 74 | run: | 75 | dotnet nuget push pkg\${{ matrix.PackageId }}*.nupkg -s https://nuget.pkg.github.com/BeyondDimension -k ${{ secrets.RMBADMIN_TOKEN }} --skip-duplicate 76 | dotnet nuget push pkg\${{ matrix.PackageId }}*.snupkg -s https://nuget.pkg.github.com/BeyondDimension -k ${{ secrets.RMBADMIN_TOKEN }} --skip-duplicate 77 | dotnet nuget push pkg\${{ matrix.PackageId }}*.nupkg -s https://api.nuget.org/v3/index.json -k ${{ secrets.NUGET_API_KEY }} --skip-duplicate 78 | dotnet nuget push pkg\${{ matrix.PackageId }}*.snupkg -s https://api.nuget.org/v3/index.json -k ${{ secrets.NUGET_API_KEY }} --skip-duplicate 79 | release: 80 | name: Release 81 | needs: build 82 | runs-on: ubuntu-latest 83 | 84 | steps: 85 | - name: Changelog 86 | uses: glennawatson/ChangeLog@v1 87 | id: changelog 88 | 89 | - name: Create Release 90 | uses: ncipollo/release-action@v1 91 | with: 92 | token: ${{ secrets.RMBADMIN_TOKEN }} 93 | body: ${{ steps.changelog.outputs.commitLog }} 94 | draft: false 95 | prerelease: false 96 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "ref/CefGlue"] 2 | path = ref/CefGlue 3 | url = https://github.com/BeyondDimension/CefGlue 4 | -------------------------------------------------------------------------------- /Avalonia.WebView2.slnx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Beyond Dimension 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Avalonia.WebView2 [![NuGet version (WebView2.Avalonia)](https://img.shields.io/nuget/v/WebView2.Avalonia.svg)](https://www.nuget.org/packages/WebView2.Avalonia/) 2 | Build .NET Avalonia Microsoft Edge WebView2 HTML5 Desktop Hybrid Apps 3 | 4 | ## Supported OS versions 5 | - [x] Windows (Edge WebView2) 6 | - [x] macOS (~~WebKit.WebView~~ | WebKit.WKWebView) 7 | - [ ] ~~Linux (CefGlue)~~ 8 | - [ ] ~~Android (Xamarin.AndroidX.WebKit)~~ 9 | - [ ] iOS (WebKit.WKWebView) 10 | 11 | ## [简介](https://docs.microsoft.com/zh-cn/microsoft-edge/webview2) 12 | Microsoft Edge WebView2 控件允许在本机应用中嵌入 web 技术(HTML、CSS 以及 JavaScript)。 WebView2 控件使用 [Microsoft Edge](https://www.microsoftedgeinsider.com) 作为绘制引擎,以在本机应用中显示 web 内容。 13 | 14 | 使用 WebView2 可以在本机应用的不同部分嵌入 Web 代码,或在单个 WebView2 实例中生成所有本机应用。 15 | 16 | ![应用示意图,其中本机 UI 区域位于左上角,WebView2 UI 区域位于右上角底部。](https://docs.microsoft.com/zh-cn/microsoft-edge/webview2/media/webview2/what-webview.png) 17 | 18 | ## Screenshots 19 | ![Win11 Sample Screenshot](https://raw.githubusercontent.com/BeyondDimension/Avalonia.WebView2/main/res/screenshots/Avalonia.WebView2.Sample.Win11.webp) 20 | ![Win7 Sample Screenshot](https://raw.githubusercontent.com/BeyondDimension/Avalonia.WebView2/main/res/screenshots/Avalonia.WebView2.Sample.Win7.webp) -------------------------------------------------------------------------------- /ref/CefGlue.Avalonia.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CefGlue.Common.Shared 6 | bin\**;obj\** 7 | 8 | 9 | 10 | 11 | CefGlue.Common 12 | bin\**;obj\** 13 | 14 | 15 | 16 | 17 | CefGlue.Avalonia 18 | bin\**;obj\** 19 | 20 | 21 | 22 | 23 | CefGlue 24 | bin\**;obj\** 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /ref/Microsoft.Web.WebView2/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * The name of Microsoft Corporation, or the names of its contributors 14 | may not be used to endorse or promote products derived from this 15 | software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /ref/Microsoft.Web.WebView2/NOTICE.txt: -------------------------------------------------------------------------------- 1 | NOTICES AND INFORMATION 2 | Do Not Translate or Localize 3 | 4 | This software incorporates material from third parties. Microsoft makes certain 5 | open source code available at https://3rdpartysource.microsoft.com, or you may 6 | send a check or money order for US $5.00, including the product name, the open 7 | source component name, and version number, to: 8 | 9 | Source Code Compliance Team 10 | Microsoft Corporation 11 | One Microsoft Way 12 | Redmond, WA 98052 13 | USA 14 | 15 | Notwithstanding any other terms, you may reverse engineer this software to the 16 | extent required to debug changes to any libraries licensed under the GNU Lesser 17 | General Public License. 18 | 19 | ---------------------------------------------------------------- 20 | 21 | Antlr3.Runtime 3.5.2-rc1 - BSD 3-Clause 22 | 23 | [The "BSD license"] 24 | Copyright (c) 2011 The ANTLR Project 25 | All rights reserved. 26 | 27 | Redistribution and use in source and binary forms, with or without 28 | modification, are permitted provided that the following conditions 29 | are met: 30 | 31 | 1. Redistributions of source code must retain the above copyright 32 | notice, this list of conditions and the following disclaimer. 33 | 2. Redistributions in binary form must reproduce the above copyright 34 | notice, this list of conditions and the following disclaimer in the 35 | documentation and/or other materials provided with the distribution. 36 | 3. Neither the name of the copyright holder nor the names of its 37 | contributors may be used to endorse or promote products derived from 38 | this software without specific prior written permission. 39 | 40 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 41 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 42 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 43 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 44 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 45 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 46 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 47 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 48 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 49 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 50 | 51 | --------------------------------------------------------- 52 | 53 | --------------------------------------------------------- 54 | 55 | StringTemplate4 4.0.9-rc1 - BSD 3-Clause 56 | 57 | [The "BSD license"] 58 | Copyright (c) 2011 The ANTLR Project 59 | All rights reserved. 60 | 61 | Redistribution and use in source and binary forms, with or without 62 | modification, are permitted provided that the following conditions 63 | are met: 64 | 65 | 1. Redistributions of source code must retain the above copyright 66 | notice, this list of conditions and the following disclaimer. 67 | 2. Redistributions in binary form must reproduce the above copyright 68 | notice, this list of conditions and the following disclaimer in the 69 | documentation and/or other materials provided with the distribution. 70 | 3. Neither the name of the copyright holder nor the names of its 71 | contributors may be used to endorse or promote products derived from 72 | this software without specific prior written permission. 73 | 74 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 75 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 76 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 77 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 78 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 79 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 80 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 81 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 82 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 83 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 84 | 85 | --------------------------------------------------------- 86 | -------------------------------------------------------------------------------- /ref/Microsoft.Web.WebView2/lib/net462/Microsoft.Web.WebView2.Core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeyondDimension/Avalonia.WebView2/88baa44aab31213598b821794a4e06e97d2dde5e/ref/Microsoft.Web.WebView2/lib/net462/Microsoft.Web.WebView2.Core.dll -------------------------------------------------------------------------------- /ref/Microsoft.Web.WebView2/lib/netcoreapp3.0/Microsoft.Web.WebView2.Core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeyondDimension/Avalonia.WebView2/88baa44aab31213598b821794a4e06e97d2dde5e/ref/Microsoft.Web.WebView2/lib/netcoreapp3.0/Microsoft.Web.WebView2.Core.dll -------------------------------------------------------------------------------- /ref/Microsoft.Web.WebView2/runtimes/win-arm64/native/WebView2Loader.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeyondDimension/Avalonia.WebView2/88baa44aab31213598b821794a4e06e97d2dde5e/ref/Microsoft.Web.WebView2/runtimes/win-arm64/native/WebView2Loader.dll -------------------------------------------------------------------------------- /ref/Microsoft.Web.WebView2/runtimes/win-x64/native/WebView2Loader.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeyondDimension/Avalonia.WebView2/88baa44aab31213598b821794a4e06e97d2dde5e/ref/Microsoft.Web.WebView2/runtimes/win-x64/native/WebView2Loader.dll -------------------------------------------------------------------------------- /ref/Microsoft.Web.WebView2/runtimes/win-x86/native/WebView2Loader.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeyondDimension/Avalonia.WebView2/88baa44aab31213598b821794a4e06e97d2dde5e/ref/Microsoft.Web.WebView2/runtimes/win-x86/native/WebView2Loader.dll -------------------------------------------------------------------------------- /res/screenshots/Avalonia.WebView2.Sample.Win11.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeyondDimension/Avalonia.WebView2/88baa44aab31213598b821794a4e06e97d2dde5e/res/screenshots/Avalonia.WebView2.Sample.Win11.webp -------------------------------------------------------------------------------- /res/screenshots/Avalonia.WebView2.Sample.Win7.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeyondDimension/Avalonia.WebView2/88baa44aab31213598b821794a4e06e97d2dde5e/res/screenshots/Avalonia.WebView2.Sample.Win7.webp -------------------------------------------------------------------------------- /src/Avalonia.Ref/AssemblyInfo.Version.Max.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | 3 | [assembly: AssemblyVersion("255.255.255.255")] -------------------------------------------------------------------------------- /src/Avalonia.Ref/Avalonia.Desktop/AppBuilderDesktopExtensions.cs: -------------------------------------------------------------------------------- 1 | using Avalonia.Controls; 2 | using Avalonia.Platform; 3 | 4 | // https://github.com/AvaloniaUI/Avalonia/blob/0.10.13/src/Avalonia.Desktop/AppBuilderDesktopExtensions.cs 5 | 6 | namespace Avalonia 7 | { 8 | public static class AppBuilderDesktopExtensions 9 | { 10 | public static AppBuilder UsePlatformDetect(this AppBuilder builder) 11 | { 12 | #if WINDOWS || NETFRAMEWORK 13 | builder.UseWin32(); 14 | #else 15 | 16 | // We don't have the ability to load every assembly right now, so we are 17 | // stuck with manual configuration here 18 | // Helpers are extracted to separate methods to take the advantage of the fact 19 | // that CLR doesn't try to load dependencies before referencing method is jitted 20 | // Additionally, by having a hard reference to each assembly, 21 | // we verify that the assemblies are in the final .deps.json file 22 | // so .NET Core knows where to load the assemblies from,. 23 | 24 | if (OperatingSystem.IsWindows()) 25 | { 26 | builder.UseWin32(); 27 | } 28 | else if (OperatingSystem.IsMacOS()) 29 | { 30 | builder.UseAvaloniaNative(); 31 | } 32 | else 33 | { 34 | builder.UseX11(); 35 | } 36 | #endif 37 | builder.UseSkia(); 38 | return builder; 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /src/Avalonia.Ref/Avalonia.Desktop/Avalonia.Desktop.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net462;net6.0;net6.0-windows;net7.0;net7.0-windows;net8.0;net8.0-windows;net9.0;net9.0-windows 5 | true 6 | false 7 | ..\avalonia.snk 8 | 9 | true 10 | false 11 | 12 | 13 | 14 | 15 | Properties 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /src/Avalonia.Ref/Avalonia.Native/Avalonia.Native.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net462;netstandard2.0; 5 | true 6 | false 7 | ..\avalonia.snk 8 | 9 | true 10 | false 11 | 12 | 13 | 14 | 15 | Properties 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/Avalonia.Ref/Avalonia.Native/AvaloniaNativePlatformExtensions.cs: -------------------------------------------------------------------------------- 1 | #if !WINDOWS 2 | 3 | using System; 4 | using Avalonia.Controls; 5 | 6 | namespace Avalonia 7 | { 8 | public static class AvaloniaNativePlatformExtensions 9 | { 10 | public static AppBuilder UseAvaloniaNative(this AppBuilder builder) 11 | { 12 | throw new PlatformNotSupportedException(); 13 | } 14 | } 15 | } 16 | 17 | #endif -------------------------------------------------------------------------------- /src/Avalonia.Ref/Avalonia.X11/Avalonia.X11.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net462;netstandard2.0; 5 | true 6 | false 7 | ..\avalonia.snk 8 | 9 | true 10 | false 11 | 12 | 13 | 14 | 15 | Properties 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/Avalonia.Ref/Avalonia.X11/AvaloniaX11PlatformExtensions.cs: -------------------------------------------------------------------------------- 1 | #if !WINDOWS 2 | 3 | using System; 4 | using Avalonia.Controls; 5 | 6 | namespace Avalonia 7 | { 8 | public static class AvaloniaX11PlatformExtensions 9 | { 10 | public static AppBuilder UseX11(this AppBuilder builder) 11 | { 12 | throw new PlatformNotSupportedException(); 13 | } 14 | } 15 | } 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /src/Avalonia.Ref/avalonia.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeyondDimension/Avalonia.WebView2/88baa44aab31213598b821794a4e06e97d2dde5e/src/Avalonia.Ref/avalonia.snk -------------------------------------------------------------------------------- /src/Avalonia.WebView2.Sample.Mobile.Android/Avalonia.WebView2.Sample.Mobile.Android.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net9.0-android 6 | com.github.beyonddimension.avalonia.webview2.sample 7 | 1 8 | 1.0 9 | apk 10 | false 11 | Avalonia.WebView2.Sample 12 | 13 | 14 | 15 | 16 | Resources\drawable\Icon.png 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/Avalonia.WebView2.Sample.Mobile.Android/Icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeyondDimension/Avalonia.WebView2/88baa44aab31213598b821794a4e06e97d2dde5e/src/Avalonia.WebView2.Sample.Mobile.Android/Icon.png -------------------------------------------------------------------------------- /src/Avalonia.WebView2.Sample.Mobile.Android/MainActivity.cs: -------------------------------------------------------------------------------- 1 | using Android.App; 2 | using Android.Content.PM; 3 | using Avalonia; 4 | using Avalonia.Android; 5 | using Avalonia.ReactiveUI; 6 | 7 | namespace Avalonia.WebView2.Sample; 8 | 9 | [Activity( 10 | Label = "Avalonia.WebView2.Sample", 11 | Theme = "@style/MyTheme.NoActionBar", 12 | Icon = "@drawable/icon", 13 | MainLauncher = true, 14 | ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize | ConfigChanges.UiMode)] 15 | public class MainActivity : AvaloniaMainActivity 16 | { 17 | protected override AppBuilder CustomizeAppBuilder(AppBuilder builder) 18 | { 19 | return base.CustomizeAppBuilder(builder) 20 | .WithInterFont() 21 | .UseReactiveUI(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Avalonia.WebView2.Sample.Mobile.Android/Properties/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/Avalonia.WebView2.Sample.Mobile.Android/Resources/AboutResources.txt: -------------------------------------------------------------------------------- 1 | Images, layout descriptions, binary blobs and string dictionaries can be included 2 | in your application as resource files. Various Android APIs are designed to 3 | operate on the resource IDs instead of dealing with images, strings or binary blobs 4 | directly. 5 | 6 | For example, a sample Android app that contains a user interface layout (main.axml), 7 | an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png) 8 | would keep its resources in the "Resources" directory of the application: 9 | 10 | Resources/ 11 | drawable/ 12 | icon.png 13 | 14 | layout/ 15 | main.axml 16 | 17 | values/ 18 | strings.xml 19 | 20 | In order to get the build system to recognize Android resources, set the build action to 21 | "AndroidResource". The native Android APIs do not operate directly with filenames, but 22 | instead operate on resource IDs. When you compile an Android application that uses resources, 23 | the build system will package the resources for distribution and generate a class called "R" 24 | (this is an Android convention) that contains the tokens for each one of the resources 25 | included. For example, for the above Resources layout, this is what the R class would expose: 26 | 27 | public class R { 28 | public class drawable { 29 | public const int icon = 0x123; 30 | } 31 | 32 | public class layout { 33 | public const int main = 0x456; 34 | } 35 | 36 | public class strings { 37 | public const int first_string = 0xabc; 38 | public const int second_string = 0xbcd; 39 | } 40 | } 41 | 42 | You would then use R.drawable.icon to reference the drawable/icon.png file, or R.layout.main 43 | to reference the layout/main.axml file, or R.strings.first_string to reference the first 44 | string in the dictionary file values/strings.xml. -------------------------------------------------------------------------------- /src/Avalonia.WebView2.Sample.Mobile.Android/Resources/drawable-night-v31/avalonia_anim.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 11 | 15 | 16 | 20 | 25 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 42 | 43 | 44 | 45 | 46 | 53 | 54 | 55 | 56 | 57 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /src/Avalonia.WebView2.Sample.Mobile.Android/Resources/drawable-v31/avalonia_anim.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 11 | 15 | 16 | 21 | 27 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 46 | 47 | 48 | 49 | 50 | 57 | 58 | 59 | 60 | 61 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /src/Avalonia.WebView2.Sample.Mobile.Android/Resources/drawable/splash_screen.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/Avalonia.WebView2.Sample.Mobile.Android/Resources/values-night/colors.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | #212121 4 | 5 | -------------------------------------------------------------------------------- /src/Avalonia.WebView2.Sample.Mobile.Android/Resources/values-v31/styles.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 6 | 7 | 17 | 21 | 22 | -------------------------------------------------------------------------------- /src/Avalonia.WebView2.Sample.Mobile.Android/Resources/values/colors.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | #FFFFFF 4 | 5 | -------------------------------------------------------------------------------- /src/Avalonia.WebView2.Sample.Mobile.Android/Resources/values/styles.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /src/Avalonia.WebView2.Sample.Mobile.iOS/AppDelegate.cs: -------------------------------------------------------------------------------- 1 | using Avalonia; 2 | using Avalonia.Controls; 3 | using Avalonia.iOS; 4 | using Avalonia.Media; 5 | using Avalonia.ReactiveUI; 6 | using Foundation; 7 | using UIKit; 8 | 9 | namespace Avalonia.WebView2.Sample; 10 | 11 | // The UIApplicationDelegate for the application. This class is responsible for launching the 12 | // User Interface of the application, as well as listening (and optionally responding) to 13 | // application events from iOS. 14 | [Register("AppDelegate")] 15 | #pragma warning disable CA1711 // Identifiers should not have incorrect suffix 16 | public partial class AppDelegate : AvaloniaAppDelegate 17 | #pragma warning restore CA1711 // Identifiers should not have incorrect suffix 18 | { 19 | protected override AppBuilder CustomizeAppBuilder(AppBuilder builder) 20 | { 21 | return base.CustomizeAppBuilder(builder) 22 | .WithInterFont() 23 | .UseReactiveUI(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Avalonia.WebView2.Sample.Mobile.iOS/Avalonia.WebView2.Sample.Mobile.iOS.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | net9.0-ios 6 | Avalonia.WebView2.Sample 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/Avalonia.WebView2.Sample.Mobile.iOS/Entitlements.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/Avalonia.WebView2.Sample.Mobile.iOS/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDisplayName 6 | Avalonia.WebView2.Sample 7 | CFBundleIdentifier 8 | com.github.beyonddimension.avalonia.webview2.sample 9 | CFBundleShortVersionString 10 | 1.0 11 | CFBundleVersion 12 | 1.0 13 | LSRequiresIPhoneOS 14 | 15 | MinimumOSVersion 16 | 13.0 17 | UIDeviceFamily 18 | 19 | 1 20 | 2 21 | 22 | UILaunchStoryboardName 23 | LaunchScreen 24 | UIRequiredDeviceCapabilities 25 | 26 | armv7 27 | 28 | UISupportedInterfaceOrientations 29 | 30 | UIInterfaceOrientationPortrait 31 | UIInterfaceOrientationPortraitUpsideDown 32 | UIInterfaceOrientationLandscapeLeft 33 | UIInterfaceOrientationLandscapeRight 34 | 35 | UISupportedInterfaceOrientations~ipad 36 | 37 | UIInterfaceOrientationPortrait 38 | UIInterfaceOrientationPortraitUpsideDown 39 | UIInterfaceOrientationLandscapeLeft 40 | UIInterfaceOrientationLandscapeRight 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /src/Avalonia.WebView2.Sample.Mobile.iOS/Main.cs: -------------------------------------------------------------------------------- 1 | using UIKit; 2 | 3 | namespace Avalonia.WebView2.Sample; 4 | static class Application 5 | { 6 | // This is the main entry point of the application. 7 | static void Main(string[] args) 8 | { 9 | // if you want to use a different Application Delegate class from "AppDelegate" 10 | // you can specify it here. 11 | UIApplication.Main(args, null, typeof(AppDelegate)); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Avalonia.WebView2.Sample.Mobile.iOS/Resources/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 21 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /src/Avalonia.WebView2.Sample.Mobile/App.axaml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/Avalonia.WebView2.Sample.Mobile/App.axaml.cs: -------------------------------------------------------------------------------- 1 | using Avalonia; 2 | using Avalonia.Controls.ApplicationLifetimes; 3 | using Avalonia.Markup.Xaml; 4 | using Avalonia.WebView2.Sample.ViewModels; 5 | using Avalonia.WebView2.Sample.Views; 6 | 7 | namespace Avalonia.WebView2.Sample; 8 | 9 | public partial class App : Application 10 | { 11 | public override void Initialize() 12 | { 13 | AvaloniaXamlLoader.Load(this); 14 | } 15 | 16 | public override void OnFrameworkInitializationCompleted() 17 | { 18 | //if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) 19 | //{ 20 | // desktop.MainWindow = new MainWindow 21 | // { 22 | // DataContext = new MainViewModel() 23 | // }; 24 | //} 25 | //else 26 | // 此示例项目仅移动端 27 | if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewPlatform) 28 | { 29 | singleViewPlatform.MainView = new MainView 30 | { 31 | DataContext = new MainViewModel() 32 | }; 33 | } 34 | 35 | base.OnFrameworkInitializationCompleted(); 36 | } 37 | } -------------------------------------------------------------------------------- /src/Avalonia.WebView2.Sample.Mobile/Assets/avalonia-logo.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BeyondDimension/Avalonia.WebView2/88baa44aab31213598b821794a4e06e97d2dde5e/src/Avalonia.WebView2.Sample.Mobile/Assets/avalonia-logo.ico -------------------------------------------------------------------------------- /src/Avalonia.WebView2.Sample.Mobile/Avalonia.WebView2.Sample.Mobile.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net9.0 5 | Avalonia.WebView2.Sample 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/Avalonia.WebView2.Sample.Mobile/ViewLocator.cs: -------------------------------------------------------------------------------- 1 | using Avalonia.Controls; 2 | using Avalonia.Controls.Templates; 3 | using Avalonia.WebView2.Sample.ViewModels; 4 | 5 | namespace Avalonia.WebView2.Sample; 6 | 7 | public class ViewLocator : IDataTemplate 8 | { 9 | public Control? Build(object? data) 10 | { 11 | if (data is null) 12 | return null; 13 | 14 | var name = data.GetType().FullName!.Replace("ViewModel", "View", StringComparison.Ordinal); 15 | var type = Type.GetType(name); 16 | 17 | if (type != null) 18 | { 19 | return (Control)Activator.CreateInstance(type)!; 20 | } 21 | 22 | return new TextBlock { Text = "Not Found: " + name }; 23 | } 24 | 25 | public bool Match(object? data) 26 | { 27 | return data is ViewModelBase; 28 | } 29 | } -------------------------------------------------------------------------------- /src/Avalonia.WebView2.Sample.Mobile/ViewModels/MainViewModel.cs: -------------------------------------------------------------------------------- 1 | namespace Avalonia.WebView2.Sample.ViewModels; 2 | 3 | public partial class MainViewModel : ViewModelBase 4 | { 5 | #pragma warning disable CA1822 // Mark members as static 6 | public string Source => "https://bing.com"; 7 | #pragma warning restore CA1822 // Mark members as static 8 | } 9 | -------------------------------------------------------------------------------- /src/Avalonia.WebView2.Sample.Mobile/ViewModels/ViewModelBase.cs: -------------------------------------------------------------------------------- 1 | using ReactiveUI; 2 | 3 | namespace Avalonia.WebView2.Sample.ViewModels; 4 | 5 | public abstract class ViewModelBase : ReactiveObject 6 | { 7 | } 8 | -------------------------------------------------------------------------------- /src/Avalonia.WebView2.Sample.Mobile/Views/MainView.axaml: -------------------------------------------------------------------------------- 1 | 13 | 14 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/Avalonia.WebView2.Sample.Mobile/Views/MainView.axaml.cs: -------------------------------------------------------------------------------- 1 | using Avalonia.Controls; 2 | 3 | namespace Avalonia.WebView2.Sample.Views; 4 | 5 | public partial class MainView : UserControl 6 | { 7 | public MainView() 8 | { 9 | InitializeComponent(); 10 | } 11 | } -------------------------------------------------------------------------------- /src/Avalonia.WebView2.Sample.Mobile/Views/MainWindow.axaml: -------------------------------------------------------------------------------- 1 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/Avalonia.WebView2.Sample.Mobile/Views/MainWindow.axaml.cs: -------------------------------------------------------------------------------- 1 | using Avalonia.Controls; 2 | 3 | namespace Avalonia.WebView2.Sample.Views; 4 | 5 | public partial class MainWindow : Window 6 | { 7 | public MainWindow() 8 | { 9 | InitializeComponent(); 10 | } 11 | } -------------------------------------------------------------------------------- /src/Avalonia.WebView2.Sample/App.xaml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/Avalonia.WebView2.Sample/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using Avalonia.Controls.ApplicationLifetimes; 2 | using Avalonia.Markup.Xaml; 3 | 4 | namespace Avalonia.WebView2.Sample; 5 | 6 | public sealed class App : Application 7 | { 8 | public override void Initialize() 9 | { 10 | AvaloniaXamlLoader.Load(this); 11 | InitWebView2(); 12 | } 13 | 14 | public override void OnFrameworkInitializationCompleted() 15 | { 16 | if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) 17 | { 18 | desktop.MainWindow = new MainWindow(); 19 | } 20 | 21 | base.OnFrameworkInitializationCompleted(); 22 | } 23 | 24 | static void InitWebView2() 25 | { 26 | #if WINDOWS 27 | if (global::Avalonia.Controls.WebView2.IsSupported) 28 | { 29 | //AvaloniaWebView2.DefaultCreationProperties = new() 30 | //{ 31 | // Language = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName, 32 | // UserDataFolder = GetUserDataFolder(), 33 | //}; 34 | 35 | //static string GetUserDataFolder() 36 | //{ 37 | // var path = Path.Combine(AppContext.BaseDirectory, "AppData", "WebView2", "UserData"); 38 | // if (!Directory.Exists(path)) Directory.CreateDirectory(path); 39 | // return path; 40 | //} 41 | } 42 | #elif !(WINDOWS || NETFRAMEWORK) && NET8_0_OR_GREATER 43 | #endif 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Avalonia.WebView2.Sample/Avalonia.WebView2.Sample.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | true 5 | 6 | 7 | 8 | 9 | 10 | 11 | net9.0-windows;net9.0 12 | 13 | 14 | 15 | 16 | 17 | net9.0-macos 18 | 19 | 20 | 21 | 22 | 23 | net9.0 24 | 25 | 26 | 27 | 28 | 29 | 30 | LINUX;$(DefineConstants) 31 | 32 | 33 | 34 | 35 | 36 | WinExe 37 | Properties\app.manifest 38 | net9.0-windows;net9.0 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | Exe 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 71 | .allowedextension 72 | 73 | none 74 | false 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /src/Avalonia.WebView2.Sample/BCL/MS/Internal/PresentationCore/SR.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | // https://github.com/dotnet/wpf/blob/v6.0.6/src/Microsoft.DotNet.Wpf/src/PresentationCore/SR.cs 5 | 6 | #if !NETFRAMEWORK && WINDOWS 7 | 8 | namespace MS.Internal.PresentationCore; 9 | 10 | internal static class SR 11 | { 12 | public static string Get(string name) => name switch 13 | { 14 | SRID.CantShowMBServiceWithOwner => "Cannot show MessageBox Service with Owner.", 15 | _ => "", 16 | }; 17 | } 18 | 19 | #endif -------------------------------------------------------------------------------- /src/Avalonia.WebView2.Sample/BCL/MS/Internal/PresentationCore/SRID.cs: -------------------------------------------------------------------------------- 1 | #if !NETFRAMEWORK && WINDOWS 2 | 3 | namespace MS.Internal.PresentationCore; 4 | 5 | static class SRID 6 | { 7 | /// 8 | /// https://github.com/dotnet/wpf/blob/v6.0.6/src/Microsoft.DotNet.Wpf/src/PresentationFramework/Resources/Strings.resx#L510 9 | /// 10 | public const string CantShowMBServiceWithOwner = "CantShowMBServiceWithOwner"; 11 | } 12 | 13 | #endif -------------------------------------------------------------------------------- /src/Avalonia.WebView2.Sample/BCL/MS/Win32/ExternDll.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | // https://github.com/dotnet/wpf/blob/v6.0.6/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/ExternDll.cs 5 | 6 | #if !NETFRAMEWORK && WINDOWS 7 | 8 | namespace MS.Win32; 9 | 10 | internal static class ExternDll 11 | { 12 | //public const string Activeds = "activeds.dll"; 13 | //public const string Advapi32 = "advapi32.dll"; 14 | //public const string Comctl32 = "comctl32.dll"; 15 | //public const string Comdlg32 = "comdlg32.dll"; 16 | //public const string DwmAPI = "dwmapi.dll"; 17 | //public const string Gdi32 = "gdi32.dll"; 18 | //public const string Gdiplus = "gdiplus.dll"; 19 | //public const string Hhctrl = "hhctrl.ocx"; 20 | //public const string Imm32 = "imm32.dll"; 21 | //public const string Kernel32 = "kernel32.dll"; 22 | //public const string Loadperf = "Loadperf.dll"; 23 | //public const string Mqrt = "mqrt.dll"; 24 | //public const string Mscoree = "mscoree.dll"; 25 | //public const string MsDrm = "msdrm.dll"; 26 | //public const string Mshwgst = "mshwgst.dll"; 27 | //public const string Msi = "msi.dll"; 28 | //public const string NaturalLanguage6 = "naturallanguage6.dll"; 29 | //public const string Ntdll = "ntdll.dll"; 30 | //public const string Ole32 = "ole32.dll"; 31 | //public const string Oleacc = "oleacc.dll"; 32 | //public const string Oleaut32 = "oleaut32.dll"; 33 | //public const string Olepro32 = "olepro32.dll"; 34 | //public const string Penimc = "PenIMC_cor3.dll"; 35 | //public const string PresentationCore = "PresentationCore.dll"; 36 | //public const string PresentationFramework = "PresentationFramework.dll"; 37 | //public const string PresentationHostDll = "PresentationHost_cor3.dll"; 38 | //public const string PresentationNativeDll = "PresentationNative_cor3.dll"; 39 | //public const string Psapi = "psapi.dll"; 40 | //public const string Shcore = "shcore.dll"; 41 | //public const string Shell32 = "shell32.dll"; 42 | //public const string Shfolder = "shfolder.dll"; 43 | //public const string Urlmon = "urlmon.dll"; 44 | public const string User32 = "user32.dll"; 45 | //public const string Uxtheme = "uxtheme.dll"; 46 | //public const string Version = "version.dll"; 47 | //public const string Vsassert = "vsassert.dll"; 48 | //public const string WindowsBase = "windowsbase.dll"; 49 | //public const string Wininet = "wininet.dll"; 50 | //public const string Winmm = "winmm.dll"; 51 | //public const string Winspool = "winspool.drv"; 52 | //public const string Wldp = "wldp.dll"; 53 | //public const string WpfGfx = "WpfGfx_cor3.dll"; 54 | //public const string WtsApi32 = "wtsapi32.dll"; 55 | } 56 | 57 | #endif -------------------------------------------------------------------------------- /src/Avalonia.WebView2.Sample/BCL/MS/Win32/UnsafeNativeMethodsCLR.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | // https://github.com/dotnet/wpf/blob/v6.0.6/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/UnsafeNativeMethodsCLR.cs 5 | 6 | #if !NETFRAMEWORK && WINDOWS 7 | 8 | using System.Runtime.InteropServices; 9 | 10 | namespace MS.Win32; 11 | 12 | internal static class UnsafeNativeMethods 13 | { 14 | [DllImport(ExternDll.User32, ExactSpelling = true, CharSet = CharSet.Auto)] 15 | public static extern IntPtr GetActiveWindow(); 16 | 17 | [DllImport(ExternDll.User32, SetLastError = true, CharSet = CharSet.Auto, BestFitMapping = false)] 18 | public static extern int MessageBox(HandleRef hWnd, string text, string caption, int type); 19 | } 20 | 21 | #endif -------------------------------------------------------------------------------- /src/Avalonia.WebView2.Sample/Common8/DomainPattern.cs: -------------------------------------------------------------------------------- 1 | // https://github.com/BeyondDimension/Common/blob/dev8/src/BD.Common8.Bcl/Net/DomainPattern.cs 2 | 3 | using System.Collections.Immutable; 4 | using System.Text.RegularExpressions; 5 | 6 | namespace System.Net; 7 | 8 | /// 9 | /// 域名表达式 10 | /// * 表示除 . 之外任意 0 到多个字符 11 | /// 12 | sealed class DomainPattern : IComparable 13 | { 14 | /// 15 | /// 通用分隔符 16 | /// 17 | public const char GeneralSeparator = ';'; 18 | 19 | readonly ImmutableArray regexs; 20 | readonly string domainPattern; 21 | 22 | /// 23 | /// 排序 24 | /// 25 | public long Order { get; init; } 26 | 27 | /// 28 | /// Initializes a new instance of the class. 29 | /// 30 | /// 31 | public DomainPattern(string domainPattern) 32 | { 33 | if (string.IsNullOrWhiteSpace(domainPattern)) 34 | throw new ArgumentNullException(nameof(domainPattern)); 35 | 36 | this.domainPattern = domainPattern; 37 | 38 | var items = domainPattern.Split( 39 | #if NETSTANDARD2_1_OR_GREATER || NETCOREAPP2_0_OR_GREATER 40 | GeneralSeparator, 41 | #else 42 | [GeneralSeparator], 43 | #endif 44 | StringSplitOptions.RemoveEmptyEntries); 45 | 46 | regexs = items.Select(s => 47 | { 48 | var isRegex = s.StartsWith( 49 | #if NETSTANDARD2_1_OR_GREATER || NETCOREAPP2_0_OR_GREATER 50 | '/' 51 | #else 52 | "/" 53 | #endif 54 | ); 55 | if (isRegex) 56 | { 57 | return new Regex(s[1..], RegexOptions.IgnoreCase); 58 | } 59 | else 60 | { 61 | var regexPattern = Regex.Escape(s).Replace(@"\*", @"[^\.]*"); 62 | return new Regex($"^{regexPattern}", RegexOptions.IgnoreCase); 63 | } 64 | #pragma warning disable IDE0305 // 简化集合初始化 65 | }).ToImmutableArray(); 66 | #pragma warning restore IDE0305 // 简化集合初始化 67 | } 68 | 69 | /// 70 | /// 与目标比较 71 | /// 72 | /// 73 | /// 74 | public int CompareTo(DomainPattern? other) 75 | { 76 | if (other is null) 77 | { 78 | return 1; 79 | } 80 | 81 | if (Order < other.Order) 82 | { 83 | return -1; 84 | } 85 | else if (Order > other.Order) 86 | { 87 | return 1; 88 | } 89 | 90 | var segmentsX = domainPattern.Split('.'); 91 | var segmentsY = other.domainPattern.Split('.'); 92 | var value = segmentsX.Length - segmentsY.Length; 93 | if (value != 0) 94 | { 95 | return value; 96 | } 97 | 98 | for (var i = segmentsX.Length - 1; i >= 0; i--) 99 | { 100 | var x = segmentsX[i]; 101 | var y = segmentsY[i]; 102 | 103 | value = Compare(x, y); 104 | if (value == 0) 105 | { 106 | continue; 107 | } 108 | return value; 109 | } 110 | 111 | return 0; 112 | } 113 | 114 | /// 115 | /// 比较两个分段 116 | /// 117 | /// 118 | /// 119 | /// 120 | static int Compare(string x, string y) 121 | { 122 | var valueX = x.Replace('*', char.MaxValue); 123 | var valueY = y.Replace('*', char.MaxValue); 124 | return valueX.CompareTo(valueY); 125 | } 126 | 127 | /// 128 | /// 是否与指定字符串匹配 129 | /// 130 | /// 131 | /// 132 | public bool IsMatch(string value) => regexs.Any(s => s.IsMatch(value)); 133 | 134 | /// 135 | /// 是否与指定域名匹配 136 | /// 137 | /// 138 | /// 139 | public bool IsMatchOnlyDomain(string domain) 140 | { 141 | try 142 | { 143 | if (domain.Contains('/')) 144 | { 145 | Uri uri = new(domain); 146 | domain = uri.Host; 147 | } 148 | } 149 | catch 150 | { 151 | } 152 | var result = regexs.Any(s => s.IsMatch(domain)); 153 | return result; 154 | } 155 | 156 | /// 157 | public override string ToString() => domainPattern; 158 | } -------------------------------------------------------------------------------- /src/Avalonia.WebView2.Sample/MainWindow.xaml: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 | 15 |