From 6dfacdfebdce42eb3c3f8a909671e2c46dfeaaae Mon Sep 17 00:00:00 2001 From: FelixSe Date: Sat, 10 Mar 2018 00:06:25 +0100 Subject: [PATCH] Remove almost unused AppService in favor of using flute.exe --- FluentTerminal.App/App.xaml.cs | 37 +++-------------- FluentTerminal.App/Package.appxmanifest | 3 -- .../SystemTrayApplicationContext.cs | 40 +------------------ 3 files changed, 7 insertions(+), 73 deletions(-) diff --git a/FluentTerminal.App/App.xaml.cs b/FluentTerminal.App/App.xaml.cs index fd121d5..8b5a0d1 100644 --- a/FluentTerminal.App/App.xaml.cs +++ b/FluentTerminal.App/App.xaml.cs @@ -13,8 +13,6 @@ using System.Linq; using System.Threading.Tasks; using Windows.ApplicationModel; using Windows.ApplicationModel.Activation; -using Windows.ApplicationModel.AppService; -using Windows.ApplicationModel.Background; using Windows.ApplicationModel.Core; using Windows.Storage; using Windows.UI.Core; @@ -27,8 +25,6 @@ namespace FluentTerminal.App { sealed partial class App : Application { - public static BackgroundTaskDeferral AppServiceDeferral = null; - public static AppServiceConnection Connection = null; public static App Instance; private bool _alreadyLaunched; private IContainer _container; @@ -108,6 +104,11 @@ namespace FluentTerminal.App var command = arguments[0]; var parameter = arguments.Length > 1 ? arguments[1] : string.Empty; + if (command == "close") + { + App.Current.Exit(); + } + if (_alreadyLaunched) { if (command == "settings") @@ -151,18 +152,6 @@ namespace FluentTerminal.App } } - protected override void OnBackgroundActivated(BackgroundActivatedEventArgs args) - { - base.OnBackgroundActivated(args); - if (args.TaskInstance.TriggerDetails is AppServiceTriggerDetails details) - { - AppServiceDeferral = args.TaskInstance.GetDeferral(); - args.TaskInstance.Canceled += OnTaskCanceled; - Connection = details.AppServiceConnection; - Connection.RequestReceived += OnRequestReceived; - } - } - protected override async void OnLaunched(LaunchActivatedEventArgs e) { if (!_alreadyLaunched) @@ -237,21 +226,5 @@ namespace FluentTerminal.App return windowId; } - - private void OnRequestReceived(AppServiceConnection sender, AppServiceRequestReceivedEventArgs args) - { - if (args.Request.Message.ContainsKey("exit")) - { - App.Current.Exit(); - } - } - - private void OnTaskCanceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason) - { - if (AppServiceDeferral != null) - { - AppServiceDeferral.Complete(); - } - } } } \ No newline at end of file diff --git a/FluentTerminal.App/Package.appxmanifest b/FluentTerminal.App/Package.appxmanifest index 8e6817b..727c747 100644 --- a/FluentTerminal.App/Package.appxmanifest +++ b/FluentTerminal.App/Package.appxmanifest @@ -26,9 +26,6 @@ - - - diff --git a/FluentTerminal.SystemTray/SystemTrayApplicationContext.cs b/FluentTerminal.SystemTray/SystemTrayApplicationContext.cs index 970c0bd..48bbb5d 100644 --- a/FluentTerminal.SystemTray/SystemTrayApplicationContext.cs +++ b/FluentTerminal.SystemTray/SystemTrayApplicationContext.cs @@ -2,18 +2,14 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using System.Threading.Tasks; using System.Windows.Forms; using Windows.ApplicationModel; -using Windows.ApplicationModel.AppService; using Windows.ApplicationModel.Core; -using Windows.Foundation.Collections; namespace FluentTerminal.SystemTray { public class SystemTrayApplicationContext : ApplicationContext { - private AppServiceConnection _connection; private readonly NotifyIcon _notifyIcon; public SystemTrayApplicationContext() @@ -34,19 +30,9 @@ namespace FluentTerminal.SystemTray _notifyIcon.Visible = true; } - private void Connection_ServiceClosed(AppServiceConnection sender, AppServiceClosedEventArgs args) + private void Exit(object sender, EventArgs e) { - _connection.ServiceClosed -= Connection_ServiceClosed; - _connection = null; - } - - private async void Exit(object sender, EventArgs e) - { - var message = new ValueSet - { - { "exit", string.Empty } - }; - await SendMessage(message); + Process.Start("flute.exe", "close"); Application.Exit(); } @@ -61,28 +47,6 @@ namespace FluentTerminal.SystemTray await appListEntries.First().LaunchAsync(); } - private async Task SendMessage(ValueSet message) - - { - if (_connection == null) - { - _connection = new AppServiceConnection - { - PackageFamilyName = Package.Current.Id.FamilyName, - AppServiceName = "FluentTerminalAppService" - }; - _connection.ServiceClosed += Connection_ServiceClosed; - AppServiceConnectionStatus connectionStatus = await _connection.OpenAsync(); - - if (connectionStatus != AppServiceConnectionStatus.Success) - { - MessageBox.Show("Status: " + connectionStatus.ToString()); - return; - } - } - await _connection.SendMessageAsync(message); - } - private void ShowSettings(object sender, EventArgs e) { Process.Start("flute.exe", "settings");