Skip to content

Commit 29943c8

Browse files
authored
fix: use custom user data dir for updater WebView2 (#138)
The default location was in the install directory, which is not writeable by regular users. We now store the WebView2 data directory in our AppData/Local folder. This is what it looked like when broken: ![image](https://github.com/user-attachments/assets/f6d241d7-9341-4c70-9e7f-b8230dc5c9d4)
1 parent cb62556 commit 29943c8

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

‎App/App.csproj‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
<LangVersion>preview</LangVersion>
1818
<!-- We have our own implementation of main with exception handling -->
1919
<DefineConstants>DISABLE_XAML_GENERATED_MAIN;DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION</DefineConstants>
20+
<!-- Default version for debug builds, overridden during releases -->
21+
<Version>0.1.0.0</Version>
2022

2123
<AssemblyName>Coder Desktop</AssemblyName>
2224
<AssemblyTitle>Coder Desktop</AssemblyTitle>

‎App/ViewModels/UpdaterUpdateAvailableViewModel.cs‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
usingSystem.IO;
55
usingSystem.Linq;
66
usingSystem.Threading.Tasks;
7+
usingCoder.Desktop.App.Services;
78
usingCommunityToolkit.Mvvm.ComponentModel;
89
usingMicrosoft.Extensions.Logging;
910
usingMicrosoft.UI.Xaml;
1011
usingMicrosoft.UI.Xaml.Controls;
12+
usingMicrosoft.Web.WebView2.Core;
1113
usingNetSparkleUpdater;
1214
usingNetSparkleUpdater.Enums;
1315
usingNetSparkleUpdater.Events;
@@ -174,8 +176,18 @@ public async Task Changelog_Loaded(object sender, RoutedEventArgs e)
174176
if(senderis not WebView2webView)
175177
return;
176178

177-
// Start the engine.
178-
awaitwebView.EnsureCoreWebView2Async();
179+
// Start the engine with a custom user data folder. The default for
180+
// unpackaged WinUI 3 apps is to write to a subfolder in the app's
181+
// install directory, which is Program Files by default and not
182+
// writeable by the user.
183+
varuserDataFolder=Path.Join(SettingsManagerUtils.AppSettingsDirectory(),"WebView2");
184+
_logger.LogDebug("Creating WebView2 user data folder at{UserDataFolder}",userDataFolder);
185+
Directory.CreateDirectory(userDataFolder);
186+
varenv=awaitCoreWebView2Environment.CreateWithOptionsAsync(
187+
null,
188+
userDataFolder,
189+
newCoreWebView2EnvironmentOptions());
190+
awaitwebView.EnsureCoreWebView2Async(env);
179191

180192
// Disable unwanted features.
181193
varsettings=webView.CoreWebView2.Settings;

0 commit comments

Comments
(0)