Added validation for TrueShade availability
Implemented a safeguard to verify that window.TrueShade and window.TrueShade.Theme are defined before invoking public APIs.
Prevents runtime errors when the TrueShade library is not properly loaded.
Improves stability and ensures API calls are only made when the underlying objects are available.
BroadcastChannel support
Theme synchronization across multiple browser tabs/windows using BroadcastChannel (replaces storage event listeners).
Theme.OnChange(cb) API
New subscription API for theme changes.
Callbacks now receive two arguments:
effective: resolved theme ('dark' | 'light')
raw: stored preference ('system-default' | 'dark' | 'light')
Backward compatible with single-argument callbacks.
Initial emit on Initialize()
Subscribers get the current theme immediately after initialization.
Smarter caching
Internal caching for module name, storage key, and last applied theme to reduce redundant localStorage lookups.
Robust seeding (ensureSeeded()):
Always guarantees a valid value (system-default) even when storage is unavailable (e.g., private mode).
Optimized setLayoutColorScheme():
Avoids redundant writes to localStorage and DOM when the value didn’t change.
Better drift prevention:
applyTheme() and onColorSchemeChange() now keep <html data-theme> strictly in sync with the chosen mode.
Error resilience:
Listener and storage errors are safely swallowed to prevent breaking apps.
Enhanced dispose():
Cleans up listeners, closes BroadcastChannel, clears subscribers, and resets internal state.
Removed window.storage event listener → replaced with BroadcastChannel.
getStorageKey() now caches results for efficiency.
setLayoutColorScheme() no longer always forces a write — it only updates when necessary.
Changed
Storage key prefix updated from $NS_ to $OS_ to align with the naming convention of OutSystems Client Variables in localStorage.
Default mode token renamed from os-default to system-default to avoid ambiguity where OS could be interpreted as OutSystems instead of Operating System, and to improve clarity in Forge documentation.