Skip to content

Display a warning if SUI is unable to write to settings file #19027

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

carlos-zamora
Copy link
Member

Summary of the Pull Request

Adds logic to display a warning popup if the settings.json is marked as read-only and we try to write to the settings.json file. Previously, this scenario would crash, which definitely isn't right. However, a simple fix of "not-crashing" wouldn't feel right either.

This leverages the existing infrastructure to display a warning dialog when we failed to write to the settings file. The main annoyance here is that that popup dialog is located in TerminalWindow and is normally triggered from a failed SettingsLoadEventArgs. To get around this, CascadiaSettings::WriteSettingsToDisk() now returns a boolean to signal if the write was successful; whereas if it fails, a warning is added to the settings object. If we fail to write to disk, the function will return false and we'll raise an event with the settings' warnings to TerminalPage which passes it along to TerminalWindow.

Additionally, this uses IVectorView<SettingsLoadWarnings> as opposed to IVector<SettingsLoadWarnings> throughout the relevant code. It's more correct as the list of warnings shouldn't be mutable and the warnings from the CascadiaSettings object are retrieved in that format.

Validation Steps Performed

  • ✅ Using SUI, save settings when the settings.json is set to read-only

Closes #18913

@carlos-zamora
Copy link
Member Author

Demo

image

Urgh. I guess the dialog's title is slightly incorrect. Can be fixed if desired.

@@ -97,6 +97,7 @@ namespace TerminalApp

event Windows.Foundation.TypedEventHandler<Object, Object> OpenSystemMenu;
event Windows.Foundation.TypedEventHandler<Object, Microsoft.Terminal.Control.ShowWindowArgs> ShowWindowChanged;
event Windows.Foundation.TypedEventHandler<Object, Windows.Foundation.Collections.IVectorView<Microsoft.Terminal.Settings.Model.SettingsLoadWarnings> > ShowLoadWarningsDialog;
Copy link
Member Author

Choose a reason for hiding this comment

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

Fun fact: you need the space here - SettingsLoadWarnings> > ShowLoadWarningsDialog or else the MIDL compiler gets angry and confused

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.

If settings.json in portable settings folder (or folder itself) is not writeable WT will crash if you try to save settings
1 participant