BSB Developer Docs
Loading...
Searching...
No Matches
js_app_settings_storage.h File Reference

Settings storage bridge for JavaScript applications. More...

Go to the source code of this file.

Typedefs

typedef struct JsAppSettingsStorage JsAppSettingsStorage
 

Enumerations

enum  JsAppSettingsStorageStatus {
  JsAppSettingsStorageStatusOk , JsAppSettingsStorageStatusSchemaMissing , JsAppSettingsStorageStatusSchemaInvalid , JsAppSettingsStorageStatusStorageFailure ,
  JsAppSettingsStorageStatusesCount
}
 Result of building a settings storage. More...
 

Functions

JsAppSettingsStorage * js_app_settings_storage_alloc (const char *app_id, JsAppSettingsStorageStatus *status)
 Build a settings storage for an application.
 
void js_app_settings_storage_free (JsAppSettingsStorage *instance)
 Release a settings storage.
 
bool js_app_settings_storage_load (JsAppSettingsStorage *instance)
 Load values from the application's data file.
 
bool js_app_settings_storage_save (JsAppSettingsStorage *instance)
 Write every value to the application's data file.
 
bool js_app_settings_storage_reset (JsAppSettingsStorage *instance)
 Reset every value to its default.
 
bool js_app_settings_storage_export (const JsAppSettingsStorage *instance, FuriString *data)
 Export the settings document.
 
bool js_app_settings_storage_import (JsAppSettingsStorage *instance, const char *data, size_t size)
 Import a settings document.
 
const SettingProviderSetting * js_app_settings_storage_get_root (JsAppSettingsStorage *instance)
 Get the root setting of the descriptor tree.
 
const JsAppSettingsNode * js_app_settings_storage_get_node (const SettingProviderSetting *instance)
 Get the schema node a setting was built from.
 
void * js_app_settings_storage_get_value (const SettingProviderSetting *instance)
 Get the value behind a setting.
 

Detailed Description

Settings storage bridge for JavaScript applications.

Composes a parsed settings schema into a setting provider descriptor tree with a single POD value block, backed by an application data file.

Enumeration Type Documentation

◆ JsAppSettingsStorageStatus

Result of building a settings storage.

Set by js_app_settings_storage_alloc(); every failure status pairs with a NULL return.

Enumerator
JsAppSettingsStorageStatusOk 

Storage built.

JsAppSettingsStorageStatusSchemaMissing 

App has no settings schema.

JsAppSettingsStorageStatusSchemaInvalid 

Schema is empty or unparsable.

JsAppSettingsStorageStatusStorageFailure 

Schema could not be read.

Function Documentation

◆ js_app_settings_storage_alloc()

JsAppSettingsStorage * js_app_settings_storage_alloc ( const char * app_id,
JsAppSettingsStorageStatus * status )

Build a settings storage for an application.

Parses the application's settings schema, composes the provider descriptor tree and allocates the value block. Does not load any values; call js_app_settings_storage_load() before reading any.

Parameters
[in]app_idApplication identifier.
[out]statusResulting status.
Returns
Allocated storage, or NULL on failure; failures are logged.

◆ js_app_settings_storage_export()

bool js_app_settings_storage_export ( const JsAppSettingsStorage * instance,
FuriString * data )

Export the settings document.

Serializes the current values into a complete settings document. Values must be current: call js_app_settings_storage_load() before exporting.

Parameters
[in]instanceStorage.
[out]dataSerialized document data.
Returns
true on success, false when a value fails to encode.

◆ js_app_settings_storage_free()

void js_app_settings_storage_free ( JsAppSettingsStorage * instance)

Release a settings storage.

Releases the storage with the schema tree, the descriptor tree and the value block.

Parameters
[in]instanceStorage returned by js_app_settings_storage_alloc().

◆ js_app_settings_storage_get_node()

const JsAppSettingsNode * js_app_settings_storage_get_node ( const SettingProviderSetting * instance)

Get the schema node a setting was built from.

Parameters
[in]instanceSetting from the descriptor tree, not the root.
Returns
Node that produced the setting.

◆ js_app_settings_storage_get_root()

const SettingProviderSetting * js_app_settings_storage_get_root ( JsAppSettingsStorage * instance)

Get the root setting of the descriptor tree.

Parameters
[in]instanceStorage.
Returns
Anonymous struct setting covering the whole value block.

◆ js_app_settings_storage_get_value()

void * js_app_settings_storage_get_value ( const SettingProviderSetting * instance)

Get the value behind a setting.

Parameters
[in]instanceSetting from the descriptor tree, not the root.
Returns
Pointer into the storage's value block, valid until free.

◆ js_app_settings_storage_import()

bool js_app_settings_storage_import ( JsAppSettingsStorage * instance,
const char * data,
size_t size )

Import a settings document.

Strict counterpart of js_app_settings_storage_export(): the document must carry the settings version and every field with a valid value; unknown keys are dropped.

Parameters
[in]instanceStorage.
[in]dataDocument data to import.
[in]sizeLength of the document data.
Returns
true on success, false on an invalid document.

◆ js_app_settings_storage_load()

bool js_app_settings_storage_load ( JsAppSettingsStorage * instance)

Load values from the application's data file.

Missing and invalid fields fall back to the schema defaults; an absent or unparsable file still loads every default.

Parameters
[in]instanceStorage.
Returns
true when the values are usable, false only on storage errors.

◆ js_app_settings_storage_reset()

bool js_app_settings_storage_reset ( JsAppSettingsStorage * instance)

Reset every value to its default.

Substitutes the schema default for every field and writes the document.

Parameters
[in]instanceStorage.
Returns
true on success, false on a write error.

◆ js_app_settings_storage_save()

bool js_app_settings_storage_save ( JsAppSettingsStorage * instance)

Write every value to the application's data file.

The file is rebuilt as a whole; a single invalid field discards the save.

Parameters
[in]instanceStorage.
Returns
true on success, false on a write or validation failure.