[FL-2495] Archive: Refresh file list on application exit #1170
Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
		
							parent
							
								
									2034b6ac4a
								
							
						
					
					
						commit
						19f42c5290
					
				| @ -27,6 +27,7 @@ struct ArchiveApp { | |||||||
|     ArchiveBrowserView* browser; |     ArchiveBrowserView* browser; | ||||||
|     TextInput* text_input; |     TextInput* text_input; | ||||||
|     Widget* widget; |     Widget* widget; | ||||||
|  |     FuriPubSubSubscription* loader_stop_subscription; | ||||||
|     char text_store[MAX_NAME_LEN]; |     char text_store[MAX_NAME_LEN]; | ||||||
|     char file_extension[MAX_EXT_LEN + 1]; |     char file_extension[MAX_EXT_LEN + 1]; | ||||||
| }; | }; | ||||||
|  | |||||||
| @ -77,6 +77,7 @@ void archive_set_item_count(ArchiveBrowserView* browser, uint32_t count) { | |||||||
|     with_view_model( |     with_view_model( | ||||||
|         browser->view, (ArchiveBrowserViewModel * model) { |         browser->view, (ArchiveBrowserViewModel * model) { | ||||||
|             model->item_cnt = count; |             model->item_cnt = count; | ||||||
|  |             model->item_idx = CLAMP(model->item_idx, model->item_cnt - 1, 0); | ||||||
|             return false; |             return false; | ||||||
|         }); |         }); | ||||||
| } | } | ||||||
| @ -397,15 +398,17 @@ void archive_enter_dir(ArchiveBrowserView* browser, string_t name) { | |||||||
| 
 | 
 | ||||||
|     archive_dir_count_items(browser, string_get_cstr(name)); |     archive_dir_count_items(browser, string_get_cstr(name)); | ||||||
| 
 | 
 | ||||||
|     with_view_model( |     if(string_cmp(browser->path, name) != 0) { | ||||||
|         browser->view, (ArchiveBrowserViewModel * model) { |         with_view_model( | ||||||
|             idx_last_array_push_back(model->idx_last, model->item_idx); |             browser->view, (ArchiveBrowserViewModel * model) { | ||||||
|             model->array_offset = 0; |                 idx_last_array_push_back(model->idx_last, model->item_idx); | ||||||
|             model->item_idx = 0; |                 model->array_offset = 0; | ||||||
|             return false; |                 model->item_idx = 0; | ||||||
|         }); |                 return false; | ||||||
|  |             }); | ||||||
| 
 | 
 | ||||||
|     string_set(browser->path, name); |         string_set(browser->path, name); | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     archive_switch_dir(browser, string_get_cstr(browser->path)); |     archive_switch_dir(browser, string_get_cstr(browser->path)); | ||||||
| } | } | ||||||
|  | |||||||
| @ -18,6 +18,18 @@ static const char* flipper_app_name[] = { | |||||||
|     [ArchiveFileTypeUpdateManifest] = "UpdaterApp", |     [ArchiveFileTypeUpdateManifest] = "UpdaterApp", | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | static void archive_loader_callback(const void* message, void* context) { | ||||||
|  |     furi_assert(message); | ||||||
|  |     furi_assert(context); | ||||||
|  |     const LoaderEvent* event = message; | ||||||
|  |     ArchiveApp* archive = (ArchiveApp*)context; | ||||||
|  | 
 | ||||||
|  |     if(event->type == LoaderEventTypeApplicationStopped) { | ||||||
|  |         view_dispatcher_send_custom_event( | ||||||
|  |             archive->view_dispatcher, ArchiveBrowserEventLoaderAppExit); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| static void archive_run_in_app(ArchiveBrowserView* browser, ArchiveFile_t* selected) { | static void archive_run_in_app(ArchiveBrowserView* browser, ArchiveFile_t* selected) { | ||||||
|     Loader* loader = furi_record_open("loader"); |     Loader* loader = furi_record_open("loader"); | ||||||
| 
 | 
 | ||||||
| @ -52,6 +64,11 @@ void archive_scene_browser_on_enter(void* context) { | |||||||
|     archive_browser_set_callback(browser, archive_scene_browser_callback, archive); |     archive_browser_set_callback(browser, archive_scene_browser_callback, archive); | ||||||
|     archive_update_focus(browser, archive->text_store); |     archive_update_focus(browser, archive->text_store); | ||||||
|     view_dispatcher_switch_to_view(archive->view_dispatcher, ArchiveViewBrowser); |     view_dispatcher_switch_to_view(archive->view_dispatcher, ArchiveViewBrowser); | ||||||
|  | 
 | ||||||
|  |     Loader* loader = furi_record_open("loader"); | ||||||
|  |     archive->loader_stop_subscription = | ||||||
|  |         furi_pubsub_subscribe(loader_get_pubsub(loader), archive_loader_callback, archive); | ||||||
|  |     furi_record_close("loader"); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| bool archive_scene_browser_on_event(void* context, SceneManagerEvent event) { | bool archive_scene_browser_on_event(void* context, SceneManagerEvent event) { | ||||||
| @ -147,11 +164,25 @@ bool archive_scene_browser_on_event(void* context, SceneManagerEvent event) { | |||||||
|             archive_file_array_load(archive->browser, 1); |             archive_file_array_load(archive->browser, 1); | ||||||
|             consumed = true; |             consumed = true; | ||||||
|             break; |             break; | ||||||
|  |         case ArchiveBrowserEventLoaderAppExit: | ||||||
|  |             if(!favorites) { | ||||||
|  |                 archive_enter_dir(browser, browser->path); | ||||||
|  |             } else { | ||||||
|  |                 archive_favorites_read(browser); | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             consumed = true; | ||||||
|  |             break; | ||||||
| 
 | 
 | ||||||
|         case ArchiveBrowserEventExit: |         case ArchiveBrowserEventExit: | ||||||
|             if(archive_get_depth(browser)) { |             if(archive_get_depth(browser)) { | ||||||
|                 archive_leave_dir(browser); |                 archive_leave_dir(browser); | ||||||
|             } else { |             } else { | ||||||
|  |                 Loader* loader = furi_record_open("loader"); | ||||||
|  |                 furi_pubsub_unsubscribe( | ||||||
|  |                     loader_get_pubsub(loader), archive->loader_stop_subscription); | ||||||
|  |                 furi_record_close("loader"); | ||||||
|  | 
 | ||||||
|                 view_dispatcher_stop(archive->view_dispatcher); |                 view_dispatcher_stop(archive->view_dispatcher); | ||||||
|             } |             } | ||||||
|             consumed = true; |             consumed = true; | ||||||
| @ -165,5 +196,9 @@ bool archive_scene_browser_on_event(void* context, SceneManagerEvent event) { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void archive_scene_browser_on_exit(void* context) { | void archive_scene_browser_on_exit(void* context) { | ||||||
|     // ArchiveApp* archive = (ArchiveApp*)context;
 |     ArchiveApp* archive = (ArchiveApp*)context; | ||||||
|  | 
 | ||||||
|  |     Loader* loader = furi_record_open("loader"); | ||||||
|  |     furi_pubsub_unsubscribe(loader_get_pubsub(loader), archive->loader_stop_subscription); | ||||||
|  |     furi_record_close("loader"); | ||||||
| } | } | ||||||
|  | |||||||
| @ -48,6 +48,8 @@ typedef enum { | |||||||
|     ArchiveBrowserEventLoadPrevItems, |     ArchiveBrowserEventLoadPrevItems, | ||||||
|     ArchiveBrowserEventLoadNextItems, |     ArchiveBrowserEventLoadNextItems, | ||||||
| 
 | 
 | ||||||
|  |     ArchiveBrowserEventLoaderAppExit, | ||||||
|  | 
 | ||||||
|     ArchiveBrowserEventExit, |     ArchiveBrowserEventExit, | ||||||
| } ArchiveBrowserEvent; | } ArchiveBrowserEvent; | ||||||
| 
 | 
 | ||||||
| @ -72,7 +74,6 @@ struct ArchiveBrowserView { | |||||||
|     View* view; |     View* view; | ||||||
|     ArchiveBrowserViewCallback callback; |     ArchiveBrowserViewCallback callback; | ||||||
|     void* context; |     void* context; | ||||||
| 
 |  | ||||||
|     string_t path; |     string_t path; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Nikolay Minaylov
						Nikolay Minaylov