Dala.Theme.AdaptiveWatcher (dala v0.0.8)

Copy Markdown View Source

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

Started automatically by use Dala.App. Subscribes to Dala.Device :appearance and, on :color_scheme_changed, calls Dala.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

Dala.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 Dala.Theme.set(Dala.Theme.Adaptive) is called, the watcher picks Dala.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 Dala.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 Dala.Theme.set(module) to re-resolve.

start_link(opts \\ [])