Skip to content

Commit

Permalink
fix: animate to/from default accent when nothing is playing
Browse files Browse the repository at this point in the history
  • Loading branch information
sophie authored and sophie-gilbert committed Jan 23, 2024
1 parent d9d9e02 commit e5b4019
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 53 deletions.
32 changes: 1 addition & 31 deletions FoxTunes.UI.Windows/Behaviours/WindowAcrylicBlurBehaviour.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using FoxTunes.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Media;

namespace FoxTunes
Expand All @@ -21,13 +20,6 @@ public override string Id
}
}

public WindowAcrylicBlurBehaviour()
{
this.AccentColors = new Dictionary<IntPtr, Color>();
}

public IDictionary<IntPtr, Color> AccentColors { get; private set; }

public Color AccentColor { get; private set; }

public override void InitializeComponent(ICore core)
Expand All @@ -46,10 +38,7 @@ public override void InitializeComponent(ICore core)
{
AccentColor = value.ToColor();
}
if (this.AccentColors.Any())
{
this.Refresh();
}
this.Refresh();
});
}

Expand All @@ -59,27 +48,8 @@ protected override void OnRefresh()
foreach (var window in WindowBase.Active)
{
windows.Add(window.Handle);
var color = default(Color);
if (AccentColors.TryGetValue(window.Handle, out color) && color == this.AccentColor)
{
continue;
}
WindowExtensions.EnableAcrylicBlur(window.Handle, this.AccentColor);
this.AccentColors[window.Handle] = this.AccentColor;
}
foreach (var handle in AccentColors.Keys.ToArray())
{
if (!windows.Contains(handle))
{
AccentColors.Remove(handle);
}
}
}

protected override void OnDisabled()
{
this.AccentColors.Clear();
base.OnDisabled();
}

public override IEnumerable<ConfigurationSection> GetConfigurationSections()
Expand Down
47 changes: 25 additions & 22 deletions FoxTunes.UI.Windows/Behaviours/WindowCoverArtAccentBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected override async void OnRefresh()
var outputStream = this.PlaybackManager.CurrentStream;
if (outputStream == null)
{
await this.Refresh(WindowExtensions.DefaultAccentColor).ConfigureAwait(false);
await this.OnRefresh(WindowExtensions.DefaultAccentColor).ConfigureAwait(false);
return;
}
var fileData = default(IFileData);
Expand All @@ -81,21 +81,40 @@ protected override async void OnRefresh()
return;
}
var color = this.GetAccentColor(fileName);
await this.Refresh(color).ConfigureAwait(false);
await this.OnRefresh(color).ConfigureAwait(false);
}

protected virtual async Task Refresh(Color color)
protected virtual async Task OnRefresh(Color color)
{
var windows = new HashSet<IntPtr>();
foreach (var window in WindowBase.Active)
{
windows.Add(window.Handle);
var currentColor = default(Color);
if (AccentColors.TryGetValue(window.Handle, out currentColor) && currentColor == color)
if (AccentColors.TryGetValue(window.Handle, out currentColor))
{
continue;
if (currentColor == color)
{
//Nothing to do.
continue;
}
await Windows.Invoke(() =>
{
ColorAnimation animation = new ColorAnimation(
currentColor,
color,
new Duration(TimeSpan.FromSeconds(1))
)
{
EasingFunction = new QuadraticEase()
};
window.BeginAnimation(WindowExtensions.AccentColorProperty, animation);
}).ConfigureAwait(false);
}
else
{
WindowExtensions.SetAccentColor(window, color);
}
await this.Refresh(window, currentColor, color).ConfigureAwait(false);
this.AccentColors[window.Handle] = color;
}
foreach (var handle in AccentColors.Keys.ToArray())
Expand All @@ -107,22 +126,6 @@ protected virtual async Task Refresh(Color color)
}
}

protected virtual Task Refresh(WindowBase window, Color currentColor, Color newColor)
{
return Windows.Invoke(() =>
{
ColorAnimation animation = new ColorAnimation(
currentColor,
newColor,
new Duration(TimeSpan.FromSeconds(1))
)
{
EasingFunction = new QuadraticEase()
};
window.BeginAnimation(WindowExtensions.AccentColorProperty, animation);
});
}

protected virtual Color GetAccentColor(string fileName)
{
var color = this.ImageResizer.GetMainColor(fileName);
Expand Down

0 comments on commit e5b4019

Please sign in to comment.