Name changer in xfw app misc + small app fixes

This commit is contained in:
Willy-JL
2023-02-19 23:22:58 +00:00
parent e338db1392
commit 0f7a65dceb
7 changed files with 147 additions and 29 deletions

View File

@@ -13,8 +13,6 @@ void namechanger_on_system_start() {
FuriString* NAMEHEADER;
NAMEHEADER = furi_string_alloc_set("Flipper Name File");
FuriString* filepath;
filepath = furi_string_alloc_set("/ext/dolphin/name.txt");
bool result = false;
@@ -22,7 +20,7 @@ void namechanger_on_system_start() {
data = furi_string_alloc();
do {
if(!flipper_format_file_open_existing(file, furi_string_get_cstr(filepath))) {
if(!flipper_format_file_open_existing(file, NAMECHANGER_PATH)) {
break;
}
@@ -59,7 +57,7 @@ void namechanger_on_system_start() {
do {
// Open file for write
if(!flipper_format_file_open_always(file, furi_string_get_cstr(filepath))) {
if(!flipper_format_file_open_always(file, NAMECHANGER_PATH)) {
break;
}
@@ -109,7 +107,7 @@ void namechanger_on_system_start() {
do {
// Open file for write
if(!flipper_format_file_open_always(file, furi_string_get_cstr(filepath))) {
if(!flipper_format_file_open_always(file, NAMECHANGER_PATH)) {
break;
}
@@ -161,7 +159,6 @@ void namechanger_on_system_start() {
furi_string_free(data);
furi_string_free(filepath);
furi_record_close(RECORD_STORAGE);
}
}

View File

@@ -5,5 +5,6 @@
#define NAMECHANGER_TEXT_STORE_SIZE 9
#define NAMECHANGER_HEADER "Flipper Name File"
#define NAMECHANGER_PATH EXT_PATH("dolphin/name.txt")
#define TAG "NameChangerSRV"

View File

@@ -4,3 +4,4 @@ ADD_SCENE(xtreme_app, statusbar, Statusbar)
ADD_SCENE(xtreme_app, protocols, Protocols)
ADD_SCENE(xtreme_app, dolphin, Dolphin)
ADD_SCENE(xtreme_app, misc, Misc)
ADD_SCENE(xtreme_app, misc_rename, MiscRename)

View File

@@ -1,5 +1,15 @@
#include "../xtreme_app.h"
enum VarItemListIndex {
VarItemListIndexSortDirsFirst,
VarItemListIndexChangeDeviceName,
};
void xtreme_app_scene_misc_var_item_list_callback(void* context, uint32_t index) {
XtremeApp* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, index);
}
static void xtreme_app_scene_misc_sort_folders_before_changed(VariableItem* item) {
XtremeApp* app = variable_item_get_context(item);
bool value = variable_item_get_current_value_index(item);
@@ -23,15 +33,31 @@ void xtreme_app_scene_misc_on_enter(void* context) {
variable_item_set_current_value_index(item, xtreme_settings->sort_dirs_first);
variable_item_set_current_value_text(item, xtreme_settings->sort_dirs_first ? "ON" : "OFF");
variable_item_list_set_selected_item(var_item_list, 0);
variable_item_list_add(var_item_list, "Change Device Name", 0, NULL, app);
variable_item_list_set_enter_callback(var_item_list, xtreme_app_scene_misc_var_item_list_callback, app);
variable_item_list_set_selected_item(var_item_list, scene_manager_get_scene_state(app->scene_manager, XtremeAppSceneMisc));
view_dispatcher_switch_to_view(app->view_dispatcher, XtremeAppViewVarItemList);
}
bool xtreme_app_scene_misc_on_event(void* context, SceneManagerEvent event) {
UNUSED(context);
UNUSED(event);
XtremeApp* app = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
scene_manager_set_scene_state(app->scene_manager, XtremeAppSceneMisc, event.event);
consumed = true;
switch(event.event) {
case VarItemListIndexChangeDeviceName:
scene_manager_next_scene(app->scene_manager, XtremeAppSceneMiscRename);
break;
default:
break;
}
}
return consumed;
}

View File

@@ -0,0 +1,54 @@
#include "../xtreme_app.h"
enum TextInputIndex {
TextInputIndexResult,
};
static void xtreme_app_scene_misc_rename_text_input_callback(void* context) {
XtremeApp* app = context;
app->save_name = true;
app->require_reboot = true;
view_dispatcher_send_custom_event(
app->view_dispatcher, TextInputIndexResult);
}
void xtreme_app_scene_misc_rename_on_enter(void* context) {
XtremeApp* app = context;
TextInput* text_input = app->text_input;
text_input_set_header_text(text_input, "Leave empty for default");
text_input_set_result_callback(
text_input,
xtreme_app_scene_misc_rename_text_input_callback,
app,
app->device_name,
NAMECHANGER_TEXT_STORE_SIZE,
true);
view_dispatcher_switch_to_view(app->view_dispatcher, XtremeAppViewTextInput);
}
bool xtreme_app_scene_misc_rename_on_event(void* context, SceneManagerEvent event) {
XtremeApp* app = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
consumed = true;
switch(event.event) {
case TextInputIndexResult:
scene_manager_previous_scene(app->scene_manager);
break;
default:
break;
}
}
return consumed;
}
void xtreme_app_scene_misc_rename_on_exit(void* context) {
XtremeApp* app = context;
text_input_reset(app->text_input);
}

View File

@@ -16,6 +16,18 @@ static bool xtreme_app_back_event_callback(void* context) {
XtremeApp* app = context;
if(!scene_manager_has_previous_scene(app->scene_manager, XtremeAppSceneStart)) {
Storage* storage = furi_record_open(RECORD_STORAGE);
if(app->save_subghz) {
FlipperFormat* subghz_range = flipper_format_file_alloc(storage);
if(flipper_format_file_open_existing(subghz_range, "/ext/subghz/assets/extend_range.txt")) {
flipper_format_insert_or_update_bool(
subghz_range, "use_ext_range_at_own_risk", &app->subghz_extend, 1);
flipper_format_insert_or_update_bool(
subghz_range, "ignore_default_tx_region", &app->subghz_bypass, 1);
}
flipper_format_free(subghz_range);
}
if(app->save_level) {
Dolphin* dolphin = furi_record_open(RECORD_DOLPHIN);
@@ -26,17 +38,27 @@ static bool xtreme_app_back_event_callback(void* context) {
furi_record_close(RECORD_DOLPHIN);
}
if(app->save_subghz) {
Storage* storage = furi_record_open(RECORD_STORAGE);
FlipperFormat* subghz_range = flipper_format_file_alloc(storage);
if(flipper_format_file_open_existing(subghz_range, "/ext/subghz/assets/extend_range.txt")) {
flipper_format_insert_or_update_bool(
subghz_range, "use_ext_range_at_own_risk", &app->subghz_extend, 1);
flipper_format_insert_or_update_bool(
subghz_range, "ignore_default_tx_region", &app->subghz_bypass, 1);
if(app->save_name) {
if(strcmp(app->device_name, "") == 0) {
storage_simply_remove(storage, NAMECHANGER_PATH);
} else {
FlipperFormat* file = flipper_format_file_alloc(storage);
do {
if(!flipper_format_file_open_always(file, NAMECHANGER_PATH)) break;
if(!flipper_format_write_header_cstr(file, NAMECHANGER_HEADER, 1)) break;
if(!flipper_format_write_comment_cstr(file, "Changing the value below will change your FlipperZero device name.")) break;
if(!flipper_format_write_comment_cstr(file, "Note: This is limited to 8 characters using the following: a-z, A-Z, 0-9, and _")) break;
if(!flipper_format_write_comment_cstr(file, "It cannot contain any other characters.")) break;
if(!flipper_format_write_string_cstr(file, "Name", app->device_name)) break;
} while(0);
flipper_format_free(file);
}
flipper_format_free(subghz_range);
furi_record_close(RECORD_STORAGE);
}
if(app->save_settings) {
@@ -54,6 +76,7 @@ static bool xtreme_app_back_event_callback(void* context) {
return true;
}
furi_record_close(RECORD_STORAGE);
}
return scene_manager_handle_back_event(app->scene_manager);
@@ -83,6 +106,12 @@ XtremeApp* xtreme_app_alloc() {
XtremeAppViewVarItemList,
variable_item_list_get_view(app->var_item_list));
app->text_input = text_input_alloc();
view_dispatcher_add_view(
app->view_dispatcher,
XtremeAppViewTextInput,
text_input_get_view(app->text_input));
app->popup = popup_alloc();
view_dispatcher_add_view(app->view_dispatcher, XtremeAppViewPopup, popup_get_view(app->popup));
@@ -90,11 +119,6 @@ XtremeApp* xtreme_app_alloc() {
XtremeSettings* xtreme_settings = XTREME_SETTINGS();
Dolphin* dolphin = furi_record_open(RECORD_DOLPHIN);
DolphinStats stats = dolphin_stats(dolphin);
app->dolphin_level = stats.level;
furi_record_close(RECORD_DOLPHIN);
Storage* storage = furi_record_open(RECORD_STORAGE);
FlipperFormat* subghz_range = flipper_format_file_alloc(storage);
app->subghz_extend = false;
@@ -105,6 +129,13 @@ XtremeApp* xtreme_app_alloc() {
}
flipper_format_free(subghz_range);
Dolphin* dolphin = furi_record_open(RECORD_DOLPHIN);
DolphinStats stats = dolphin_stats(dolphin);
app->dolphin_level = stats.level;
furi_record_close(RECORD_DOLPHIN);
strlcpy(app->device_name, furi_hal_version_get_name_ptr(), NAMECHANGER_TEXT_STORE_SIZE);
app->asset_pack = 0;
asset_packs_init(app->asset_packs);
File* folder = storage_file_alloc(storage);
@@ -148,6 +179,8 @@ void xtreme_app_free(XtremeApp* app) {
// Gui modules
view_dispatcher_remove_view(app->view_dispatcher, XtremeAppViewVarItemList);
variable_item_list_free(app->var_item_list);
view_dispatcher_remove_view(app->view_dispatcher, XtremeAppViewTextInput);
text_input_free(app->text_input);
view_dispatcher_remove_view(app->view_dispatcher, XtremeAppViewPopup);
popup_free(app->popup);

View File

@@ -7,8 +7,10 @@
#include <gui/scene_manager.h>
#include <assets_icons.h>
#include <gui/modules/variable_item_list.h>
#include <gui/modules/text_input.h>
#include <gui/modules/popup.h>
#include <lib/toolbox/value_index.h>
#include <namechangersrv/namechangersrv.h>
#include "scenes/xtreme_app_scene.h"
#include "dolphin/helpers/dolphin_state.h"
#include "dolphin/dolphin.h"
@@ -25,20 +27,24 @@ typedef struct {
SceneManager* scene_manager;
ViewDispatcher* view_dispatcher;
VariableItemList* var_item_list;
TextInput* text_input;
Popup* popup;
int dolphin_level;
bool subghz_extend;
bool subghz_bypass;
bool save_settings;
bool require_reboot;
bool save_subghz;
bool save_level;
int dolphin_level;
char device_name[NAMECHANGER_TEXT_STORE_SIZE];
uint asset_pack;
asset_packs_t asset_packs;
FuriString* version_tag;
bool save_subghz;
bool save_level;
bool save_name;
bool save_settings;
bool require_reboot;
} XtremeApp;
typedef enum {
XtremeAppViewVarItemList,
XtremeAppViewTextInput,
XtremeAppViewPopup,
} XtremeAppView;