Skip to content

Commit

Permalink
Add start menu to mass storage
Browse files Browse the repository at this point in the history
  • Loading branch information
Willy-JL committed Aug 2, 2023
1 parent c4e2dba commit 01690e2
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 6 deletions.
8 changes: 7 additions & 1 deletion applications/external/mass_storage/mass_storage_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,16 @@ MassStorageApp* mass_storage_app_alloc(char* arg) {
MassStorageAppViewWork,
mass_storage_get_view(app->mass_storage_view));

app->submenu = submenu_alloc();
view_dispatcher_add_view(
app->view_dispatcher, MassStorageAppViewSubmenu, submenu_get_view(app->submenu));

view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);

if(storage_file_exists(app->fs_api, furi_string_get_cstr(app->file_path))) {
scene_manager_next_scene(app->scene_manager, MassStorageSceneWork);
} else {
scene_manager_next_scene(app->scene_manager, MassStorageSceneFileSelect);
scene_manager_next_scene(app->scene_manager, MassStorageSceneStart);
}

return app;
Expand All @@ -72,6 +76,8 @@ void mass_storage_app_free(MassStorageApp* app) {
// Views
view_dispatcher_remove_view(app->view_dispatcher, MassStorageAppViewWork);
mass_storage_free(app->mass_storage_view);
view_dispatcher_remove_view(app->view_dispatcher, MassStorageAppViewSubmenu);
submenu_free(app->submenu);

// View dispatcher
view_dispatcher_free(app->view_dispatcher);
Expand Down
5 changes: 3 additions & 2 deletions applications/external/mass_storage/mass_storage_app_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
#include <gui/gui.h>
#include <gui/view_dispatcher.h>
#include <gui/scene_manager.h>
#include <gui/modules/submenu.h>
#include <dialogs/dialogs.h>
#include <notification/notification_messages.h>
#include <gui/modules/variable_item_list.h>
#include <gui/modules/widget.h>
#include <gui/modules/submenu.h>
#include <storage/storage.h>
#include "views/mass_storage_view.h"

Expand All @@ -27,6 +26,7 @@ struct MassStorageApp {
NotificationApp* notifications;
DialogsApp* dialogs;
Widget* widget;
Submenu* submenu;

FuriString* file_path;
File* file;
Expand All @@ -39,4 +39,5 @@ struct MassStorageApp {
typedef enum {
MassStorageAppViewError,
MassStorageAppViewWork,
MassStorageAppViewSubmenu,
} MassStorageAppView;
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
ADD_SCENE(mass_storage, start, Start)
ADD_SCENE(mass_storage, file_select, FileSelect)
ADD_SCENE(mass_storage, work, Work)
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,15 @@ void mass_storage_scene_file_select_on_enter(void* context) {
scene_manager_next_scene(mass_storage->scene_manager, MassStorageSceneWork);
} else {
scene_manager_previous_scene(mass_storage->scene_manager);
view_dispatcher_stop(mass_storage->view_dispatcher);
}
}

bool mass_storage_scene_file_select_on_event(void* context, SceneManagerEvent event) {
UNUSED(context);
UNUSED(event);
// MassStorageApp* mass_storage = context;
return false;
}

void mass_storage_scene_file_select_on_exit(void* context) {
UNUSED(context);
// MassStorageApp* mass_storage = context;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "../mass_storage_app_i.h"

static void mass_storage_scene_start_submenu_callback(void* context, uint32_t index) {
MassStorageApp* app = context;
scene_manager_next_scene(app->scene_manager, index);
}

void mass_storage_scene_start_on_enter(void* context) {
MassStorageApp* app = context;
Submenu* submenu = app->submenu;

submenu_add_item(
submenu,
"Emulate Image",
MassStorageSceneFileSelect,
mass_storage_scene_start_submenu_callback,
app);

submenu_set_header(submenu, "USB Mass Storage");

view_dispatcher_switch_to_view(app->view_dispatcher, MassStorageAppViewSubmenu);
}

bool mass_storage_scene_start_on_event(void* context, SceneManagerEvent event) {
UNUSED(context);
bool consumed = false;

if(event.type == SceneManagerEventTypeCustom) {
consumed = true;
}

return consumed;
}

void mass_storage_scene_start_on_exit(void* context) {
MassStorageApp* app = context;
submenu_reset(app->submenu);
}

0 comments on commit 01690e2

Please sign in to comment.