LavaUI docs GitHub

enum AppSettings

Swift

enum AppSettings

Cross-platform, file-backed key/value settings for LavaUI apps.

One JSON file per app under the platform config directory:

Platform Location
Linux ~/.config/<AppName>/settings.json (or $XDG_CONFIG_HOME)
macOS ~/Library/Application Support/<AppName>/settings.json
fallback temp dir / <AppName>/settings.json

Call configure(appName:) once at process start (before the first get/set), typically next to LavaApp.open. Keys are plain strings; values are JSON scalars or anything Codable. Writes are atomic and locked.

AppSettings.configure(appName: "LavaSpotify")
AppSettings.set("midnight-groove", forKey: "theme.id")
let id = AppSettings.string(forKey: "theme.id")

Not a replacement for secrets that need tighter permissioning — OAuth tokens should stay in their own 0600 file — but fine for theme, window layout, and other non-sensitive preferences.

Sources/LavaUI/AppSettings.swift:26

Properties

static var directoryURL: URL { get }

Directory that holds settings.json (created on first write).

Sources/LavaUI/AppSettings.swift:47

static var fileURL: URL { get }

The settings file itself: directoryURL followed by settings.json.

Sources/LavaUI/AppSettings.swift:55

static var keys: [String] { get }

All keys currently stored (for diagnostics).

Sources/LavaUI/AppSettings.swift:199

Methods

static func bool(forKey key: String) -> Bool?

The Boolean stored under key, or nil if the key is missing or holds something else. Also accepts numbers and the strings true/false, 1/0 and yes/no.

Sources/LavaUI/AppSettings.swift:90

static func configure(appName: String)

Sets the product name used for the config directory. Safe to call more than once; reloads from the new path.

Sources/LavaUI/AppSettings.swift:36

static func double(forKey key: String) -> Double?

The number stored under key, or nil if the key is missing or holds something else. Integers are widened and numeric strings are parsed.

Sources/LavaUI/AppSettings.swift:111

static func int(forKey key: String) -> Int?

The integer stored under key, or nil if the key is missing or holds something else. Numbers stored as doubles are truncated and numeric strings are parsed.

Sources/LavaUI/AppSettings.swift:73

static func remove(_ key: String)

Deletes key and writes the file. Does nothing if the key is not there.

Sources/LavaUI/AppSettings.swift:181

static func removeAll()

Deletes every key and writes an empty settings file.

Sources/LavaUI/AppSettings.swift:190

static func set(_ value: String, forKey key: String)

Stores value under key and writes the file.

Sources/LavaUI/AppSettings.swift:67

static func set(_ value: Int, forKey key: String)

Stores value under key and writes the file.

Sources/LavaUI/AppSettings.swift:84

static func set(_ value: Bool, forKey key: String)

Stores value under key and writes the file.

Sources/LavaUI/AppSettings.swift:105

static func set(_ value: Double, forKey key: String)

Stores value under key and writes the file.

Sources/LavaUI/AppSettings.swift:122

static func set<T>(_ value: T, forKey key: String) where T : Encodable

Stores any Encodable value under key as JSON and writes the file. Strings and numbers are stored as plain JSON scalars. A value that does not encode is silently dropped.

Sources/LavaUI/AppSettings.swift:155

static func string(forKey key: String) -> String?

The string stored under key, or nil if the key is missing or holds another type.

Sources/LavaUI/AppSettings.swift:62

static func value<T>(forKey key: String, as type: T.Type) -> T? where T : Decodable

Decodes the value stored under key as T, or returns nil when the key is missing or does not decode.

Sources/LavaUI/AppSettings.swift:130