Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: use custom user data dir for updater WebView2 #138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions App/App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<LangVersion>preview</LangVersion>
<!-- We have our own implementation of main with exception handling -->
<DefineConstants>DISABLE_XAML_GENERATED_MAIN;DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION</DefineConstants>
<!-- Default version for debug builds, overridden during releases -->
<Version>0.1.0.0</Version>

<AssemblyName>Coder Desktop</AssemblyName>
<AssemblyTitle>Coder Desktop</AssemblyTitle>
Expand Down
16 changes: 14 additions & 2 deletions App/ViewModels/UpdaterUpdateAvailableViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Coder.Desktop.App.Services;
using CommunityToolkit.Mvvm.ComponentModel;
using Microsoft.Extensions.Logging;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.Web.WebView2.Core;
using NetSparkleUpdater;
using NetSparkleUpdater.Enums;
using NetSparkleUpdater.Events;
Expand Down Expand Up @@ -174,8 +176,18 @@ public async Task Changelog_Loaded(object sender, RoutedEventArgs e)
if (sender is not WebView2 webView)
return;

// Start the engine.
await webView.EnsureCoreWebView2Async();
// Start the engine with a custom user data folder. The default for
// unpackaged WinUI 3 apps is to write to a subfolder in the app's
// install directory, which is Program Files by default and not
// writeable by the user.
var userDataFolder = Path.Join(SettingsManagerUtils.AppSettingsDirectory(), "WebView2");
_logger.LogDebug("Creating WebView2 user data folder at {UserDataFolder}", userDataFolder);
Directory.CreateDirectory(userDataFolder);
var env = await CoreWebView2Environment.CreateWithOptionsAsync(
null,
userDataFolder,
new CoreWebView2EnvironmentOptions());
await webView.EnsureCoreWebView2Async(env);

// Disable unwanted features.
var settings = webView.CoreWebView2.Settings;
Expand Down
Loading