Raxol.Core.UserPreferences (Raxol v0.3.0)

View Source

Manages user preferences for the Raxol application.

Acts as a GenServer holding the preferences state and handles persistence.

Summary

Functions

Returns a specification to start this module under a supervisor.

Gets a user preference value by key path.

Retrieves the entire preferences map. Accepts an optional PID or registered name

Forces an immediate save of the current preferences.

Sets a user preference value by key path.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get(key_or_path, pid_or_name \\ __MODULE__)

Gets a user preference value by key path.

Accepts a single key or a list of keys for nested access.

Examples

UserPreferences.get(:theme) #=> "dark"
UserPreferences.get([:accessibility, :high_contrast]) #=> true
UserPreferences.get(:theme, my_prefs_pid) #=> "dark"

get_all(pid_or_name \\ __MODULE__)

Retrieves the entire preferences map. Accepts an optional PID or registered name

Examples

UserPreferences.get_all()
UserPreferences.get_all(my_prefs_pid)

save!(pid_or_name \\ __MODULE__)

Forces an immediate save of the current preferences.

set(key_or_path, value, pid_or_name \\ __MODULE__)

@spec set(atom() | [atom()], any(), GenServer.server() | atom() | nil) :: :ok

Sets a user preference value by key path.

Accepts a single key or a list of keys for nested access. Triggers an automatic save after a short delay.

Examples

UserPreferences.set(:theme, "light")
UserPreferences.set([:accessibility, :high_contrast], false)
UserPreferences.set(:theme, "light", my_prefs_pid)