# `Mob.Theme.AdaptiveWatcher`
[🔗](https://github.com/genericjam/mob/blob/master/lib/mob/theme/adaptive_watcher.ex#L1)

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 the theme the app registered as its "follow OS" theme (via
`register_adaptive/1`), but only while the active theme was set from that
module. Any other active theme stays put.

## Which `Mob.Theme.set/1` calls follow the OS

With `MyApp.Theme.Adaptive` registered:

- `Mob.Theme.set(MyApp.Theme.Adaptive)` follows the OS.
- `Mob.Theme.set({MyApp.Theme.Adaptive, primary: :rose_500})` follows the
  OS and keeps the overrides on every flip.
- A struct (`Mob.Theme.set(MyApp.Theme.Adaptive.theme())`), a keyword
  list, or any other module is a fixed theme: the flip leaves it alone.

## 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

`Mob.Theme.Adaptive` is registered by default, so
`Mob.Theme.set(Mob.Theme.Adaptive)` (or `use Mob.App, theme:
Mob.Theme.Adaptive`) follows the OS with no further setup. To use a
custom adaptive theme module instead, call
`register_adaptive(MyApp.Theme.Adaptive)`.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `register_adaptive`

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

Register `module` as the app's follow-OS theme. Whenever a
`:color_scheme_changed` event arrives while the active theme was set
from `module` (or `{module, overrides}`), the watcher calls
`Mob.Theme.set/1` with it again to re-resolve.

# `start_link`

```elixir
@spec start_link(keyword()) :: GenServer.on_start()
```

---

*Consult [api-reference.md](api-reference.md) for complete listing*
