Skip to content

Commit

Permalink
Updated settings file schema
Browse files Browse the repository at this point in the history
  • Loading branch information
kala13x committed Oct 8, 2023
1 parent faf5524 commit e56a0c2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion xremote.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@

#define XREMOTE_VERSION_MAJOR 1
#define XREMOTE_VERSION_MINOR 0
#define XREMOTE_BUILD_NUMBER 3
#define XREMOTE_BUILD_NUMBER 4

void xremote_get_version(char* version, size_t length);
26 changes: 15 additions & 11 deletions xremote_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,18 @@ bool xremote_app_settings_store(XRemoteAppSettings* settings) {
do {
/* Write header in config file */
if(!flipper_format_file_open_always(ff, XREMOTE_APP_SETTINGS)) break;
if(!flipper_format_write_header_cstr(ff, "XRemote settings file", 1)) break;
if(!flipper_format_write_header_cstr(ff, "XRemote", 1)) break;
if(!flipper_format_write_comment_cstr(ff, "")) break;

/* Write actual configuration to the settings file */
if(!flipper_format_write_uint32(ff, "orientation", (uint32_t*)&settings->orientation, 1))
break;
if(!flipper_format_write_uint32(ff, "repeat", (uint32_t*)&settings->repeat_count, 1))
break;
if(!flipper_format_write_uint32(ff, "exit", (uint32_t*)&settings->exit_behavior, 1)) break;
uint32_t value = settings->orientation == ViewOrientationHorizontal ? 0 : 1;
if(!flipper_format_write_uint32(ff, "orientation", &value, 1)) break;

value = settings->exit_behavior == XRemoteAppExitPress ? 0 : 1;
if(!flipper_format_write_uint32(ff, "appexit", &value, 1)) break;

value = settings->repeat_count;
if(!flipper_format_write_uint32(ff, "repeat", &value, 1)) break;

success = true;
} while(false);
Expand All @@ -74,15 +77,15 @@ bool xremote_app_settings_load(XRemoteAppSettings* settings) {
/* Open file and read the header */
if(!flipper_format_buffered_file_open_existing(ff, XREMOTE_APP_SETTINGS)) break;
if(!flipper_format_read_header(ff, header, &version)) break;
if(!furi_string_equal(header, "XRemote settings file") || (version != 1)) break;
if(!furi_string_equal(header, "XRemote") || (version != 1)) break;

/* Parse config data from the buffer */
if(!flipper_format_read_uint32(ff, "orientation", &value, 1)) break;
settings->orientation = value;
settings->orientation = value == 0 ? ViewOrientationHorizontal : ViewOrientationVertical;
if(!flipper_format_read_uint32(ff, "appexit", &value, 1)) break;
settings->exit_behavior = value == 0 ? XRemoteAppExitPress : XRemoteAppExitHold;
if(!flipper_format_read_uint32(ff, "repeat", &value, 1)) break;
settings->repeat_count = value;
if(!flipper_format_read_uint32(ff, "exit", &value, 1)) break;
settings->exit_behavior = value;

success = true;
} while(false);
Expand Down Expand Up @@ -225,7 +228,7 @@ void xremote_app_submenu_alloc(XRemoteApp* app, uint32_t index, ViewNavigationCa
View* view = submenu_get_view(app->submenu);
view_set_previous_callback(view, prev_cb);

#ifdef FW_ORIGIN_Unleashed
#if defined(FW_ORIGIN_Unleashed) || defined(FW_ORIGIN_RM)
submenu_set_orientation(app->submenu, settings->orientation);
#else
view_set_orientation(view, settings->orientation);
Expand Down Expand Up @@ -299,6 +302,7 @@ void xremote_app_free(XRemoteApp* app) {
xremote_app_submenu_free(app);
xremote_app_view_free(app);

/* Call clear callback if there is an user context attached */
if(app->on_clear != NULL) app->on_clear(app->context);

free(app);
Expand Down
1 change: 1 addition & 0 deletions xremote_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ void xremote_app_submenu_add(
const char* name,
uint32_t index,
SubmenuItemCallback callback);

void xremote_app_submenu_alloc(XRemoteApp* app, uint32_t index, ViewNavigationCallback prev_cb);
void xremote_app_submenu_free(XRemoteApp* app);

Expand Down
2 changes: 1 addition & 1 deletion xremote_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ typedef struct {

#define XREMOTE_EXIT_BEHAVIOR_TEXT_PRESS "Press"
#define XREMOTE_EXIT_BEHAVIOR_TEXT_HOLD "Hold"
#define XREMOTE_EXIT_BEHAVIOR_TEXT "Exit App"
#define XREMOTE_EXIT_BEHAVIOR_TEXT "Exit Apps"
#define XREMOTE_EXIT_BEHAVIOR_INDEX_PRESS 0
#define XREMOTE_EXIT_BEHAVIOR_INDEX_HOLD 1
#define XREMOTE_EXIT_BEHAVIOR_MAX 2
Expand Down

0 comments on commit e56a0c2

Please sign in to comment.