Skip to content
This repository has been archived by the owner on Dec 6, 2022. It is now read-only.

Commit

Permalink
Hide window on closing - fix bugs #23, #24
Browse files Browse the repository at this point in the history
  • Loading branch information
avdynut committed Oct 2, 2019
1 parent 0ab586c commit d88e996
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
2 changes: 1 addition & 1 deletion AimpLyrics.Test/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public partial class App : Application
{
private void OnStartup(object sender, StartupEventArgs e)
{
var window = new LyricsWindow(new Player());
var window = new LyricsWindow(new Player(), new AimpMessageHook());
window.Show();
}
}
Expand Down
15 changes: 12 additions & 3 deletions AimpLyrics/AimpLyricsPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,18 @@ namespace AimpLyrics
[AimpPlugin("AimpLyrics", "Andrey Arekhva", "1.0.3", AimpPluginType = AimpPluginType.Addons, Description = "Display lyrics for current playing song. Find lyrics in file, tag or Google")]
public class AimpLyricsPlugin : AimpPlugin
{
private LyricsWindow _lyricsWindow;
private AimpMessageHook _hook;

public override void Initialize()
{
SetUpLogger();
AddMenuItem();

_hook = new AimpMessageHook();
Player.ServiceMessageDispatcher.Hook(_hook);
_lyricsWindow = new LyricsWindow(Player, _hook);

Trace.WriteLine($"Initialized AIMP Lyrics Plugin v{Assembly.GetExecutingAssembly().GetName().Version}");
}

Expand All @@ -37,9 +45,8 @@ private void AddMenuItem()

action.OnExecute += (sender, args) =>
{
var lyricsWindow = new LyricsWindow(Player);
lyricsWindow.Show();
lyricsWindow.Activate();
_lyricsWindow.Show();
_lyricsWindow.Activate();
};

menuItem.Action = action;
Expand All @@ -49,6 +56,8 @@ private void AddMenuItem()

public override void Dispose()
{
_lyricsWindow?.Close();
Player.ServiceMessageDispatcher.Unhook(_hook);
Trace.Close();
}
}
Expand Down
1 change: 0 additions & 1 deletion AimpLyrics/LyricsWIndow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Lyrics"
WindowStyle="ToolWindow"
Closing="OnClosing"
SizeToContent="Width" MinWidth="250">
<Grid>
<Grid.RowDefinitions>
Expand Down
25 changes: 21 additions & 4 deletions AimpLyrics/LyricsWIndow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ public partial class LyricsWindow : Window
private string _filePath;
private LyricsSource _source;

public LyricsWindow(IAimpPlayer player)
private bool _hideOnClosing = true;

public LyricsWindow(IAimpPlayer player, AimpMessageHook hook)
{
InitializeComponent();

_player = player;
_hook = hook;

_hook = new AimpMessageHook();
_hook.FileInfoReceived += UpdateSongInfo;
_hook.PlayerStopped += ResetFileInfo;
_player.ServiceMessageDispatcher.Hook(_hook);
Expand Down Expand Up @@ -232,11 +234,26 @@ private void OnSearchButtonClick(object sender, RoutedEventArgs e)
SearchLyricsInGoogleOnBackground();
}

private void OnClosing(object sender, CancelEventArgs e)
protected override void OnClosing(CancelEventArgs e)
{
if (_hideOnClosing)
{
Hide();
e.Cancel = true;
}
else
{
base.OnClosing(e);
}
}

public new void Close()
{
_hideOnClosing = false;
_hook.FileInfoReceived -= UpdateSongInfo;
_hook.PlayerStopped -= ResetFileInfo;
_player.ServiceMessageDispatcher.Unhook(_hook);

base.Close();
}
}
}

0 comments on commit d88e996

Please sign in to comment.