[Settings]Fix MWB infobars to hide when the module is disabled (#33562)

## Summary of the Pull Request

This PR fixes two bugs for the info bars on the MWB settings page:
- The bars are shown if module is disabled.
- Some bars can be closed.
- Some bars are reacting to tab stop on closed state.
This commit is contained in:
Heiko 2024-07-17 15:42:22 +02:00 committed by GitHub
parent c24000ec41
commit c87d8c37e1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 8 deletions

View File

@ -170,9 +170,9 @@
<InfoBar
x:Uid="MouseWithoutBorders_CannotDragDropAsAdmin"
IsClosable="True"
IsOpen="{x:Bind ViewModel.IsElevated, Mode=OneWay}"
IsTabStop="True"
IsClosable="False"
IsOpen="{x:Bind ViewModel.ShowInfobarCannotDragDropAsAdmin, Mode=OneWay}"
IsTabStop="{x:Bind ViewModel.ShowInfobarCannotDragDropAsAdmin, Mode=OneWay}"
Severity="Informational" />
@ -191,14 +191,14 @@
<InfoBar
x:Uid="MouseWithoutBorders_RunAsAdminText"
IsClosable="False"
IsOpen="{x:Bind ViewModel.CanToggleUseService, Mode=OneWay, Converter={StaticResource BoolNegationConverter}}"
IsTabStop="True"
IsOpen="{x:Bind ViewModel.ShowInfobarRunAsAdminText, Mode=OneWay}"
IsTabStop="{x:Bind ViewModel.ShowInfobarRunAsAdminText, Mode=OneWay}"
Severity="Informational" />
<InfoBar
x:Uid="MouseWithoutBorders_ServiceUserUninstallWarning"
IsClosable="True"
IsOpen="True"
IsTabStop="True"
IsClosable="False"
IsOpen="{x:Bind ViewModel.IsEnabled, Mode=OneWay}"
IsTabStop="{x:Bind ViewModel.IsEnabled, Mode=OneWay}"
Severity="Warning" />
<tkcontrols:SettingsCard
x:Uid="MouseWithoutBorders_UninstallService"

View File

@ -92,6 +92,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
Settings.Properties.UseService = value;
OnPropertyChanged(nameof(UseService));
OnPropertyChanged(nameof(CanUninstallService));
OnPropertyChanged(nameof(ShowInfobarRunAsAdminText));
// Must block here until the process exits
Task.Run(async () =>
@ -566,6 +567,8 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
_isEnabled = value;
GeneralSettingsConfig.Enabled.MouseWithoutBorders = value;
OnPropertyChanged(nameof(IsEnabled));
OnPropertyChanged(nameof(ShowInfobarRunAsAdminText));
OnPropertyChanged(nameof(ShowInfobarCannotDragDropAsAdmin));
Task.Run(async () =>
{
@ -1045,6 +1048,14 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
public void NotifyPropertyChanged([CallerMemberName] string propertyName = null)
{
OnPropertyChanged(propertyName);
// Skip saving settings for UI properties
if (propertyName == nameof(ShowInfobarCannotDragDropAsAdmin) ||
propertyName == nameof(ShowInfobarRunAsAdminText))
{
return;
}
SettingsUtils.SaveSettings(Settings.ToJsonString(), MouseWithoutBordersSettings.ModuleName);
if (propertyName == nameof(UseService))
@ -1071,5 +1082,15 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
SendCustomAction("uninstall_service");
}
public bool ShowInfobarCannotDragDropAsAdmin
{
get { return IsElevated && IsEnabled; }
}
public bool ShowInfobarRunAsAdminText
{
get { return !CanToggleUseService && IsEnabled; }
}
}
}