Skip to content

[WIP] Add Store Services SDK #260

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion CommunityToolkit.App.Shared/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Windows.UI;
using CommunityToolkit.App.Shared.Helpers;

#if WINAPPSDK
using UnhandledExceptionEventArgs = Microsoft.UI.Xaml.UnhandledExceptionEventArgs;
#else
using UnhandledExceptionEventArgs = Windows.UI.Xaml.UnhandledExceptionEventArgs;
#endif

namespace CommunityToolkit.App.Shared;

Expand All @@ -26,6 +32,13 @@ public sealed partial class App : Application
public App()
{
this.InitializeComponent();

UnhandledException += this.App_UnhandledException;
}

private void App_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
TrackingManager.TrackException(e.Exception);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<Compile Include="$(MSBuildThisFileDirectory)DocOrSampleTemplateSelector.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Helpers\IconHelper.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Helpers\NavigationViewHelper.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Helpers\TrackingManager.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Pages\GettingStartedPage.xaml.cs">
<DependentUpon>GettingStartedPage.xaml</DependentUpon>
</Compile>
Expand Down
78 changes: 78 additions & 0 deletions CommunityToolkit.App.Shared/Helpers/TrackingManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;

#if !DEBUG && WINDOWS_UWP && !HAS_UNO
// See https://learn.microsoft.com/windows/uwp/monetize/log-custom-events-for-dev-center
using Microsoft.Services.Store.Engagement;
#endif

namespace CommunityToolkit.App.Shared.Helpers;

#if DEBUG || !WINDOWS_UWP || HAS_UNO
// Stub for non-UWP platforms and DEBUG mode
internal class StoreServicesCustomEventLogger
{
public static StoreServicesCustomEventLogger GetDefault() => new();

public void Log(string message)
{
Debug.WriteLine($"Log - {message}");
}
}
#endif

public static class TrackingManager
{
private static StoreServicesCustomEventLogger? logger;

static TrackingManager()
{
try
{
logger = StoreServicesCustomEventLogger.GetDefault();
}
catch
{
// Ignoring error
}
}

public static void TrackException(Exception ex)
{
try
{
logger?.Log($"exception - {ex.Message} - {ex.StackTrace}");
}
catch
{
// Ignore error
}
}

public static void TrackSample(string name)
{
try
{
logger?.Log($"sample - {name}");
}
catch
{
// Ignore error
}
}

public static void TrackPage(string pageName)
{
try
{
logger?.Log($"openpage - {pageName}");
}
catch
{
// Ignore error
}
}
}
5 changes: 5 additions & 0 deletions CommunityToolkit.App.Shared/Pages/Shell.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,23 @@ private void NavView_ItemInvoked(MUXC.NavigationView sender, MUXC.NavigationView
if (NavigationFrame.CurrentSourcePageType != typeof(SettingsPage))
{
NavigationFrame.Navigate(typeof(SettingsPage));
TrackingManager.TrackPage("Settings");
}
}

// Check if Getting Started page
else if (selectedItem.Tag != null && selectedItem.Tag.GetType() == typeof(string))
{
NavigationFrame.Navigate(typeof(GettingStartedPage), samplePages);
TrackingManager.TrackPage("GettingStarted");
}
else
{
var selectedMetadata = selectedItem.Tag as ToolkitFrontMatter;
if (selectedMetadata is null)
return;
NavigationFrame.Navigate(typeof(ToolkitDocumentationRenderer), selectedMetadata);
TrackingManager.TrackSample(selectedMetadata.Title!);
}
}

Expand All @@ -93,10 +96,12 @@ public void NavigateToSample(ToolkitFrontMatter? sample)
if (sample is null)
{
NavigationFrame.Navigate(typeof(GettingStartedPage), samplePages);
TrackingManager.TrackPage("GettingStarted");
}
else
{
NavigationFrame.Navigate(typeof(ToolkitDocumentationRenderer), sample);
TrackingManager.TrackSample(sample.Title!);
}

EnsureNavigationSelection(sample?.FilePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<WinUIMajorVersion>2</WinUIMajorVersion>

<IsAllExperimentHead>true</IsAllExperimentHead>
<AppxBundle>Always</AppxBundle>
<AppxBundlePlatforms>x86|x64|arm64</AppxBundlePlatforms>
</PropertyGroup>

<Import Project="$(ToolingDirectory)\MultiTarget\EnabledTargetFrameworks.props" />
Expand Down
7 changes: 7 additions & 0 deletions ProjectHeads/App.Head.Uwp.Dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@
<PackageReference Include="Microsoft.Xaml.Behaviors.Uwp.Managed" Version="3.0.0" />
<PackageReference Include="System.Collections.Immutable" Version="9.0.0" />
</ItemGroup>

<ItemGroup Condition=" '$(Configuration)' == 'Release' ">
<PackageReference Include="Microsoft.Services.Store.Engagement" Version="10.2307.3001" />
<SDKReference Include="Microsoft.Services.Store.Engagement, Version=10.0">
<Name>Microsoft Engagement Framework</Name>
</SDKReference>
</ItemGroup>
</Project>
Loading