The blurred 60fps worker-orb canvas is the main remaining Firefox lag source after the #935 sweep (multiple Discord lag reports). So for a FIRST-TIME user with no saved preference, default the orbs OFF on Firefox (smooth first impression where it's needed) and ON everywhere else (full polish where the browser handles it). An explicit saved choice ALWAYS wins — this only picks the default when the user hasn't chosen. Done kettui-style with a SINGLE source of truth, not the dual browser-detection I first floated (server UA + client _isFirefox would be the same fact in two places that can drift — exactly the server/client class #943's green-flash fix just cleaned up): - core/ui_appearance.py (new, pure + importable): is_firefox_user_agent + resolve_worker_orbs_default(explicit, is_firefox) — explicit wins, unset → !firefox. - web_server: the SERVER decides (UA via _request_is_firefox, request-context-safe) and injects initial_worker_orbs_enabled; config default flipped None so "unset" is distinguishable from an explicit False. The client just consumes the injected value (init.js unchanged) — no client-side re-derivation of "is Firefox". - settings.js: the orb checkbox default now reflects the server value when unset, so saving Settings can't silently flip a first-time Firefox user's orbs back on. No regression: Chrome users unchanged; users with an explicit setting unchanged (it wins regardless of browser); /api/settings returns raw config so it can't clobber the default for an unset value. Verified end-to-end through a real Flask request context (Firefox→off, Chrome→on, explicit wins both ways, no crash outside a request). 8 pure seam tests pin the contract; ruff clean.
56 lines
2.1 KiB
Python
56 lines
2.1 KiB
Python
"""Pure UI-appearance default rules (core/ui_appearance.py).
|
|
|
|
Pins the worker-orbs default contract: explicit saved choice ALWAYS wins; when unset,
|
|
default OFF on Firefox (the blurred orb canvas is the main remaining Firefox lag
|
|
source) and ON elsewhere."""
|
|
|
|
from core.ui_appearance import is_firefox_user_agent, resolve_worker_orbs_default
|
|
|
|
_FIREFOX_UA = ("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) "
|
|
"Gecko/20100101 Firefox/128.0")
|
|
_CHROME_UA = ("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
|
|
"(KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36")
|
|
_SAFARI_UA = ("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 "
|
|
"(KHTML, like Gecko) Version/17.0 Safari/605.1.15")
|
|
_EDGE_UA = ("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
|
|
"(KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0")
|
|
|
|
|
|
# ── is_firefox_user_agent ──
|
|
|
|
def test_detects_firefox():
|
|
assert is_firefox_user_agent(_FIREFOX_UA) is True
|
|
|
|
|
|
def test_non_firefox_browsers_are_false():
|
|
for ua in (_CHROME_UA, _SAFARI_UA, _EDGE_UA):
|
|
assert is_firefox_user_agent(ua) is False
|
|
|
|
|
|
def test_empty_or_none_ua_is_not_firefox():
|
|
assert is_firefox_user_agent('') is False
|
|
assert is_firefox_user_agent(None) is False
|
|
|
|
|
|
# ── resolve_worker_orbs_default: explicit ALWAYS wins ──
|
|
|
|
def test_unset_defaults_off_on_firefox():
|
|
assert resolve_worker_orbs_default(None, is_firefox=True) is False
|
|
|
|
|
|
def test_unset_defaults_on_elsewhere():
|
|
assert resolve_worker_orbs_default(None, is_firefox=False) is True
|
|
|
|
|
|
def test_explicit_true_wins_even_on_firefox():
|
|
# A Firefox user who explicitly enabled orbs keeps them — default never overrides.
|
|
assert resolve_worker_orbs_default(True, is_firefox=True) is True
|
|
|
|
|
|
def test_explicit_false_wins_even_off_firefox():
|
|
assert resolve_worker_orbs_default(False, is_firefox=False) is False
|
|
|
|
|
|
def test_explicit_values_ignore_browser():
|
|
assert resolve_worker_orbs_default(True, is_firefox=False) is True
|
|
assert resolve_worker_orbs_default(False, is_firefox=True) is False
|