diff --git a/Hyperbar.Controls.Windows/Hyperbar.Controls.Windows.csproj b/Hyperbar.Controls.Windows/Hyperbar.Controls.Windows.csproj index d7898a0..a28294b 100644 --- a/Hyperbar.Controls.Windows/Hyperbar.Controls.Windows.csproj +++ b/Hyperbar.Controls.Windows/Hyperbar.Controls.Windows.csproj @@ -17,7 +17,7 @@ - + diff --git a/Hyperbar.UI.Windows/Hyperbar.UI.Windows.csproj b/Hyperbar.UI.Windows/Hyperbar.UI.Windows.csproj index 2071b13..52c8d48 100644 --- a/Hyperbar.UI.Windows/Hyperbar.UI.Windows.csproj +++ b/Hyperbar.UI.Windows/Hyperbar.UI.Windows.csproj @@ -9,7 +9,7 @@ enable - + diff --git a/Hyperbar.UI.Windows/StreamToImageSourceConverter.cs b/Hyperbar.UI.Windows/StreamToImageSourceConverter.cs index 328f470..1ab1c36 100644 --- a/Hyperbar.UI.Windows/StreamToImageSourceConverter.cs +++ b/Hyperbar.UI.Windows/StreamToImageSourceConverter.cs @@ -5,9 +5,9 @@ using Windows.Storage.Streams; namespace Hyperbar.UI.Windows; public class StreamToImageSourceConverter : - ValueConverter + ValueConverter { - protected override ImageSource? ConvertTo(Stream value, + protected override ImageSource? ConvertTo(byte[] value, Type? targetType, object? parameter, string? language) @@ -17,8 +17,8 @@ public class StreamToImageSourceConverter : return default; } - IRandomAccessStream randomAccessStream = - WindowsRuntimeStreamExtensions.AsRandomAccessStream(value); + MemoryStream memoryStream = new(value); + IRandomAccessStream randomAccessStream = memoryStream.AsRandomAccessStream(); BitmapImage bitmapImage = new(); bitmapImage.SetSource(randomAccessStream); diff --git a/Hyperbar.Widget.MediaController.Windows/Hyperbar.Widget.MediaController.Windows.csproj b/Hyperbar.Widget.MediaController.Windows/Hyperbar.Widget.MediaController.Windows.csproj index 378699a..bdc5404 100644 --- a/Hyperbar.Widget.MediaController.Windows/Hyperbar.Widget.MediaController.Windows.csproj +++ b/Hyperbar.Widget.MediaController.Windows/Hyperbar.Widget.MediaController.Windows.csproj @@ -12,7 +12,7 @@ - + diff --git a/Hyperbar.Widget.MediaController.Windows/IMediaButtonViewModel.cs b/Hyperbar.Widget.MediaController.Windows/IMediaButtonViewModel.cs new file mode 100644 index 0000000..9080668 --- /dev/null +++ b/Hyperbar.Widget.MediaController.Windows/IMediaButtonViewModel.cs @@ -0,0 +1,13 @@ +using CommunityToolkit.Mvvm.Input; + +namespace Hyperbar.Widget.MediaController.Windows; + +public interface IMediaButtonViewModel : + IObservableViewModel +{ + IRelayCommand? InvokeCommand { get; set; } + + bool IsEnabled { get; set; } + + string? State { get; set; } +} diff --git a/Hyperbar.Widget.MediaController.Windows/Previous.cs b/Hyperbar.Widget.MediaController.Windows/MediaButton.cs similarity index 56% rename from Hyperbar.Widget.MediaController.Windows/Previous.cs rename to Hyperbar.Widget.MediaController.Windows/MediaButton.cs index 4690f2c..fc507fa 100644 --- a/Hyperbar.Widget.MediaController.Windows/Previous.cs +++ b/Hyperbar.Widget.MediaController.Windows/MediaButton.cs @@ -1,3 +1,3 @@ namespace Hyperbar.Widget.MediaController.Windows; -public record Previous : INotification; +public record MediaButton(bool IsEnabled); diff --git a/Hyperbar.Widget.MediaController.Windows/MediaButtonView.xaml b/Hyperbar.Widget.MediaController.Windows/MediaButtonView.xaml index 3bc7768..d34d2ff 100644 --- a/Hyperbar.Widget.MediaController.Windows/MediaButtonView.xaml +++ b/Hyperbar.Widget.MediaController.Windows/MediaButtonView.xaml @@ -4,7 +4,8 @@ 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:interactivity="using:Microsoft.Xaml.Interactivity" + xmlns:triggers="using:CommunityToolkit.WinUI.UI.Triggers"> @@ -16,18 +17,49 @@ 40 diff --git a/Hyperbar.Widget.MediaController.Windows/MediaButtonView.xaml.cs b/Hyperbar.Widget.MediaController.Windows/MediaButtonView.xaml.cs index b35ceff..8c57d7e 100644 --- a/Hyperbar.Widget.MediaController.Windows/MediaButtonView.xaml.cs +++ b/Hyperbar.Widget.MediaController.Windows/MediaButtonView.xaml.cs @@ -9,5 +9,5 @@ public sealed partial class MediaButtonView : public MediaButtonView() => this.InitializeComponent(ref _contentLoaded); - private MediaButtonViewModel ViewModel => (MediaButtonViewModel)DataContext; + private IMediaButtonViewModel ViewModel => (IMediaButtonViewModel)DataContext; } diff --git a/Hyperbar.Widget.MediaController.Windows/MediaButtonViewModel.cs b/Hyperbar.Widget.MediaController.Windows/MediaButtonViewModel.cs index 51d5316..f59c1ef 100644 --- a/Hyperbar.Widget.MediaController.Windows/MediaButtonViewModel.cs +++ b/Hyperbar.Widget.MediaController.Windows/MediaButtonViewModel.cs @@ -3,42 +3,33 @@ using CommunityToolkit.Mvvm.Input; namespace Hyperbar.Widget.MediaController.Windows; -[NotificationHandler(nameof(PlaybackButtonType))] -public partial class MediaButtonViewModel(IServiceFactory serviceFactory, +public partial class MediaButtonViewModel(IServiceFactory serviceFactory, IMediator mediator, IDisposer disposer, ITemplateFactory templateFactory, - PlaybackButtonType playbackButtonType, - Guid guid = default, - string? text = null, - string? icon = null, - RelayCommand? command = null) : - WidgetButtonViewModel(serviceFactory, mediator, disposer, templateFactory, guid, text, icon, command) + IRelayCommand invokeCommand) : + WidgetComponentViewModel(serviceFactory, mediator, disposer, templateFactory), + INotificationHandler>, + IMediaButtonViewModel + where TMediaButton : + MediaButton { [ObservableProperty] - private PlaybackButtonType playbackButtonType = playbackButtonType; + private IRelayCommand? invokeCommand = invokeCommand; - public Task Handle(Changed notification, + [ObservableProperty] + private bool isEnabled; + + [ObservableProperty] + private string? state = $"{typeof(TMediaButton).Name}"; + + public Task Handle(Changed args, CancellationToken cancellationToken) { - if (notification.Value is MediaControllerPlaybackStatus information) - { - //switch (buttonType) - //{ - // case PlaybackButtonType.Play: - // Visible = information.Status is PlaybackStatus.Paused; - // break; - // case PlaybackButtonType.Pause: - // Visible = information.Status is PlaybackStatus.Playing; - // break; - //} - } - + IsEnabled = args.Value is not null && args.Value.IsEnabled; return Task.CompletedTask; } - //public override Task OnInitializeAsync() - //{ - // await Mediator.PublishAsync>(); - //} -} + public override async Task InitializeAsync() => + await Mediator.PublishAsync>(); +} \ No newline at end of file diff --git a/Hyperbar.Widget.MediaController.Windows/MediaController.cs b/Hyperbar.Widget.MediaController.Windows/MediaController.cs index 82411ce..4aad3b4 100644 --- a/Hyperbar.Widget.MediaController.Windows/MediaController.cs +++ b/Hyperbar.Widget.MediaController.Windows/MediaController.cs @@ -1,13 +1,16 @@ -using Windows.Media.Control; +using System.Collections.Concurrent; +using System.Diagnostics; +using Windows.Media.Control; using Windows.Storage.Streams; namespace Hyperbar.Widget.MediaController.Windows; public class MediaController : - INotificationHandler, - INotificationHandler, - INotificationHandler>, + INotificationHandler>, + INotificationHandler>, INotificationHandler>, + INotificationHandler>, + INotificationHandler>, IDisposable { private readonly AsyncLock asyncLock = new(); @@ -38,79 +41,100 @@ public class MediaController : disposer.Dispose(this); } - public async Task Handle(Play notification, - CancellationToken cancellationToken) - { - await session.TryPlayAsync(); - await UpdateMediaPlaybackPropertiesAsync(); - } - - public async Task Handle(Pause notification, - CancellationToken cancellationToken) - { - await session.TryPauseAsync(); - await UpdateMediaPlaybackPropertiesAsync(); - } - - public async Task Handle(Request args, - CancellationToken cancellationToken) => await UpdateMediaPlaybackPropertiesAsync(); - public async Task Handle(Request args, - CancellationToken cancellationToken) => await UpdateMediaPropertiesAsync(); + CancellationToken cancellationToken) => await UpdateMediaInformationAsync(); + + public async Task Handle(Request args, + CancellationToken cancellationToken) + { + await session.TrySkipNextAsync(); + await UpdateMediaStateAsync(); + } + + public async Task Handle(Request args, CancellationToken cancellationToken) + { + await session.TrySkipPreviousAsync(); + await UpdateMediaStateAsync(); + } + + public async Task Handle(Request args, + CancellationToken cancellationToken) => await UpdateMediaStateAsync(); + + public async Task Handle(Request args, + CancellationToken cancellationToken) => await UpdateMediaStateAsync(); private async void OnMediaPropertiesChanged(GlobalSystemMediaTransportControlsSession sender, - MediaPropertiesChangedEventArgs args) => await UpdateMediaPropertiesAsync(); + MediaPropertiesChangedEventArgs args) + { + await UpdateMediaInformationAsync(); + await UpdateMediaStateAsync(); + } private async void OnPlaybackInfoChanged(GlobalSystemMediaTransportControlsSession sender, - PlaybackInfoChangedEventArgs args) => await UpdateMediaPlaybackPropertiesAsync(); + PlaybackInfoChangedEventArgs args) => await UpdateMediaStateAsync(); - private async Task UpdateMediaPlaybackPropertiesAsync() + private async Task UpdateMediaInformationAsync() { - using (await asyncLock) + try { - try + GlobalSystemMediaTransportControlsSessionMediaProperties mediaProperties = + await session.TryGetMediaPropertiesAsync(); + + byte[]? buffer = null; + + if (mediaProperties.Thumbnail is not null) { - GlobalSystemMediaTransportControlsSessionPlaybackInfo playbackInfo = session.GetPlaybackInfo(); + IRandomAccessStreamWithContentType randomAccessStream = + await mediaProperties.Thumbnail.OpenReadAsync(); - if (playbackInfo.PlaybackStatus != playbackStatus) - { - playbackStatus = playbackInfo.PlaybackStatus; - await mediator.PublishAsync(new Changed( - new MediaControllerPlaybackStatus((PlaybackStatus)playbackStatus))); + var stream = randomAccessStream.AsStream(); - } + using MemoryStream memoryStream = new(); + await stream.CopyToAsync(memoryStream); + buffer = memoryStream.ToArray(); } - catch - { - } + await mediator.PublishAsync(new Changed(new MediaInformation(mediaProperties.Title, + mediaProperties.Artist, buffer))); + } + catch + { + } } - private async Task UpdateMediaPropertiesAsync() + private bool isPreviousEnabled; + private bool isNextEnabled; + + private async Task UpdateMediaStateAsync() { - using (await asyncLock) + try { - try + GlobalSystemMediaTransportControlsSessionPlaybackInfo playbackInfo = + session.GetPlaybackInfo(); + + bool isPreviousEnabled = playbackInfo.Controls.IsPreviousEnabled; + if (this.isPreviousEnabled != isPreviousEnabled) { + await mediator.PublishAsync(new Changed(new + MediaPreviousButton(isPreviousEnabled))); - GlobalSystemMediaTransportControlsSessionMediaProperties mediaProperties = - await session.TryGetMediaPropertiesAsync(); - - IRandomAccessStreamWithContentType? randomAccessStream = null; - if (mediaProperties.Thumbnail is not null) - { - randomAccessStream = - await mediaProperties.Thumbnail.OpenReadAsync(); - } - - await mediator.PublishAsync(new Changed(new MediaInformation(mediaProperties.Title, - mediaProperties.Artist, randomAccessStream is not null ? randomAccessStream.AsStream() : default))); + this.isPreviousEnabled = isPreviousEnabled; } - catch + + bool isNextEnabled = playbackInfo.Controls.IsNextEnabled; + if (this.isNextEnabled != isNextEnabled) { + await mediator.PublishAsync(new Changed(new + MediaNextButton(isNextEnabled))); + this.isNextEnabled = isNextEnabled; } + + } + catch + { + } } } \ No newline at end of file diff --git a/Hyperbar.Widget.MediaController.Windows/MediaControllerPlaybackStatus.cs b/Hyperbar.Widget.MediaController.Windows/MediaControllerPlaybackStatus.cs deleted file mode 100644 index 2d7b223..0000000 --- a/Hyperbar.Widget.MediaController.Windows/MediaControllerPlaybackStatus.cs +++ /dev/null @@ -1,4 +0,0 @@ -namespace Hyperbar.Widget.MediaController.Windows; - -public record MediaControllerPlaybackStatus(PlaybackStatus Status) : - INotification; diff --git a/Hyperbar.Widget.MediaController.Windows/MediaControllerPlaybackStatusHandler.cs b/Hyperbar.Widget.MediaController.Windows/MediaControllerPlaybackStatusHandler.cs deleted file mode 100644 index 7ad160f..0000000 --- a/Hyperbar.Widget.MediaController.Windows/MediaControllerPlaybackStatusHandler.cs +++ /dev/null @@ -1,31 +0,0 @@ -using CommunityToolkit.Mvvm.Input; - -namespace Hyperbar.Widget.MediaController.Windows; - -public class MediaControllerPlaybackStatusHandler(IMediator mediator, - IServiceFactory factory) : - INotificationHandler> -{ - public async Task Handle(Changed notification, - CancellationToken cancellationToken) - { - if (notification.Value is MediaControllerPlaybackStatus mediaControllerPlaybackInformation) - { - if (mediaControllerPlaybackInformation.Status is PlaybackStatus.Playing) - { - await mediator.PublishAsync(new Replaced(2, factory.Create( - PlaybackButtonType.Pause, "Pause", "\uE769", - new RelayCommand(async () => await mediator.PublishAsync()))), nameof(MediaControllerViewModel), - cancellationToken); - } - - if (mediaControllerPlaybackInformation.Status is PlaybackStatus.Paused) - { - await mediator.PublishAsync(new Replaced(2, factory.Create( - PlaybackButtonType.Pause, "Play", "\uE768", - new RelayCommand(async () => await mediator.PublishAsync()))), nameof(MediaControllerViewModel), - cancellationToken); - } - } - } -} diff --git a/Hyperbar.Widget.MediaController.Windows/MediaControllerViewModel.cs b/Hyperbar.Widget.MediaController.Windows/MediaControllerViewModel.cs index 1ad79f9..bf9188c 100644 --- a/Hyperbar.Widget.MediaController.Windows/MediaControllerViewModel.cs +++ b/Hyperbar.Widget.MediaController.Windows/MediaControllerViewModel.cs @@ -2,6 +2,8 @@ namespace Hyperbar.Widget.MediaController.Windows; + + [NotificationHandler(nameof(MediaControllerViewModel))] public class MediaControllerViewModel : ObservableCollectionViewModel, @@ -16,17 +18,14 @@ public class MediaControllerViewModel : Add(); - Add(PlaybackButtonType.Previous, - "Previous", "\uEB9E", - new RelayCommand(async () => await mediator.PublishAsync())); + Add>(new RelayCommand(async () => + await mediator.PublishAsync>())); - Add(PlaybackButtonType.Pause, - "Pause", "\uE769", - new RelayCommand(async () => await mediator.PublishAsync())); + Add>(new RelayCommand(async () => + await mediator.PublishAsync>())); - Add(PlaybackButtonType.Forward, - "Forward", "\uEB9D", - new RelayCommand(async () => await mediator.PublishAsync())); + Add>(new RelayCommand(async () => + await mediator.PublishAsync>())); } public ITemplateFactory TemplateFactory { get; set; } diff --git a/Hyperbar.Widget.MediaController.Windows/MediaControllerWidget.cs b/Hyperbar.Widget.MediaController.Windows/MediaControllerWidget.cs index 8040444..fc923f7 100644 --- a/Hyperbar.Widget.MediaController.Windows/MediaControllerWidget.cs +++ b/Hyperbar.Widget.MediaController.Windows/MediaControllerWidget.cs @@ -23,9 +23,10 @@ public class MediaControllerWidget : .AddHandler() .AddTransient, MediaControllerViewModelFactory>() .AddCache() - .AddHandler() .AddContentTemplate() .AddContentTemplate() - .AddContentTemplate(); + .AddContentTemplate, MediaButtonView>() + .AddContentTemplate, MediaButtonView>() + .AddContentTemplate, MediaButtonView>(); }); } \ No newline at end of file diff --git a/Hyperbar.Widget.MediaController.Windows/MediaInformation.cs b/Hyperbar.Widget.MediaController.Windows/MediaInformation.cs index e518dde..33e7689 100644 --- a/Hyperbar.Widget.MediaController.Windows/MediaInformation.cs +++ b/Hyperbar.Widget.MediaController.Windows/MediaInformation.cs @@ -2,6 +2,4 @@ public record MediaInformation(string Title, string Description, - Stream? ThumbnailSource); - - + byte[]? Image); diff --git a/Hyperbar.Widget.MediaController.Windows/MediaInformationView.xaml b/Hyperbar.Widget.MediaController.Windows/MediaInformationView.xaml index 2048f11..19f949d 100644 --- a/Hyperbar.Widget.MediaController.Windows/MediaInformationView.xaml +++ b/Hyperbar.Widget.MediaController.Windows/MediaInformationView.xaml @@ -16,7 +16,7 @@ Grid.Column="0" Width="40" Height="40"> - + - + diff --git a/Hyperbar.Widget.MediaController.Windows/MediaInformationViewModel.cs b/Hyperbar.Widget.MediaController.Windows/MediaInformationViewModel.cs index cbb9d3a..5982798 100644 --- a/Hyperbar.Widget.MediaController.Windows/MediaInformationViewModel.cs +++ b/Hyperbar.Widget.MediaController.Windows/MediaInformationViewModel.cs @@ -13,7 +13,7 @@ public partial class MediaInformationViewModel(IServiceFactory serviceFactory, private string? description; [ObservableProperty] - private Stream? thumbnailSource; + private byte[]? image; [ObservableProperty] private string? title; @@ -25,12 +25,12 @@ public partial class MediaInformationViewModel(IServiceFactory serviceFactory, { Title = value.Title; Description = value.Description; - ThumbnailSource = value.ThumbnailSource; + Image = value.Image; } return Task.CompletedTask; } - public override async Task OnInitializeAsync() => + public override async Task InitializeAsync() => await Mediator.PublishAsync>(); } diff --git a/Hyperbar.Widget.MediaController.Windows/Play.cs b/Hyperbar.Widget.MediaController.Windows/MediaNext.cs similarity index 61% rename from Hyperbar.Widget.MediaController.Windows/Play.cs rename to Hyperbar.Widget.MediaController.Windows/MediaNext.cs index 4b1df84..e37ed83 100644 --- a/Hyperbar.Widget.MediaController.Windows/Play.cs +++ b/Hyperbar.Widget.MediaController.Windows/MediaNext.cs @@ -1,3 +1,3 @@ namespace Hyperbar.Widget.MediaController.Windows; -public record Play : INotification; \ No newline at end of file +public record MediaNext; diff --git a/Hyperbar.Widget.MediaController.Windows/MediaNextButton.cs b/Hyperbar.Widget.MediaController.Windows/MediaNextButton.cs new file mode 100644 index 0000000..c512deb --- /dev/null +++ b/Hyperbar.Widget.MediaController.Windows/MediaNextButton.cs @@ -0,0 +1,4 @@ +namespace Hyperbar.Widget.MediaController.Windows; + +public record MediaNextButton(bool IsEnabled) : + MediaButton(IsEnabled); \ No newline at end of file diff --git a/Hyperbar.Widget.MediaController.Windows/Pause.cs b/Hyperbar.Widget.MediaController.Windows/MediaPlayPause.cs similarity index 59% rename from Hyperbar.Widget.MediaController.Windows/Pause.cs rename to Hyperbar.Widget.MediaController.Windows/MediaPlayPause.cs index 1a54ab0..1516216 100644 --- a/Hyperbar.Widget.MediaController.Windows/Pause.cs +++ b/Hyperbar.Widget.MediaController.Windows/MediaPlayPause.cs @@ -1,3 +1,3 @@ namespace Hyperbar.Widget.MediaController.Windows; -public record Pause : INotification; +public record MediaPlayPause; diff --git a/Hyperbar.Widget.MediaController.Windows/MediaPlayPauseButton.cs b/Hyperbar.Widget.MediaController.Windows/MediaPlayPauseButton.cs new file mode 100644 index 0000000..3002308 --- /dev/null +++ b/Hyperbar.Widget.MediaController.Windows/MediaPlayPauseButton.cs @@ -0,0 +1,4 @@ +namespace Hyperbar.Widget.MediaController.Windows; + +public record MediaPlayPauseButton(bool IsEnabled) : + MediaButton(IsEnabled); \ No newline at end of file diff --git a/Hyperbar.Widget.MediaController.Windows/Forward.cs b/Hyperbar.Widget.MediaController.Windows/MediaPrevious.cs similarity index 58% rename from Hyperbar.Widget.MediaController.Windows/Forward.cs rename to Hyperbar.Widget.MediaController.Windows/MediaPrevious.cs index a83d403..757bbb6 100644 --- a/Hyperbar.Widget.MediaController.Windows/Forward.cs +++ b/Hyperbar.Widget.MediaController.Windows/MediaPrevious.cs @@ -1,3 +1,3 @@ namespace Hyperbar.Widget.MediaController.Windows; -public record Forward : INotification; +public record MediaPrevious; \ No newline at end of file diff --git a/Hyperbar.Widget.MediaController.Windows/MediaPreviousButton.cs b/Hyperbar.Widget.MediaController.Windows/MediaPreviousButton.cs new file mode 100644 index 0000000..71547db --- /dev/null +++ b/Hyperbar.Widget.MediaController.Windows/MediaPreviousButton.cs @@ -0,0 +1,5 @@ +namespace Hyperbar.Widget.MediaController.Windows; + +public record MediaPreviousButton(bool IsEnabled) : + MediaButton(IsEnabled); + diff --git a/Hyperbar.Widget.MediaController.Windows/PlaybackButtonType.cs b/Hyperbar.Widget.MediaController.Windows/PlaybackButtonType.cs deleted file mode 100644 index 37a240f..0000000 --- a/Hyperbar.Widget.MediaController.Windows/PlaybackButtonType.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Hyperbar.Widget.MediaController.Windows; - -public enum PlaybackButtonType -{ - Previous, - Play, - Pause, - Forward -} diff --git a/Hyperbar.Widget.MediaController.Windows/PlaybackStatus.cs b/Hyperbar.Widget.MediaController.Windows/PlaybackStatus.cs deleted file mode 100644 index bf5e959..0000000 --- a/Hyperbar.Widget.MediaController.Windows/PlaybackStatus.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace Hyperbar.Widget.MediaController.Windows; - -public enum PlaybackStatus -{ - Closed, - Opened, - Changing, - Stopped, - Playing, - Paused -} \ No newline at end of file diff --git a/Hyperbar.Widget.Windows/Hyperbar.Widget.Windows.csproj b/Hyperbar.Widget.Windows/Hyperbar.Widget.Windows.csproj index dd0738e..1760bb5 100644 --- a/Hyperbar.Widget.Windows/Hyperbar.Widget.Windows.csproj +++ b/Hyperbar.Widget.Windows/Hyperbar.Widget.Windows.csproj @@ -8,7 +8,7 @@ enable - + diff --git a/Hyperbar.Widget.Windows/WidgetButtonView.xaml b/Hyperbar.Widget.Windows/WidgetButtonView.xaml index 51a7207..8def768 100644 --- a/Hyperbar.Widget.Windows/WidgetButtonView.xaml +++ b/Hyperbar.Widget.Windows/WidgetButtonView.xaml @@ -17,7 +17,7 @@ Width="{StaticResource ButtonWidth}" Height="{StaticResource ButtonHeight}" Padding="{StaticResource ButtonPadding}" - Command="{Binding Click}" + Command="{Binding InvokeCommand}" Content="{Binding Icon}" FontFamily="{StaticResource SymbolThemeFontFamily}" FontSize="16" diff --git a/Hyperbar.Widget.Windows/WidgetSplitButtonView.xaml b/Hyperbar.Widget.Windows/WidgetSplitButtonView.xaml index 1bc2494..6678932 100644 --- a/Hyperbar.Widget.Windows/WidgetSplitButtonView.xaml +++ b/Hyperbar.Widget.Windows/WidgetSplitButtonView.xaml @@ -16,7 +16,7 @@ diff --git a/Hyperbar.Widget.Windows/WidgetView.xaml b/Hyperbar.Widget.Windows/WidgetView.xaml index 6b28c6a..d0b0bb1 100644 --- a/Hyperbar.Widget.Windows/WidgetView.xaml +++ b/Hyperbar.Widget.Windows/WidgetView.xaml @@ -20,7 +20,7 @@ - + diff --git a/Hyperbar.Widget/WidgetButtonViewModel.cs b/Hyperbar.Widget/WidgetButtonViewModel.cs index 7721629..3969098 100644 --- a/Hyperbar.Widget/WidgetButtonViewModel.cs +++ b/Hyperbar.Widget/WidgetButtonViewModel.cs @@ -11,14 +11,8 @@ public partial class WidgetButtonViewModel(IServiceFactory serviceFactory, Guid id, string? text = null, string? icon = null, - RelayCommand? command = null) : WidgetComponentViewModel(serviceFactory, mediator, disposer, templateFactory) + RelayCommand? invokeCommand = null) : WidgetComponentViewModel(serviceFactory, mediator, disposer, templateFactory) { - [ObservableProperty] - private IRelayCommand? click = command; - - [ObservableProperty] - private bool enabled; - [ObservableProperty] private string? icon = icon; @@ -26,8 +20,11 @@ public partial class WidgetButtonViewModel(IServiceFactory serviceFactory, private Guid id = id; [ObservableProperty] - private string? text = text; + private IRelayCommand? invokeCommand = invokeCommand; [ObservableProperty] - private bool visible; + private bool isEnabled; + + [ObservableProperty] + private string? text = text; } \ No newline at end of file diff --git a/Hyperbar.Windows/Hyperbar.Windows.csproj b/Hyperbar.Windows/Hyperbar.Windows.csproj index ffc1135..67f6af9 100644 --- a/Hyperbar.Windows/Hyperbar.Windows.csproj +++ b/Hyperbar.Windows/Hyperbar.Windows.csproj @@ -29,7 +29,7 @@ - + diff --git a/Hyperbar/Lifecycles/IInitialization.cs b/Hyperbar/Lifecycles/IInitialization.cs index ddb9bc2..c9af65d 100644 --- a/Hyperbar/Lifecycles/IInitialization.cs +++ b/Hyperbar/Lifecycles/IInitialization.cs @@ -4,7 +4,7 @@ namespace Hyperbar; public interface IInitialization { - ICommand Initialize { get; } + ICommand InitializeCommand { get; } Task InitializeAsync(); } diff --git a/Hyperbar/Lifecycles/IObservableCollectionViewModel.cs b/Hyperbar/Lifecycles/IObservableCollectionViewModel.cs index 18093d0..7da3040 100644 --- a/Hyperbar/Lifecycles/IObservableCollectionViewModel.cs +++ b/Hyperbar/Lifecycles/IObservableCollectionViewModel.cs @@ -1,3 +1,4 @@ namespace Hyperbar; -public interface IObservableCollectionViewModel; \ No newline at end of file +public interface IObservableCollectionViewModel : + IObservableViewModel; diff --git a/Hyperbar/Lifecycles/IObservableViewModel.cs b/Hyperbar/Lifecycles/IObservableViewModel.cs new file mode 100644 index 0000000..f9f6e35 --- /dev/null +++ b/Hyperbar/Lifecycles/IObservableViewModel.cs @@ -0,0 +1,8 @@ +using System.Windows.Input; + +namespace Hyperbar; + +public interface IObservableViewModel +{ + ICommand InitializeCommand { get; } +} \ No newline at end of file diff --git a/Hyperbar/Lifecycles/ObservableCollectionViewModel.cs b/Hyperbar/Lifecycles/ObservableCollectionViewModel.cs index 29b7289..bbf621f 100644 --- a/Hyperbar/Lifecycles/ObservableCollectionViewModel.cs +++ b/Hyperbar/Lifecycles/ObservableCollectionViewModel.cs @@ -30,7 +30,7 @@ public partial class ObservableCollectionViewModel : private bool isInitialized; public ObservableCollectionViewModel(IServiceFactory serviceFactory, - IMediator mediator, + IMediator mediator, IDisposer disposer) { ServiceFactory = serviceFactory; @@ -54,7 +54,6 @@ public partial class ObservableCollectionViewModel : mediator.Subscribe(this); collection.CollectionChanged += OnCollectionChanged; - AddRange(items); } @@ -62,8 +61,8 @@ public partial class ObservableCollectionViewModel : public int Count => collection.Count; - public ICommand Initialize => - new AsyncRelayCommand(InitializeAsync); + public ICommand InitializeCommand => + new AsyncRelayCommand(CoreInitializeAsync); bool IList.IsFixedSize => false; @@ -297,7 +296,7 @@ public partial class ObservableCollectionViewModel : return true; } - public virtual Task OnInitializeAsync() + public virtual Task InitializeAsync() { return Task.CompletedTask; } @@ -370,7 +369,7 @@ public partial class ObservableCollectionViewModel : private static bool IsCompatibleObject(object? value) => (value is TItem) || (value == null && default(TItem) == null); - public async Task InitializeAsync() + private async Task CoreInitializeAsync() { if (isInitialized) { @@ -380,8 +379,9 @@ public partial class ObservableCollectionViewModel : isInitialized = true; await Mediator.PublishAsync>(); - await OnInitializeAsync(); + await InitializeAsync(); } + private void OnCollectionChanged(object? sender, NotifyCollectionChangedEventArgs args) => CollectionChanged?.Invoke(this, args); }