[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;
|
||||
TextInput* text_input;
|
||||
Widget* widget;
|
||||
FuriPubSubSubscription* loader_stop_subscription;
|
||||
char text_store[MAX_NAME_LEN];
|
||||
char file_extension[MAX_EXT_LEN + 1];
|
||||
};
|
||||
|
@ -77,6 +77,7 @@ void archive_set_item_count(ArchiveBrowserView* browser, uint32_t count) {
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
model->item_cnt = count;
|
||||
model->item_idx = CLAMP(model->item_idx, model->item_cnt - 1, 0);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
@ -397,6 +398,7 @@ void archive_enter_dir(ArchiveBrowserView* browser, string_t name) {
|
||||
|
||||
archive_dir_count_items(browser, string_get_cstr(name));
|
||||
|
||||
if(string_cmp(browser->path, name) != 0) {
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
idx_last_array_push_back(model->idx_last, model->item_idx);
|
||||
@ -406,6 +408,7 @@ void archive_enter_dir(ArchiveBrowserView* browser, string_t name) {
|
||||
});
|
||||
|
||||
string_set(browser->path, name);
|
||||
}
|
||||
|
||||
archive_switch_dir(browser, string_get_cstr(browser->path));
|
||||
}
|
||||
|
@ -18,6 +18,18 @@ static const char* flipper_app_name[] = {
|
||||
[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) {
|
||||
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_update_focus(browser, archive->text_store);
|
||||
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) {
|
||||
@ -147,11 +164,25 @@ bool archive_scene_browser_on_event(void* context, SceneManagerEvent event) {
|
||||
archive_file_array_load(archive->browser, 1);
|
||||
consumed = true;
|
||||
break;
|
||||
case ArchiveBrowserEventLoaderAppExit:
|
||||
if(!favorites) {
|
||||
archive_enter_dir(browser, browser->path);
|
||||
} else {
|
||||
archive_favorites_read(browser);
|
||||
}
|
||||
|
||||
consumed = true;
|
||||
break;
|
||||
|
||||
case ArchiveBrowserEventExit:
|
||||
if(archive_get_depth(browser)) {
|
||||
archive_leave_dir(browser);
|
||||
} 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);
|
||||
}
|
||||
consumed = true;
|
||||
@ -165,5 +196,9 @@ bool archive_scene_browser_on_event(void* context, SceneManagerEvent event) {
|
||||
}
|
||||
|
||||
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,
|
||||
ArchiveBrowserEventLoadNextItems,
|
||||
|
||||
ArchiveBrowserEventLoaderAppExit,
|
||||
|
||||
ArchiveBrowserEventExit,
|
||||
} ArchiveBrowserEvent;
|
||||
|
||||
@ -72,7 +74,6 @@ struct ArchiveBrowserView {
|
||||
View* view;
|
||||
ArchiveBrowserViewCallback callback;
|
||||
void* context;
|
||||
|
||||
string_t path;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user