Skip to content

Commit

Permalink
Make webview2 disposal safer (#14888)
Browse files Browse the repository at this point in the history
* update

* Update NodeModelAssemblyLoader.cs

* update

* update

* update

* update

* Update AnalyticsTests.cs

* Update SerializationTests.cs

* Update Setup.cs

* update

* update

* Update SplashScreen.xaml.cs

* Update PublishPackageViewModelTests.cs

* Update PublishPackageViewModelTests.cs

* update

* Update AssemblyInfo.cs

* Update TestUtilities.cs

* update

* upate

* update

* update

* update

* Update AnalyticsTests.cs

* Update WebView2Utilities.cs

* update

* update

* Update Setup.cs

* update

* update

* Update PeriodicEvaluationTests.cs

* update

* update

* update

* update - review comments

---------

Co-authored-by: pinzart <[email protected]>
  • Loading branch information
pinzart90 and pinzart authored Feb 8, 2024
1 parent 091cbbf commit 8775f64
Show file tree
Hide file tree
Showing 16 changed files with 330 additions and 323 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ jobs:
uses: microsoft/[email protected]
- name: Install dependencies for windows runtime
run: |
dotnet restore ${{ github.workspace }}\Dynamo\src\Dynamo.All.sln /p:Configuration=Release --runtime=win-x64 -p:DotNet=net8.0
dotnet restore ${{ github.workspace }}\Dynamo\src\Dynamo.All.sln /p:Configuration=Release --runtime=win-x64
- name: Build Dynamo with MSBuild for Windows
run: |
Write-Output "***Continue with the build, Good luck developer!***"
msbuild ${{ github.workspace }}\Dynamo\src\Dynamo.All.sln /p:Configuration=Release /p:DotNet=net8.0
msbuild ${{ github.workspace }}\Dynamo\src\Dynamo.All.sln /p:Configuration=Release
- name: Look for DynamoCLI.exe
run: |
Write-Output "***Locating DynamoCLI.exe!***"
Expand Down
41 changes: 0 additions & 41 deletions .github/workflows/build_dynamo_all_net6.0.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build DynamoCore.sln with .NET 6.0 on linux
name: Build DynamoCore.sln net6.0 linux
# Build DynamoCore.sln with .NET 8.0 on linux
name: Build DynamoCore.sln net8.0 linux

on:
push:
Expand All @@ -17,22 +17,24 @@ jobs:
path: Dynamo
- name: Setup dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: Disable problem matcher
run: echo "::remove-matcher owner=csc::"
- name: Install dependencies for linux runtime
run: dotnet restore ${{ github.workspace }}/Dynamo/src/DynamoCore.sln -p:Platform=NET60_Linux --runtime=linux-x64
run: dotnet restore ${{ github.workspace }}/Dynamo/src/DynamoCore.sln -p:Platform=NET_Linux --runtime=linux-x64
- name: Build Dynamo with MSBuild for Linux
run: |
echo "***Continue with the build, Good luck developer!***"
dotnet build ${{ github.workspace }}/Dynamo/src/DynamoCore.sln -c Release /p:Platform=NET60_Linux
dotnet build ${{ github.workspace }}/Dynamo/src/DynamoCore.sln -c Release /p:Platform=NET_Linux
- name: Look for DynamoCLI.exe
run: |
cd "${{ github.workspace }}/Dynamo/bin/NET60_Linux/Release"
cd "${{ github.workspace }}/Dynamo/bin/NET_Linux/Release"
echo "***Locating DynamoCLI for Linux!***"
test "./DynamoCLI.exe" && echo "DynamoCLI exists!"
- name: Run smoke tests
run: |
cd "${{ github.workspace }}/Dynamo/bin/NET60_Linux/Release"
cd "${{ github.workspace }}/Dynamo/bin/NET_Linux/Release"
echo "***Running Smoke tests on linux***"
#TODO unfortunately dotnet does not find any tests in this assembly.
#dotnet test DynamoCoreTests.dll --filter "TestCategory~UnitTest"
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Setup dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: '6.0.x'
dotnet-version: '8.0.x'
- name: Disable problem matcher
run: Write-Output "::remove-matcher owner=csc::"
- name: Setup msbuild
Expand All @@ -40,15 +40,15 @@ jobs:
Write-Error "DynamoCLI.exe was not found!"
}
- name: Install dependencies for linux runtime
run: dotnet restore ${{ github.workspace }}\Dynamo\src\DynamoCore.sln -p:Platform=NET60_Linux --runtime=linux-x64
run: dotnet restore ${{ github.workspace }}\Dynamo\src\DynamoCore.sln -p:Platform=NET_Linux --runtime=linux-x64
- name: Build Dynamo with MSBuild for Linux
run: |
Write-Output "***Continue with the build, Good luck developer!***"
msbuild ${{ github.workspace }}\Dynamo\src\DynamoCore.sln /p:Configuration=Release /p:Platform=NET60_Linux
msbuild ${{ github.workspace }}\Dynamo\src\DynamoCore.sln /p:Configuration=Release /p:Platform=NET_Linux
- name: Look for DynamoCLI
run: |
Write-Output "***Locating DynamoCLI for Linux!***"
if (Test-Path -Path "${{ github.workspace }}\Dynamo\bin\NET60_Linux\Release\DynamoCLI") {
if (Test-Path -Path "${{ github.workspace }}\Dynamo\bin\NET_Linux\Release\DynamoCLI") {
Write-Output "DynamoCLI exists!"
} else {
Write-Error "DynamoCLI was not found!"
Expand Down
2 changes: 1 addition & 1 deletion src/Config/CS_SDK.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Platforms>AnyCPU;NET60_Linux;</Platforms>
<Platforms>AnyCPU;NET_Linux;</Platforms>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<PlatformTarget >x64</PlatformTarget>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,22 +170,30 @@ async void InitializeAsync()
};
}

