Skip to content

Commit 1cfcb85

Browse files
Nycz-labNikIsHerebigbrodude6119
authored
added dialogue for selecting a portal (#41)
* added dialogue for selecting a portal * default formatting * allow seeing current logs without portal reset * format --------- Co-authored-by: NIK\nickw <nyczdesignz@gmail.com> Co-authored-by: bigbrodude6119 <138256922+bigbrodude6119@users.noreply.github.com>
1 parent b5adc38 commit 1cfcb85

File tree

5 files changed

+70
-22
lines changed

5 files changed

+70
-22
lines changed

flipper/flipper-evil-portal/evil_portal_app.c

+6-5
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ Evil_PortalApp *evil_portal_app_alloc() {
2929
app->sent_html = false;
3030
app->sent_ap = false;
3131
app->sent_reset = false;
32-
app->has_command_queue = false;
32+
app->has_command_queue = false;
3333
app->command_index = 0;
3434
app->portal_logs = furi_string_alloc();
3535

3636
app->gui = furi_record_open(RECORD_GUI);
37+
app->dialogs = furi_record_open(RECORD_DIALOGS);
3738

3839
app->view_dispatcher = view_dispatcher_alloc();
3940
app->scene_manager = scene_manager_alloc(&evil_portal_scene_handlers, app);
@@ -70,8 +71,7 @@ Evil_PortalApp *evil_portal_app_alloc() {
7071
return app;
7172
}
7273

73-
void evil_portal_app_free(Evil_PortalApp *app) {
74-
74+
void evil_portal_app_free(Evil_PortalApp *app) {
7575
// save latest logs
7676
if (furi_string_utf8_length(app->portal_logs) > 0) {
7777
write_logs(app->portal_logs);
@@ -101,17 +101,18 @@ void evil_portal_app_free(Evil_PortalApp *app) {
101101

102102
// Close records
103103
furi_record_close(RECORD_GUI);
104+
furi_record_close(RECORD_DIALOGS);
104105

105106
free(app);
106107
}
107108

108-
int32_t evil_portal_app(void *p) {
109+
int32_t evil_portal_app(void *p) {
109110
UNUSED(p);
110111
Evil_PortalApp *evil_portal_app = evil_portal_app_alloc();
111112

112113
evil_portal_app->uart = evil_portal_uart_init(evil_portal_app);
113114

114-
view_dispatcher_run(evil_portal_app->view_dispatcher);
115+
view_dispatcher_run(evil_portal_app->view_dispatcher);
115116

116117
evil_portal_app_free(evil_portal_app);
117118

flipper/flipper-evil-portal/evil_portal_app_i.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
#include <gui/scene_manager.h>
1212
#include <gui/view_dispatcher.h>
1313

14+
#include <assets_icons.h>
15+
#include <dialogs/dialogs.h>
16+
1417
#define NUM_MENU_ITEMS (4)
1518

1619
#define EVIL_PORTAL_TEXT_BOX_STORE_SIZE (4096)
@@ -20,12 +23,16 @@
2023
#define SET_AP_CMD "setap"
2124
#define RESET_CMD "reset"
2225

26+
#define EVIL_PORTAL_INDEX_EXTENSION ".html"
27+
#define EVIL_PORTAL_BASE_FOLDER "/apps_data/evil_portal/"
28+
2329
struct Evil_PortalApp {
2430
Gui *gui;
2531
ViewDispatcher *view_dispatcher;
2632
SceneManager *scene_manager;
33+
DialogsApp *dialogs;
2734

28-
FuriString* portal_logs;
35+
FuriString *portal_logs;
2936
const char *command_queue[1];
3037
int command_index;
3138
bool has_command_queue;

flipper/flipper-evil-portal/helpers/evil_portal_storage.c

+23-5
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,32 @@ static Storage *evil_portal_open_storage() {
66

77
static void evil_portal_close_storage() { furi_record_close(RECORD_STORAGE); }
88

9-
void evil_portal_read_index_html(void *context) {
9+
bool evil_portal_read_index_html(void *context) {
10+
FuriString *file_path = furi_string_alloc();
11+
12+
DialogsFileBrowserOptions browser_options;
13+
dialog_file_browser_set_basic_options(&browser_options,
14+
EVIL_PORTAL_INDEX_EXTENSION,
15+
NULL); // TODO configure icon
16+
browser_options.base_path = EVIL_PORTAL_BASE_FOLDER;
1017

1118
Evil_PortalApp *app = context;
19+
bool res = dialog_file_browser_show(app->dialogs, file_path, file_path,
20+
&browser_options);
21+
22+
if (!res) {
23+
furi_string_free(file_path);
24+
return false;
25+
}
26+
1227
Storage *storage = evil_portal_open_storage();
1328
FileInfo fi;
1429

15-
if (storage_common_stat(storage, EVIL_PORTAL_INDEX_SAVE_PATH, &fi) ==
30+
if (storage_common_stat(storage, furi_string_get_cstr(file_path), &fi) ==
1631
FSE_OK) {
1732
File *index_html = storage_file_alloc(storage);
18-
if (storage_file_open(index_html, EVIL_PORTAL_INDEX_SAVE_PATH, FSAM_READ,
19-
FSOM_OPEN_EXISTING)) {
33+
if (storage_file_open(index_html, furi_string_get_cstr(file_path),
34+
FSAM_READ, FSOM_OPEN_EXISTING)) {
2035
app->index_html = malloc((size_t)fi.size);
2136
uint8_t *buf_ptr = app->index_html;
2237
size_t read = 0;
@@ -31,6 +46,7 @@ void evil_portal_read_index_html(void *context) {
3146
}
3247
free(buf_ptr);
3348
}
49+
furi_string_free(file_path);
3450
storage_file_close(index_html);
3551
storage_file_free(index_html);
3652
} else {
@@ -43,6 +59,7 @@ void evil_portal_read_index_html(void *context) {
4359
}
4460

4561
evil_portal_close_storage();
62+
return true;
4663
}
4764

4865
void evil_portal_read_ap_name(void *context) {
@@ -110,7 +127,8 @@ void write_logs(FuriString *portal_logs) {
110127
File *file = storage_file_alloc(storage);
111128

112129
if (storage_file_open(file, seq_file_path, FSAM_WRITE, FSOM_CREATE_ALWAYS)) {
113-
storage_file_write(file, furi_string_get_cstr(portal_logs), furi_string_utf8_length(portal_logs));
130+
storage_file_write(file, furi_string_get_cstr(portal_logs),
131+
furi_string_utf8_length(portal_logs));
114132
}
115133
storage_file_close(file);
116134
storage_file_free(file);

flipper/flipper-evil-portal/helpers/evil_portal_storage.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "../evil_portal_app_i.h"
2+
#include <dialogs/dialogs.h>
23
#include <flipper_format/flipper_format_i.h>
34
#include <lib/toolbox/stream/file_stream.h>
45
#include <stdlib.h>
@@ -10,8 +11,8 @@
1011
#define EVIL_PORTAL_AP_SAVE_PATH PORTAL_FILE_DIRECTORY_PATH "/ap.config.txt"
1112
#define EVIL_PORTAL_LOG_SAVE_PATH PORTAL_FILE_DIRECTORY_PATH "/logs"
1213

13-
void evil_portal_read_index_html(void *context);
14+
bool evil_portal_read_index_html(void *context);
1415
void evil_portal_read_ap_name(void *context);
15-
void write_logs(FuriString* portal_logs);
16+
void write_logs(FuriString *portal_logs);
1617
char *sequential_file_resolve_path(Storage *storage, const char *dir,
1718
const char *prefix, const char *extension);

flipper/flipper-evil-portal/scenes/evil_portal_scene_console_output.c

+30-9
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ void evil_portal_console_output_handle_rx_data_cb(uint8_t *buf, size_t len,
2424
void evil_portal_scene_console_output_on_enter(void *context) {
2525
Evil_PortalApp *app = context;
2626

27+
bool portal_file_set = false;
28+
2729
TextBox *text_box = app->text_box;
2830
text_box_reset(app->text_box);
2931
text_box_set_font(text_box, TextBoxFontText);
@@ -67,14 +69,26 @@ void evil_portal_scene_console_output_on_enter(void *context) {
6769

6870
if (0 ==
6971
strncmp(SET_HTML_CMD, app->selected_tx_string, strlen(SET_HTML_CMD))) {
70-
app->command_queue[0] = SET_AP_CMD;
71-
app->has_command_queue = true;
72-
app->command_index = 0;
73-
if (app->show_stopscan_tip) {
74-
const char *msg =
75-
"Starting portal\nIf no response press\nBACK to return\n";
76-
furi_string_cat_str(app->text_box_store, msg);
77-
app->text_box_store_strlen += strlen(msg);
72+
73+
portal_file_set = evil_portal_read_index_html(context);
74+
75+
if (portal_file_set) {
76+
app->command_queue[0] = SET_AP_CMD;
77+
app->has_command_queue = true;
78+
app->command_index = 0;
79+
if (app->show_stopscan_tip) {
80+
const char *msg =
81+
"Starting portal\nIf no response press\nBACK to return\n";
82+
furi_string_cat_str(app->text_box_store, msg);
83+
app->text_box_store_strlen += strlen(msg);
84+
}
85+
} else {
86+
if (app->show_stopscan_tip) {
87+
const char *msg = "No portal selected\nShowing current logs\nPress "
88+
"BACK to return\n";
89+
furi_string_cat_str(app->text_box_store, msg);
90+
app->text_box_store_strlen += strlen(msg);
91+
}
7892
}
7993
}
8094

@@ -102,7 +116,14 @@ void evil_portal_scene_console_output_on_enter(void *context) {
102116
if (app->is_command && app->selected_tx_string) {
103117
if (0 ==
104118
strncmp(SET_HTML_CMD, app->selected_tx_string, strlen(SET_HTML_CMD))) {
105-
evil_portal_read_index_html(context);
119+
120+
if (!portal_file_set) {
121+
scene_manager_set_scene_state(app->scene_manager,
122+
Evil_PortalSceneConsoleOutput, 0);
123+
view_dispatcher_switch_to_view(app->view_dispatcher,
124+
Evil_PortalAppViewConsoleOutput);
125+
return;
126+
}
106127

107128
FuriString *data = furi_string_alloc();
108129
furi_string_cat(data, "sethtml=");

0 commit comments

Comments
 (0)