Remove almost unused AppService in favor of using flute.exe
This commit is contained in:
1 parent
1ca7371103
commit
6dfacdfebd
3 files changed
+7
-73
No files matched your search
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,9 +26,6 @@
|
||||
<uap:SplashScreen Image="Assets\AppIcons\SplashScreen.png" uap5:Optional="true" />
|
||||
</uap:VisualElements>
|
||||
<Extensions>
|
||||
<uap:Extension Category="windows.appService">
|
||||
<uap:AppService Name="FluentTerminalAppService" />
|
||||
</uap:Extension>
|
||||
<desktop:Extension Category="windows.fullTrustProcess" Executable="Win32\FluentTerminal.SystemTray.exe" />
|
||||
<uap5:Extension Category="windows.appExecutionAlias" Executable="FluentTerminal.App.exe" EntryPoint="FluentTerminal.App.App">
|
||||
<uap5:AppExecutionAlias>
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in new issue
Block a user