Added a user value snapshot when a configuration plugin takes over a setting

This commit is contained in:
Thorsten Sommer 2026-08-09 20:31:51 +02:00
parent c4471213fa
commit 4bdf64b262
Signed by untrusted user who does not match committer: tsommer
GPG Key ID: 371BBA77A02C0108
2 changed files with 21 additions and 2 deletions

View File

@ -159,11 +159,14 @@ public abstract record ConfigMetaBase(string SettingName) : IConfig
/// <remarks>
/// Only an unmanaged setting holds a value which belongs to the user. When one configuration
/// plugin takes a setting over from another, the current value belongs to the previous plugin,
/// so the snapshot of the user's value must survive that handover untouched.
/// so the snapshot of the user's value must survive that handover untouched.<br/><br/>
/// The persisted editable default counts as managed as well: unlike a locked setting, it is not
/// restored into the in-memory state when the settings are loaded, so right after a start it is
/// the only evidence that a configuration plugin is already in charge.
/// </remarks>
public void CaptureUserValueSnapshot()
{
if (this.ManagedMode is not null)
if (this.ManagedMode is not null || SettingsManagerAccess.ConfigurationData.ManagedEditableDefaults.ContainsKey(this.SettingName))
return;
var snapshots = SettingsManagerAccess.ConfigurationData.ManagedUserValueSnapshots;

View File

@ -913,6 +913,13 @@ public static partial class ManagedConfiguration
if (!MayManageSetting(configPluginId, configMeta))
return false;
//
// Remember the value the user had chosen before any configuration plugin took this setting
// over. Once no plugin manages it anymore, we hand that value back to the user:
//
if (successful)
configMeta.CaptureUserValueSnapshot();
switch (successful)
{
case true:
@ -967,6 +974,15 @@ public static partial class ManagedConfiguration
if (!MayManageSetting(configPluginId, configMeta))
return false;
//
// Remember the value the user had chosen before any configuration plugin took this setting
// over. Once no plugin manages it anymore, we hand that value back to the user. This has to
// happen before the managed state below changes, because only an unmanaged setting holds a
// value which belongs to the user:
//
if (successful)
configMeta.CaptureUserValueSnapshot();
switch (successful)
{
case true when managedMode is ManagedConfigurationMode.LOCKED: