Skip to content

Commit

Permalink
[FL-2495] Archive: Refresh file list on application exit #1170
Browse files Browse the repository at this point in the history
Co-authored-by: あく <[email protected]>
  • Loading branch information
nminaylov and skotopes authored Apr 27, 2022
1 parent 2034b6a commit 19f42c5
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 10 deletions.
1 change: 1 addition & 0 deletions applications/archive/archive_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
};
19 changes: 11 additions & 8 deletions applications/archive/helpers/archive_browser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}
Expand Down Expand Up @@ -397,15 +398,17 @@ void archive_enter_dir(ArchiveBrowserView* browser, string_t name) {

archive_dir_count_items(browser, string_get_cstr(name));

with_view_model(
browser->view, (ArchiveBrowserViewModel * model) {
idx_last_array_push_back(model->idx_last, model->item_idx);
model->array_offset = 0;
model->item_idx = 0;
return false;
});
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);
model->array_offset = 0;
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));
}
Expand Down
37 changes: 36 additions & 1 deletion applications/archive/scenes/archive_scene_browser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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");
}
3 changes: 2 additions & 1 deletion applications/archive/views/archive_browser_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ typedef enum {
ArchiveBrowserEventLoadPrevItems,
ArchiveBrowserEventLoadNextItems,

ArchiveBrowserEventLoaderAppExit,

ArchiveBrowserEventExit,
} ArchiveBrowserEvent;

Expand All @@ -72,7 +74,6 @@ struct ArchiveBrowserView {
View* view;
ArchiveBrowserViewCallback callback;
void* context;

string_t path;
};

Expand Down

0 comments on commit 19f42c5

Please sign in to comment.