Wino.Server and Wino.Packaging projects. Enabling full trust for UWP and app service connection manager basics.
This commit is contained in:
41
Wino.Mail/Activation/BackgroundActivationHandlerEx.cs
Normal file
41
Wino.Mail/Activation/BackgroundActivationHandlerEx.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System.Threading.Tasks;
|
||||
using Windows.ApplicationModel;
|
||||
using Windows.ApplicationModel.Activation;
|
||||
using Windows.ApplicationModel.AppService;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
|
||||
namespace Wino.Activation
|
||||
{
|
||||
internal class BackgroundActivationHandlerEx : ActivationHandler<BackgroundActivatedEventArgs>
|
||||
{
|
||||
private readonly IWinoServerConnectionManager<AppServiceConnection> _winoServerConnectionManager;
|
||||
|
||||
public BackgroundActivationHandlerEx(IWinoServerConnectionManager<AppServiceConnection> winoServerConnectionManager)
|
||||
{
|
||||
_winoServerConnectionManager = winoServerConnectionManager;
|
||||
}
|
||||
|
||||
protected override Task HandleInternalAsync(BackgroundActivatedEventArgs args)
|
||||
{
|
||||
if (args.TaskInstance == null || args.TaskInstance.TriggerDetails == null) return Task.CompletedTask;
|
||||
|
||||
if (args.TaskInstance.TriggerDetails is AppServiceTriggerDetails appServiceTriggerDetails)
|
||||
{
|
||||
// only accept connections from callers in the same package
|
||||
if (appServiceTriggerDetails.CallerPackageFamilyName == Package.Current.Id.FamilyName)
|
||||
{
|
||||
// Connection established from the fulltrust process
|
||||
_winoServerConnectionManager.Connection = appServiceTriggerDetails.AppServiceConnection;
|
||||
|
||||
var deferral = args.TaskInstance.GetDeferral();
|
||||
|
||||
args.TaskInstance.Canceled += App.Current.OnBackgroundTaskCanceled;
|
||||
|
||||
// AppServiceConnected?.Invoke(this, args.TaskInstance.TriggerDetails as AppServiceTriggerDetails);
|
||||
}
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,8 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using Serilog;
|
||||
using Windows.ApplicationModel;
|
||||
using Windows.ApplicationModel.Activation;
|
||||
using Windows.ApplicationModel.AppService;
|
||||
using Windows.ApplicationModel.Background;
|
||||
using Windows.ApplicationModel.Core;
|
||||
using Windows.Foundation.Metadata;
|
||||
using Windows.Storage;
|
||||
@@ -37,6 +39,7 @@ namespace Wino
|
||||
public new static App Current => (App)Application.Current;
|
||||
public IServiceProvider Services { get; }
|
||||
|
||||
private readonly IWinoServerConnectionManager<AppServiceConnection> _appServiceConnectionManager;
|
||||
private readonly ILogInitializer _logInitializer;
|
||||
private readonly IThemeService _themeService;
|
||||
private readonly IDatabaseService _databaseService;
|
||||
@@ -47,8 +50,9 @@ namespace Wino
|
||||
// Order matters.
|
||||
private List<IInitializeAsync> initializeServices => new List<IInitializeAsync>()
|
||||
{
|
||||
_translationService,
|
||||
_databaseService,
|
||||
_appServiceConnectionManager,
|
||||
_translationService,
|
||||
_themeService,
|
||||
_synchronizerFactory
|
||||
};
|
||||
@@ -60,6 +64,7 @@ namespace Wino
|
||||
UnhandledException += OnAppUnhandledException;
|
||||
EnteredBackground += OnEnteredBackground;
|
||||
LeavingBackground += OnLeavingBackground;
|
||||
Suspending += OnSuspending;
|
||||
|
||||
Services = ConfigureServices();
|
||||
|
||||
@@ -70,6 +75,7 @@ namespace Wino
|
||||
ConfigurePrelaunch();
|
||||
ConfigureXbox();
|
||||
|
||||
_appServiceConnectionManager = Services.GetService<IWinoServerConnectionManager<AppServiceConnection>>();
|
||||
_themeService = Services.GetService<IThemeService>();
|
||||
_databaseService = Services.GetService<IDatabaseService>();
|
||||
_appInitializerService = Services.GetService<IAppInitializerService>();
|
||||
@@ -79,6 +85,12 @@ namespace Wino
|
||||
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
||||
}
|
||||
|
||||
private void OnSuspending(object sender, SuspendingEventArgs e)
|
||||
{
|
||||
var deferral = e.SuspendingOperation.GetDeferral();
|
||||
deferral.Complete();
|
||||
}
|
||||
|
||||
private void LogActivation(string log) => Log.Information($"{WinoLaunchLogPrefix}{log}");
|
||||
private void OnLeavingBackground(object sender, LeavingBackgroundEventArgs e) => LogActivation($"Wino went foreground.");
|
||||
private void OnEnteredBackground(object sender, EnteredBackgroundEventArgs e) => LogActivation($"Wino went background.");
|
||||
@@ -101,7 +113,8 @@ namespace Wino
|
||||
private void RegisterActivationHandlers(IServiceCollection services)
|
||||
{
|
||||
services.AddTransient<ProtocolActivationHandler>();
|
||||
services.AddTransient<BackgroundActivationHandler>();
|
||||
services.AddTransient<BackgroundActivationHandlerEx>();
|
||||
// services.AddTransient<BackgroundActivationHandler>();
|
||||
services.AddTransient<ToastNotificationActivationHandler>();
|
||||
services.AddTransient<FileActivationHandler>();
|
||||
}
|
||||
@@ -246,7 +259,10 @@ namespace Wino
|
||||
|
||||
private async Task ActivateWinoAsync(object args)
|
||||
{
|
||||
await PreInitializationAsync();
|
||||
foreach (var service in initializeServices)
|
||||
{
|
||||
await service.InitializeAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (IsInteractiveLaunchArgs(args))
|
||||
{
|
||||
@@ -270,37 +286,6 @@ namespace Wino
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tasks that must run before the activation and launch.
|
||||
/// Regardless of whether it's an interactive launch or not.
|
||||
/// </summary>
|
||||
private async Task PreInitializationAsync()
|
||||
{
|
||||
// Handle migrations.
|
||||
// TODO: Automate migration process with more proper way.
|
||||
|
||||
if (!ApplicationData.Current.LocalSettings.Values.ContainsKey("Migration_169"))
|
||||
{
|
||||
try
|
||||
{
|
||||
await _appInitializerService.MigrateAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex, $"{WinoLaunchLogPrefix}Migration_169 failed.");
|
||||
}
|
||||
finally
|
||||
{
|
||||
ApplicationData.Current.LocalSettings.Values["Migration_169"] = true;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var service in initializeServices)
|
||||
{
|
||||
await service.InitializeAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task HandleActivationAsync(object activationArgs)
|
||||
{
|
||||
var activationHandler = GetActivationHandlers().FirstOrDefault(h => h.CanHandle(activationArgs));
|
||||
@@ -323,9 +308,15 @@ namespace Wino
|
||||
private IEnumerable<ActivationHandler> GetActivationHandlers()
|
||||
{
|
||||
yield return Services.GetService<ProtocolActivationHandler>();
|
||||
yield return Services.GetService<BackgroundActivationHandler>();
|
||||
yield return Services.GetService<BackgroundActivationHandlerEx>(); // New app service background task handler.
|
||||
// yield return Services.GetService<BackgroundActivationHandler>(); // Old UWP background task handler.
|
||||
yield return Services.GetService<ToastNotificationActivationHandler>();
|
||||
yield return Services.GetService<FileActivationHandler>();
|
||||
}
|
||||
|
||||
public void OnBackgroundTaskCanceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason)
|
||||
{
|
||||
Log.Information($"Background task {sender.Task.Name} was canceled. Reason: {reason}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -515,6 +515,14 @@
|
||||
IsOpen="False"
|
||||
PreferredPlacement="Bottom"
|
||||
Target="{x:Bind ShellInfoBar}" />
|
||||
|
||||
<Grid
|
||||
Grid.Column="1"
|
||||
Padding="14"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Bottom">
|
||||
<TextBlock Text="{x:Bind ViewModel.ServerConnectionManager.Status, Mode=OneWay}" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
</muxc:NavigationView>
|
||||
|
||||
|
||||
@@ -92,13 +92,6 @@
|
||||
Enabled="false"
|
||||
DisplayName="Wino Startup Service" />
|
||||
</uap5:Extension>
|
||||
|
||||
<!-- Registration of full trust backend application. -->
|
||||
<!--<uap:Extension Category="windows.appService">
|
||||
<uap:AppService Name="Wino.AppService" />
|
||||
</uap:Extension>-->
|
||||
|
||||
<!--<desktop:Extension Category="windows.fullTrustProcess" Executable="Wino.AppService.exe" />-->
|
||||
</Extensions>
|
||||
</Application>
|
||||
</Applications>
|
||||
|
||||
@@ -15,12 +15,12 @@ using Wino.Core.Domain.Enums;
|
||||
using Wino.Core.Domain.Interfaces;
|
||||
using Wino.Core.Domain.Models.Accounts;
|
||||
using Wino.Core.Domain.Models.Folders;
|
||||
using Wino.Core.Domain.Models.Requests;
|
||||
using Wino.Core.Domain.Models.Synchronization;
|
||||
using Wino.Core.Messages.Shell;
|
||||
using Wino.Core.Messages.Synchronization;
|
||||
using Wino.Core.UWP.Extensions;
|
||||
using Wino.Dialogs;
|
||||
using Wino.Messages.Server;
|
||||
|
||||
namespace Wino.Services
|
||||
{
|
||||
|
||||
@@ -6,9 +6,9 @@ using MoreLinq;
|
||||
using Windows.UI.Xaml.Media.Animation;
|
||||
using Windows.UI.Xaml.Navigation;
|
||||
using Wino.Core.Domain.Enums;
|
||||
using Wino.Core.Domain.Models.Requests;
|
||||
using Wino.Core.Messages.Navigation;
|
||||
using Wino.Mail.ViewModels.Data;
|
||||
using Wino.Messages.Server;
|
||||
using Wino.Views.Abstract;
|
||||
using Wino.Views.Account;
|
||||
using Wino.Views.Settings;
|
||||
|
||||
@@ -229,6 +229,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="Activation\ActivationHandler.cs" />
|
||||
<Compile Include="Activation\BackgroundActivationHandler.cs" />
|
||||
<Compile Include="Activation\BackgroundActivationHandlerEx.cs" />
|
||||
<Compile Include="Activation\DefaultActivationHandler.cs" />
|
||||
<Compile Include="Activation\FileActivationHandler.cs" />
|
||||
<Compile Include="Activation\ProtocolActivationHandler.cs" />
|
||||
@@ -770,7 +771,6 @@
|
||||
<Content Include="Assets\Square44x44Logo.scale-200.png" />
|
||||
<Content Include="Assets\Square44x44Logo.targetsize-24_altform-unplated.png" />
|
||||
<Content Include="Assets\Wide310x150Logo.scale-200.png" />
|
||||
<None Include="Wino.Mail_TemporaryKey.pfx" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Assets\Thumbnails\uber.com.png" />
|
||||
@@ -812,7 +812,9 @@
|
||||
<Name>Windows Desktop Extensions for the UWP</Name>
|
||||
</SDKReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<ItemGroup>
|
||||
<Folder Include="Server\" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' < '14.0' ">
|
||||
<VisualStudioVersion>14.0</VisualStudioVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
Reference in New Issue
Block a user