Skip to content

Commit

Permalink
SCOOBE info bar polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
stefansjfw committed Aug 1, 2024
1 parent 5ead4f9 commit faedb8b
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private static bool IsDataDiagnosticsEnabled()
object registryValue = null;
try
{
registryValue = Registry.GetValue(DataDiagnosticsRegistryKey, DataDiagnosticsRegistryValueName, false);
registryValue = Registry.GetValue(DataDiagnosticsRegistryKey, DataDiagnosticsRegistryValueName, 0);
}
catch
{
Expand Down
34 changes: 33 additions & 1 deletion src/settings-ui/Settings.UI/Helpers/DataDiagnostics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ public static class DataDiagnostics
{
private static readonly string DataDiagnosticsRegistryKey = @"HKEY_CURRENT_USER\Software\Classes\PowerToys\";
private static readonly string DataDiagnosticsRegistryValueName = @"AllowDataDiagnostics";
private static readonly string DataDiagnosticsDataDiagnosticsUserActionRegistryValueName = @"DataDiagnosticsUserAction";

public static bool GetValue()
{
object registryValue = null;
try
{
registryValue = Registry.GetValue(DataDiagnosticsRegistryKey, DataDiagnosticsRegistryValueName, false);
registryValue = Registry.GetValue(DataDiagnosticsRegistryKey, DataDiagnosticsRegistryValueName, 0);
}
catch
{
Expand All @@ -43,5 +44,36 @@ public static void SetValue(bool value)
Logger.LogError($"Failed to set the Data Diagnostics value in the registry: {ex.Message}");
}
}

public static bool GetUserActionValue()
{
object registryValue = null;
try
{
registryValue = Registry.GetValue(DataDiagnosticsRegistryKey, DataDiagnosticsDataDiagnosticsUserActionRegistryValueName, 0);
}
catch
{
}

if (registryValue is not null)
{
return (int)registryValue == 1 ? true : false;
}

return false;
}

public static void SetUserActionValue(bool value)
{
try
{
Registry.SetValue(DataDiagnosticsRegistryKey, DataDiagnosticsDataDiagnosticsUserActionRegistryValueName, value ? 1 : 0);
}
catch (Exception ex)
{
Logger.LogError($"Failed to set the Data Diagnostics user action value in the registry: {ex.Message}");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:tk7controls="using:CommunityToolkit.WinUI.UI.Controls"
xmlns:tkcontrols="using:CommunityToolkit.WinUI.Controls"
xmlns:ui="using:CommunityToolkit.WinUI"
Loaded="Page_Loaded"
mc:Ignorable="d">

Expand All @@ -17,27 +19,39 @@
<RowDefinition Height="*" />
</Grid.RowDefinitions>

<InfoBar
x:Name="DataDiagnosticsInfoBar"
x:Uid="Oobe_WhatsNew_DataDiagnostics_InfoBar"
Grid.Row="0"
VerticalAlignment="Top"
IsClosable="True"
IsOpen="{x:Bind IsDataDiagnosticsInfoBarEnabled, Mode=OneWay}"
IsTabStop="{x:Bind IsDataDiagnosticsInfoBarEnabled, Mode=OneWay}"
Severity="Informational">
<InfoBar.Content>
<StackPanel Spacing="16">
<HyperlinkButton
x:Name="DataDiagnosticsInfoBarDesc"
x:Uid="Oobe_WhatsNew_DataDiagnostics_InfoBar_Desc"
NavigateUri="https://aka.ms/powertoys-data-and-privacy-documentation" />
<tkcontrols:SettingsCard
Visibility="{x:Bind ShowDataDiagnosticsInfoBar, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}}"
IsTabStop="{x:Bind ShowDataDiagnosticsInfoBar, Mode=OneWay}"
x:Name="WhatsNewDataDiagnosticsInfoBar" x:Uid="Oobe_WhatsNew_DataDiagnostics_InfoBar" Background="{ThemeResource InfoBarInformationalSeverityBackgroundBrush}">
<tkcontrols:SettingsCard.HeaderIcon>
<FontIcon Foreground="{ThemeResource InfoBarInformationalSeverityIconBackground}" Glyph="&#xF167;" />
</tkcontrols:SettingsCard.HeaderIcon>
<tkcontrols:SettingsCard.Description>
<StackPanel>
<TextBlock x:Name="WhatsNewDataDiagnosticsInfoBarDescText" >
<Hyperlink NavigateUri="https://aka.ms/powertoys-data-and-privacy-documentation">
<Run x:Uid="Oobe_WhatsNew_DataDiagnostics_InfoBar_Desc" />
</Hyperlink>
</TextBlock>
<TextBlock x:Name="WhatsNewDataDiagnosticsInfoBarDescTextYesClicked" Visibility="Collapsed">
<Run x:Uid="Oobe_WhatsNew_DataDiagnostics_Yes_Click_InfoBar_Desc" />
<Hyperlink Click="DataDiagnostics_OpenSettings_Click">
<Run x:Uid="Oobe_WhatsNew_DataDiagnostics_Yes_Click_OpenSettings_Text" />
</Hyperlink>
</TextBlock>
</StackPanel>
</InfoBar.Content>
<InfoBar.ActionButton>
<Button x:Uid="Oobe_WhatsNew_DataDiagnostics_InfoBar_Button_Enable" Click="EnableDataDiagnostics_Click" />
</InfoBar.ActionButton>
</InfoBar>
</tkcontrols:SettingsCard.Description>
<StackPanel Orientation="Horizontal" Spacing="8">
<Button x:Name="DataDiagnosticsButtonYes" x:Uid="Oobe_WhatsNew_DataDiagnostics_Button_Yes" Click="DataDiagnostics_InfoBar_YesNo_Click" CommandParameter="Yes" />
<HyperlinkButton x:Name="DataDiagnosticsButtonNo" x:Uid="Oobe_WhatsNew_DataDiagnostics_Button_No" Click="DataDiagnostics_InfoBar_YesNo_Click" CommandParameter="No" />
<Button
Margin="16,0,0,0"
Content="{ui:FontIcon Glyph=&#xE894;,
FontSize=16}"
Style="{StaticResource SubtleButtonStyle}"
Click="DataDiagnostics_InfoBar_Close_Click" />
</StackPanel>
</tkcontrols:SettingsCard>

<StackPanel
Grid.Row="1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using Microsoft.PowerToys.Settings.UI.OOBE.ViewModel;
using Microsoft.PowerToys.Settings.UI.Views;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Documents;
using Microsoft.UI.Xaml.Navigation;
using Microsoft.Win32;

Expand All @@ -48,7 +49,7 @@ private sealed class PowerToysReleaseInfo

public OobePowerToysModule ViewModel { get; set; }

public bool IsDataDiagnosticsInfoBarEnabled => GetIsDataDiagnosticsInfoBarEnabled();
public bool ShowDataDiagnosticsInfoBar => GetShowDataDiagnosticsInfoBar();

/// <summary>
/// Initializes a new instance of the <see cref="OobeWhatsNew"/> class.
Expand All @@ -60,7 +61,7 @@ public OobeWhatsNew()
DataContext = ViewModel;
}

private bool GetIsDataDiagnosticsInfoBarEnabled()
private bool GetShowDataDiagnosticsInfoBar()
{
var isDataDiagnosticsGpoDisallowed = GPOWrapper.GetAllowDataDiagnosticsValue() == GpoRuleConfigured.Disabled;

Expand All @@ -69,6 +70,13 @@ private bool GetIsDataDiagnosticsInfoBarEnabled()
return false;
}

bool userActed = DataDiagnostics.GetUserActionValue();

if (userActed)
{
return false;
}

bool registryValue = DataDiagnostics.GetValue();

bool isFirstRunAfterUpdate = (App.Current as Microsoft.PowerToys.Settings.UI.App).ShowScoobe;
Expand Down Expand Up @@ -194,20 +202,64 @@ private void ReleaseNotesMarkdown_LinkClicked(object sender, LinkClickedEventArg
}
}

private void EnableDataDiagnostics_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
private void DataDiagnostics_InfoBar_YesNo_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
{
string commandArg = string.Empty;
if (sender is Button senderBtn)
{
commandArg = senderBtn.CommandParameter.ToString();
}
else if (sender is HyperlinkButton senderLink)
{
commandArg = senderLink.CommandParameter.ToString();
}

if (string.IsNullOrEmpty(commandArg))
{
return;
}

// Update UI
DataDiagnosticsInfoBar.Title = ResourceLoaderInstance.ResourceLoader.GetString("Oobe_WhatsNew_DataDiagnostics_Enabled_InfoBar_Title");
DataDiagnosticsInfoBarDesc.Content = ResourceLoaderInstance.ResourceLoader.GetString("Oobe_WhatsNew_DataDiagnostics_Enabled_InfoBar_Desc");
DataDiagnosticsInfoBar.ActionButton.Visibility = Microsoft.UI.Xaml.Visibility.Collapsed;
if (commandArg == "Yes")
{
WhatsNewDataDiagnosticsInfoBar.Header = ResourceLoaderInstance.ResourceLoader.GetString("Oobe_WhatsNew_DataDiagnostics_Yes_Click_InfoBar_Title");
}
else
{
WhatsNewDataDiagnosticsInfoBar.Header = ResourceLoaderInstance.ResourceLoader.GetString("Oobe_WhatsNew_DataDiagnostics_No_Click_InfoBar_Title");
}

WhatsNewDataDiagnosticsInfoBarDescText.Visibility = Microsoft.UI.Xaml.Visibility.Collapsed;
WhatsNewDataDiagnosticsInfoBarDescTextYesClicked.Visibility = Microsoft.UI.Xaml.Visibility.Visible;
DataDiagnosticsButtonYes.Visibility = Microsoft.UI.Xaml.Visibility.Collapsed;
DataDiagnosticsButtonNo.Visibility = Microsoft.UI.Xaml.Visibility.Collapsed;

// Set Data Diagnostics registry values
if (commandArg == "Yes")
{
DataDiagnostics.SetValue(true);
}
else
{
DataDiagnostics.SetValue(false);
}

// Enable Data Diagnostics
DataDiagnostics.SetValue(true);
DataDiagnostics.SetUserActionValue(true);

this.DispatcherQueue.TryEnqueue(Microsoft.UI.Dispatching.DispatcherQueuePriority.Normal, () =>
{
ShellPage.ShellHandler?.SignalGeneralDataUpdate();
});
}

private void DataDiagnostics_InfoBar_Close_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
{
WhatsNewDataDiagnosticsInfoBar.Visibility = Microsoft.UI.Xaml.Visibility.Collapsed;
}

private void DataDiagnostics_OpenSettings_Click(Microsoft.UI.Xaml.Documents.Hyperlink sender, Microsoft.UI.Xaml.Documents.HyperlinkClickEventArgs args)
{
Common.UI.SettingsDeepLink.OpenSettings(Common.UI.SettingsDeepLink.SettingsWindow.Overview, true);
}
}
}
22 changes: 17 additions & 5 deletions src/settings-ui/Settings.UI/Strings/en-us/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -2102,20 +2102,32 @@ Take a moment to preview the various utilities listed or view our comprehensive
<data name="Oobe_Overview_EnableDataDiagnostics.Description" xml:space="preserve">
<value>Helps inform bug fixes, performance, and product decisions</value>
</data>
<data name="Oobe_WhatsNew_DataDiagnostics_InfoBar.Title" xml:space="preserve">
<data name="Oobe_WhatsNew_DataDiagnostics_InfoBar.Header" xml:space="preserve">
<value>Turn on diagnostic data to help us improve PowerToys?</value>
</data>
<data name="Oobe_WhatsNew_DataDiagnostics_InfoBar_Desc.Content" xml:space="preserve">
<data name="Oobe_WhatsNew_DataDiagnostics_InfoBar_Desc.Text" xml:space="preserve">
<value>PowerToys diagnostic data is completely optional.</value>
</data>
<data name="Oobe_WhatsNew_DataDiagnostics_InfoBar_Button_Enable.Content" xml:space="preserve">
<value>Enable</value>
</data>
<data name="Oobe_WhatsNew_DataDiagnostics_Enabled_InfoBar_Title" xml:space="preserve">
<data name="Oobe_WhatsNew_DataDiagnostics_Yes_Click_InfoBar_Title" xml:space="preserve">
<value>Thank you for helping to make PowerToys better!</value>
</data>
<data name="Oobe_WhatsNew_DataDiagnostics_Enabled_InfoBar_Desc" xml:space="preserve">
<value>You can change this at any time from settings.</value>
<data name="Oobe_WhatsNew_DataDiagnostics_No_Click_InfoBar_Title" xml:space="preserve">
<value>Preference updated.</value>
</data>
<data name="Oobe_WhatsNew_DataDiagnostics_Yes_Click_InfoBar_Desc.Text" xml:space="preserve">
<value>You can change this at any time from </value>
</data>
<data name="Oobe_WhatsNew_DataDiagnostics_Yes_Click_OpenSettings_Text.Text" xml:space="preserve">
<value>settings.</value>
</data>
<data name="Oobe_WhatsNew_DataDiagnostics_Button_Yes.Content" xml:space="preserve">
<value>Yes</value>
</data>
<data name="Oobe_WhatsNew_DataDiagnostics_Button_No.Content" xml:space="preserve">
<value>No</value>
</data>
<data name="ReleaseNotes.Content" xml:space="preserve">
<value>Release notes</value>
Expand Down

0 comments on commit faedb8b

Please sign in to comment.