Wino.Server and Wino.Packaging projects. Enabling full trust for UWP and app service connection manager basics.
This commit is contained in:
10
Wino.Server/App.xaml
Normal file
10
Wino.Server/App.xaml
Normal file
@@ -0,0 +1,10 @@
|
||||
<Application
|
||||
x:Class="Wino.Server.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
ShutdownMode="OnExplicitShutdown"
|
||||
xmlns:local="clr-namespace:Wino.Server">
|
||||
<Application.Resources>
|
||||
<ResourceDictionary Source="TrayIconResources.xaml" />
|
||||
</Application.Resources>
|
||||
</Application>
|
||||
25
Wino.Server/App.xaml.cs
Normal file
25
Wino.Server/App.xaml.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System.Windows;
|
||||
using H.NotifyIcon;
|
||||
|
||||
namespace Wino.Server
|
||||
{
|
||||
public partial class App : Application
|
||||
{
|
||||
private TaskbarIcon? notifyIcon;
|
||||
|
||||
protected override void OnStartup(StartupEventArgs e)
|
||||
{
|
||||
base.OnStartup(e);
|
||||
|
||||
//create the notifyicon (it's a resource declared in NotifyIconResources.xaml
|
||||
notifyIcon = (TaskbarIcon)FindResource("NotifyIcon");
|
||||
notifyIcon.ForceCreate(enablesEfficiencyMode: true);
|
||||
}
|
||||
|
||||
protected override void OnExit(ExitEventArgs e)
|
||||
{
|
||||
notifyIcon?.Dispose();
|
||||
base.OnExit(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
10
Wino.Server/AssemblyInfo.cs
Normal file
10
Wino.Server/AssemblyInfo.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System.Windows;
|
||||
|
||||
[assembly: ThemeInfo(
|
||||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
|
||||
//(used if a resource is not found in the page,
|
||||
// or application resource dictionaries)
|
||||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
|
||||
//(used if a resource is not found in the page,
|
||||
// app, or any theme specific resource dictionaries)
|
||||
)]
|
||||
BIN
Wino.Server/Images/Wino_Icon.ico
Normal file
BIN
Wino.Server/Images/Wino_Icon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 124 KiB |
50
Wino.Server/ServerContext.cs
Normal file
50
Wino.Server/ServerContext.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using Windows.ApplicationModel;
|
||||
using Windows.ApplicationModel.AppService;
|
||||
|
||||
namespace Wino.Server
|
||||
{
|
||||
public class ServerContext
|
||||
{
|
||||
private AppServiceConnection connection = null;
|
||||
|
||||
public ServerContext()
|
||||
{
|
||||
InitializeAppServiceConnection();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Open connection to UWP app service
|
||||
/// </summary>
|
||||
public async void InitializeAppServiceConnection()
|
||||
{
|
||||
connection = new AppServiceConnection
|
||||
{
|
||||
AppServiceName = "WinoInteropService",
|
||||
PackageFamilyName = Package.Current.Id.FamilyName
|
||||
};
|
||||
|
||||
connection.RequestReceived += OnWinRTMessageReceived;
|
||||
connection.ServiceClosed += OnConnectionClosed;
|
||||
|
||||
AppServiceConnectionStatus status = await connection.OpenAsync();
|
||||
|
||||
if (status != AppServiceConnectionStatus.Success)
|
||||
{
|
||||
// TODO: Handle connection error
|
||||
}
|
||||
}
|
||||
|
||||
private void OnConnectionClosed(AppServiceConnection sender, AppServiceClosedEventArgs args)
|
||||
{
|
||||
// TODO: Handle connection closed.
|
||||
|
||||
// UWP app might've been terminated.
|
||||
}
|
||||
|
||||
private void OnWinRTMessageReceived(AppServiceConnection sender, AppServiceRequestReceivedEventArgs args)
|
||||
{
|
||||
// TODO: Handle incoming messages from UWP/WINUI Application.
|
||||
}
|
||||
}
|
||||
}
|
||||
25
Wino.Server/TrayIconResources.xaml
Normal file
25
Wino.Server/TrayIconResources.xaml
Normal file
@@ -0,0 +1,25 @@
|
||||
<ResourceDictionary
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:tb="http://www.hardcodet.net/taskbar"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:server="clr-namespace:Wino.Server">
|
||||
|
||||
<ContextMenu x:Shared="false" x:Key="SysTrayMenu">
|
||||
<MenuItem Header="Launch Wino Mail" Command="{Binding LaunchWinoCommand}" />
|
||||
<Separator />
|
||||
<MenuItem Header="Exit" Command="{Binding ExitApplicationCommand}" />
|
||||
</ContextMenu>
|
||||
|
||||
<tb:TaskbarIcon
|
||||
x:Key="NotifyIcon"
|
||||
IconSource="Images/Wino_Icon.ico"
|
||||
ToolTipText="Wino Mail"
|
||||
LeftClickCommand="{Binding LaunchWinoCommand}"
|
||||
NoLeftClickDelay="True"
|
||||
ContextMenu="{StaticResource SysTrayMenu}">
|
||||
|
||||
<tb:TaskbarIcon.DataContext>
|
||||
<server:TrayIconViewModel />
|
||||
</tb:TaskbarIcon.DataContext>
|
||||
</tb:TaskbarIcon>
|
||||
</ResourceDictionary>
|
||||
27
Wino.Server/TrayIconViewModel.cs
Normal file
27
Wino.Server/TrayIconViewModel.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System.Windows;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
|
||||
namespace Wino.Server
|
||||
{
|
||||
public partial class TrayIconViewModel : ObservableObject
|
||||
{
|
||||
private readonly ServerContext _context = new ServerContext();
|
||||
|
||||
[RelayCommand]
|
||||
public void LaunchWino()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shuts down the application.
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
public void ExitApplication()
|
||||
{
|
||||
// TODO: App service send message to UWP app to terminate itself.
|
||||
|
||||
Application.Current.Shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
30
Wino.Server/Wino.Server.csproj
Normal file
30
Wino.Server/Wino.Server.csproj
Normal file
@@ -0,0 +1,30 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<UseWPF>true</UseWPF>
|
||||
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
|
||||
<TargetFramework>net8.0-windows10.0.17763.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<StartupObject>Wino.Server.App</StartupObject>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<None Remove="Images\Wino_Icon.ico" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Resource Include="Images\Wino_Icon.ico">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Resource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
|
||||
<PackageReference Include="H.NotifyIcon.Wpf" Version="2.1.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Wino.Core.Domain\Wino.Core.Domain.csproj" />
|
||||
<ProjectReference Include="..\Wino.Core\Wino.Core.csproj" />
|
||||
<ProjectReference Include="..\Wino.Messages\Wino.Messages.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user