Laev.Settings (laev v0.1.40)

Copy Markdown View Source

Reading and changing what laev is configured with, from anywhere.

The terminal has always had this: a Settings screen that lists every option, what it is set to, what it may be set to, and writes the change back so it applies at once. All of that logic sat inside the screen that drew it, which is fine until something else needs to ask the same questions — a web page wanting to render a form, say, or to tell somebody their Real-Debrid key was rejected before they try to play something.

So the questions live here, answered as data: all/0 describes every setting, put/2 changes one, validate/2 asks the service itself whether a key works. Within a scope all of that is that user's and nobody else's; without one it is this machine's, which is what the CLI has always meant by it.

Summary

Functions

Every setting, with its current value — ready to render as a form.

Connect this user to a laev key and say whether it worked, in one call.

One setting's current value, unmasked — for the code that uses it.

Settings grouped the way the screens group them.

Which keys are missing for laev to be able to play anything at all.

Change a setting, for whoever is asking.

What the sync is doing, for a settings page to show without asking anyone to press anything: {:ok, %{watchlist: 37, …}}, or why not.

Ask the service itself whether a key works, before it is relied on.

Functions

all(interface \\ :browser)

Every setting, with its current value — ready to render as a form.

A secret comes back masked rather than in full: a settings page has no reason to put somebody's debrid token back on the wire, and "set" or "not set" is what the page is actually asking.

connect_sync(key, url \\ nil)

Connect this user to a laev key and say whether it worked, in one call.

The thing a "paste your key" box should do: nothing is saved unless the key actually reaches the server and returns a document.

get(key)

One setting's current value, unmasked — for the code that uses it.

groups(interface \\ :browser)

Settings grouped the way the screens group them.

missing_essentials()

Which keys are missing for laev to be able to play anything at all.

put(key, value)

Change a setting, for whoever is asking.

Both halves, as the terminal does it: the value is written down so it survives a restart, and put into the running scope so it applies to the next thing that reads it rather than the next launch.

sync_status()

What the sync is doing, for a settings page to show without asking anyone to press anything: {:ok, %{watchlist: 37, …}}, or why not.

validate(arg1, value)

Ask the service itself whether a key works, before it is relied on.

{:ok, detail} carries what the service said about the account — the plan and the days left on it — which is the useful half of the answer.