Skip to content
This repository was archived by the owner on Apr 30, 2024. It is now read-only.

Commit b2e928c

Browse files
committed
WIP AppConnection setup
1 parent ad4841d commit b2e928c

File tree

12 files changed

+141
-1
lines changed

12 files changed

+141
-1
lines changed

Quarrel.sln

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Patreon.API", "src\API\Patr
2828
EndProject
2929
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Discord.API.Status", "src\API\Discord.API.Status\Discord.API.Status.csproj", "{D34F80C0-0316-43C3-BBE9-7AF099A1C6A0}"
3030
EndProject
31+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Libs", "Libs", "{29E0E840-B85F-4209-933B-8369DB2EA187}"
32+
EndProject
3133
Global
3234
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3335
Alpha|Any CPU = Alpha|Any CPU

src/Quarrel.ViewModels/Services/Analytics/Enums/LoggedEvent.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,15 @@ public enum LoggedEvent
8888
GitHubRequestFailed,
8989

9090
#endregion
91+
92+
#region AppServiceConnection
93+
94+
/// <summary>
95+
/// An app service connection was actived.
96+
/// </summary>
97+
[StringValue("App Service Connection Received")]
98+
AppServiceConnectionReceived,
99+
100+
#endregion
91101
}
92102
}

src/Quarrel/App.AppService.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Quarrel © 2022
2+
3+
using Microsoft.Extensions.DependencyInjection;
4+
using Quarrel.Services.AppConnections;
5+
using Windows.ApplicationModel.AppService;
6+
7+
namespace Quarrel
8+
{
9+
partial class App
10+
{
11+
private void SetupAppServiceConnection(AppServiceTriggerDetails triggerDetails)
12+
{
13+
AppConnectionService? appConnectionService = Services.GetService<AppConnectionService>();
14+
if (appConnectionService is not null)
15+
{
16+
appConnectionService.RegisterAppConnection(triggerDetails);
17+
}
18+
}
19+
}
20+
}

src/Quarrel/App.xaml.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
using Quarrel.ViewModels.SubPages.Meta;
2525
using System;
2626
using Windows.ApplicationModel.Activation;
27+
using Windows.ApplicationModel.AppService;
2728
using Windows.Storage;
2829
using Windows.UI.Xaml;
2930

