forked from flipperdevices/flipperzero-firmware
-
-
Notifications
You must be signed in to change notification settings - Fork 545
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
37 changed files
with
2,512 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
App( | ||
appid="CFW", | ||
name="CFW Settings", | ||
apptype=FlipperAppType.EXTERNAL, | ||
entry_point="cfw_app", | ||
requires=[ | ||
"gui", | ||
"dolphin", | ||
], | ||
stack_size=2 * 1024, | ||
# icon="A_CFW_14", | ||
order=90, | ||
fap_libs=["assets"], | ||
fap_category="Settings", | ||
fap_icon="cfw_app_10px.png", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,316 @@ | ||
#include "cfw_app.h" | ||
|
||
static bool cfw_app_custom_event_callback(void* context, uint32_t event) { | ||
furi_assert(context); | ||
CfwApp* app = context; | ||
return scene_manager_handle_custom_event(app->scene_manager, event); | ||
} | ||
|
||
void callback_reboot(void* context) { | ||
UNUSED(context); | ||
power_reboot(PowerBootModeNormal); | ||
} | ||
|
||
bool cfw_app_apply(CfwApp* app) { | ||
Storage* storage = furi_record_open(RECORD_STORAGE); | ||
|
||
if(app->save_mainmenu_apps) { | ||
Stream* stream = file_stream_alloc(storage); | ||
if(file_stream_open(stream, CFW_APPS_PATH, FSAM_READ_WRITE, FSOM_CREATE_ALWAYS)) { | ||
CharList_it_t it; | ||
CharList_it(it, app->mainmenu_app_paths); | ||
for(uint i = 0; i < CharList_size(app->mainmenu_app_paths); i++) { | ||
stream_write_format(stream, "%s\n", *CharList_get(app->mainmenu_app_paths, i)); | ||
} | ||
} | ||
file_stream_close(stream); | ||
stream_free(stream); | ||
} | ||
|
||
if(app->save_subghz_frequencies) { | ||
FlipperFormat* file = flipper_format_file_alloc(storage); | ||
do { | ||
FrequencyList_it_t it; | ||
if(!flipper_format_file_open_always(file, EXT_PATH("subghz/assets/setting_user.txt"))) | ||
break; | ||
|
||
if(!flipper_format_write_header_cstr( | ||
file, SUBGHZ_SETTING_FILE_TYPE, SUBGHZ_SETTING_FILE_VERSION)) | ||
break; | ||
|
||
while(flipper_format_delete_key(file, "Add_standard_frequencies")) | ||
; | ||
flipper_format_write_bool( | ||
file, "Add_standard_frequencies", &app->subghz_use_defaults, 1); | ||
|
||
if(!flipper_format_rewind(file)) break; | ||
while(flipper_format_delete_key(file, "Frequency")) | ||
; | ||
FrequencyList_it(it, app->subghz_static_freqs); | ||
for(uint i = 0; i < FrequencyList_size(app->subghz_static_freqs); i++) { | ||
flipper_format_write_uint32( | ||
file, "Frequency", FrequencyList_get(app->subghz_static_freqs, i), 1); | ||
} | ||
|
||
if(!flipper_format_rewind(file)) break; | ||
while(flipper_format_delete_key(file, "Hopper_frequency")) | ||
; | ||
for(uint i = 0; i < FrequencyList_size(app->subghz_hopper_freqs); i++) { | ||
flipper_format_write_uint32( | ||
file, "Hopper_frequency", FrequencyList_get(app->subghz_hopper_freqs, i), 1); | ||
} | ||
} while(false); | ||
flipper_format_free(file); | ||
} | ||
|
||
if(app->save_subghz) { | ||
furi_hal_subghz_set_is_extended(app->subghz_extend); | ||
} | ||
|
||
if(app->save_name) { | ||
if(strcmp(app->device_name, "") == 0) { | ||
storage_simply_remove(storage, NAMESPOOF_PATH); | ||
} else { | ||
FlipperFormat* file = flipper_format_file_alloc(storage); | ||
|
||
do { | ||
if(!flipper_format_file_open_always(file, NAMESPOOF_PATH)) break; | ||
if(!flipper_format_write_header_cstr(file, NAMESPOOF_HEADER, NAMESPOOF_VERSION)) | ||
break; | ||
if(!flipper_format_write_string_cstr(file, "Name", app->device_name)) break; | ||
} while(0); | ||
|
||
flipper_format_free(file); | ||
} | ||
} | ||
|
||
// if(app->save_level) { | ||
// Dolphin* dolphin = furi_record_open(RECORD_DOLPHIN); | ||
// int32_t xp = app->xp_level > 1 ? dolphin_get_levels()[app->xp_level - 2] : 0; | ||
// dolphin->state->data.icounter = xp + 1; | ||
// dolphin->state->dirty = true; | ||
// dolphin_state_save(dolphin->state); | ||
// furi_record_close(RECORD_DOLPHIN); | ||
// } | ||
|
||
if(app->save_backlight) { | ||
rgb_backlight_save_settings(); | ||
} | ||
|
||
if(app->save_settings) { | ||
CFW_SETTINGS_SAVE(); | ||
} | ||
|
||
// if(app->show_slideshow) { | ||
// callback_reboot(NULL); | ||
// } | ||
|
||
if(app->require_reboot) { | ||
popup_set_header(app->popup, "Rebooting...", 64, 26, AlignCenter, AlignCenter); | ||
popup_set_text(app->popup, "Applying changes...", 64, 40, AlignCenter, AlignCenter); | ||
popup_set_callback(app->popup, callback_reboot); | ||
popup_set_context(app->popup, app); | ||
popup_set_timeout(app->popup, 1000); | ||
popup_enable_timeout(app->popup); | ||
view_dispatcher_switch_to_view(app->view_dispatcher, CfwAppViewPopup); | ||
return true; | ||
} | ||
|
||
furi_record_close(RECORD_STORAGE); | ||
return false; | ||
} | ||
|
||
static bool cfw_app_back_event_callback(void* context) { | ||
furi_assert(context); | ||
CfwApp* app = context; | ||
|
||
if(!scene_manager_has_previous_scene(app->scene_manager, CfwAppSceneStart)) { | ||
if(cfw_app_apply(app)) { | ||
return true; | ||
} | ||
} | ||
|
||
return scene_manager_handle_back_event(app->scene_manager); | ||
} | ||
|
||
CfwApp* cfw_app_alloc() { | ||
CfwApp* app = malloc(sizeof(CfwApp)); | ||
app->gui = furi_record_open(RECORD_GUI); | ||
app->dialogs = furi_record_open(RECORD_DIALOGS); | ||
app->notification = furi_record_open(RECORD_NOTIFICATION); | ||
|
||
// View Dispatcher and Scene Manager | ||
app->view_dispatcher = view_dispatcher_alloc(); | ||
app->scene_manager = scene_manager_alloc(&cfw_app_scene_handlers, app); | ||
view_dispatcher_enable_queue(app->view_dispatcher); | ||
view_dispatcher_set_event_callback_context(app->view_dispatcher, app); | ||
|
||
view_dispatcher_set_custom_event_callback( | ||
app->view_dispatcher, cfw_app_custom_event_callback); | ||
view_dispatcher_set_navigation_event_callback( | ||
app->view_dispatcher, cfw_app_back_event_callback); | ||
|
||
view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen); | ||
|
||
// Gui Modules | ||
app->var_item_list = variable_item_list_alloc(); | ||
view_dispatcher_add_view( | ||
app->view_dispatcher, | ||
CfwAppViewVarItemList, | ||
variable_item_list_get_view(app->var_item_list)); | ||
|
||
app->text_input = text_input_alloc(); | ||
view_dispatcher_add_view( | ||
app->view_dispatcher, CfwAppViewTextInput, text_input_get_view(app->text_input)); | ||
|
||
app->popup = popup_alloc(); | ||
view_dispatcher_add_view(app->view_dispatcher, CfwAppViewPopup, popup_get_view(app->popup)); | ||
|
||
// Settings init | ||
|
||
CfwSettings* cfw_settings = CFW_SETTINGS(); | ||
|
||
// app->asset_pack_index = 0; | ||
// CharList_init(app->asset_pack_names); | ||
Storage* storage = furi_record_open(RECORD_STORAGE); | ||
// File* folder = storage_file_alloc(storage); | ||
// FileInfo info; | ||
// char* name = malloc(CFW_ASSETS_PACK_NAME_LEN); | ||
// if(storage_dir_open(folder, CFW_ASSETS_PATH)) { | ||
// while(storage_dir_read(folder, &info, name, CFW_ASSETS_PACK_NAME_LEN)) { | ||
// if(info.flags & FSF_DIRECTORY) { | ||
// char* copy = malloc(CFW_ASSETS_PACK_NAME_LEN); | ||
// strlcpy(copy, name, CFW_ASSETS_PACK_NAME_LEN); | ||
// uint idx = 0; | ||
// if(strcmp(copy, "NSFW") != 0) { | ||
// for(; idx < CharList_size(app->asset_pack_names); idx++) { | ||
// char* comp = *CharList_get(app->asset_pack_names, idx); | ||
// if(strcasecmp(copy, comp) < 0 && strcmp(comp, "NSFW") != 0) { | ||
// break; | ||
// } | ||
// } | ||
// } | ||
// CharList_push_at(app->asset_pack_names, idx, copy); | ||
// if(app->asset_pack_index != 0) { | ||
// if(idx < app->asset_pack_index) app->asset_pack_index++; | ||
// } else { | ||
// if(strcmp(copy, CFW_settings->asset_pack) == 0) | ||
// app->asset_pack_index = idx + 1; | ||
// } | ||
// } | ||
// } | ||
// } | ||
// free(name); | ||
// storage_file_free(folder); | ||
|
||
CharList_init(app->mainmenu_app_names); | ||
CharList_init(app->mainmenu_app_paths); | ||
Stream* stream = file_stream_alloc(storage); | ||
FuriString* line = furi_string_alloc(); | ||
if(file_stream_open(stream, CFW_APPS_PATH, FSAM_READ, FSOM_OPEN_EXISTING)) { | ||
while(stream_read_line(stream, line)) { | ||
furi_string_replace_all(line, "\r", ""); | ||
furi_string_replace_all(line, "\n", ""); | ||
CharList_push_back(app->mainmenu_app_paths, strdup(furi_string_get_cstr(line))); | ||
fap_loader_load_name_and_icon(line, storage, NULL, line); | ||
CharList_push_back(app->mainmenu_app_names, strdup(furi_string_get_cstr(line))); | ||
} | ||
} | ||
furi_string_free(line); | ||
file_stream_close(stream); | ||
stream_free(stream); | ||
|
||
FlipperFormat* file = flipper_format_file_alloc(storage); | ||
FrequencyList_init(app->subghz_static_freqs); | ||
FrequencyList_init(app->subghz_hopper_freqs); | ||
app->subghz_use_defaults = true; | ||
do { | ||
uint32_t temp; | ||
if(!flipper_format_file_open_existing(file, EXT_PATH("subghz/assets/setting_user.txt"))) break; | ||
|
||
flipper_format_read_bool(file, "Add_standard_frequencies", &app->subghz_use_defaults, 1); | ||
|
||
if(!flipper_format_rewind(file)) break; | ||
while(flipper_format_read_uint32(file, "Frequency", &temp, 1)) { | ||
if(furi_hal_subghz_is_frequency_valid(temp)) { | ||
FrequencyList_push_back(app->subghz_static_freqs, temp); | ||
} | ||
} | ||
|
||
if(!flipper_format_rewind(file)) break; | ||
while(flipper_format_read_uint32(file, "Hopper_frequency", &temp, 1)) { | ||
if(furi_hal_subghz_is_frequency_valid(temp)) { | ||
FrequencyList_push_back(app->subghz_hopper_freqs, temp); | ||
} | ||
} | ||
} while(false); | ||
flipper_format_free(file); | ||
furi_record_close(RECORD_STORAGE); | ||
|
||
app->subghz_extend = furi_hal_subghz_get_is_extended(); | ||
|
||
strlcpy(app->device_name, furi_hal_version_get_name_ptr(), FURI_HAL_VERSION_ARRAY_NAME_LENGTH); | ||
|
||
// Dolphin* dolphin = furi_record_open(RECORD_DOLPHIN); | ||
// DolphinStats stats = dolphin_stats(dolphin); | ||
// app->xp_level = stats.level; | ||
// furi_record_close(RECORD_DOLPHIN); | ||
|
||
app->version_tag = | ||
furi_string_alloc_printf("%s %s", version_get_version(NULL), version_get_builddate(NULL)); | ||
|
||
return app; | ||
} | ||
|
||
void cfw_app_free(CfwApp* app) { | ||
furi_assert(app); | ||
|
||
// Gui modules | ||
view_dispatcher_remove_view(app->view_dispatcher, CfwAppViewVarItemList); | ||
variable_item_list_free(app->var_item_list); | ||
view_dispatcher_remove_view(app->view_dispatcher, CfwAppViewTextInput); | ||
text_input_free(app->text_input); | ||
view_dispatcher_remove_view(app->view_dispatcher, CfwAppViewPopup); | ||
popup_free(app->popup); | ||
|
||
// View Dispatcher and Scene Manager | ||
view_dispatcher_free(app->view_dispatcher); | ||
scene_manager_free(app->scene_manager); | ||
|
||
// Settings deinit | ||
|
||
CharList_it_t it; | ||
// for(CharList_it(it, app->asset_pack_names); !CharList_end_p(it); CharList_next(it)) { | ||
// free(*CharList_cref(it)); | ||
// } | ||
// CharList_clear(app->asset_pack_names); | ||
|
||
for(CharList_it(it, app->mainmenu_app_names); !CharList_end_p(it); CharList_next(it)) { | ||
free(*CharList_cref(it)); | ||
} | ||
CharList_clear(app->mainmenu_app_names); | ||
for(CharList_it(it, app->mainmenu_app_paths); !CharList_end_p(it); CharList_next(it)) { | ||
free(*CharList_cref(it)); | ||
} | ||
CharList_clear(app->mainmenu_app_paths); | ||
|
||
FrequencyList_clear(app->subghz_static_freqs); | ||
FrequencyList_clear(app->subghz_hopper_freqs); | ||
|
||
furi_string_free(app->version_tag); | ||
|
||
// Records | ||
furi_record_close(RECORD_NOTIFICATION); | ||
furi_record_close(RECORD_DIALOGS); | ||
furi_record_close(RECORD_GUI); | ||
free(app); | ||
} | ||
|
||
extern int32_t cfw_app(void* p) { | ||
UNUSED(p); | ||
CfwApp* app = cfw_app_alloc(); | ||
scene_manager_next_scene(app->scene_manager, CfwAppSceneStart); | ||
view_dispatcher_run(app->view_dispatcher); | ||
cfw_app_free(app); | ||
return 0; | ||
} |
Oops, something went wrong.