2021-11-26 16:53:51 +03:00
|
|
|
#include "../bad_usb_script.h"
|
|
|
|
#include "../bad_usb_app_i.h"
|
|
|
|
#include "../views/bad_usb_view.h"
|
2022-01-05 19:10:18 +03:00
|
|
|
#include "furi_hal.h"
|
2022-06-01 16:07:53 +03:00
|
|
|
#include "m-string.h"
|
|
|
|
#include "toolbox/path.h"
|
2021-11-26 16:53:51 +03:00
|
|
|
|
2022-08-03 20:20:49 +03:00
|
|
|
void bad_usb_scene_work_button_callback(InputKey key, void* context) {
|
2021-11-26 16:53:51 +03:00
|
|
|
furi_assert(context);
|
|
|
|
BadUsbApp* app = context;
|
2022-08-03 20:20:49 +03:00
|
|
|
view_dispatcher_send_custom_event(app->view_dispatcher, key);
|
2021-11-26 16:53:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool bad_usb_scene_work_on_event(void* context, SceneManagerEvent event) {
|
|
|
|
BadUsbApp* app = context;
|
|
|
|
bool consumed = false;
|
|
|
|
|
|
|
|
if(event.type == SceneManagerEventTypeCustom) {
|
2022-08-03 20:20:49 +03:00
|
|
|
if(event.event == InputKeyLeft) {
|
|
|
|
scene_manager_next_scene(app->scene_manager, BadUsbSceneConfig);
|
|
|
|
consumed = true;
|
|
|
|
} else if(event.event == InputKeyOk) {
|
|
|
|
bad_usb_script_toggle(app->bad_usb_script);
|
|
|
|
consumed = true;
|
|
|
|
}
|
2021-11-26 16:53:51 +03:00
|
|
|
} else if(event.type == SceneManagerEventTypeTick) {
|
|
|
|
bad_usb_set_state(app->bad_usb_view, bad_usb_script_get_state(app->bad_usb_script));
|
|
|
|
}
|
|
|
|
return consumed;
|
|
|
|
}
|
|
|
|
|
|
|
|
void bad_usb_scene_work_on_enter(void* context) {
|
|
|
|
BadUsbApp* app = context;
|
|
|
|
|
|
|
|
string_t file_name;
|
|
|
|
string_init(file_name);
|
2022-06-01 16:07:53 +03:00
|
|
|
path_extract_filename(app->file_path, file_name, true);
|
|
|
|
bad_usb_set_file_name(app->bad_usb_view, string_get_cstr(file_name));
|
2021-11-26 16:53:51 +03:00
|
|
|
string_clear(file_name);
|
|
|
|
|
2022-08-08 21:14:15 +03:00
|
|
|
string_t layout;
|
|
|
|
string_init(layout);
|
|
|
|
path_extract_filename(app->keyboard_layout, layout, true);
|
|
|
|
bad_usb_set_layout(app->bad_usb_view, string_get_cstr(layout));
|
|
|
|
string_clear(layout);
|
|
|
|
|
2021-11-26 16:53:51 +03:00
|
|
|
bad_usb_set_state(app->bad_usb_view, bad_usb_script_get_state(app->bad_usb_script));
|
|
|
|
|
2022-08-08 13:58:32 +03:00
|
|
|
// set app state - is executed from archive app
|
|
|
|
bad_usb_script_set_run_state(bad_usb_script_get_state(app->bad_usb_script), false);
|
|
|
|
|
2022-08-03 20:20:49 +03:00
|
|
|
bad_usb_set_button_callback(app->bad_usb_view, bad_usb_scene_work_button_callback, app);
|
2021-11-26 16:53:51 +03:00
|
|
|
view_dispatcher_switch_to_view(app->view_dispatcher, BadUsbAppViewWork);
|
|
|
|
}
|
|
|
|
|
|
|
|
void bad_usb_scene_work_on_exit(void* context) {
|
2022-08-03 20:20:49 +03:00
|
|
|
UNUSED(context);
|
2021-11-26 16:53:51 +03:00
|
|
|
}
|