From f478e1c4c1e96e9dab95945af4cc444ff8d00553 Mon Sep 17 00:00:00 2001 From: Andrey Arekhva Date: Mon, 5 Aug 2019 16:49:35 +0300 Subject: [PATCH] Prerelease fixes --- AimpLyrics/AimpLyrics.csproj | 1 - AimpLyrics/AimpLyricsPlugin.cs | 7 ++++++- AimpLyrics/LyricsWIndow.xaml | 2 +- AimpLyrics/LyricsWIndow.xaml.cs | 32 +++++++++++++++++++++++--------- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/AimpLyrics/AimpLyrics.csproj b/AimpLyrics/AimpLyrics.csproj index 307829c..f8394b8 100644 --- a/AimpLyrics/AimpLyrics.csproj +++ b/AimpLyrics/AimpLyrics.csproj @@ -55,7 +55,6 @@ ..\packages\AimpSDK.4.50.2048\lib\net462\AIMP.SDK.dll - diff --git a/AimpLyrics/AimpLyricsPlugin.cs b/AimpLyrics/AimpLyricsPlugin.cs index da20aa7..d5cb732 100644 --- a/AimpLyrics/AimpLyricsPlugin.cs +++ b/AimpLyrics/AimpLyricsPlugin.cs @@ -39,7 +39,12 @@ private void AddMenuItem() action.Id = "aimp.lyrics.open.window"; action.Name = "Open Lyrics"; action.GroupName = "Lyrics"; - action.OnExecute += (sender, args) => _lyricsWindow.Show(); + + action.OnExecute += (sender, args) => + { + _lyricsWindow.Show(); + _lyricsWindow.Activate(); + }; menuItem.Action = action; Player.ActionManager.Register(action); diff --git a/AimpLyrics/LyricsWIndow.xaml b/AimpLyrics/LyricsWIndow.xaml index d06fe95..cbd2acf 100644 --- a/AimpLyrics/LyricsWIndow.xaml +++ b/AimpLyrics/LyricsWIndow.xaml @@ -30,7 +30,7 @@ - + diff --git a/AimpLyrics/LyricsWIndow.xaml.cs b/AimpLyrics/LyricsWIndow.xaml.cs index c69bdf4..ea251aa 100644 --- a/AimpLyrics/LyricsWIndow.xaml.cs +++ b/AimpLyrics/LyricsWIndow.xaml.cs @@ -33,7 +33,7 @@ public LyricsWindow(IAimpPlayer player, AimpMessageHook hook) #if DEBUG BrowserPanel.Visibility = Visibility.Visible; #endif - UpdateSongInfo(); + Loaded += (s, e) => UpdateSongInfo(); } private void UpdateSongInfo() @@ -43,14 +43,10 @@ private void UpdateSongInfo() Artist.Text = _fileInfo.Artist; Title.Text = _fileInfo.Title; - if (!GetLyricsFromFile() && !string.IsNullOrEmpty(_fileInfo.Lyrics)) - { - Lyrics.Text = _fileInfo.Lyrics; - _source = LyricsSource.Tag; - Source.Text = _source.ToString(); - Trace.WriteLine("Lyrics received from lyrics tag"); - } - else + bool found = GetLyricsFromFile(); + if (!found) + found = GetLyricsFromTag(); + if (!found) SearchLyricsInGoogle(); } @@ -78,6 +74,18 @@ private bool GetLyricsFromFile() return true; } + private bool GetLyricsFromTag() + { + if (string.IsNullOrEmpty(_fileInfo.Lyrics)) + return false; + + Lyrics.Text = _fileInfo.Lyrics; + _source = LyricsSource.Tag; + Source.Text = _source.ToString(); + Trace.WriteLine("Lyrics received from lyrics tag"); + return true; + } + private void SearchLyricsInGoogle() { string searchTerm = HttpUtility.UrlEncode($"{Artist.Text} {Title.Text} lyrics"); @@ -106,6 +114,11 @@ private void OnBrowserLoadCompleted(object sender, NavigationEventArgs e) break; } } + if (_source == LyricsSource.None) + { + Trace.WriteLine("Lyrics not found"); + Source.Text = "Not Found"; + } } private void SaveLyricsToFile() @@ -143,6 +156,7 @@ private void SaveLyrics(object sender, RoutedEventArgs e) case LyricsSource.Google: _filePath = Path.ChangeExtension(_fileInfo.FileName, "txt"); _source = LyricsSource.File; + Source.Text = Path.GetFileName(_filePath); SaveLyricsToFile(); break; }