Settings: Reload desktop keybinds without realloc

This commit is contained in:
Willy-JL
2024-08-24 03:06:31 +02:00
parent d87a45f78d
commit 131416971d
4 changed files with 7 additions and 3 deletions

View File

@@ -1,7 +1,6 @@
#pragma once #pragma once
#include <furi.h> #include <furi.h>
#include <input/input.h>
#include "desktop_settings.h" #include "desktop_settings.h"

View File

@@ -109,7 +109,12 @@ static FuriString*
void desktop_keybinds_load(Desktop* desktop, DesktopKeybinds* keybinds) { void desktop_keybinds_load(Desktop* desktop, DesktopKeybinds* keybinds) {
for(DesktopKeybindType type = 0; type < DesktopKeybindTypeMAX; type++) { for(DesktopKeybindType type = 0; type < DesktopKeybindTypeMAX; type++) {
for(DesktopKeybindKey key = 0; key < DesktopKeybindKeyMAX; key++) { for(DesktopKeybindKey key = 0; key < DesktopKeybindKeyMAX; key++) {
(*keybinds)[type][key] = furi_string_alloc_set(desktop_keybinds_defaults[type][key]); const char* default_keybind = desktop_keybinds_defaults[type][key];
if((*keybinds)[type][key]) {
furi_string_set((*keybinds)[type][key], default_keybind);
} else {
(*keybinds)[type][key] = furi_string_alloc_set(default_keybind);
}
} }
} }

View File

@@ -1,6 +1,7 @@
#pragma once #pragma once
#include <furi/core/string.h> #include <furi/core/string.h>
#include <input/input.h>
#include "desktop.h" #include "desktop.h"

View File

@@ -33,7 +33,6 @@ bool desktop_settings_scene_keybinds_reset_on_event(void* context, SceneManagerE
case DialogExResultRight: case DialogExResultRight:
storage_common_remove(furi_record_open(RECORD_STORAGE), DESKTOP_KEYBINDS_PATH); storage_common_remove(furi_record_open(RECORD_STORAGE), DESKTOP_KEYBINDS_PATH);
furi_record_close(RECORD_STORAGE); furi_record_close(RECORD_STORAGE);
desktop_keybinds_free(&app->keybinds);
desktop_keybinds_load(furi_record_open(RECORD_DESKTOP), &app->keybinds); desktop_keybinds_load(furi_record_open(RECORD_DESKTOP), &app->keybinds);
furi_record_close(RECORD_DESKTOP); furi_record_close(RECORD_DESKTOP);
app->save_keybinds = false; app->save_keybinds = false;