added single instancing
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using TheXamlGuy.TaskbarGroup.Core;
|
||||
|
||||
namespace TheXamlGuy.TaskbarGroup
|
||||
@@ -11,20 +10,13 @@ namespace TheXamlGuy.TaskbarGroup
|
||||
{
|
||||
private readonly TaskbarButtonFlyoutWindow flyoutWindow;
|
||||
private readonly IEnumerable<IInitializable> initializables;
|
||||
private readonly IMediator mediator;
|
||||
private bool isInitialized;
|
||||
|
||||
public ApplicationHost(IEnumerable<IInitializable> initializables,
|
||||
IMessenger messenger,
|
||||
IMediator mediator,
|
||||
TaskbarButtonFlyoutWindow flyoutWindow)
|
||||
{
|
||||
this.initializables = initializables;
|
||||
this.mediator = mediator;
|
||||
this.flyoutWindow = flyoutWindow;
|
||||
|
||||
messenger.Subscribe<TaskbarButtonInvoked>(OnTaskbarButtonInvoked);
|
||||
messenger.Subscribe<TaskbarButtonDragEnter>(OnTaskbarButtonDragEnter);
|
||||
}
|
||||
|
||||
public async Task StartAsync(CancellationToken cancellationToken)
|
||||
@@ -40,6 +32,7 @@ namespace TheXamlGuy.TaskbarGroup
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
private async Task InitializeAsync()
|
||||
{
|
||||
if (!isInitialized)
|
||||
@@ -53,21 +46,6 @@ namespace TheXamlGuy.TaskbarGroup
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTaskbarButtonDragEnter(TaskbarButtonDragEnter args)
|
||||
{
|
||||
Application.Current.Dispatcher.Invoke(() => Open(args.Button));
|
||||
}
|
||||
|
||||
private void OnTaskbarButtonInvoked(TaskbarButtonInvoked args)
|
||||
{
|
||||
Application.Current.Dispatcher.Invoke(() => Open(args.Button));
|
||||
}
|
||||
|
||||
private void Open(TaskbarButton button)
|
||||
{
|
||||
mediator.Handle(new TaskbarButtonFlyoutActivation(button));
|
||||
}
|
||||
|
||||
private async Task StartupAsync()
|
||||
{
|
||||
if (!isInitialized)
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
namespace TheXamlGuy.TaskbarGroup
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
[STAThread()]
|
||||
public static void Main()
|
||||
{
|
||||
using (new Mutex(true, "TheXamlGuy.TaskbarGroup", out var createdNew))
|
||||
{
|
||||
if (createdNew)
|
||||
{
|
||||
using (new Flyout.App())
|
||||
{
|
||||
var app = new App();
|
||||
app.Run();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Environment.Exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace TheXamlGuy.TaskbarGroup
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
[STAThread()]
|
||||
public static void Main()
|
||||
{
|
||||
using (new Flyout.App())
|
||||
{
|
||||
var app = new App();
|
||||
app.Run();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,9 @@
|
||||
<UseWPF>true</UseWPF>
|
||||
<StartupObject>TheXamlGuy.TaskbarGroup.Program</StartupObject>
|
||||
<AssetTargetFallback>uap10.0.19041</AssetTargetFallback>
|
||||
<TargetPlatformVersion>10.0.19041</TargetPlatformVersion>
|
||||
<Platforms>x64;x86</Platforms>
|
||||
<RuntimeIdentifiers>win10-x64;win10-x86</RuntimeIdentifiers>
|
||||
<LangVersion>10.0</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Threading;
|
||||
using TheXamlGuy.TaskbarGroup.Core;
|
||||
using TheXamlGuy.TaskbarGroup.Flyout.Controls;
|
||||
|
||||
namespace TheXamlGuy.TaskbarGroup
|
||||
{
|
||||
public class TaskbarButtonFlyoutWindow : TransparentXamlWindow<TaskbarButtonFlyout>
|
||||
{
|
||||
public TaskbarButtonFlyoutWindow()
|
||||
private readonly IMediator mediator;
|
||||
|
||||
public TaskbarButtonFlyoutWindow(IMessenger messenger,
|
||||
IMediator mediator)
|
||||
{
|
||||
Deactivated += OnDeactivated;
|
||||
this.mediator = mediator;
|
||||
|
||||
Topmost = true;
|
||||
Width = 258;
|
||||
Height = 258;
|
||||
@@ -19,15 +22,36 @@ namespace TheXamlGuy.TaskbarGroup
|
||||
{
|
||||
Hide();
|
||||
}), DispatcherPriority.ContextIdle, null);
|
||||
|
||||
messenger.Subscribe<TaskbarButtonInvoked>(OnTaskbarButtonInvoked);
|
||||
messenger.Subscribe<TaskbarButtonDragEnter>(OnTaskbarButtonDragEnter);
|
||||
}
|
||||
|
||||
private void OnDeactivated(object? sender, EventArgs args)
|
||||
protected override void OnDeactivated(EventArgs args)
|
||||
{
|
||||
if (XamlContent is TaskbarButtonFlyout flyout)
|
||||
{
|
||||
flyout.Close();
|
||||
Hide();
|
||||
}
|
||||
}
|
||||
|
||||
base.OnDeactivated(args);
|
||||
}
|
||||
|
||||
private void Open(TaskbarButton button)
|
||||
{
|
||||
mediator.Handle(new TaskbarButtonFlyoutActivation(button));
|
||||
}
|
||||
|
||||
private void OnTaskbarButtonDragEnter(TaskbarButtonDragEnter args)
|
||||
{
|
||||
Dispatcher.Invoke(() => Open(args.Button));
|
||||
}
|
||||
|
||||
private void OnTaskbarButtonInvoked(TaskbarButtonInvoked args)
|
||||
{
|
||||
Dispatcher.Invoke(() => Open(args.Button));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user