RPC App: state message and GUI update (#1423)

* RPC App: state message and GUI update
* Protobuf submodule update

Co-authored-by: SG <who.just.the.doctor@gmail.com>
Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
Nikolay Minaylov
2022-07-25 17:16:45 +03:00
committed by GitHub
parent f1cb95655c
commit d80edba891
17 changed files with 237 additions and 62 deletions

View File

@@ -9,4 +9,5 @@ enum NfcCustomEvent {
NfcCustomEventByteInputDone,
NfcCustomEventTextInputDone,
NfcCustomEventDictAttackDone,
NfcCustomEventRpcLoad,
};

View File

@@ -31,6 +31,7 @@ void nfc_rpc_exit_callback(Nfc* nfc) {
}
if(nfc->rpc_ctx) {
rpc_system_app_set_callback(nfc->rpc_ctx, NULL, NULL);
rpc_system_app_send_exited(nfc->rpc_ctx);
nfc->rpc_ctx = NULL;
}
}
@@ -82,6 +83,7 @@ static bool nfc_rpc_command_callback(RpcAppSystemEvent event, const char* arg, v
nfc->worker, NfcWorkerStateEmulate, &nfc->dev->dev_data, NULL, nfc);
}
nfc->rpc_state = NfcRpcStateEmulating;
view_dispatcher_send_custom_event(nfc->view_dispatcher, NfcCustomEventRpcLoad);
result = true;
}
}
@@ -107,7 +109,6 @@ Nfc* nfc_alloc() {
// Open GUI record
nfc->gui = furi_record_open("gui");
view_dispatcher_attach_to_gui(nfc->view_dispatcher, nfc->gui, ViewDispatcherTypeFullscreen);
// Open Notification record
nfc->notifications = furi_record_open("notification");
@@ -291,21 +292,30 @@ int32_t nfc_app(void* p) {
if(sscanf(p, "RPC %lX", &rpc_ctx) == 1) {
nfc->rpc_ctx = (void*)rpc_ctx;
rpc_system_app_set_callback(nfc->rpc_ctx, nfc_rpc_command_callback, nfc);
rpc_system_app_send_started(nfc->rpc_ctx);
view_dispatcher_attach_to_gui(
nfc->view_dispatcher, nfc->gui, ViewDispatcherTypeDesktop);
scene_manager_next_scene(nfc->scene_manager, NfcSceneRpc);
} else if(nfc_device_load(nfc->dev, p, true)) {
if(nfc->dev->format == NfcDeviceSaveFormatMifareUl) {
scene_manager_next_scene(nfc->scene_manager, NfcSceneEmulateMifareUl);
} else if(nfc->dev->format == NfcDeviceSaveFormatMifareClassic) {
scene_manager_next_scene(nfc->scene_manager, NfcSceneEmulateMifareClassic);
} else {
scene_manager_next_scene(nfc->scene_manager, NfcSceneEmulateUid);
}
} else {
// Exit app
view_dispatcher_stop(nfc->view_dispatcher);
view_dispatcher_attach_to_gui(
nfc->view_dispatcher, nfc->gui, ViewDispatcherTypeFullscreen);
if(nfc_device_load(nfc->dev, p, true)) {
if(nfc->dev->format == NfcDeviceSaveFormatMifareUl) {
scene_manager_next_scene(nfc->scene_manager, NfcSceneEmulateMifareUl);
} else if(nfc->dev->format == NfcDeviceSaveFormatMifareClassic) {
scene_manager_next_scene(nfc->scene_manager, NfcSceneEmulateMifareClassic);
} else {
scene_manager_next_scene(nfc->scene_manager, NfcSceneEmulateUid);
}
} else {
// Exit app
view_dispatcher_stop(nfc->view_dispatcher);
}
}
nfc_device_set_loading_callback(nfc->dev, NULL, nfc);
} else {
view_dispatcher_attach_to_gui(
nfc->view_dispatcher, nfc->gui, ViewDispatcherTypeFullscreen);
scene_manager_next_scene(nfc->scene_manager, NfcSceneStart);
}

View File

@@ -2,24 +2,33 @@
void nfc_scene_rpc_on_enter(void* context) {
Nfc* nfc = context;
Widget* widget = nfc->widget;
Popup* popup = nfc->popup;
widget_add_text_box_element(
widget, 0, 0, 128, 28, AlignCenter, AlignCenter, "RPC mode", false);
popup_set_header(popup, "NFC", 82, 28, AlignCenter, AlignBottom);
popup_set_text(popup, "RPC mode", 82, 32, AlignCenter, AlignTop);
popup_set_icon(popup, 2, 14, &I_Warning_30x23); // TODO: icon
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewPopup);
notification_message(nfc->notifications, &sequence_display_backlight_on);
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
}
bool nfc_scene_rpc_on_event(void* context, SceneManagerEvent event) {
Nfc* nfc = context;
Popup* popup = nfc->popup;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
consumed = true;
if(event.event == NfcCustomEventViewExit) {
view_dispatcher_stop(nfc->view_dispatcher);
nfc_blink_stop(nfc);
} else if(event.event == NfcCustomEventRpcLoad) {
nfc_blink_start(nfc);
nfc_text_store_set(nfc, "emulating\n%s", nfc->dev->dev_name);
popup_set_text(popup, nfc->text_store, 82, 32, AlignCenter, AlignTop);
}
}
return consumed;
@@ -27,8 +36,12 @@ bool nfc_scene_rpc_on_event(void* context, SceneManagerEvent event) {
void nfc_scene_rpc_on_exit(void* context) {
Nfc* nfc = context;
Popup* popup = nfc->popup;
nfc_rpc_exit_callback(nfc);
nfc_blink_stop(nfc);
widget_reset(nfc->widget);
popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom);
popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop);
popup_set_icon(popup, 0, 0, NULL);
}