From cb8625711b5eed4b36dfccfbdb934d341ddee33f Mon Sep 17 00:00:00 2001 From: Royce551 Date: Thu, 14 Jul 2022 15:25:45 -0500 Subject: [PATCH] Bug fixes, reimplement tab persistence --- .../Controls/BlurryImage/BlurryImage.cs | 1 + .../Handlers/Configuration/ConfigurationFile.cs | 5 +++-- .../ViewModels/LyricsViewModel.cs | 16 ++++++++++++++++ .../ViewModels/MainWindowViewModel.cs | 9 +++++---- .../ViewModels/TrackInfoViewModel.cs | 2 ++ .../FRESHMusicPlayer-Avalonia/Views/Lyrics.axaml | 2 +- .../Views/MainWindow.axaml | 2 +- .../Views/MainWindow.axaml.cs | 2 +- .../FRESHMusicPlayer-Avalonia/Views/Search.axaml | 6 ++++++ .../Views/Settings.axaml | 10 +++++----- 10 files changed, 41 insertions(+), 14 deletions(-) diff --git a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Controls/BlurryImage/BlurryImage.cs b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Controls/BlurryImage/BlurryImage.cs index e8c0d61..9d21489 100644 --- a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Controls/BlurryImage/BlurryImage.cs +++ b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Controls/BlurryImage/BlurryImage.cs @@ -22,6 +22,7 @@ namespace FRESHMusicPlayer.Controls.BlurryImage public override void Render(DrawingContext context) { + if (Source is null) return; var source = Source; var mem = new MemoryStream(); Source.Save(mem); diff --git a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Handlers/Configuration/ConfigurationFile.cs b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Handlers/Configuration/ConfigurationFile.cs index 1e0097c..e8ba4d8 100644 --- a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Handlers/Configuration/ConfigurationFile.cs +++ b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Handlers/Configuration/ConfigurationFile.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using FRESHMusicPlayer.ViewModels; +using System.Collections.Generic; namespace FRESHMusicPlayer.Handlers.Configuration { @@ -51,7 +52,7 @@ namespace FRESHMusicPlayer.Handlers.Configuration /// /// The last tab FMP was on before closing /// - public int CurrentTab { get; set; } = 0; + public Tab CurrentTab { get; set; } = Tab.Import; /// /// Directories to scan for tracks to import from on startup /// diff --git a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/ViewModels/LyricsViewModel.cs b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/ViewModels/LyricsViewModel.cs index 8aa58c2..8a46aea 100644 --- a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/ViewModels/LyricsViewModel.cs +++ b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/ViewModels/LyricsViewModel.cs @@ -1,4 +1,5 @@ using ATL; +using Avalonia.Media; using Avalonia.Media.Imaging; using FRESHMusicPlayer.Handlers.Lyrics; using ReactiveUI; @@ -48,6 +49,8 @@ namespace FRESHMusicPlayer.ViewModels public void Update() { + if (!MainWindow.Player.FileLoaded) return; + var track = new Track(MainWindow.Player.FilePath); CoverArt = track.EmbeddedPictures.Count <= 0 ? null : new Bitmap(new MemoryStream(track.EmbeddedPictures[0].PictureData)); @@ -56,16 +59,22 @@ namespace FRESHMusicPlayer.ViewModels { TimedLyrics = new LRCTimedLyricsProvider(MainWindow.Player.FilePath); Text = string.Empty; + TextMinus2 = TextMinus1 = TextPlus1 = TextPlus2 = string.Empty; + FontWeight = FontWeight.Bold; } else if (!string.IsNullOrWhiteSpace(track.Lyrics.UnsynchronizedLyrics)) // Embedded untimed lyrics { Text = track.Lyrics.UnsynchronizedLyrics; TimedLyrics = null; + TextMinus2 = TextMinus1 = TextPlus1 = TextPlus2 = string.Empty; + FontWeight = FontWeight.Regular; } else // No lyrics { Text = Properties.Resources.Lyrics_NoLyrics; TimedLyrics = null; + TextMinus2 = TextMinus1 = TextPlus1 = TextPlus2 = string.Empty; + FontWeight = FontWeight.Regular; } } @@ -100,6 +109,13 @@ namespace FRESHMusicPlayer.ViewModels set => this.RaiseAndSetIfChanged(ref textPlus2, value); } + private FontWeight fontWeight = FontWeight.Regular; + public FontWeight FontWeight + { + get => fontWeight; + set => this.RaiseAndSetIfChanged(ref fontWeight, value); + } + private Bitmap coverArt; public Bitmap CoverArt { diff --git a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/ViewModels/MainWindowViewModel.cs b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/ViewModels/MainWindowViewModel.cs index 4d70ac3..2806657 100644 --- a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/ViewModels/MainWindowViewModel.cs +++ b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/ViewModels/MainWindowViewModel.cs @@ -492,12 +492,13 @@ namespace FRESHMusicPlayer.ViewModels Player.CurrentTime.Add(TimeSpan.FromSeconds(Program.Config.FilePosition)); } } - //await Dispatcher.UIThread.InvokeAsync(() => SelectedTab = Program.Config.CurrentTab, DispatcherPriority.ApplicationIdle); + + SelectedTab = Program.Config.CurrentTab; // this delays the tab switch until avalonia is ready - + HandleIntegrations(); - //(GetMainWindow() as MainWindow).RootPanel.Opacity = 1; // this triggers the startup fade + await Dispatcher.UIThread.InvokeAsync(() => (GetMainWindow() as MainWindow).RootPanel.Opacity = 1, DispatcherPriority.ApplicationIdle); // this triggers the startup fade await PerformAutoImport(); } @@ -545,7 +546,7 @@ namespace FRESHMusicPlayer.ViewModels Library?.Database.Dispose(); Integrations.Dispose(); Program.Config.Volume = Volume; - //Program.Config.CurrentTab = SelectedTab; + Program.Config.CurrentTab = SelectedTab; if (Player.FileLoaded) { Program.Config.FilePath = Player.FilePath; diff --git a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/ViewModels/TrackInfoViewModel.cs b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/ViewModels/TrackInfoViewModel.cs index ef2729b..b38368d 100644 --- a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/ViewModels/TrackInfoViewModel.cs +++ b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/ViewModels/TrackInfoViewModel.cs @@ -92,6 +92,8 @@ namespace FRESHMusicPlayer.ViewModels public void Update() { + if (!Player.FileLoaded) return; + var track = new Track(Player.FilePath); CoverArt = track.EmbeddedPictures.Count <= 0 ? null : new Bitmap(new MemoryStream(track.EmbeddedPictures[0].PictureData)); diff --git a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/Lyrics.axaml b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/Lyrics.axaml index 5a103a3..fe00335 100644 --- a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/Lyrics.axaml +++ b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/Lyrics.axaml @@ -24,7 +24,7 @@ - + diff --git a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/MainWindow.axaml b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/MainWindow.axaml index df79744..9c28836 100644 --- a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/MainWindow.axaml +++ b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/MainWindow.axaml @@ -136,7 +136,7 @@ - + diff --git a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/MainWindow.axaml.cs b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/MainWindow.axaml.cs index f2f5ade..e26c6d8 100644 --- a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/MainWindow.axaml.cs +++ b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/MainWindow.axaml.cs @@ -128,7 +128,7 @@ namespace FRESHMusicPlayer.Views private async void OnKeyDown(object sender, KeyEventArgs e) { - if (e.Source is not TextBox && e.Source is not ListBoxItem) + if ((e.Source is not TextBox && e.Source is not ListBoxItem) || e.KeyModifiers.HasFlag(KeyModifiers.Control)) switch (e.Key) { case Key.Q: diff --git a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/Search.axaml b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/Search.axaml index d2c9704..eade0ea 100644 --- a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/Search.axaml +++ b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/Search.axaml @@ -4,11 +4,17 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:vm="using:FRESHMusicPlayer.ViewModels" xmlns:resx ="clr-namespace:FRESHMusicPlayer.Properties" + xmlns:svg="clr-namespace:Avalonia.Svg.Skia;assembly=Avalonia.Svg.Skia" mc:Ignorable="d" d:DesignWidth="400" d:DesignHeight="450" x:Class="FRESHMusicPlayer.Views.Search"> + + + + + diff --git a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/Settings.axaml b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/Settings.axaml index f659897..08e843b 100644 --- a/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/Settings.axaml +++ b/FRESHMusicPlayer/FRESHMusicPlayer-Avalonia/Views/Settings.axaml @@ -5,7 +5,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:resx ="clr-namespace:FRESHMusicPlayer.Properties" mc:Ignorable="d" - d:DesignWidth="600" d:DesignHeight="400" + d:DesignWidth="350" d:DesignHeight="900" x:Class="FRESHMusicPlayer.Views.Settings"> @@ -28,20 +28,20 @@ - +