unleashed-firmware/applications/system/updater/scenes/updater_scene_loadcfg.c
Sergey Gavrilov 4bf29827f8
M*LIB: non-inlined strings, FuriString primitive (#1795)
* Quicksave 1
* Header stage complete
* Source stage complete
* Lint & merge fixes
* Includes
* Documentation step 1
* FBT: output free size considering BT STACK
* Documentation step 2
* py lint
* Fix music player plugin
* unit test stage 1: string allocator, mem, getters, setters, appends, compare, search.
* unit test: string equality
* unit test: string replace
* unit test: string start_with, end_with
* unit test: string trim
* unit test: utf-8
* Rename
* Revert fw_size changes
* Simplify CLI backspace handling
* Simplify CLI character insert
* Merge fixes
* Furi: correct filenaming and spelling
* Bt: remove furi string include

Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2022-10-06 00:15:23 +09:00

107 lines
3.3 KiB
C

#include "../updater_i.h"
#include "updater_scene.h"
#include <update_util/update_operation.h>
#include <furi_hal.h>
void updater_scene_loadcfg_apply_callback(GuiButtonType result, InputType type, void* context) {
furi_assert(context);
Updater* updater = context;
if(type != InputTypeShort) {
return;
}
if(result == GuiButtonTypeRight) {
view_dispatcher_send_custom_event(updater->view_dispatcher, UpdaterCustomEventStartUpdate);
} else if(result == GuiButtonTypeLeft) {
view_dispatcher_send_custom_event(
updater->view_dispatcher, UpdaterCustomEventCancelUpdate);
}
}
void updater_scene_loadcfg_on_enter(void* context) {
Updater* updater = (Updater*)context;
UpdaterManifestProcessingState* pending_upd = updater->pending_update =
malloc(sizeof(UpdaterManifestProcessingState));
pending_upd->manifest = update_manifest_alloc();
if(update_manifest_init(pending_upd->manifest, furi_string_get_cstr(updater->startup_arg))) {
widget_add_string_element(
updater->widget, 64, 12, AlignCenter, AlignCenter, FontPrimary, "Update");
widget_add_text_box_element(
updater->widget,
5,
20,
118,
32,
AlignCenter,
AlignCenter,
furi_string_get_cstr(pending_upd->manifest->version),
true);
widget_add_button_element(
updater->widget,
GuiButtonTypeRight,
"Install",
updater_scene_loadcfg_apply_callback,
updater);
} else {
widget_add_string_element(
updater->widget, 64, 24, AlignCenter, AlignCenter, FontPrimary, "Invalid manifest");
}
widget_add_button_element(
updater->widget,
GuiButtonTypeLeft,
"Cancel",
updater_scene_loadcfg_apply_callback,
updater);
view_dispatcher_switch_to_view(updater->view_dispatcher, UpdaterViewWidget);
}
bool updater_scene_loadcfg_on_event(void* context, SceneManagerEvent event) {
Updater* updater = (Updater*)context;
bool consumed = false;
if(event.type == SceneManagerEventTypeBack) {
view_dispatcher_stop(updater->view_dispatcher);
consumed = true;
} else if(event.type == SceneManagerEventTypeCustom) {
switch(event.event) {
case UpdaterCustomEventStartUpdate:
updater->preparation_result =
update_operation_prepare(furi_string_get_cstr(updater->startup_arg));
if(updater->preparation_result == UpdatePrepareResultOK) {
furi_hal_power_reset();
} else {
#ifndef FURI_RAM_EXEC
scene_manager_next_scene(updater->scene_manager, UpdaterSceneError);
#endif
}
consumed = true;
break;
case UpdaterCustomEventCancelUpdate:
view_dispatcher_stop(updater->view_dispatcher);
consumed = true;
break;
default:
break;
}
}
return consumed;
}
void updater_scene_loadcfg_on_exit(void* context) {
Updater* updater = (Updater*)context;
if(updater->pending_update) {
update_manifest_free(updater->pending_update->manifest);
furi_string_free(updater->pending_update->message);
}
widget_reset(updater->widget);
free(updater->pending_update);
}