add uid loading support

This commit is contained in:
TheXamlGuy
2024-01-27 20:28:40 +00:00
parent 640b3292b2
commit 9f6cc35bc1
23 changed files with 147 additions and 99 deletions
@@ -8,10 +8,43 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.231202003-experimental1" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26031-preview" />
<None Remove="WidgetBarView.xaml" />
<None Remove="WidgetButtonView.xaml" />
<None Remove="WidgetContainerView.xaml" />
<None Remove="WidgetSplitButtonView.xaml" />
<None Remove="WidgetView.xaml" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Hyperbar\Hyperbar.csproj" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.231202003-experimental1" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26031-preview" />
<PackageReference Include="Microsoft.Xaml.Behaviors.WinUI.Managed" Version="2.0.9" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Hyperbar.Interop.Windows\Hyperbar.Interop.Windows.csproj" />
<ProjectReference Include="..\Hyperbar.UI.Windows\Hyperbar.UI.Windows.csproj" />
<ProjectReference Include="..\Hyperbar.Widget\Hyperbar.Widget.csproj" />
<ProjectReference Include="..\Hyperbar\Hyperbar.csproj" />
</ItemGroup>
<ItemGroup>
<Page Update="WidgetBarView.xaml">
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
<SubType>Designer</SubType>
</Page>
<Page Update="WidgetButtonView.xaml">
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
<SubType>Designer</SubType>
</Page>
<Page Update="WidgetContainerView.xaml">
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
<SubType>Designer</SubType>
</Page>
<Page Update="WidgetSplitButtonView.xaml">
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
<SubType>Designer</SubType>
</Page>
<Page Update="WidgetView.xaml">
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
<SubType>Designer</SubType>
</Page>
</ItemGroup>
</Project>
@@ -0,0 +1,41 @@
using Hyperbar.Interop.Windows;
using Hyperbar.UI.Windows;
using Microsoft.Extensions.DependencyInjection;
namespace Hyperbar.Widget.Windows;
public static class IServiceCollectionExtensions
{
public static IServiceCollection AddWidgetWindows(this IServiceCollection services)
{
services.AddContentTemplate<WidgetBarViewModel, WidgetBarView>();
// We need to feed information to the Widgets about our Windows host,
// so the Windows host can make discussions how to display and interact with the widgets.
services.AddTransient<IProxyServiceCollection<IWidgetBuilder>>(provider =>
new ProxyServiceCollection<IWidgetBuilder>(services =>
{
services.AddSingleton(provider.GetRequiredService<IDispatcher>());
services.AddTransient<IFactory<IWidgetHost, WidgetContainerViewModel?>,
WidgetContainerFactory>();
services.AddTransient<ITemplateFactory, TemplateFactory>();
services.AddScoped<IVirtualKeyboard, VirtualKeyboard>();
services.AddHandler<KeyAcceleratorHandler>();
services.AddHandler<StartProcessHandler>();
services.AddHandler<WidgetViewModelEnumerator>();
services.AddTransient<IWidgetView, WidgetView>();
services.AddTransient<IInitializer, WidgetResourceInitialization>();
services.AddContentTemplate<WidgetContainerViewModel, WidgetContainerView>();
services.AddContentTemplate<WidgetButtonViewModel, WidgetButtonView>();
services.AddContentTemplate<WidgetSplitButtonViewModel, WidgetSplitButtonView>();
}));
return services;
}
}
@@ -1,31 +0,0 @@
using Windows.ApplicationModel.Resources.Core;
using Windows.Storage;
namespace Hyperbar.Widget;
public interface IWidgetResourceInitialization :
IInitializer
{
}
public class WidgetResourceInitialization :
IInitializer
{
public async Task InitializeAsync()
{
//FileInfo resourcePriFileInfo = new(Path.Combine(ForeignAssemblyDir, "resources.pri"));
//if (!resourcePriFileInfo.Exists)
//{
// resourcePriFileInfo = new(Path.Combine(ForeignAssemblyDir, $"{ForeignAssemblyName}.pri"));
//}
//if (!resourcePriFileInfo.Exists)
//{
// return;
//}
//StorageFile file = await StorageFile.GetFileFromPathAsync(resourcePriFileInfo.FullName);
//ResourceManager.Current.LoadPriFiles(new[] { file });
}
}
@@ -0,0 +1,14 @@
using Hyperbar.Interop.Windows;
namespace Hyperbar.Widget.Windows;
internal class KeyAcceleratorHandler(IVirtualKeyboard virtualKeyboard) :
IHandler<KeyAccelerator>
{
public Task<Unit> Handle(KeyAccelerator request,
CancellationToken cancellationToken)
{
virtualKeyboard.Send((int)request.Key, request.Modifiers?.Select(modifier => (int)modifier).ToArray() ?? []);
return Task.FromResult<Unit>(default);
}
}
@@ -0,0 +1,14 @@
using System.Diagnostics;
namespace Hyperbar.Widget.Windows;
internal class StartProcessHandler :
IHandler<StartProcess>
{
public Task<Unit> Handle(StartProcess request,
CancellationToken cancellationToken)
{
Process.Start(request.Process);
return Task.FromResult<Unit>(default);
}
}
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8" ?>
<UserControl
x:Class="Hyperbar.Widget.Windows.WidgetBarView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ui="using:Hyperbar.UI.Windows">
<ItemsControl ItemTemplateSelector="{Binding Converter={ui:DataTemplateConverter}}" ItemsSource="{Binding}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerTransitions>
<TransitionCollection>
<AddDeleteThemeTransition />
</TransitionCollection>
</ItemsControl.ItemContainerTransitions>
</ItemsControl>
</UserControl>
@@ -0,0 +1,9 @@
using Microsoft.UI.Xaml.Controls;
namespace Hyperbar.Widget.Windows;
public sealed partial class WidgetBarView :
UserControl
{
public WidgetBarView() => InitializeComponent();
}
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8" ?>
<UserControl
x:Class="Hyperbar.Widget.Windows.WidgetButtonView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<UserControl.Resources>
<SolidColorBrush x:Key="ButtonBackground" Color="Transparent" />
<SolidColorBrush x:Key="ButtonBorderBrush" Color="Transparent" />
<SolidColorBrush x:Key="ButtonBorderBrushPointerOver" Color="Transparent" />
<SolidColorBrush x:Key="ButtonBorderBrushPressed" Color="Transparent" />
<SolidColorBrush x:Key="ButtonBorderBrushDisabled" Color="Transparent" />
<Thickness x:Key="ButtonPadding">0</Thickness>
<x:Double x:Key="ButtonWidth">40</x:Double>
<x:Double x:Key="ButtonHeight">40</x:Double>
</UserControl.Resources>
<Button
Width="{StaticResource ButtonWidth}"
Height="{StaticResource ButtonHeight}"
Padding="{StaticResource ButtonPadding}"
Command="{Binding Click}"
Content="{Binding Icon}"
FontFamily="{StaticResource SymbolThemeFontFamily}"
FontSize="16"
ToolTipService.ToolTip="{Binding Text}" />
</UserControl>
@@ -0,0 +1,9 @@
using Microsoft.UI.Xaml.Controls;
namespace Hyperbar.Widget.Windows;
public sealed partial class WidgetButtonView :
UserControl
{
public WidgetButtonView() => InitializeComponent();
}
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8" ?>
<UserControl
x:Class="Hyperbar.Widget.Windows.WidgetContainerView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:interactions="using:Microsoft.Xaml.Interactions.Core"
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:ui="using:Hyperbar.UI.Windows">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Rectangle
Width="1"
Height="40"
Margin="6,2,6,2"
Fill="Red" />
<ItemsControl
Grid.Column="1"
ItemTemplateSelector="{Binding Converter={ui:DataTemplateConverter}}"
ItemsSource="{Binding}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<interactivity:Interaction.Behaviors>
<interactions:EventTriggerBehavior EventName="Loaded">
<interactions:InvokeCommandAction Command="{Binding Initialize}" />
</interactions:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</ItemsControl>
</Grid>
</UserControl>
@@ -0,0 +1,9 @@
using Microsoft.UI.Xaml.Controls;
namespace Hyperbar.Widget.Windows;
public sealed partial class WidgetContainerView :
UserControl
{
public WidgetContainerView() => InitializeComponent();
}
@@ -0,0 +1,35 @@
using System.Reflection;
using Windows.ApplicationModel.Resources.Core;
using Windows.Storage;
namespace Hyperbar.Widget.Windows;
internal class WidgetResourceInitialization(IWidgetAssembly widgetAssembly) :
IInitializer
{
public async Task InitializeAsync()
{
if (widgetAssembly.Assembly is Assembly assembly)
{
if (Path.GetDirectoryName(assembly.Location) is string assemblyDirectory)
{
FileInfo resourceFileInfo = new(Path.Combine(assemblyDirectory,
"resources.pri"));
if (!resourceFileInfo.Exists)
{
resourceFileInfo = new(Path.Combine(assemblyDirectory,
$"{assembly.GetName().Name}.pri"));
}
if (!resourceFileInfo.Exists)
{
return;
}
StorageFile file = await StorageFile.GetFileFromPathAsync(resourceFileInfo.FullName);
ResourceManager.Current.LoadPriFiles(new[] { file });
}
}
}
}
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8" ?>
<UserControl
x:Class="Hyperbar.Widget.Windows.WidgetSplitButtonView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<UserControl.Resources>
<SolidColorBrush x:Key="SplitButtonBackground" Color="Transparent" />
<SolidColorBrush x:Key="SplitButtonBorderBrush" Color="Transparent" />
<SolidColorBrush x:Key="SplitButtonBorderBrushPointerOver" Color="Transparent" />
<SolidColorBrush x:Key="SplitButtonBorderBrushPressed" Color="Transparent" />
<SolidColorBrush x:Key="SplitButtonBorderBrushDisabled" Color="Transparent" />
<Thickness x:Key="ButtonPadding">0</Thickness>
<x:Double x:Key="ButtonWidth">40</x:Double>
<x:Double x:Key="ButtonHeight">38</x:Double>
</UserControl.Resources>
<SplitButton
Height="{StaticResource ButtonHeight}"
Margin="0,1,0,0"
Command="{Binding Click}"
Content="{Binding Icon}"
FontFamily="{StaticResource SymbolThemeFontFamily}"
FontSize="16">
<SplitButton.Flyout>
<Flyout ShouldConstrainToRootBounds="False">
<ItemsControl Margin="-16,-13,-16,-15" ItemsSource="{Binding Mode=TwoWay}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<MenuFlyoutItem Text="{Binding Text}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Flyout>
</SplitButton.Flyout>
</SplitButton>
</UserControl>
@@ -0,0 +1,9 @@
using Microsoft.UI.Xaml.Controls;
namespace Hyperbar.Widget.Windows;
public sealed partial class WidgetSplitButtonView :
UserControl
{
public WidgetSplitButtonView() => InitializeComponent();
}
+28
View File
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8" ?>
<UserControl
x:Class="Hyperbar.Widget.Windows.WidgetView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:interactions="using:Microsoft.Xaml.Interactions.Core"
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:ui="using:Hyperbar.UI.Windows">
<Grid>
<ItemsControl ItemTemplateSelector="{Binding Converter={ui:DataTemplateConverter}}" ItemsSource="{Binding Mode=TwoWay}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" Spacing="8" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerTransitions>
<TransitionCollection>
<AddDeleteThemeTransition />
</TransitionCollection>
</ItemsControl.ItemContainerTransitions>
<interactivity:Interaction.Behaviors>
<interactions:EventTriggerBehavior EventName="Loaded">
<interactions:InvokeCommandAction Command="{Binding Initialize}" />
</interactions:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</ItemsControl>
</Grid>
</UserControl>
@@ -0,0 +1,11 @@
using Hyperbar.Widget;
using Microsoft.UI.Xaml.Controls;
namespace Hyperbar.Widget.Windows;
public sealed partial class WidgetView :
UserControl,
IWidgetView
{
public WidgetView() => InitializeComponent();
}