Skip to content

armgit / Filee

Public Imported from GitHub
0

Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.

Donut: no accent flash when the highlight moves on, always appears after a long idle

KnifeLemond1a28df4b80b
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e711c39d..2a0fd154 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,19 @@ version it publishes under "What's Changed" in the GitHub release notes, above t
Add a `## <version>` section before tagging a release. Write what someone using Filee notices: what's new, where to
find it, what it does and doesn't do.
+## 1.7.1
+
+### Fixes
+
+- Moving the pointer from one slice of the donut to another no longer makes the slice it left flash in the accent
+ colour as its highlight fades.
+- After Filee sat unused for a long time, the donut could take seconds to appear or open without its animation. A
+ frame the animation waited for could get lost; the donut now asks again and, if frames still don't come, shows
+ itself fully open.
+- With "Reduce animations" following Windows, a moment when Windows reported animations off (a remote session,
+ waking from sleep) could switch them off in Filee until the setting was changed. Filee reads the Windows setting
+ again whenever the donut or the main window opens.
+
## 1.7.0
### macOS and Linux (preview)
diff --git a/Directory.Build.props b/Directory.Build.props
index 8b79436d..16521d64 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -14,7 +14,7 @@
parameters of a member is fine (CS1573). -->
<NoWarn>$(NoWarn);CS1591;CS1573</NoWarn>
- <Version>1.7.0</Version>
+ <Version>1.7.1</Version>
<Product>Filee</Product>
<Authors>Filee contributors</Authors>
<Copyright>Copyright (c) Filee contributors</Copyright>
diff --git a/src/Filee.App/Controls/DonutMenu.cs b/src/Filee.App/Controls/DonutMenu.cs
index 5417530a..adef5b5a 100644
--- a/src/Filee.App/Controls/DonutMenu.cs
+++ b/src/Filee.App/Controls/DonutMenu.cs
@@ -13,6 +13,7 @@ using Avalonia.Controls;
using Avalonia.Controls.Documents;
using Avalonia.Input;
using Avalonia.Media;
+using Avalonia.Threading;
using Filee.App.Services;
namespace Filee.App.Controls;
@@ -287,13 +288,14 @@ public sealed partial class DonutMenu : Control
}
/// <summary>Moves the slices and the preview towards their places. Returns true while they are still moving.</summary>
- private bool StepLayout(double dt)
+ private bool StepLayout(double dt, bool snap = false)
{
+ snap |= !Motion.Enabled;
var active = false;
for (var i = 0; i < _mid.Length; i++)
{
var (mid, span) = LayoutTarget(i);
- if (!Motion.Enabled)
+ if (snap)
{
_mid[i] = new Spring { Value = mid };
_span[i] = new Spring { Value = span };
@@ -305,7 +307,7 @@ public sealed partial class DonutMenu : Control
var m = SlotCount(_previewRemoved);
var previewMid = _previewSlot >= 0 ? DonutGeometry.MidAngle(_previewSlot, m) : _previewMid.Value;
var previewSpan = _previewSlot >= 0 ? DonutGeometry.Span(m) : 0;
- if (!Motion.Enabled)
+ if (snap)
{
_previewMid = new Spring { Value = previewMid };
_previewSpan = new Spring { Value = previewSpan };
@@ -467,7 +469,10 @@ public sealed partial class DonutMenu : Control
// ───────────────────────── Animation ─────────────────────────
- /// <summary>Critically-underdamped spring: gives the soft "boing" when a slice pops out.</summary>
+ /// <summary>Damping at which a spring of stiffness 320 settles without overshooting (2·√320).</summary>
+ private const double CriticalDamping = 36;
+
+ /// <summary>Underdamped spring: gives the soft "boing" when a slice pops out.</summary>
private struct Spring
{
public double Value;
@@ -498,11 +503,22 @@ public sealed partial class DonutMenu : Control
private int _loop; // the current frame loop; frames of an older one are ignored
private long _lastTick; // Environment.TickCount64 of the last frame or frame request
+ /// <summary>Frame requests asked again before the animation is finished at once (see <see cref="CheckLoop"/>).</summary>
+ internal const int FrameRetries = 2;
+
+ private int _stalls; // times the current animation's frames stopped coming
+
private void StartAnimation()
{
InvalidateVisual();
if (_animating && Environment.TickCount64 - _lastTick < StalledLoopMs)
return;
+ _stalls = 0;
+ StartLoop();
+ }
+
+ private void StartLoop()
+ {
var top = TopLevel.GetTopLevel(this);
if (top is null)
{
@@ -514,6 +530,59 @@ public sealed partial class DonutMenu : Control
_lastTick = Environment.TickCount64;
var loop = ++_loop;
top.RequestAnimationFrame(time => OnFrame(time, loop));
+ Watch(loop);
+ }
+
+ private void Watch(int loop) =>
+ DispatcherTimer.RunOnce(() =>
+ {
+ if (loop == _loop)
+ CheckLoop();
+ }, TimeSpan.FromMilliseconds(StalledLoopMs + 50));
+
+ /// <summary>
+ /// Watches the frame loop without waiting for another animation call. When its frames stop (a request lost
+ /// while the window was hidden, or the renderer waking up after a long idle), the frame is asked for again; after
+ /// <see cref="FrameRetries"/> stalls the animations jump to their end, so an opening donut always appears. Stalls
+ /// are counted per animation: frames that trickle in once per retry would otherwise open the donut over seconds.
+ /// </summary>
+ internal void CheckLoop()
+ {
+ if (!_animating)
+ return;
+ if (Environment.TickCount64 - _lastTick < StalledLoopMs)
+ {
+ Watch(_loop); // frames are coming: keep watching until the loop ends
+ return;
+ }
+ if (++_stalls <= FrameRetries)
+ {
+ StartLoop();
+ return;
+ }
+ _animating = false;
+ _loop++;
+ FinishAnimations();
+ }
+
+ /// <summary>
+ /// Sets the opening, the highlights and the slice layout to where they end (a closing donut closes). The progress
+ /// ring keeps its own timers.
+ /// </summary>
+ internal void FinishAnimations()
+ {
+ for (var i = 0; i < _hover.Length; i++)
+ _hover[i] = new Spring { Value = i == ActiveIndex ? 1 : 0 };
+ _centerPulse = default;
+ StepLayout(0, snap: true);
+ if (_openClock < double.MaxValue)
+ {
+ _openClock = double.MaxValue;
+ Array.Fill(_open, _closing ? 0 : 1);
+ if (_closing)
+ FinishClose();
+ }
+ InvalidateVisual();
}
private void OnFrame(TimeSpan time, int loop)
@@ -556,8 +625,10 @@ public sealed partial class DonutMenu : Control
}
else
{
+ // Popping out bounces; letting go settles without a bounce: one below zero would make the faded accent
+ // flash once more on its way back.
for (var i = 0; i < _hover.Length; i++)
- active |= _hover[i].Step(i == ActiveIndex ? 1 : 0, dt);
+ active |= i == ActiveIndex ? _hover[i].Step(1, dt) : _hover[i].Step(0, dt, 320, CriticalDamping);
active |= _centerPulse.Step(0, dt, 260, 12);
active |= StepProgress(dt);
active |= StepLayout(dt);
@@ -662,9 +733,10 @@ public sealed partial class DonutMenu : Control
var wedge = CreateWedge(center, r1, r2, mid, span);
context.DrawGeometry(WithOpacity(SliceBrush, SliceOpacity * (item.IsEnabled ? 1 : 0.55)), BorderPen(), wedge);
+ // The accent fades in and out with the highlight (no floor: a floor made it vanish with a jump).
var emphasis = i == _dropTargetIndex ? 1.0 : hover;
if (emphasis > 0.01 && item.IsEnabled)
- context.DrawGeometry(WithOpacity(AccentBrush, 0.22 + 0.6 * Math.Clamp(emphasis, 0, 1)), null, wedge);
+ context.DrawGeometry(WithOpacity(AccentBrush, 0.82 * Math.Clamp(emphasis, 0, 1)), null, wedge);
var hot = (i == ActiveIndex || i == _dropTargetIndex) && item.IsEnabled;
DrawLabel(context, item, center, (r1 + r2) / 2, mid, span * (r1 + r2) / 2 - 10,
diff --git a/src/Filee.App/Services/Motion.cs b/src/Filee.App/Services/Motion.cs
index 428af755..5b19cb77 100644
--- a/src/Filee.App/Services/Motion.cs
+++ b/src/Filee.App/Services/Motion.cs
@@ -15,6 +15,40 @@ public static class Motion
public static event EventHandler? Changed;
+ private static bool? _reduceMotion;
+ private static Func<bool>? _systemPrefersReduced;
+
+ /// <summary>
+ /// The user's choice (null follows the system) and how to read the system's. Following the system, the value is
+ /// read again by <see cref="Refresh"/>: a moment when Windows reported animations off (a remote session, waking
+ /// from sleep) must not switch them off for good.
+ /// </summary>
+ public static void Configure(bool? reduceMotion, Func<bool> systemPrefersReduced)
+ {
+ _reduceMotion = reduceMotion;
+ _systemPrefersReduced = systemPrefersReduced;
+ Set(!Current());
+ }
+
+ /// <summary>Reads the system's setting again when following it (call before showing a window).</summary>
+ public static void Refresh()
+ {
+ if (_reduceMotion is null && _systemPrefersReduced is not null && Enabled == Current())
+ Set(!Current());
+ }
+
+ private static bool Current()
+ {
+ try
+ {
+ return _reduceMotion ?? _systemPrefersReduced?.Invoke() ?? false;
+ }
+ catch (Exception ex) when (ex is not OutOfMemoryException)
+ {
+ return false;
+ }
+ }
+
public static void Set(bool enabled)
{
Enabled = enabled;
diff --git a/src/Filee.App/Services/RadialController.cs b/src/Filee.App/Services/RadialController.cs
index 25dbcdd1..5154c7b3 100644
--- a/src/Filee.App/Services/RadialController.cs
+++ b/src/Filee.App/Services/RadialController.cs
@@ -293,6 +293,7 @@ public sealed class RadialController(
Math.Clamp(position.Y, area.Y, Math.Max(area.Y, area.Bottom - sidePx)));
}
+ Motion.Refresh();
window.Position = position;
if (!window.IsVisible)
window.Show();
diff --git a/src/Filee.App/Services/ThemeService.cs b/src/Filee.App/Services/ThemeService.cs
index 6f14882d..e87ca333 100644
--- a/src/Filee.App/Services/ThemeService.cs
+++ b/src/Filee.App/Services/ThemeService.cs
@@ -64,7 +64,7 @@ public sealed class ThemeService(IPlatformServices platform)
: $"{Korean}, {Chinese}";
res["AppFontFamily"] = FontFamily.Parse($"{Latin}, {cjk}, {SystemFallbacks}");
- Motion.Set(!(theme.ReduceMotion ?? platform.PrefersReducedMotion));
+ Motion.Configure(theme.ReduceMotion, () => platform.PrefersReducedMotion);
}
/// <summary>Lightens (amount &gt; 0) or darkens (amount &lt; 0) a colour.</summary>
diff --git a/src/Filee.App/Services/WindowService.cs b/src/Filee.App/Services/WindowService.cs
index b70ceb92..bc78e42b 100644
--- a/src/Filee.App/Services/WindowService.cs
+++ b/src/Filee.App/Services/WindowService.cs
@@ -26,6 +26,7 @@ public sealed class WindowService(ILocalizer loc, IServiceProvider services)
/// <summary>Shows (or brings to front) the main window, optionally on a page.</summary>
public void ShowMain(string? page = null)
{
+ Motion.Refresh();
if (_main is null)
{
_main = new MainWindow { DataContext = services.GetRequiredService<MainWindowViewModel>() };
diff --git a/tests/Filee.App.Tests/DonutHighlightTests.cs b/tests/Filee.App.Tests/DonutHighlightTests.cs
index bff8df25..e8aa0f72 100644
--- a/tests/Filee.App.Tests/DonutHighlightTests.cs
+++ b/tests/Filee.App.Tests/DonutHighlightTests.cs
@@ -38,6 +38,82 @@ public class DonutHighlightTests
window.Close();
}
+ [AvaloniaFact]
+ public void An_opening_donut_appears_even_when_no_frame_ever_comes()
+ {
+ TestServices.EnsureInitialized("ko");
+ var donut = new DonutMenu
+ {
+ Items = new[] { "PNG", "JPG", "WEBP", "PDF" }.Select(l => new DonutItem { Id = l, Label = l }).ToList(),
+ };
+ var window = new Window { Content = donut, SizeToContent = SizeToContent.WidthAndHeight };
+ window.Show();
+ Dispatcher.UIThread.RunJobs();
+
+ donut.PlayOpenAnimation(); // the render timer never ticks in this test: every frame request is lost
+ Assert.Equal(0, Open(donut).Max());
+ // The watchdog's checks, each after the loop got no frame for a while: two retries, then the donut is drawn open.
+ for (var check = 0; check <= DonutMenu.FrameRetries; check++)
+ {
+ Set(donut, "_lastTick", Environment.TickCount64 - DonutMenu.StalledLoopMs * 2);
+ donut.CheckLoop();
+ Dispatcher.UIThread.RunJobs();
+ }
+
+ Assert.All(Open(donut), open => Assert.Equal(1, open, 3));
+ window.Close();
+ }
+
+ [AvaloniaFact]
+ public void A_highlight_settles_without_dipping_below_zero()
+ {
+ TestServices.EnsureInitialized("ko");
+ var donut = new DonutMenu
+ {
+ Items = new[] { "PNG", "JPG", "WEBP" }.Select(l => new DonutItem { Id = l, Label = l }).ToList(),
+ };
+ donut.SetExternalHighlight(1);
+ for (var i = 0; i < 120; i++)
+ donut.Advance(1 / 60.0);
+ Assert.True(donut.LitAmount(1) > 0.99);
+
+ donut.SetExternalHighlight(2); // the pointer moves on: slice 1 lets go
+ var lowest = double.MaxValue;
+ for (var i = 0; i < 120; i++)
+ {
+ donut.Advance(1 / 60.0);
+ lowest = Math.Min(lowest, donut.LitAmount(1));
+ }
+ Assert.True(lowest >= 0, $"dipped to {lowest:0.000}");
+ Assert.Equal(0, donut.LitAmount(1), 3);
+ }
+
+ [Fact]
+ public void Following_the_system_reads_it_again_when_a_window_opens()
+ {
+ var reduced = true;
+ try
+ {
+ Filee.App.Services.Motion.Configure(null, () => reduced);
+ Assert.False(Filee.App.Services.Motion.Enabled); // the system reported animations off for a moment
+
+ reduced = false;
+ Filee.App.Services.Motion.Refresh();
+ Assert.True(Filee.App.Services.Motion.Enabled);
+
+ Filee.App.Services.Motion.Configure(true, () => false); // the user's own choice wins over the system
+ Filee.App.Services.Motion.Refresh();
+ Assert.False(Filee.App.Services.Motion.Enabled);
+ }
+ finally
+ {
+ Filee.App.Services.Motion.Configure(false, () => false);
+ }
+ }
+
+ private static double[] Open(DonutMenu donut) =>
+ (double[])typeof(DonutMenu).GetField("_open", BindingFlags.Instance | BindingFlags.NonPublic)!.GetValue(donut)!;
+
private static void Set(DonutMenu donut, string field, object value) =>
typeof(DonutMenu).GetField(field, BindingFlags.Instance | BindingFlags.NonPublic)!.SetValue(donut, value);
}