Mob.Theme.AdaptiveWatcher (mob v0.5.14)

Copy Markdown View Source

GenServer that re-resolves the active theme when the OS appearance flips.

Started automatically by use Mob.App. Subscribes to Mob.Device :appearance and, on :color_scheme_changed, calls Mob.Theme.set/1 again with whatever theme the app has registered as its "follow OS" theme (via register_adaptive/1). If no adaptive theme is registered the event is ignored — fixed themes stay put.

Why a GenServer

Mob.Theme.set/1 snapshots the theme into Application env at call time; subsequent renders read from that env. To track an OS toggle while the app is foregrounded, something has to listen for the :appearance event and call set/1 again. A singleton process fits — apps don't need per-screen handlers, and the framework owns the wiring end-to-end.

Default registration

When Mob.Theme.set(Mob.Theme.Adaptive) is called, the watcher picks Mob.Theme.Adaptive as the active follow-OS theme. To use a custom adaptive theme module instead, call register_adaptive(MyApp.Theme.Adaptive).

Summary

Functions

Returns a specification to start this module under a supervisor.

Register module as the app's follow-OS theme. Whenever a :color_scheme_changed event arrives, the watcher calls Mob.Theme.set(module) to re-resolve.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

register_adaptive(module)

@spec register_adaptive(module()) :: :ok

Register module as the app's follow-OS theme. Whenever a :color_scheme_changed event arrives, the watcher calls Mob.Theme.set(module) to re-resolve.

start_link(opts \\ [])