Skip to content

Settings: Add pending changes tracking and apply confirmation dialog#14425

Open
dabhattimsft wants to merge 13 commits intomasterfrom
user/dabhatti/wslSettingsRestart
Open

Settings: Add pending changes tracking and apply confirmation dialog#14425
dabhattimsft wants to merge 13 commits intomasterfrom
user/dabhatti/wslSettingsRestart

Conversation

@dabhattimsft
Copy link

@dabhattimsft dabhattimsft commented Mar 12, 2026

Summary of the Pull Request

Adds "Apply Changes" workflow to the WSL Settings app. Settings changes are now tracked as pending and only written to disk when the user confirms, giving clear visibility into what will change.

PR Checklist

  • Closes: Link to issue #xxx
  • Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • Tests: Added/updated if needed and all pass
  • Localization: All end user facing strings can be localized
  • Dev docs: Added/updated if needed
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

SetWslConfigSetting no longer writes to disk immediately. Instead it records changes in a pending dictionary, comparing against the persisted value to auto-remove no-op edits.

New PendingChangesChanged event so the UI can react when the pending set becomes non-empty or empty.

  • "Apply changes" button appears at the bottom of each settings page (Developer, FileSystem, MemAndProc, Networking, OptionalFeatures) when there are pending changes.
    • "Shutdown WSL now" — commits all pending changes to disk and runs wsl --shutdown so they take effect on next launch.
    • "Later" — commits changes to disk without shutting down; settings apply on the next WSL start.
    • Dismiss / close — leaves changes pending (nothing is written).
image

Validation Steps Performed

Manually tested

Darshak Bhatti added 3 commits March 5, 2026 17:48
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an “Apply changes” workflow to the WinUI-based WSL Settings app by tracking configuration edits as pending, and only committing them to disk after explicit user confirmation (optionally followed by wsl --shutdown).

Changes:

  • Introduces pending-changes tracking in IWslConfigService/WslConfigService, with a new PendingChangesChanged event and commit/clear APIs.
  • Updates Settings view models/pages to react to pending state (HasPendingChanges) and show an “Apply changes” button.
  • Adds an apply confirmation dialog that summarizes pending edits and offers “Shutdown WSL now” vs “Later”.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/windows/wslsettings/Views/Settings/SettingsApplyHelper.cs New helper that builds and shows the apply/confirm dialog and triggers commit + optional shutdown.
src/windows/wslsettings/Views/Settings/DeveloperPage.xaml(.cs) Adds “Apply changes” button and hooks pending-changes notifications.
src/windows/wslsettings/Views/Settings/FileSystemPage.xaml(.cs) Adds “Apply changes” button and hooks pending-changes notifications.
src/windows/wslsettings/Views/Settings/MemAndProcPage.xaml(.cs) Adds “Apply changes” button and hooks pending-changes notifications.
src/windows/wslsettings/Views/Settings/NetworkingPage.xaml(.cs) Adds “Apply changes” button and hooks pending-changes notifications.
src/windows/wslsettings/Views/Settings/OptionalFeaturesPage.xaml(.cs) Adds “Apply changes” button and hooks pending-changes notifications.
src/windows/wslsettings/ViewModels/Settings/WslConfigSettingViewModel.cs Adds HasPendingChanges property + handler to update UI when pending state changes.
src/windows/wslsettings/Services/WslConfigService.cs Implements pending dictionary, commit/clear APIs, and new pending-changes event.
src/windows/wslsettings/Contracts/Services/IWslConfigService.cs Extends contract with pending-changes APIs and WslConfigPendingChange model.
src/windows/wslsettings/CMakeLists.txt Adds the new helper source file to the build.
localization/strings/en-US/Resources.resw Adds localized strings for apply dialog/buttons and error messages.

@benhillis
Copy link
Member

This seems like a lot of code to handle this. Instead could we just keep track of the config struct when we launch and compare it to the current config (and then update that initial struct when we click apply / shutdown / whatever).

@dabhattimsft dabhattimsft requested a review from OneBlue March 13, 2026 17:15
Darshak Bhatti added 2 commits March 13, 2026 13:39
@dabhattimsft dabhattimsft requested a review from Copilot March 18, 2026 20:55
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 5 comments.

@dabhattimsft dabhattimsft requested a review from Copilot March 18, 2026 23:01
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.

@dabhattimsft dabhattimsft requested a review from Copilot March 18, 2026 23:33
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 8 comments.

@dabhattimsft dabhattimsft requested a review from Copilot March 19, 2026 00:10
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 5 comments.

var changeLines = new List<string>(pendingChanges.Count);
foreach (var change in pendingChanges)
{
changeLines.Add($"- {GetSettingDisplayName(change.ConfigEntry)}: {FormatSettingValue(change.PendingSetting)}");
Copy link

Copilot AI Mar 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pending-changes lines are constructed with hardcoded punctuation/formatting ("- {name}: {value}"). This makes part of the user-facing dialog content non-localizable and may not read well in all locales. Consider using a localized format string/resource (or a structured UI like a ListView) to format each entry.

Suggested change
changeLines.Add($"- {GetSettingDisplayName(change.ConfigEntry)}: {FormatSettingValue(change.PendingSetting)}");
changeLines.Add(string.Format(
"Settings_ApplyChangesDialogChangeLineFormat".GetLocalized(),
GetSettingDisplayName(change.ConfigEntry),
FormatSettingValue(change.PendingSetting)));

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name and value are both already localized. The only hardcoded pieces are the bullet dash and colon. Won't fix for now unless reviewers say otherwise.

Comment on lines 21 to 50
@@ -27,41 +33,147 @@ public WslConfigService()
_wslConfigFileSystemWatcher.Renamed += OnWslConfigFileChanged;

_wslConfigFileSystemWatcher!.EnableRaisingEvents = true;

// Read all current config values into both snapshots so they start in sync
lock (_wslCoreConfigInterfaceLockObj!)
{
RefreshSnapshots_NoLock();
}
}

~WslConfigService()
{
DisposeSnapshot(_baselineSnapshot);
DisposeSnapshot(_workingSnapshot);
WslCoreConfigInterface.FreeWslConfig(_wslConfig);
WslCoreConfigInterface.FreeWslConfig(_wslConfigDefaults);
}
Copy link

Copilot AI Mar 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WslConfigService creates a FileSystemWatcher but never disposes it. Since this service is a singleton, the watcher will keep OS handles for the app lifetime; and even at shutdown the finalizer currently doesn't dispose it. Consider implementing IDisposable and disposing/unsubscribing the watcher (and disabling events) when the app shuts down.

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings March 21, 2026 00:01
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 3 comments.

public required IWslConfigSetting PendingSetting { get; init; }
}

public interface IWslConfigSetting
Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetPendingChanges() returns WslConfigPendingChange objects containing IWslConfigSetting instances that wrap unmanaged allocations (LibWsl.WslConfigSetting implements IDisposable). Since IWslConfigSetting doesn’t expose disposal, callers (like the Apply dialog) can’t deterministically free these clones, which can lead to avoidable unmanaged-memory growth. Consider changing WslConfigPendingChange to carry managed value snapshots (e.g., entry + strongly-typed value fields), or expose a disposable type (e.g., WslConfigSettingManaged / IDisposable) with clear ownership semantics.

Suggested change
public interface IWslConfigSetting
public interface IWslConfigSetting : System.IDisposable

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pre-existing. Can take it up in future PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants