Switch back to WPF server.

This commit is contained in:
Burak Kaan Köse
2024-07-19 04:26:06 +02:00
parent 756cf5992c
commit 7d0934b679
11 changed files with 57 additions and 166 deletions

View File

@@ -2,6 +2,7 @@
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" />

View File

@@ -1,16 +1,14 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using H.NotifyIcon;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Input;
using Windows.Storage;
using Wino.Core;
using Wino.Core.Domain.Interfaces;
using Wino.Core.Services;
using Wino.Core.UWP.Services;
using Wino.Services;
//using Wino.Core.UWP;
namespace Wino.Server
{
@@ -29,17 +27,12 @@ namespace Wino.Server
public new static App Current => (App)Application.Current;
private TaskbarIcon notifyIcon;
private TaskbarIcon? notifyIcon;
private static Mutex _mutex = null;
private EventWaitHandle _eventWaitHandle;
public IServiceProvider Services { get; private set; }
public App()
{
InitializeComponent();
}
private IServiceProvider ConfigureServices()
{
var services = new ServiceCollection();
@@ -48,13 +41,14 @@ namespace Wino.Server
services.AddTransient<ServerViewModel>();
services.RegisterCoreServices();
// services.RegisterCoreUWPServices();
// Below services belongs to UWP.Core package and some APIs are not available for WPF.
// We register them here to avoid compilation errors.
services.AddSingleton<IConfigurationService, ConfigurationService>();
services.AddSingleton<INativeAppService, NativeAppService>();
services.AddSingleton<IPreferencesService, PreferencesService>();
//services.AddSingleton<IConfigurationService, ConfigurationService>();
//services.AddSingleton<INativeAppService, NativeAppService>();
//services.AddSingleton<IPreferencesService, PreferencesService>();
return services.BuildServiceProvider();
}
@@ -78,10 +72,8 @@ namespace Wino.Server
return serverViewModel;
}
protected override void OnLaunched(LaunchActivatedEventArgs args)
protected override async void OnStartup(StartupEventArgs e)
{
base.OnLaunched(args);
_mutex = new Mutex(true, WinoServerAppName, out bool isCreatedNew);
_eventWaitHandle = new EventWaitHandle(false, EventResetMode.AutoReset, WinoServerActiatedName);
@@ -110,6 +102,7 @@ namespace Wino.Server
Services = ConfigureServices();
base.OnStartup(e);
var serverViewModel = await InitializeNewServerAsync();
@@ -124,21 +117,14 @@ namespace Wino.Server
_eventWaitHandle.Set();
// Terminate this instance.
// Shutdown();
Shutdown();
}
}
private void InitializeNotifyIcon()
protected override void OnExit(ExitEventArgs e)
{
var showHideWindowCommand = (XamlUICommand)Resources["ShowHideWindowCommand"];
showHideWindowCommand.ExecuteRequested += ShowHideWindowCommand_ExecuteRequested;
var exitApplicationCommand = (XamlUICommand)Resources["ExitApplicationCommand"];
exitApplicationCommand.ExecuteRequested += ExitApplicationCommand_ExecuteRequested;
notifyIcon = (TaskbarIcon)Resources["TrayIcon"];
notifyIcon.ForceCreate();
notifyIcon?.Dispose();
base.OnExit(e);
}
}
}

View File

@@ -1,25 +0,0 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.UI.Dispatching;
namespace Wino.Server.WinUI
{
[STAThread]
static async Task Main(string[] args)
{
WinRT.ComWrappersSupport.InitializeComWrappers();
bool isRedirect = await DecideRedirection();
if (!isRedirect)
{
Microsoft.UI.Xaml.Application.Start((p) =>
{
var context = new DispatcherQueueSynchronizationContext(
DispatcherQueue.GetForCurrentThread());
SynchronizationContext.SetSynchronizationContext(context);
new App();
});
}
return 0;
}
}

View File

@@ -1,42 +0,0 @@
<ResourceDictionary
x:Class="Wino.Server.WinUI.TrayIconResources"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:domain="using:Wino.Core.Domain"
xmlns:tb="using:H.NotifyIcon"
xmlns:local="using:Wino.Server.WinUI">
<XamlUICommand
x:Key="LaunchCommand"
Label="Launch"
Description="Activates Wino Mail window.">
<XamlUICommand.IconSource>
<SymbolIconSource Symbol="Accept" />
</XamlUICommand.IconSource>
</XamlUICommand>
<XamlUICommand
x:Key="TerminateCommand"
Label="Quit"
Description="Close Wino Mail completely.">
<XamlUICommand.IconSource>
<SymbolIconSource Symbol="ClosePane" />
</XamlUICommand.IconSource>
</XamlUICommand>
<tb:TaskbarIcon
x:Key="TrayIcon"
Visibility="Visible"
ToolTipText="Wino Mail"
ContextMenuMode="SecondWindow"
LeftClickCommand="{StaticResource LaunchCommand}"
NoLeftClickDelay="True"
IconSource="\Images\Wino_Icon.ico">
<tb:TaskbarIcon.ContextFlyout>
<MenuFlyout>
<MenuFlyoutItem Command="{StaticResource LaunchCommand}" />
<MenuFlyoutItem Command="{StaticResource TerminateCommand}" />
</MenuFlyout>
</tb:TaskbarIcon.ContextFlyout>
</tb:TaskbarIcon>
</ResourceDictionary>

View File

@@ -1,17 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.UI.Xaml;
namespace Wino.Server.WinUI
{
partial class TrayIconResources : ResourceDictionary
{
public TrayIconResources()
{
this.InitializeComponent();
}
}
}

View File

@@ -6,7 +6,8 @@
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
<UseWPF>true</UseWPF>
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
<RuntimeIdentifiers Condition="$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)')) &gt;= 8">win-x86;win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifiers Condition="$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)')) &lt; 8">win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
<CsWinRTComponent>true</CsWinRTComponent>
<CsWinRTWindowsMetadata>10.0.22621.0</CsWinRTWindowsMetadata>
</PropertyGroup>
@@ -16,12 +17,6 @@
<ItemGroup>
<None Remove="Images\Wino_Icon.ico" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\Wino.Core.UWP\Services\ConfigurationService.cs" Link="Services\ConfigurationService.cs" />
<Compile Include="..\Wino.Core.UWP\Services\NativeAppService.cs" Link="Services\NativeAppService.cs" />
<Compile Include="..\Wino.Core.UWP\Services\NotificationBuilder.cs" Link="Services\NotificationBuilder.cs" />
<Compile Include="..\Wino.Core.UWP\Services\PreferencesService.cs" Link="Services\PreferencesService.cs" />
</ItemGroup>
<ItemGroup>
<Resource Include="Images\Wino_Icon.ico">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
@@ -32,11 +27,9 @@
<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.Messaging.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Services\" />
<ProjectReference Include="..\Wino.Core.Domain\Wino.Core.Domain.NET8.csproj" />
<ProjectReference Include="..\Wino.Core.UWP\Wino.Core.WinUI.csproj" />
<ProjectReference Include="..\Wino.Core\Wino.Core.NET8.csproj" />
<ProjectReference Include="..\Wino.Messages\Wino.Messaging.NET8.csproj" />
</ItemGroup>
</Project>