Skip to content

Commit 0a9ea5c

Browse files
authored
Fixed issue with App Service Demo (microsoft#531)
This PR addresses microsoft#529
1 parent 8c00691 commit 0a9ea5c

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

samples/AppServiceDemo/windows/appservicedemo.sln

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
44
VisualStudioVersion = 17.0.31612.314
55
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{C7167F0D-BC9F-4E6E-AFE1-012C56B48DB5}") = "appservicedemo.Package", "appservicedemo.Package\appservicedemo.Package.wapproj", "{E0C2D328-2554-4450-BB40-DEABF4E44BB8}"
7+
EndProject
68
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "appservicedemo", "appservicedemo\appservicedemo.csproj", "{418AD1A7-D045-478A-AA6B-34A597088C0D}"
79
EndProject
810
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Folly", "..\node_modules\react-native-windows\Folly\Folly.vcxproj", "{A990658C-CE31-4BCC-976F-0FC6B1AF693D}"
@@ -38,8 +40,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReactNativeAppServiceModule
3840
EndProject
3941
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RegistryApp", "RegistryApp\RegistryApp.csproj", "{0A122BD2-9C76-4B58-A0E1-C4D9844D857C}"
4042
EndProject
41-
Project("{C7167F0D-BC9F-4E6E-AFE1-012C56B48DB5}") = "appservicedemo.Package", "appservicedemo.Package\appservicedemo.Package.wapproj", "{E0C2D328-2554-4450-BB40-DEABF4E44BB8}"
42-
EndProject
4343
Global
4444
GlobalSection(SharedMSBuildProjectFiles) = preSolution
4545
..\node_modules\react-native-windows\Shared\Shared.vcxitems*{2049dbe9-8d13-42c9-ae4b-413ae38fffd0}*SharedItemsImports = 9

samples/AppServiceDemo/windows/appservicedemo/App.xaml.cs

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using Microsoft.ReactNative;
2+
using Windows.ApplicationModel.Activation;
3+
using Windows.ApplicationModel.AppService;
4+
using Windows.ApplicationModel.Background;
25
#if USE_WINUI3
36
using Microsoft.UI.Xaml;
47
using Microsoft.UI.Xaml.Controls;
58
#else
6-
using Windows.ApplicationModel.Activation;
79
using Windows.UI.Xaml;
810
using Windows.UI.Xaml.Controls;
911
#endif
@@ -12,6 +14,8 @@ namespace appservicedemo
1214
{
1315
sealed partial class App : ReactApplication
1416
{
17+
private BackgroundTaskDeferral appServiceDeferral;
18+
1519
public App()
1620
{
1721
#if BUNDLE
@@ -33,6 +37,7 @@ public App()
3337
Microsoft.ReactNative.Managed.AutolinkedNativeModules.RegisterAutolinkedNativeModulePackages(PackageProviders); // Includes any autolinked modules
3438

3539
PackageProviders.Add(new Microsoft.ReactNative.Managed.ReactPackageProvider());
40+
PackageProviders.Add(new ReactNativeAppServiceModule.ReactPackageProvider());
3641
PackageProviders.Add(new ReactPackageProvider());
3742

3843
InitializeComponent();
@@ -64,5 +69,20 @@ protected override void OnActivated(Windows.ApplicationModel.Activation.IActivat
6469
frame.Navigate(typeof(MainPage), null);
6570
}
6671
}
72+
73+
protected override void OnBackgroundActivated(BackgroundActivatedEventArgs args)
74+
{
75+
base.OnBackgroundActivated(args);
76+
77+
if (args.TaskInstance.TriggerDetails is AppServiceTriggerDetails details)
78+
{
79+
appServiceDeferral = args.TaskInstance.GetDeferral();
80+
81+
var ns = ReactPropertyBagHelper.GetNamespace("RegistryChannel");
82+
var name = ReactPropertyBagHelper.GetName(ns, "AppServiceConnection");
83+
84+
InstanceSettings.Properties.Set(name, details.AppServiceConnection);
85+
}
86+
}
6787
}
6888
}

website/blog/2021-08-05-win32component.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ author: Matteo Pagani
44
authorURL: https://twitter.com/qmatteoq
55
description: "How to use Win32 features from a React Native for Windows application"
66
is_blog: true
7-
published_date: August 5, 2021
7+
published_date: August 30, 2021
88
---
99

1010
If you have adopted React Native to build your Windows applications, you'll know that the final output is a [Universal Windows Platform application](https://docs.microsoft.com/windows/uwp/get-started/universal-application-platform-guide). This development platform gives you access to all the latest enhancements in the Windows ecosystem (modern UI platform, notifications, integration with features like inking and Windows Hello, etc.), plus greater security and reliability thanks to the sandbox the application runs in.

0 commit comments

Comments
 (0)