break widget related stuff into its own project as the main HB project was just becoming too bloated
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Hyperbar\Hyperbar.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,65 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public static class IServiceCollectionExtensions
|
||||
{
|
||||
public static IServiceCollection AddWidget(this IServiceCollection services)
|
||||
{
|
||||
services.AddTransient<IInitializer, WidgetInitializer>();
|
||||
services.AddTransient<IFactory<Type, IWidget>, WidgetFactory>();
|
||||
|
||||
services.AddHandler<WidgetEnumeratorHandler>();
|
||||
services.AddHandler<WidgetAssemblyHandler>();
|
||||
services.AddHandler<WidgetHandler>();
|
||||
services.AddHandler<WidgetHostHandler>();
|
||||
|
||||
services.AddTransient<IFactory<IWidgetHost, WidgetContainerViewModel?>, WidgetContainerFactory>();
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
public static IServiceCollection AddWidgetTemplate<TWidgetContent>(this IServiceCollection services)
|
||||
where TWidgetContent :
|
||||
IWidgetViewModel
|
||||
{
|
||||
Type contentType = typeof(TWidgetContent);
|
||||
Type templateType = typeof(IWidgetView);
|
||||
|
||||
string key = contentType.Name;
|
||||
|
||||
services.AddTransient(typeof(IWidgetViewModel), contentType);
|
||||
services.TryAddTransient(templateType, provider => provider.GetService<IWidgetView>()!);
|
||||
|
||||
services.AddKeyedTransient(typeof(IWidgetViewModel), key, contentType);
|
||||
services.TryAddKeyedTransient(key, (provider, key) => provider.GetService<IWidgetView>()!);
|
||||
|
||||
services.AddTransient<IContentTemplateDescriptor>(provider => new ContentTemplateDescriptor { ContentType = contentType, TemplateType = templateType, Key = key });
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
public static IServiceCollection AddWidgetTemplate<TWidgetContent,
|
||||
TWidgetTemplate>(this IServiceCollection services)
|
||||
where TWidgetContent :
|
||||
IWidgetViewModel
|
||||
{
|
||||
Type contentType = typeof(TWidgetContent);
|
||||
Type templateType = typeof(TWidgetTemplate);
|
||||
|
||||
string key = contentType.Name;
|
||||
|
||||
services.AddTransient(typeof(IWidgetViewModel), contentType);
|
||||
services.TryAddTransient(templateType);
|
||||
|
||||
services.AddKeyedTransient(typeof(IWidgetViewModel), key, contentType);
|
||||
services.TryAddKeyedTransient(templateType, key);
|
||||
|
||||
services.AddTransient<IContentTemplateDescriptor>(provider =>
|
||||
new ContentTemplateDescriptor { ContentType = contentType,
|
||||
TemplateType = templateType, Key = key });
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public interface IWidget
|
||||
{
|
||||
IWidgetBuilder Create();
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public interface IWidgetBuilder
|
||||
{
|
||||
IWidgetHost Build();
|
||||
|
||||
IWidgetBuilder ConfigureServices(Action<IServiceCollection> configureDelegate);
|
||||
}
|
||||
|
||||
public interface IWidgetBuilder<TConfiguration> :
|
||||
IWidgetBuilder
|
||||
where TConfiguration :
|
||||
WidgetConfiguration,
|
||||
new()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public static class IWidgetBuilderExtensions
|
||||
{
|
||||
//public static IWidgetBuilder ConfigureServices(this IWidgetBuilder builder,
|
||||
// Action<IServiceCollection> servicesDelegate)
|
||||
//{
|
||||
// servicesDelegate(builder.Services);
|
||||
// return builder;
|
||||
//}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public interface IWidgetComponentViewModel : IDisposable;
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public interface IWidgetHost :
|
||||
IInitializer
|
||||
{
|
||||
WidgetConfiguration Configuration { get; }
|
||||
|
||||
IServiceProvider Services { get; }
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public interface IWidgetView;
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public interface IWidgetViewModel : IDisposable;
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public record Started<TValue>(TValue Value) : INotification;
|
||||
@@ -0,0 +1,3 @@
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public record Stopped<TValue>(TValue Value) : INotification;
|
||||
@@ -0,0 +1,6 @@
|
||||
using System.Reflection;
|
||||
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public record WidgetAssembly(Assembly? Assembly = default) :
|
||||
INotification;
|
||||
@@ -0,0 +1,23 @@
|
||||
using System.Reflection;
|
||||
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public class WidgetAssemblyHandler(IMediator mediator,
|
||||
IFactory<Type, IWidget> factory) :
|
||||
INotificationHandler<Created<Assembly>>
|
||||
{
|
||||
public Task Handle(Created<Assembly> notification,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (notification.Value?.GetTypes().FirstOrDefault(x => typeof(IWidget).IsAssignableFrom(x)) is Type widgetType)
|
||||
{
|
||||
if (factory.Create(widgetType) is IWidget widget)
|
||||
{
|
||||
mediator.PublishAsync(new Created<IWidget>(widget),
|
||||
cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public record WidgetAvailability
|
||||
{
|
||||
public bool Value { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
[NotificationHandler(nameof(WidgetBarViewModel))]
|
||||
public partial class WidgetBarViewModel(ITemplateFactory templateFactory,
|
||||
IServiceFactory serviceFactory,
|
||||
IMediator mediator,
|
||||
IDisposer disposer) :
|
||||
ObservableCollectionViewModel<WidgetContainerViewModel>(serviceFactory, mediator, disposer),
|
||||
ITemplatedViewModel
|
||||
{
|
||||
public ITemplateFactory TemplateFactory => templateFactory;
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public class WidgetBuilder<TConfiguration>(TConfiguration configuration) :
|
||||
IWidgetBuilder<TConfiguration>
|
||||
where TConfiguration :
|
||||
WidgetConfiguration,
|
||||
new()
|
||||
{
|
||||
private readonly IHostBuilder hostBuilder = new HostBuilder()
|
||||
.UseContentRoot(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
|
||||
Assembly.GetEntryAssembly()?.GetName().Name!), true)
|
||||
.ConfigureAppConfiguration(config =>
|
||||
{
|
||||
config.AddJsonFile("Settings.json", true, true);
|
||||
})
|
||||
.ConfigureServices((context, services) =>
|
||||
{
|
||||
services.AddScoped<IServiceFactory>(provider =>
|
||||
new ServiceFactory((type, parameters) =>
|
||||
ActivatorUtilities.CreateInstance(provider, type, parameters!)));
|
||||
|
||||
services.AddHostedService<WidgetService>();
|
||||
|
||||
services.AddScoped<IMediator, Mediator>();
|
||||
services.AddScoped<IDisposer, Disposer>();
|
||||
|
||||
services.AddSingleton<IValue<WidgetAvailability>,
|
||||
Value<WidgetAvailability>>();
|
||||
|
||||
services.AddHandler<WidgetConfigurationHandler>();
|
||||
|
||||
services.AddConfiguration<WidgetConfiguration>(section: configuration.GetType().Name,
|
||||
configuration: configuration);
|
||||
services.AddConfiguration(configuration);
|
||||
});
|
||||
|
||||
public static IWidgetBuilder Configure(Action<TConfiguration> configurationDelegate)
|
||||
{
|
||||
TConfiguration configuration = new();
|
||||
configurationDelegate(configuration);
|
||||
|
||||
return new WidgetBuilder<TConfiguration>(configuration);
|
||||
}
|
||||
|
||||
public IWidgetHost Build()
|
||||
{
|
||||
IHost host = hostBuilder.Build();
|
||||
return (IWidgetHost)ActivatorUtilities.CreateInstance(host.Services,
|
||||
typeof(WidgetHost), host);
|
||||
}
|
||||
|
||||
public IWidgetBuilder ConfigureServices(Action<IServiceCollection> configureDelegate)
|
||||
{
|
||||
hostBuilder.ConfigureServices(configureDelegate.Invoke);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
[NotificationHandler(nameof(Id))]
|
||||
public partial class WidgetButtonViewModel(IServiceFactory serviceFactory,
|
||||
IMediator mediator,
|
||||
IDisposer disposer,
|
||||
ITemplateFactory templateFactory,
|
||||
Guid id,
|
||||
string? text = null,
|
||||
string? icon = null,
|
||||
RelayCommand? command = null) : WidgetComponentViewModel(serviceFactory, mediator, disposer, templateFactory)
|
||||
{
|
||||
[ObservableProperty]
|
||||
private IRelayCommand? click = command;
|
||||
|
||||
[ObservableProperty]
|
||||
private string? icon = icon;
|
||||
|
||||
[ObservableProperty]
|
||||
private Guid id = id;
|
||||
|
||||
[ObservableProperty]
|
||||
private string? text = text;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public partial class WidgetComponentViewModel :
|
||||
ObservableCollectionViewModel<IWidgetComponentViewModel>,
|
||||
IWidgetComponentViewModel,
|
||||
ITemplatedViewModel
|
||||
{
|
||||
public WidgetComponentViewModel(IServiceFactory serviceFactory,
|
||||
IMediator mediator,
|
||||
IDisposer disposer,
|
||||
ITemplateFactory templateFactory,
|
||||
IEnumerable<IWidgetComponentViewModel> items) : base(serviceFactory, mediator, disposer, items)
|
||||
{
|
||||
TemplateFactory = templateFactory;
|
||||
}
|
||||
|
||||
public WidgetComponentViewModel(IServiceFactory serviceFactory,
|
||||
IMediator mediator,
|
||||
IDisposer disposer,
|
||||
ITemplateFactory templateFactory) : base(serviceFactory, mediator, disposer)
|
||||
{
|
||||
TemplateFactory = templateFactory;
|
||||
}
|
||||
|
||||
public ITemplateFactory TemplateFactory { get; private set; }
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Hyperbar.Widget;
|
||||
public class WidgetConfiguration
|
||||
{
|
||||
public string? Description { get; set; }
|
||||
|
||||
[JsonInclude]
|
||||
internal Guid Id { get; set; } = Guid.NewGuid();
|
||||
|
||||
public string? Name { get; set; }
|
||||
|
||||
[JsonInclude]
|
||||
internal bool IsAvailable { get; set; }
|
||||
}
|
||||
|
||||
public class WidgetConfiguration<TConfiguration>;
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public record WidgetConfigurationChanged<TConfiguration> : INotification;
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public class WidgetConfigurationHandler(IValue<WidgetAvailability> widgetAvailability) :
|
||||
INotificationHandler<ConfigurationChanged<WidgetConfiguration>>
|
||||
{
|
||||
public async Task Handle(ConfigurationChanged<WidgetConfiguration> notification,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (notification.Configuration is WidgetConfiguration configuration)
|
||||
{
|
||||
await widgetAvailability.SetAsync(args => args with { Value = configuration.IsAvailable });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public class WidgetContainerFactory(IServiceFactory factory) :
|
||||
IFactory<IWidgetHost, WidgetContainerViewModel?>
|
||||
{
|
||||
public WidgetContainerViewModel? Create(IWidgetHost value)
|
||||
{
|
||||
if (value.Services.GetServices<IWidgetViewModel>() is
|
||||
IEnumerable<IWidgetViewModel> viewModels)
|
||||
{
|
||||
return factory.Create<WidgetContainerViewModel>(value.Configuration.Id);
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public partial class WidgetContainerViewModel(ITemplateFactory templateFactory,
|
||||
IServiceFactory serviceFactory,
|
||||
IMediator mediator,
|
||||
IDisposer disposer,
|
||||
Guid id) :
|
||||
ObservableCollectionViewModel<IWidgetViewModel>(serviceFactory, mediator, disposer),
|
||||
ITemplatedViewModel
|
||||
{
|
||||
[ObservableProperty]
|
||||
private Guid id = id;
|
||||
|
||||
public ITemplateFactory TemplateFactory => templateFactory;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Loader;
|
||||
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public class WidgetEnumeratorHandler(IHostEnvironment hostEnvironment,
|
||||
IMediator mediator) :
|
||||
INotificationHandler<Enumerate<IWidget>>
|
||||
{
|
||||
public Task Handle(Enumerate<IWidget> notification,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
string extensionsDirectory = Path.Combine(hostEnvironment.ContentRootPath, "Extensions");
|
||||
if (Directory.Exists(extensionsDirectory))
|
||||
{
|
||||
List<string> assemblyPaths =
|
||||
[
|
||||
.. Directory.GetDirectories(extensionsDirectory)
|
||||
.AsParallel()
|
||||
.SelectMany(assemblyDirectory => Directory.GetFiles(assemblyDirectory, "*.dll"))
|
||||
];
|
||||
|
||||
Parallel.ForEach(assemblyPaths, (string assemblyPath) =>
|
||||
{
|
||||
Assembly assembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(assemblyPath);
|
||||
mediator.PublishAsync(new Created<Assembly>(assembly));
|
||||
});
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public class WidgetFactory :
|
||||
IFactory<Type, IWidget>
|
||||
{
|
||||
public IWidget? Create(Type value)
|
||||
{
|
||||
if (Activator.CreateInstance(value) is IWidget widget)
|
||||
{
|
||||
return widget;
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public class WidgetHandler(IProxyServiceCollection<IWidgetBuilder> typedServices,
|
||||
IServiceProvider provider,
|
||||
IMediator mediator) :
|
||||
INotificationHandler<Created<IWidget>>
|
||||
{
|
||||
public async Task Handle(Created<IWidget> notification,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if(notification.Value is IWidget widget)
|
||||
{
|
||||
IWidgetBuilder builder = widget.Create();
|
||||
|
||||
builder.ConfigureServices(args =>
|
||||
{
|
||||
args.AddTransient(_ => provider.GetRequiredService<IProxyService<IMediator>>());
|
||||
args.AddRange(typedServices.Services);
|
||||
});
|
||||
|
||||
IWidgetHost host = builder.Build();
|
||||
await host.InitializeAsync();
|
||||
|
||||
await mediator.PublishAsync(new Created<IWidgetHost>(host),
|
||||
cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public class WidgetHost :
|
||||
INotificationHandler<Changed<WidgetAvailability>>,
|
||||
IWidgetHost
|
||||
{
|
||||
private readonly IConfigurationInitializer<WidgetConfiguration> configurationInitializer;
|
||||
private readonly IHost host;
|
||||
private readonly IEnumerable<IInitializer> initializers;
|
||||
private readonly IMediator mediator;
|
||||
private readonly IProxyService<IMediator> proxyMediator;
|
||||
|
||||
public WidgetHost(IHost host,
|
||||
IMediator mediator,
|
||||
IEnumerable<IInitializer> initializers,
|
||||
IProxyService<IMediator> proxyMediator,
|
||||
IConfigurationInitializer<WidgetConfiguration> configurationInitializer)
|
||||
{
|
||||
this.host = host;
|
||||
this.mediator = mediator;
|
||||
this.initializers = initializers;
|
||||
this.proxyMediator = proxyMediator;
|
||||
this.configurationInitializer = configurationInitializer;
|
||||
|
||||
mediator.Subscribe(this);
|
||||
}
|
||||
|
||||
public WidgetConfiguration Configuration => host.Services.GetRequiredService<WidgetConfiguration>();
|
||||
|
||||
public IServiceProvider Services => host.Services;
|
||||
|
||||
public async Task Handle(Changed<WidgetAvailability> notification,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (notification.Value is WidgetAvailability widgetAvailability)
|
||||
{
|
||||
if (widgetAvailability.Value)
|
||||
{
|
||||
await StartAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async Task InitializeAsync() => await configurationInitializer.InitializeAsync();
|
||||
|
||||
private async Task StartAsync()
|
||||
{
|
||||
if (proxyMediator.Proxy is IMediator mediator)
|
||||
{
|
||||
await mediator.PublishAsync(new Started<IWidgetHost>(this));
|
||||
}
|
||||
|
||||
foreach (IInitializer initializer in initializers)
|
||||
{
|
||||
await initializer.InitializeAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public class WidgetHostHandler(IMediator mediator,
|
||||
IFactory<IWidgetHost, WidgetContainerViewModel?> factory) :
|
||||
INotificationHandler<Started<IWidgetHost>>,
|
||||
INotificationHandler<Stopped<IWidgetHost>>
|
||||
{
|
||||
public async Task Handle(Started<IWidgetHost> notification,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (notification.Value is IWidgetHost host)
|
||||
{
|
||||
if (factory.Create(host) is WidgetContainerViewModel containerViewModel)
|
||||
{
|
||||
await mediator.PublishAsync(new Created<WidgetContainerViewModel>(containerViewModel),
|
||||
nameof(WidgetBarViewModel), cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Task Handle(Stopped<IWidgetHost> notification,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public class WidgetInitializer(IMediator mediator) :
|
||||
IInitializer
|
||||
{
|
||||
public Task InitializeAsync()
|
||||
{
|
||||
mediator.PublishAsync<Enumerate<IWidget>>();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
[NotificationHandler(nameof(Id))]
|
||||
public partial class WidgetMenuViewModel(IServiceFactory serviceFactory,
|
||||
IMediator mediator,
|
||||
IDisposer disposer,
|
||||
ITemplateFactory templateFactory,
|
||||
Guid id = default,
|
||||
string? text = null,
|
||||
string? icon = null,
|
||||
RelayCommand? command = null) : WidgetComponentViewModel(serviceFactory, mediator, disposer, templateFactory)
|
||||
{
|
||||
[ObservableProperty]
|
||||
private IRelayCommand? click = command;
|
||||
|
||||
[ObservableProperty]
|
||||
private string? icon = icon;
|
||||
|
||||
[ObservableProperty]
|
||||
private Guid id = id;
|
||||
|
||||
[ObservableProperty]
|
||||
private string? text = text;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public class WidgetMonitor :
|
||||
IInitializer
|
||||
{
|
||||
public Task InitializeAsync()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public sealed class WidgetService(IEnumerable<IInitializer> initializers) :
|
||||
IHostedService
|
||||
{
|
||||
public async Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
foreach (IInitializer initializer in initializers)
|
||||
{
|
||||
await initializer.InitializeAsync();
|
||||
}
|
||||
}
|
||||
|
||||
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
[NotificationHandler(nameof(Id))]
|
||||
public partial class WidgetSplitButtonViewModel(IServiceFactory serviceFactory,
|
||||
IMediator mediator,
|
||||
IDisposer disposer,
|
||||
ITemplateFactory templateFactory,
|
||||
IEnumerable<IWidgetComponentViewModel> items,
|
||||
Guid id = default,
|
||||
string? text = null,
|
||||
string? icon = null,
|
||||
RelayCommand? command = null) : WidgetComponentViewModel(serviceFactory, mediator, disposer, templateFactory, items)
|
||||
{
|
||||
[ObservableProperty]
|
||||
private IRelayCommand? click = command;
|
||||
|
||||
[ObservableProperty]
|
||||
private string? icon = icon;
|
||||
|
||||
[ObservableProperty]
|
||||
private Guid id = id;
|
||||
|
||||
[ObservableProperty]
|
||||
private string? text = text;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public class WidgetViewModelEnumerator :
|
||||
INotificationHandler<Enumerate<IWidgetViewModel>>
|
||||
{
|
||||
public Task Handle(Enumerate<IWidgetViewModel> notification,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user