2022-09-14 16:11:38 +00:00
|
|
|
#include "../updater_i.h"
|
2022-04-13 20:50:25 +00:00
|
|
|
#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, string_get_cstr(updater->startup_arg))) {
|
|
|
|
widget_add_string_element(
|
|
|
|
updater->widget, 64, 12, AlignCenter, AlignCenter, FontPrimary, "Update");
|
|
|
|
|
2022-06-21 13:25:05 +00:00
|
|
|
widget_add_text_box_element(
|
2022-04-13 20:50:25 +00:00
|
|
|
updater->widget,
|
2022-06-21 13:25:05 +00:00
|
|
|
5,
|
|
|
|
20,
|
|
|
|
118,
|
2022-04-13 20:50:25 +00:00
|
|
|
32,
|
|
|
|
AlignCenter,
|
|
|
|
AlignCenter,
|
2022-06-21 13:25:05 +00:00
|
|
|
string_get_cstr(pending_upd->manifest->version),
|
|
|
|
true);
|
2022-04-13 20:50:25 +00:00
|
|
|
|
|
|
|
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(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);
|
|
|
|
string_clear(updater->pending_update->message);
|
|
|
|
}
|
|
|
|
|
|
|
|
widget_reset(updater->widget);
|
|
|
|
free(updater->pending_update);
|
2022-05-06 13:37:10 +00:00
|
|
|
}
|