Skip to content
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.

Delay setting up RequestReceived handler #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
11 changes: 9 additions & 2 deletions SecureInput/NativeMessagingHostInProcess/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ sealed partial class App : Application
{
private BackgroundTaskDeferral appServiceDeferral = null;
private AppServiceConnection connection = null;
private AppServiceConnection edgeConnection = null;
private BackgroundTaskDeferral desktopBridgeAppServiceDeferral = null;
private AppServiceConnection desktopBridgeConnection = null;
private bool desktopBridgeAppLaunched = true;
Expand Down Expand Up @@ -77,13 +78,16 @@ protected async override void OnBackgroundActivated(BackgroundActivatedEventArgs
desktopBridgeAppServiceDeferrals.Add(desktopBridgeConnectionIndex, this.desktopBridgeAppServiceDeferral);
desktopBridgeConnectionIndex++;
}

// wait before configuring RequestReceived
this.edgeConnection.RequestReceived += OnAppServiceRequestReceived;
}
else // App service connection from Edge browser
{
this.appServiceDeferral = taskInstance.GetDeferral(); // Get a deferral so that the service isn't terminated.
taskInstance.Canceled += OnAppServicesCanceled; // Associate a cancellation handler with the background task.
this.connection = appService.AppServiceConnection;
this.connection.RequestReceived += OnAppServiceRequestReceived;
this.edgeConnection = this.connection;
this.connection.ServiceClosed += AppServiceConnection_ServiceClosed;

lock (thisLock)
Expand Down Expand Up @@ -120,7 +124,10 @@ private async void OnAppServiceRequestReceived(AppServiceConnection sender, AppS
{
if (this.desktopBridgeAppLaunched)
{
this.currentConnectionIndex = Int32.Parse(sender.AppServiceName);
lock (thisLock)
{
this.currentConnectionIndex = Int32.Parse(sender.AppServiceName);
}
this.desktopBridgeConnection = desktopBridgeConnections[this.currentConnectionIndex];

// Send message to the desktopBridge component and wait for response
Expand Down