@@ -32,61 +32,26 @@ static void nfc_rpc_command_callback(RpcAppSystemEvent event, void* context) {
3232 }
3333}
3434
35- Nfc * nfc_min_alloc () {
35+ Nfc * nfc_alloc () {
3636 Nfc * nfc = malloc (sizeof (Nfc ));
3737
38+ nfc -> worker = nfc_worker_alloc ();
3839 nfc -> view_dispatcher = view_dispatcher_alloc ();
3940 nfc -> scene_manager = scene_manager_alloc (& nfc_scene_handlers , nfc );
4041 view_dispatcher_enable_queue (nfc -> view_dispatcher );
4142 view_dispatcher_set_event_callback_context (nfc -> view_dispatcher , nfc );
4243 view_dispatcher_set_custom_event_callback (nfc -> view_dispatcher , nfc_custom_event_callback );
4344 view_dispatcher_set_navigation_event_callback (nfc -> view_dispatcher , nfc_back_event_callback );
4445
46+ // Nfc device
47+ nfc -> dev = nfc_device_alloc ();
48+
4549 // Open GUI record
4650 nfc -> gui = furi_record_open (RECORD_GUI );
4751
4852 // Open Notification record
4953 nfc -> notifications = furi_record_open (RECORD_NOTIFICATION );
5054
51- // Popup
52- nfc -> popup = popup_alloc ();
53- view_dispatcher_add_view (nfc -> view_dispatcher , NfcViewPopup , popup_get_view (nfc -> popup ));
54-
55- return nfc ;
56- }
57-
58- void nfc_min_free (Nfc * nfc ) {
59- furi_assert (nfc );
60-
61- // Popup
62- view_dispatcher_remove_view (nfc -> view_dispatcher , NfcViewPopup );
63- popup_free (nfc -> popup );
64-
65- // View Dispatcher
66- view_dispatcher_free (nfc -> view_dispatcher );
67-
68- // Scene Manager
69- scene_manager_free (nfc -> scene_manager );
70-
71- // GUI
72- furi_record_close (RECORD_GUI );
73- nfc -> gui = NULL ;
74-
75- // Notifications
76- furi_record_close (RECORD_NOTIFICATION );
77- nfc -> notifications = NULL ;
78-
79- free (nfc );
80- }
81-
82- Nfc * nfc_alloc () {
83- Nfc * nfc = nfc_min_alloc ();
84-
85- nfc -> worker = nfc_worker_alloc ();
86-
87- // Nfc device
88- nfc -> dev = nfc_device_alloc ();
89-
9055 // Submenu
9156 nfc -> submenu = submenu_alloc ();
9257 view_dispatcher_add_view (nfc -> view_dispatcher , NfcViewMenu , submenu_get_view (nfc -> submenu ));
@@ -96,6 +61,10 @@ Nfc* nfc_alloc() {
9661 view_dispatcher_add_view (
9762 nfc -> view_dispatcher , NfcViewDialogEx , dialog_ex_get_view (nfc -> dialog_ex ));
9863
64+ // Popup
65+ nfc -> popup = popup_alloc ();
66+ view_dispatcher_add_view (nfc -> view_dispatcher , NfcViewPopup , popup_get_view (nfc -> popup ));
67+
9968 // Loading
10069 nfc -> loading = loading_alloc ();
10170 view_dispatcher_add_view (nfc -> view_dispatcher , NfcViewLoading , loading_get_view (nfc -> loading ));
@@ -165,6 +134,10 @@ void nfc_free(Nfc* nfc) {
165134 view_dispatcher_remove_view (nfc -> view_dispatcher , NfcViewDialogEx );
166135 dialog_ex_free (nfc -> dialog_ex );
167136
137+ // Popup
138+ view_dispatcher_remove_view (nfc -> view_dispatcher , NfcViewPopup );
139+ popup_free (nfc -> popup );
140+
168141 // Loading
169142 view_dispatcher_remove_view (nfc -> view_dispatcher , NfcViewLoading );
170143 loading_free (nfc -> loading );
@@ -198,7 +171,21 @@ void nfc_free(Nfc* nfc) {
198171 nfc_worker_stop (nfc -> worker );
199172 nfc_worker_free (nfc -> worker );
200173
201- nfc_min_free (nfc );
174+ // View Dispatcher
175+ view_dispatcher_free (nfc -> view_dispatcher );
176+
177+ // Scene Manager
178+ scene_manager_free (nfc -> scene_manager );
179+
180+ // GUI
181+ furi_record_close (RECORD_GUI );
182+ nfc -> gui = NULL ;
183+
184+ // Notifications
185+ furi_record_close (RECORD_NOTIFICATION );
186+ nfc -> notifications = NULL ;
187+
188+ free (nfc );
202189}
203190
204191void nfc_text_store_set (Nfc * nfc , const char * text , ...) {
@@ -239,14 +226,16 @@ void nfc_show_loading_popup(void* context, bool show) {
239226int32_t nfc_app (void * p ) {
240227 if (!furi_hal_nfc_is_init ()) {
241228 // No connection to the chip, show an error screen
242- Nfc * nfc = nfc_min_alloc ();
243- view_dispatcher_attach_to_gui (
244- nfc -> view_dispatcher , nfc -> gui , ViewDispatcherTypeFullscreen );
245- scene_manager_next_scene (nfc -> scene_manager , NfcSceneNotInit );
246- view_dispatcher_run (nfc -> view_dispatcher );
247-
248- nfc_min_free (nfc );
249-
229+ DialogsApp * dialogs = furi_record_open (RECORD_DIALOGS );
230+ DialogMessage * message = dialog_message_alloc ();
231+ dialog_message_set_text (
232+ message ,
233+ "Error!\nNFC chip failed to start\n\n\nSend a photo of this to:\[email protected] " ,
234+ 0 ,
235+ 0 ,
236+ AlignLeft ,
237+ AlignTop );
238+ dialog_message_show (dialogs , message );
250239 return 0 ;
251240 }
252241
0 commit comments