Skip to content

Commit

Permalink
[WIP] Add view data option
Browse files Browse the repository at this point in the history
needs service to listen to events
  • Loading branch information
stefansjfw committed Aug 14, 2024
1 parent 2171df0 commit ed8c240
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 6 deletions.
32 changes: 32 additions & 0 deletions src/settings-ui/Settings.UI/Helpers/DataDiagnostics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ 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";
private static readonly string DataDiagnosticsDataDiagnosticsViewDataRegistryValueName = @"DataDiagnosticsViewEnabled";

public static bool GetValue()
{
Expand Down Expand Up @@ -75,5 +76,36 @@ public static void SetUserActionValue(bool value)
Logger.LogError($"Failed to set the Data Diagnostics user action value in the registry: {ex.Message}");
}
}

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

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

return false;
}

public static void SetViewEnabledValue(bool value)
{
try
{
Registry.SetValue(DataDiagnosticsRegistryKey, DataDiagnosticsDataDiagnosticsViewDataRegistryValueName, value ? 1 : 0);
}
catch (Exception ex)
{
Logger.LogError($"Failed to set the Data Diagnostics view enabled value in the registry: {ex.Message}");
}
}
}
}
27 changes: 22 additions & 5 deletions src/settings-ui/Settings.UI/SettingsXAML/Views/GeneralPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -374,12 +374,29 @@
IsEnabled="{x:Bind ViewModel.IsDataDiagnosticsGPOManaged, Mode=OneWay, Converter={StaticResource BoolNegationConverter}}">
<ToggleSwitch x:Uid="ToggleSwitch" IsOn="{x:Bind ViewModel.EnableDataDiagnostics, Mode=TwoWay}" />
</tkcontrols:SettingsCard>
<tkcontrols:SettingsExpander
x:Uid="GeneralPage_ViewDiagnosticData"
HeaderIcon="{ui:FontIcon Glyph=&#xE7EF;}"
IsEnabled="{x:Bind ViewModel.IsDataDiagnosticsGPOManaged, Mode=OneWay, Converter={StaticResource BoolNegationConverter}}"
IsExpanded="False">
<tkcontrols:SettingsExpander.Items>
<tkcontrols:SettingsCard x:Uid="GeneralPage_EnableViewDiagnosticData">
<ToggleSwitch x:Uid="ToggleSwitch" IsOn="{x:Bind ViewModel.EnableViewDataDiagnostics, Mode=TwoWay}" />
</tkcontrols:SettingsCard>
<tkcontrols:SettingsCard
x:Uid="GeneralPage_ViewDiagnosticDataViewer"
ActionIcon="{ui:FontIcon Glyph=&#xE8A7;}"
IsClickEnabled="True"
IsEnabled="{x:Bind ViewModel.EnableViewDataDiagnostics, Mode=TwoWay}" />
</tkcontrols:SettingsExpander.Items>
</tkcontrols:SettingsExpander>
<InfoBar
x:Uid="GPO_SettingIsManaged"
IsClosable="False"
IsOpen="{x:Bind ViewModel.IsDataDiagnosticsGPOManaged, Mode=OneWay}"
IsTabStop="{x:Bind ViewModel.IsDataDiagnosticsGPOManaged, Mode=OneWay}"
Severity="Informational" />
x:Uid="GPO_SettingIsManaged"
IsClosable="False"
IsOpen="{x:Bind ViewModel.IsDataDiagnosticsGPOManaged, Mode=OneWay}"
IsTabStop="{x:Bind ViewModel.IsDataDiagnosticsGPOManaged, Mode=OneWay}"
Severity="Informational" />

</StackPanel>
</controls:SettingsGroup>
</StackPanel>
Expand Down
17 changes: 16 additions & 1 deletion src/settings-ui/Settings.UI/Strings/en-us/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -3802,7 +3802,22 @@ Activate by holding the key for the character you want to add an accent to, then
<value>Diagnostic data</value>
</data>
<data name="GeneralPage_EnableDataDiagnostics.Description" xml:space="preserve">
<value>Telemetry helps inform bug fixes, performance, and improvements</value>
<value>Helps inform bug fixes, performance, and improvements</value>
</data>
<data name="GeneralPage_ViewDiagnosticData.Header" xml:space="preserve">
<value>View diagnostic data</value>
</data>
<data name="GeneralPage_EnableViewDiagnosticData.Header" xml:space="preserve">
<value>Enable viewing</value>
</data>
<data name="GeneralPage_EnableViewDiagnosticData.Description" xml:space="preserve">
<value>Uses up to 1GB (or more) of hard drive space on your PC</value>
</data>
<data name="GeneralPage_ViewDiagnosticDataViewer.Header" xml:space="preserve">
<value>Diagnostic data viewer</value>
</data>
<data name="GeneralPage_ViewDiagnosticDataViewer.Description" xml:space="preserve">
<value>This folder may include .anr, .log, .tomb and .etl files</value>
</data>
<data name="Shell_AdvancedPaste.Content" xml:space="preserve">
<value>Advanced Paste</value>
Expand Down
22 changes: 22 additions & 0 deletions src/settings-ui/Settings.UI/ViewModels/GeneralViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ public GeneralViewModel(ISettingsRepository<GeneralSettings> settingsRepository,
_enableDataDiagnostics = DataDiagnostics.GetValue();
}

_enableViewDataDiagnostics = DataDiagnostics.GetViewEnabledValue();

if (dispatcherAction != null)
{
_fileWatcher = Helper.GetFileWatcher(string.Empty, UpdatingSettings.SettingsFile, dispatcherAction);
Expand All @@ -176,6 +178,7 @@ public GeneralViewModel(ISettingsRepository<GeneralSettings> settingsRepository,
private bool _experimentationIsGpoDisallowed;
private bool _enableDataDiagnostics;
private bool _enableDataDiagnosticsIsGpoDisallowed;
private bool _enableViewDataDiagnostics;

private UpdatingSettings.UpdatingState _updatingState = UpdatingSettings.UpdatingState.UpToDate;
private string _newAvailableVersion = string.Empty;
Expand Down Expand Up @@ -423,6 +426,25 @@ public bool EnableDataDiagnostics
}
}

public bool EnableViewDataDiagnostics
{
get
{
return _enableViewDataDiagnostics;
}

set
{
if (_enableViewDataDiagnostics != value)
{
_enableViewDataDiagnostics = value;

DataDiagnostics.SetViewEnabledValue(_enableViewDataDiagnostics);
OnPropertyChanged(nameof(EnableViewDataDiagnostics));
}
}
}

public bool IsExperimentationGpoDisallowed
{
get => _experimentationIsGpoDisallowed;
Expand Down

0 comments on commit ed8c240

Please sign in to comment.