-
-
Notifications
You must be signed in to change notification settings - Fork 235
fix(settings): normalize icon refresh rate onto a 1–30 fps grid #929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
diazdesandi
merged 3 commits into
thaw-app:development
from
CamilleGuillory:fix/icon-refresh-rate-grid
Aug 11, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
ThawTests/Settings/Models/IconRefreshIntervalNormalizationTests.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| // | ||
| // IconRefreshIntervalNormalizationTests.swift | ||
| // Project: Thaw | ||
| // | ||
| // Copyright (Thaw) © 2026 Toni Förster | ||
| // Licensed under the GNU GPLv3 | ||
|
|
||
| import Foundation | ||
| import Testing | ||
| @testable import Thaw | ||
|
|
||
| /// Pins ``AdvancedSettings.normalizedIconRefreshInterval`` to the discrete | ||
| /// grid the "Icon refresh rate" slider can express: Off, or 1…30 fps. | ||
| /// | ||
| /// Pure function; safe to run in parallel with the rest of the suite. | ||
| @Suite("Icon refresh interval normalization") | ||
| struct IconRefreshIntervalNormalizationTests { | ||
| @Test("Zero stays Off") | ||
| func zeroStaysOff() { | ||
| #expect(AdvancedSettings.normalizedIconRefreshInterval(0) == 0) | ||
| #expect(AdvancedSettings.normalizedIconRefreshInterval(-1) == 0) | ||
| } | ||
|
|
||
| @Test("A rate above the capture ceiling snaps down to it") | ||
| func ceilingClamp() { | ||
| let ceiling = MenuBarItemImageCache.maxIconRefreshRate | ||
| let floor = MenuBarItemImageCache.minIconRefreshInterval | ||
| #expect(AdvancedSettings.normalizedIconRefreshInterval(1.0 / 30.0) == floor) | ||
| #expect(AdvancedSettings.normalizedIconRefreshInterval(1.0 / 60.0) == floor) | ||
| #expect(AdvancedSettings.normalizedIconRefreshInterval(floor / 2) == floor) | ||
| #expect(AdvancedSettings.normalizedIconRefreshInterval(1.0 / ceiling) == floor) | ||
| } | ||
|
|
||
| @Test("Slow intervals snap to 1 fps rather than displaying as Off") | ||
| func slowValuesSnapToOneFPS() { | ||
| #expect(AdvancedSettings.normalizedIconRefreshInterval(3.0) == 1.0) | ||
| #expect(AdvancedSettings.normalizedIconRefreshInterval(5.0) == 1.0) | ||
| #expect(AdvancedSettings.normalizedIconRefreshInterval(2.5) == 1.0) | ||
| #expect(AdvancedSettings.normalizedIconRefreshInterval(3.5) == 1.0) | ||
| } | ||
|
|
||
| @Test("A sub-millisecond interval snaps to the floor instead of a zero sleep") | ||
| func subMillisecondSnapsToFloor() { | ||
| let floor = MenuBarItemImageCache.minIconRefreshInterval | ||
| #expect(AdvancedSettings.normalizedIconRefreshInterval(0.0001) == floor) | ||
| #expect(AdvancedSettings.normalizedIconRefreshInterval(0.0005) == floor) | ||
| } | ||
|
|
||
| @Test("Already-on-grid values are idempotent") | ||
| func idempotent() { | ||
| #expect(AdvancedSettings.normalizedIconRefreshInterval(0) == 0) | ||
| let ceiling = Int(MenuBarItemImageCache.maxIconRefreshRate) | ||
| for fps in 1 ... ceiling { | ||
| let interval = 1.0 / Double(fps) | ||
| let once = AdvancedSettings.normalizedIconRefreshInterval(interval) | ||
| let twice = AdvancedSettings.normalizedIconRefreshInterval(once) | ||
| #expect(once == twice) | ||
| #expect(abs(1.0 / once - Double(fps)) < 1e-9) | ||
| } | ||
| } | ||
|
|
||
| @Test("Every on-grid interval survives an interval → fps → interval round trip") | ||
| func roundTrip() { | ||
| let ceiling = Int(MenuBarItemImageCache.maxIconRefreshRate) | ||
| for fps in 0 ... ceiling { | ||
| let interval: TimeInterval = fps == 0 ? 0 : 1.0 / Double(fps) | ||
| let normalized = AdvancedSettings.normalizedIconRefreshInterval(interval) | ||
| let displayedFPS = normalized > 0 ? (1.0 / normalized).rounded() : 0 | ||
| let restored: TimeInterval = displayedFPS > 0 ? 1.0 / displayedFPS : 0 | ||
| #expect(AdvancedSettings.normalizedIconRefreshInterval(restored) == normalized) | ||
| #expect(Int(displayedFPS) == fps) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.