Stuff for tunesync
This commit is contained in:
@@ -7,4 +7,4 @@ public class DispatcherTimerFactory :
|
||||
{
|
||||
public IDispatcherTimer Create(Action actionDelegate, TimeSpan interval) =>
|
||||
new DispatcherTimer(actionDelegate, interval);
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ public static class IServiceCollectionExtensions
|
||||
{
|
||||
services.AddTransient<IDispatcher, WinUIDispatcher>();
|
||||
services.AddTransient<IDispatcherTimerFactory, DispatcherTimerFactory>();
|
||||
services.AddSingleton<IWindowRegistry, WindowRegistry>();
|
||||
|
||||
services.AddTransient((Func<IServiceProvider, IProxyServiceCollection<IComponentBuilder>>)(provider =>
|
||||
new ProxyServiceCollection<IComponentBuilder>(services =>
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
using Microsoft.UI.Xaml;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Toolkit.WinUI;
|
||||
|
||||
public interface IWindowRegistry
|
||||
{
|
||||
void Add(Window window);
|
||||
|
||||
bool TryGet<TWindow>([DisallowNull] out TWindow? window)
|
||||
where TWindow : Window;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
using Microsoft.UI.Xaml.Media.Imaging;
|
||||
using System.Drawing;
|
||||
using Windows.Storage;
|
||||
using Windows.Win32;
|
||||
using Windows.Win32.UI.WindowsAndMessaging;
|
||||
|
||||
namespace Toolkit.WinUI;
|
||||
|
||||
public static class ImageSourceExtensions
|
||||
{
|
||||
public static Icon? ConvertToIcon(this Stream stream, uint dpi)
|
||||
{
|
||||
return ExtractIcon(dpi, stream);
|
||||
}
|
||||
|
||||
private static Icon? ExtractIcon(uint dpi, Stream stream)
|
||||
{
|
||||
Bitmap bitmap = (Bitmap)Image.FromStream(stream);
|
||||
Icon icon = Icon.FromHandle(bitmap.GetHicon());
|
||||
|
||||
return new Icon(icon, new Size(PInvoke.GetSystemMetricsForDpi(SYSTEM_METRICS_INDEX.SM_CXICON, dpi),
|
||||
PInvoke.GetSystemMetricsForDpi(SYSTEM_METRICS_INDEX.SM_CYICON, dpi)));
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Toolkit.Foundation\Toolkit.Foundation.csproj" />
|
||||
<ProjectReference Include="..\Toolkit.Windows\Toolkit.Windows.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -11,4 +11,4 @@ public class WinUIDispatcher :
|
||||
DispatcherQueue.GetForCurrentThread().TryEnqueue(action.Invoke);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using Microsoft.UI.Xaml;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Toolkit.WinUI;
|
||||
|
||||
public class WindowRegistry :
|
||||
IWindowRegistry
|
||||
{
|
||||
private readonly List<Window> windows = [];
|
||||
|
||||
public void Add(Window window)
|
||||
{
|
||||
if (!windows.Contains(window))
|
||||
{
|
||||
void OnWindowClosed(object sender, WindowEventArgs args)
|
||||
{
|
||||
window.Closed -= OnWindowClosed;
|
||||
windows.Remove(window);
|
||||
}
|
||||
|
||||
windows.Add(window);
|
||||
window.Closed += OnWindowClosed;
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryGet<TWindow>([DisallowNull] out TWindow? window)
|
||||
where TWindow : Window
|
||||
{
|
||||
window = windows.OfType<TWindow>().FirstOrDefault() ?? null;
|
||||
return window is not null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user