@@ -34,7 +35,6 @@ namespace Quarrel
3435
/// </summary>
3536
sealed partial class App : Application
3637
{
37-
3838
/// <summary>
3939
/// Initializes the singleton application object. This is the first line of authored code
4040
/// executed, and as such is the logical equivalent of main() or WinMain().
@@ -71,13 +71,25 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
7171

7272
protected override void OnActivated(IActivatedEventArgs args)
7373
{
74+
base.OnActivated(args);
75+
7476
if (args.Kind == ActivationKind.Protocol && args is ProtocolActivatedEventArgs protocolArgs)
7577
{
7678
LaunchArgsBase? launchArgs = LaunchArgsBase.Parse(protocolArgs.Uri.ToString());
7779
Launch(false, launchArgs);
7880
}
7981
}
8082

83+
protected override void OnBackgroundActivated(BackgroundActivatedEventArgs args)
84+
{
85+
base.OnBackgroundActivated(args);
86+
87+
if (args.TaskInstance.TriggerDetails is AppServiceTriggerDetails appServiceTriggerDetails)
88+
{
89+
SetupAppServiceConnection(appServiceTriggerDetails);
90+
}
91+
}
92+
8193
private void Launch(bool isPrelaunchActivated, LaunchArgsBase? args = null)
8294
{
8395
if (Window.Current.Content is not WindowHost)

src/Quarrel/Package.Alpha.appxmanifest

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
<uap:DisplayName>Quarrel</uap:DisplayName>
5353
</uap:Protocol>
5454
</uap:Extension>
55+
<uap:Extension Category="windows.appService">
56+
<uap:AppService Name="Quarrel.RichPresenceAPI"/>
57+
</uap:Extension>
5558
</Extensions>
5659
</Application>
5760
</Applications>

src/Quarrel/Package.Dev.appxmanifest

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
<uap:DisplayName>Quarrel</uap:DisplayName>
5353
</uap:Protocol>
5454
</uap:Extension>
55+
<uap:Extension Category="windows.appService">
56+
<uap:AppService Name="Quarrel.RichPresenceAPI"/>
57+
</uap:Extension>
5558
</Extensions>
5659
</Application>
5760
</Applications>

src/Quarrel/Package.Insider.appxmanifest

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
<uap:DisplayName>Quarrel</uap:DisplayName>
5353
</uap:Protocol>
5454
</uap:Extension>
55+
<uap:Extension Category="windows.appService">
56+
<uap:AppService Name="Quarrel.RichPresenceAPI"/>
57+
</uap:Extension>
5558
</Extensions>
5659
</Application>
5760
</Applications>

src/Quarrel/Package.Release.appxmanifest

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
<uap:DisplayName>Quarrel</uap:DisplayName>
5353
</uap:Protocol>
5454
</uap:Extension>
55+
<uap:Extension Category="windows.appService">
56+
<uap:AppService Name="Quarrel.RichPresenceAPI"/>
57+
</uap:Extension>
5558
</Extensions>
5659
</Application>
5760
</Applications>

src/Quarrel/Quarrel.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
<SuppressPseudoWarning Condition="'$(Configuration)' == 'Debug'">true</SuppressPseudoWarning>
8484
</PropertyGroup>
8585
<ItemGroup>
86+
<Compile Include="App.AppService.cs" />
8687
<Compile Include="App.xaml.cs">
8788
<DependentUpon>App.xaml</DependentUpon>
8889
</Compile>
@@ -157,6 +158,9 @@
157158
<Compile Include="Services\Analytics\AppCenterService.cs" />
158159
<Compile Include="Services\Analytics\LoggingAnalyticsService.cs" />
159160
<Compile Include="Services\APIs\PatreonService\PatreonService.cs" />
161+
<Compile Include="Services\AppConnections\Models\AppConnection.cs" />
162+
<Compile Include="Services\AppConnections\AppConnectionService.cs" />
163+
<Compile Include="Services\AppConnections\Models\RichPresenceConnection.cs" />
160164
<Compile Include="Services\Dispatcher\DispatcherService.cs" />
161165
<Compile Include="Services\Keyboard\KeyboardService.cs" />
162166
<Compile Include="Services\Localization\LocalizationService.cs" />
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Quarrel © 2022
2+
3+
using Quarrel.Services.Analytics;
4+
using Quarrel.Services.Analytics.Enums;
5+
using Quarrel.Services.AppConnections.Models;
6+
using System.Collections.Generic;
7+
using Windows.ApplicationModel.AppService;
8+
9+
namespace Quarrel.Services.AppConnections
10+
{
11+
public class AppConnectionService
12+
{
13+
private const string RichPresenceConnectionName = "Quarrel.RichPresenceAPI";
14+
15+
private readonly IAnalyticsService _analyticsService;
16+
private readonly Dictionary<string, AppConnection> _connections;
17+
18+
public AppConnectionService(IAnalyticsService analyticsService)
19+
{
20+
_analyticsService = analyticsService;
21+
_connections = new Dictionary<string, AppConnection>();
22+
}
23+
24+
public bool RegisterAppConnection(AppServiceTriggerDetails connection)
25+
{
26+
_analyticsService.Log(LoggedEvent.AppServiceConnectionReceived,
27+
(nameof(connection.Name), connection.Name),
28+
(nameof(connection.CallerPackageFamilyName), connection.CallerPackageFamilyName));
29+
30+
AppConnection? appConnection = connection.Name switch
31+
{
32+
RichPresenceConnectionName => new RichPresenceConnection(connection.AppServiceConnection),
33+
_ => null,
34+
};
35+
36+
if (appConnection is null)
37+
{
38+
return false;
39+
}
40+
41+
_connections.Add(appConnection.Id, appConnection);
42+
43+
return true;
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)