//Initialize the CoreWebView2 component otherwise we can't navigate to a web page
await documentationBrowser.EnsureCoreWebView2Async();

this.documentationBrowser.CoreWebView2.WebMessageReceived += CoreWebView2OnWebMessageReceived;
comScriptingObject = new ScriptingObject(this.viewModel);
//register the interop object into the browser.
this.documentationBrowser.CoreWebView2.AddHostObjectToScript("bridge", comScriptingObject);

this.documentationBrowser.CoreWebView2.Settings.IsZoomControlEnabled = true;
this.documentationBrowser.CoreWebView2.Settings.AreDevToolsEnabled = true;

initState = AsyncMethodState.Done;
try
{
//Initialize the CoreWebView2 component otherwise we can't navigate to a web page
await documentationBrowser.Initialize(Log);

this.documentationBrowser.CoreWebView2.WebMessageReceived += CoreWebView2OnWebMessageReceived;
comScriptingObject = new ScriptingObject(this.viewModel);
//register the interop object into the browser.
this.documentationBrowser.CoreWebView2.AddHostObjectToScript("bridge", comScriptingObject);

this.documentationBrowser.CoreWebView2.Settings.IsZoomControlEnabled = true;
this.documentationBrowser.CoreWebView2.Settings.AreDevToolsEnabled = true;

initState = AsyncMethodState.Done;
}
catch(ObjectDisposedException ex)
{
Log(ex.Message);
}

}
//if we make it this far, for example to do re-entry to to this method, while we're still
//initializing, don't do anything, just bail.
if(initState == AsyncMethodState.Done)
if (initState == AsyncMethodState.Done)
{
if (Directory.Exists(VirtualFolderPath))
{
Expand All @@ -211,11 +219,6 @@ private void CoreWebView2OnWebMessageReceived(object sender, CoreWebView2WebMess
/// </summary>
public void Dispose()
{
if (initState == AsyncMethodState.Started)
{
Log("DocumentationBrowserView is being disposed but async initialization is still not done");
}

Dispose(true);
GC.SuppressFinalize(this);
}
Expand Down
Loading

0 comments on commit 8775f64

Please sign in to comment.