From 4620a44c9165b6c6f78674e0b9c8de418fde7fc6 Mon Sep 17 00:00:00 2001 From: Maximilien Noal Date: Sun, 29 Dec 2024 21:25:37 +0100 Subject: [PATCH] refactor: Status bar collapses after 5 secs --- src/Spice86/ViewModels/DebugWindowViewModel.cs | 2 +- src/Spice86/ViewModels/StatusMessageViewModel.cs | 15 ++++++++++++++- src/Spice86/Views/StatusMessageView.axaml | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Spice86/ViewModels/DebugWindowViewModel.cs b/src/Spice86/ViewModels/DebugWindowViewModel.cs index 25e78b9d2..377d4cbfc 100644 --- a/src/Spice86/ViewModels/DebugWindowViewModel.cs +++ b/src/Spice86/ViewModels/DebugWindowViewModel.cs @@ -75,7 +75,7 @@ public DebugWindowViewModel(State cpuState, Stack stack, IMemory memory, Midi ex _messenger = messenger; _uiDispatcher = uiDispatcher; BreakpointsViewModel = new(emulatorBreakpointsManager); - StatusMessageViewModel = new(_messenger); + StatusMessageViewModel = new(_uiDispatcher, _messenger); _pauseHandler = pauseHandler; IsPaused = pauseHandler.IsPaused; pauseHandler.Pausing += () => uiDispatcher.Post(() => IsPaused = true); diff --git a/src/Spice86/ViewModels/StatusMessageViewModel.cs b/src/Spice86/ViewModels/StatusMessageViewModel.cs index 0d713df04..0e394db1c 100644 --- a/src/Spice86/ViewModels/StatusMessageViewModel.cs +++ b/src/Spice86/ViewModels/StatusMessageViewModel.cs @@ -3,15 +3,28 @@ namespace Spice86.ViewModels; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Messaging; +using Spice86.Infrastructure; using Spice86.Messages; public partial class StatusMessageViewModel : ViewModelBase, IRecipient { + private readonly IUIDispatcher _uiDispatcher; + [ObservableProperty] private StatusMessage? _message; - public StatusMessageViewModel(IMessenger messenger) => messenger.Register(this); + [ObservableProperty] + private bool _isVisible; + + public StatusMessageViewModel(IUIDispatcher dispatcher, IMessenger messenger) { + messenger.Register(this); + _uiDispatcher = dispatcher; + } public void Receive(StatusMessage message) { Message = message; + IsVisible = true; + Task.Delay(millisecondsDelay: 5000).ContinueWith(_ => { + _uiDispatcher.Post(() => IsVisible = false); + }); } } \ No newline at end of file diff --git a/src/Spice86/Views/StatusMessageView.axaml b/src/Spice86/Views/StatusMessageView.axaml index 6de797f33..cb5a4ed9f 100644 --- a/src/Spice86/Views/StatusMessageView.axaml +++ b/src/Spice86/Views/StatusMessageView.axaml @@ -7,7 +7,7 @@ mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:Class="Spice86.Views.StatusMessageView" x:DataType="viewModels:StatusMessageViewModel"> - +