Skip to content

Commit

Permalink
Merge pull request #126 from microsoft/user/niels9001/data-permission
Browse files Browse the repository at this point in the history
Data permission banner and setting
  • Loading branch information
niels9001 authored Jan 29, 2025
2 parents 96c55a7 + cebc43c commit e5524c8
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 20 deletions.
21 changes: 21 additions & 0 deletions AIDevGallery/Pages/HomePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
xmlns:ui="using:CommunityToolkit.WinUI"
xmlns:utils="using:AIDevGallery.Utils"
xmlns:wuc="using:WinUICommunity"
Loaded="Page_Loaded"
mc:Ignorable="d">
<Grid>
<Grid.RowDefinitions>
Expand All @@ -43,5 +44,25 @@
</StackPanel>
</Grid>
</ScrollViewer>
<InfoBar
x:Name="DiagnosticsInfoBar"
Title="Send optional diagnostic data"
Margin="16"
VerticalAlignment="Bottom"
Background="{ThemeResource SolidBackgroundFillColorBaseBrush}"
IsClosable="False"
IsOpen="False"
Message="Help us improve this app by sharing diagnostics data to inform bug fixes, performance, and feature enhancements.">
<StackPanel
Margin="0,0,0,8"
Orientation="Horizontal"
Spacing="8">
<Button
Click="DiagnosticsYesButton_Click"
Content="Allow"
Style="{StaticResource AccentButtonStyle}" />
<Button Click="DiagnosticsNoButton_Click" Content="Don't allow" />
</StackPanel>
</InfoBar>
</Grid>
</Page>
27 changes: 27 additions & 0 deletions AIDevGallery/Pages/HomePage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using AIDevGallery.Telemetry;
using AIDevGallery.Telemetry.Events;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Navigation;
Expand All @@ -19,4 +20,30 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
base.OnNavigatedTo(e);
NavigatedToPageEvent.Log(nameof(HomePage));
}

private void Page_Loaded(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
{
if (!App.AppData.IsDiagnosticsMessageDismissed && PrivacyConsentHelpers.IsPrivacySensitiveRegion())
{
DiagnosticsInfoBar.IsOpen = true;
}
}

private void DiagnosticsYesButton_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
{
HandleDiagnosticsSetting(true);
}

private void DiagnosticsNoButton_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
{
HandleDiagnosticsSetting(false);
}

private async void HandleDiagnosticsSetting(bool isEnabled)
{
DiagnosticsInfoBar.IsOpen = false;
App.AppData.IsDiagnosticsMessageDismissed = true;
App.AppData.IsDiagnosticDataEnabled = isEnabled;
await App.AppData.SaveAsync();
}
}
18 changes: 7 additions & 11 deletions AIDevGallery/Pages/SettingsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,15 @@
</DataTemplate>
</toolkit:SettingsExpander.ItemTemplate>
</toolkit:SettingsExpander>
<!--<TextBlock Style="{StaticResource SettingsSectionHeaderTextBlockStyle}" Text="Diagnostics &amp; feedback" />
<toolkit:SettingsCard Header="Send optional diagnostic data" HeaderIcon="{ui:FontIcon Glyph=&#xE9D9;}">
<toolkit:SettingsCard.Description>
<TextBlock FontSize="12" >
<Run Text="Help Microsoft improve your Application experience and fix problems more quickly by sending us additional diagnostic data." />
</TextBlock>
</toolkit:SettingsCard.Description>

<TextBlock Style="{StaticResource SettingsSectionHeaderTextBlockStyle}" Text="Diagnostics &amp; feedback" />
<toolkit:SettingsCard
Description="Help us improve this app by sharing optional diagnostics data to inform bug fixes, performance, and feature enhancements"
Header="Optional diagnostic data"
HeaderIcon="{ui:FontIcon Glyph=&#xE9D9;}">
<ToggleSwitch x:Name="DiagnosticDataToggleSwitch" Toggled="DiagnosticDataToggleSwitch_Toggled" />
</toolkit:SettingsCard>
<TextBlock TextWrapping="Wrap" FontSize="10">
<Bold> You're sending required diagnostic data. </Bold>
<Run> As a part of using this app, your app sends Microsoft a limited set of data that is necessary to keep this app secure, up to date, and working as expected. </Run>
</TextBlock>-->

<TextBlock Style="{StaticResource SettingsSectionHeaderTextBlockStyle}" Text="About" />
<toolkit:SettingsExpander
AutomationProperties.AccessibilityView="Raw"
Expand Down
19 changes: 10 additions & 9 deletions AIDevGallery/Pages/SettingsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
VersionTextRun.Text = AppUtils.GetAppVersion();
GetStorageInfo();

// DiagnosticDataToggleSwitch.IsOn = App.AppData.IsDiagnosticDataEnabled;
DiagnosticDataToggleSwitch.IsOn = App.AppData.IsDiagnosticDataEnabled;
if (e.Parameter is string manageModels && manageModels == "ModelManagement")
{
ModelsExpander.IsExpanded = true;
Expand Down Expand Up @@ -153,14 +153,15 @@ private void ModelFolder_Click(object sender, RoutedEventArgs e)
}
}

// private async void DiagnosticDataToggleSwitch_Toggled(object sender, RoutedEventArgs e)
// {
// if (App.AppData.IsDiagnosticDataEnabled != DiagnosticDataToggleSwitch.IsOn)
// {
// App.AppData.IsDiagnosticDataEnabled = DiagnosticDataToggleSwitch.IsOn;
// await App.AppData.SaveAsync();
// }
// }
private async void DiagnosticDataToggleSwitch_Toggled(object sender, RoutedEventArgs e)
{
if (App.AppData.IsDiagnosticDataEnabled != DiagnosticDataToggleSwitch.IsOn)
{
App.AppData.IsDiagnosticDataEnabled = DiagnosticDataToggleSwitch.IsOn;
await App.AppData.SaveAsync();
}
}

private async void ChangeCacheFolder_Click(object sender, RoutedEventArgs e)
{
var downloadCount = App.ModelCache.DownloadQueue.GetDownloads().Count;
Expand Down
3 changes: 3 additions & 0 deletions AIDevGallery/Utils/AppData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ internal class AppData

public bool IsFirstRun { get; set; }

public bool IsDiagnosticsMessageDismissed { get; set; }

public AppData()
{
IsDiagnosticDataEnabled = !PrivacyConsentHelpers.IsPrivacySensitiveRegion();
IsFirstRun = true;
IsDiagnosticsMessageDismissed = false;
}

private static string GetConfigFilePath()
Expand Down

0 comments on commit e5524c8

Please sign in to comment.