moerfixes
This commit is contained in:
@@ -13,8 +13,7 @@ public partial class MediaButtonViewModel(IServiceFactory serviceFactory,
|
||||
string? text = null,
|
||||
string? icon = null,
|
||||
RelayCommand? command = null) :
|
||||
WidgetButtonViewModel(serviceFactory, mediator, disposer, templateFactory, guid, text, icon, command),
|
||||
IInitialization
|
||||
WidgetButtonViewModel(serviceFactory, mediator, disposer, templateFactory, guid, text, icon, command)
|
||||
{
|
||||
[ObservableProperty]
|
||||
private PlaybackButtonType playbackButtonType = playbackButtonType;
|
||||
@@ -38,6 +37,8 @@ public partial class MediaButtonViewModel(IServiceFactory serviceFactory,
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
//public override async Task InitializeAsync() =>
|
||||
//public override Task OnInitializeAsync()
|
||||
//{
|
||||
// await Mediator.PublishAsync<Request<PlaybackInformation>>();
|
||||
//}
|
||||
}
|
||||
|
||||
@@ -97,9 +97,15 @@ public class MediaController :
|
||||
GlobalSystemMediaTransportControlsSessionMediaProperties mediaProperties =
|
||||
await session.TryGetMediaPropertiesAsync();
|
||||
|
||||
IRandomAccessStreamWithContentType randomAccessStream = await mediaProperties.Thumbnail.OpenReadAsync();
|
||||
IRandomAccessStreamWithContentType? randomAccessStream = null;
|
||||
if (mediaProperties.Thumbnail is not null)
|
||||
{
|
||||
randomAccessStream =
|
||||
await mediaProperties.Thumbnail.OpenReadAsync();
|
||||
}
|
||||
|
||||
await mediator.PublishAsync(new Changed<MediaInformation>(new MediaInformation(mediaProperties.Title,
|
||||
mediaProperties.Artist, randomAccessStream.AsStream())));
|
||||
mediaProperties.Artist, randomAccessStream is not null ? randomAccessStream.AsStream() : default)));
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
@@ -27,7 +27,7 @@ public class MediaControllerService(IMediator mediator,
|
||||
|
||||
public Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private async Task InitializeSessionAsync(GlobalSystemMediaTransportControlsSession session)
|
||||
|
||||
@@ -4,9 +4,8 @@
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:windows="using:Hyperbar.UI.Windows">
|
||||
<Button>sfsdf</Button>
|
||||
<!--<FlipView
|
||||
<FlipView
|
||||
Width="360"
|
||||
ItemTemplateSelector="{Binding Converter={windows:DataTemplateConverter}}"
|
||||
ItemsSource="{Binding}" />-->
|
||||
ItemsSource="{Binding}" />
|
||||
</UserControl>
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
|
||||
public record MediaInformation(string Title,
|
||||
string Description,
|
||||
Stream ThumbnailSource);
|
||||
Stream? ThumbnailSource);
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
|
||||
namespace Hyperbar.Widget.MediaController.Windows;
|
||||
|
||||
@@ -8,7 +7,6 @@ public partial class MediaInformationViewModel(IServiceFactory serviceFactory,
|
||||
IDisposer disposer,
|
||||
ITemplateFactory templateFactory) :
|
||||
WidgetComponentViewModel(serviceFactory, mediator, disposer, templateFactory),
|
||||
IInitialization,
|
||||
INotificationHandler<Changed<MediaInformation>>
|
||||
{
|
||||
[ObservableProperty]
|
||||
@@ -33,6 +31,6 @@ public partial class MediaInformationViewModel(IServiceFactory serviceFactory,
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public override async Task InitializeAsync() =>
|
||||
public override async Task OnInitializeAsync() =>
|
||||
await Mediator.PublishAsync<Request<MediaInformation>>();
|
||||
}
|
||||
|
||||
@@ -30,8 +30,8 @@ public static class IServiceCollectionExtensions
|
||||
services.AddHandler<WidgetViewModelEnumerator>();
|
||||
|
||||
services.AddTransient<IWidgetView, WidgetView>();
|
||||
services.AddTransient<IInitialization, WidgetResourceInitializer>();
|
||||
services.AddTransient<IInitialization, WidgetXamlMetadataInitializer>();
|
||||
services.AddTransient<IInitializer, WidgetResourceInitializer>();
|
||||
services.AddTransient<IInitializer, WidgetXamlMetadataInitializer>();
|
||||
|
||||
services.AddContentTemplate<WidgetButtonViewModel, WidgetButtonView>();
|
||||
services.AddContentTemplate<WidgetSplitButtonViewModel, WidgetSplitButtonView>();
|
||||
|
||||
@@ -4,7 +4,7 @@ using Windows.Storage;
|
||||
namespace Hyperbar.Widget.Windows;
|
||||
|
||||
internal class WidgetResourceInitializer(IWidgetAssembly widgetAssembly) :
|
||||
IInitialization
|
||||
IInitializer
|
||||
{
|
||||
public async Task InitializeAsync()
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace Hyperbar.Widget.Windows;
|
||||
|
||||
public class WidgetXamlMetadataInitializer(IWidgetAssembly widgetAssembly,
|
||||
IList<IXamlMetadataProvider> xamlMetadataProviders) :
|
||||
IInitialization
|
||||
IInitializer
|
||||
{
|
||||
public Task InitializeAsync()
|
||||
{
|
||||
|
||||
@@ -7,7 +7,7 @@ public static class IServiceCollectionExtensions
|
||||
{
|
||||
public static IServiceCollection AddWidget(this IServiceCollection services)
|
||||
{
|
||||
services.AddTransient<IInitialization, WidgetExtensionInitializer>();
|
||||
services.AddTransient<IInitializer, WidgetExtensionInitializer>();
|
||||
services.AddTransient<IFactory<Type, IWidget>, WidgetFactory>();
|
||||
|
||||
services.AddHandler<WidgetExtensionEnumerator>();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public class WidgetExtensionInitializer(IMediator mediator) :
|
||||
IInitialization
|
||||
IInitializer
|
||||
{
|
||||
public async Task InitializeAsync() =>
|
||||
await mediator.PublishAsync<Enumerate<WidgetExtension>>();
|
||||
|
||||
@@ -9,16 +9,17 @@ public sealed class WidgetHost :
|
||||
private readonly IServiceProvider services;
|
||||
private readonly IMediator mediator;
|
||||
private readonly IProxyService<IMediator> proxyMediator;
|
||||
private readonly IEnumerable<IHostedService> hostedServices;
|
||||
|
||||
public WidgetHost(IServiceProvider services,
|
||||
IMediator mediator,
|
||||
IProxyService<IMediator> proxyMediator)
|
||||
IProxyService<IMediator> proxyMediator,
|
||||
IEnumerable<IHostedService> hostedServices)
|
||||
{
|
||||
this.services = services;
|
||||
this.mediator = mediator;
|
||||
this.proxyMediator = proxyMediator;
|
||||
|
||||
mediator.Subscribe(this);
|
||||
this.hostedServices = hostedServices;
|
||||
}
|
||||
|
||||
public WidgetConfiguration Configuration =>
|
||||
@@ -33,6 +34,11 @@ public sealed class WidgetHost :
|
||||
|
||||
public async Task StartAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
foreach (IHostedService service in hostedServices)
|
||||
{
|
||||
await service.StartAsync(cancellationToken);
|
||||
}
|
||||
|
||||
if (proxyMediator.Proxy is IMediator mediator)
|
||||
{
|
||||
await mediator.PublishAsync(new Started<IWidgetHost>(this),
|
||||
@@ -43,8 +49,11 @@ public sealed class WidgetHost :
|
||||
cancellationToken);
|
||||
}
|
||||
|
||||
public Task StopAsync(CancellationToken cancellationToken = default)
|
||||
public async Task StopAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
foreach(IHostedService service in hostedServices)
|
||||
{
|
||||
await service.StopAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,10 +10,10 @@ public class WidgetHostHandler :
|
||||
{
|
||||
if (notification.Value is IWidgetHost host)
|
||||
{
|
||||
if (host.Services.GetServices<IInitialization>() is
|
||||
IEnumerable<IInitialization> initializations)
|
||||
if (host.Services.GetServices<IInitializer>() is
|
||||
IEnumerable<IInitializer> initializations)
|
||||
{
|
||||
foreach (IInitialization initialization in initializations)
|
||||
foreach (IInitializer initialization in initializations)
|
||||
{
|
||||
await initialization.InitializeAsync();
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public class WidgetMonitor :
|
||||
IInitialization
|
||||
IInitializer
|
||||
{
|
||||
public Task InitializeAsync()
|
||||
{
|
||||
|
||||
@@ -5,16 +5,16 @@ namespace Hyperbar.Widget;
|
||||
public class WidgetService :
|
||||
IHostedService
|
||||
{
|
||||
private readonly IEnumerable<IInitialization> initializers;
|
||||
private readonly IEnumerable<IInitializer> initializers;
|
||||
|
||||
public WidgetService(IEnumerable<IInitialization> initializers)
|
||||
public WidgetService(IEnumerable<IInitializer> initializers)
|
||||
{
|
||||
this.initializers = initializers;
|
||||
}
|
||||
|
||||
public async Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
foreach (IInitialization initializer in initializers)
|
||||
foreach (IInitializer initializer in initializers)
|
||||
{
|
||||
await initializer.InitializeAsync();
|
||||
}
|
||||
|
||||
@@ -46,8 +46,7 @@ public partial class App :
|
||||
args.Placement = DesktopBarPlacemenet.Top;
|
||||
});
|
||||
|
||||
services.AddTransient<IInitialization, AppInitializer>();
|
||||
|
||||
services.AddTransient<IInitializer, AppInitializer>();
|
||||
services.AddSingleton<DesktopBar>();
|
||||
})
|
||||
.Build();
|
||||
|
||||
@@ -9,7 +9,7 @@ public class AppInitializer([FromKeyedServices(nameof(WidgetViewModel))] WidgetB
|
||||
[FromKeyedServices(nameof(WidgetViewModel))] WidgetViewModel viewModel,
|
||||
DesktopBar desktopFlyout,
|
||||
AppConfiguration configuration) :
|
||||
IInitialization
|
||||
IInitializer
|
||||
{
|
||||
public Task InitializeAsync()
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@ public class ConfigurationInitializer<TConfiguration>(IMediator mediator,
|
||||
IConfigurationWriter<TConfiguration> writer,
|
||||
IConfigurationFactory<TConfiguration> factory) :
|
||||
IConfigurationInitializer<TConfiguration>,
|
||||
IInitialization
|
||||
IInitializer
|
||||
where TConfiguration :
|
||||
class
|
||||
{
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
namespace Hyperbar;
|
||||
|
||||
public interface IConfigurationMonitor<TConfiguration> :
|
||||
IInitialization
|
||||
IInitializer
|
||||
where TConfiguration :
|
||||
class;
|
||||
@@ -117,7 +117,7 @@ public static class IServiceCollectionExtensions
|
||||
services.AddTransient<IConfigurationFactory<TConfiguration>>(provider => new ConfigurationFactory<TConfiguration>(() =>
|
||||
configuration ?? provider.GetRequiredService<TConfiguration>()));
|
||||
|
||||
services.AddTransient<IInitialization, ConfigurationInitializer<TConfiguration>>();
|
||||
services.AddTransient<IInitializer, ConfigurationInitializer<TConfiguration>>();
|
||||
services.AddTransient<IConfigurationInitializer<TConfiguration>, ConfigurationInitializer<TConfiguration>>();
|
||||
|
||||
services.AddTransient<IWritableConfiguration<TConfiguration>, WritableConfiguration<TConfiguration>>();
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
|
||||
namespace Hyperbar;
|
||||
|
||||
public class AppService(IEnumerable<IInitialization> initializers) :
|
||||
public class AppService(IEnumerable<IInitializer> initializers) :
|
||||
IHostedService
|
||||
{
|
||||
public async Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
foreach (IInitialization initializer in initializers)
|
||||
foreach (IInitializer initializer in initializers)
|
||||
{
|
||||
await initializer.InitializeAsync();
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Hyperbar;
|
||||
|
||||
public interface IInitialization2
|
||||
public interface IInitialization
|
||||
{
|
||||
ICommand Initialize { get; }
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace Hyperbar;
|
||||
|
||||
public interface IInitialization
|
||||
public interface IInitializer
|
||||
{
|
||||
Task InitializeAsync();
|
||||
}
|
||||
@@ -20,14 +20,17 @@ public partial class ObservableCollectionViewModel<TItem> :
|
||||
INotificationHandler<Inserted<TItem>>,
|
||||
INotificationHandler<Moved<TItem>>,
|
||||
INotificationHandler<Replaced<TItem>>,
|
||||
IDisposable
|
||||
IDisposable,
|
||||
IInitialization
|
||||
where TItem :
|
||||
IDisposable
|
||||
{
|
||||
private readonly ObservableCollection<TItem> collection = new();
|
||||
private readonly ObservableCollection<TItem> collection = [];
|
||||
|
||||
private bool isInitialized;
|
||||
|
||||
public ObservableCollectionViewModel(IServiceFactory serviceFactory,
|
||||
IMediator mediator,
|
||||
IMediator mediator,
|
||||
IDisposer disposer)
|
||||
{
|
||||
ServiceFactory = serviceFactory;
|
||||
@@ -268,11 +271,7 @@ public partial class ObservableCollectionViewModel<TItem> :
|
||||
int IList.IndexOf(object? value) =>
|
||||
IsCompatibleObject(value) ?
|
||||
IndexOf((TItem)value!) : -1;
|
||||
|
||||
public virtual async Task InitializeAsync() =>
|
||||
await Mediator.PublishAsync<Enumerate<TItem>>();
|
||||
|
||||
public void Insert(int index, TItem item) =>
|
||||
public void Insert(int index, TItem item) =>
|
||||
InsertItem(index, item);
|
||||
|
||||
void IList.Insert(int index,
|
||||
@@ -284,22 +283,6 @@ public partial class ObservableCollectionViewModel<TItem> :
|
||||
}
|
||||
}
|
||||
|
||||
public bool Replace(int index, TItem item)
|
||||
{
|
||||
if (index <= Count - 1)
|
||||
{
|
||||
RemoveItem(index);
|
||||
}
|
||||
else
|
||||
{
|
||||
index = Count;
|
||||
}
|
||||
|
||||
Insert(index, item);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Move(int index, TItem item)
|
||||
{
|
||||
int oldIndex = collection.IndexOf(item);
|
||||
@@ -314,6 +297,11 @@ public partial class ObservableCollectionViewModel<TItem> :
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual Task OnInitializeAsync()
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public bool Remove(TItem item)
|
||||
{
|
||||
int index = collection.IndexOf(item);
|
||||
@@ -339,7 +327,23 @@ public partial class ObservableCollectionViewModel<TItem> :
|
||||
public void RemoveAt(int index) =>
|
||||
RemoveItem(index);
|
||||
|
||||
protected virtual void ClearItems() =>
|
||||
public bool Replace(int index, TItem item)
|
||||
{
|
||||
if (index <= Count - 1)
|
||||
{
|
||||
RemoveItem(index);
|
||||
}
|
||||
else
|
||||
{
|
||||
index = Count;
|
||||
}
|
||||
|
||||
Insert(index, item);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected virtual void ClearItems() =>
|
||||
collection.Clear();
|
||||
|
||||
protected virtual void InsertItem(int index,
|
||||
@@ -357,15 +361,27 @@ public partial class ObservableCollectionViewModel<TItem> :
|
||||
collection.Insert(index, value);
|
||||
}
|
||||
|
||||
protected virtual void RemoveItem(int index) =>
|
||||
protected virtual void RemoveItem(int index) =>
|
||||
collection.RemoveAt(index);
|
||||
|
||||
protected virtual void SetItem(int index, TItem item) =>
|
||||
protected virtual void SetItem(int index, TItem item) =>
|
||||
collection[index] = item;
|
||||
|
||||
private static bool IsCompatibleObject(object? value) =>
|
||||
private static bool IsCompatibleObject(object? value) =>
|
||||
(value is TItem) || (value == null && default(TItem) == null);
|
||||
|
||||
public async Task InitializeAsync()
|
||||
{
|
||||
if (isInitialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
isInitialized = true;
|
||||
|
||||
await Mediator.PublishAsync<Enumerate<TItem>>();
|
||||
await OnInitializeAsync();
|
||||
}
|
||||
private void OnCollectionChanged(object? sender, NotifyCollectionChangedEventArgs args) =>
|
||||
CollectionChanged?.Invoke(this, args);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user