Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/core/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,11 @@ int loopOptions(

// handleSerialCommands(); // always use serial task for it
#ifdef HAS_KEYBOARD
checkShortcutPress(); // shortctus to quickly start apps without navigating the menus
if (checkShortcutPress()) {
// Shortcut opened a submenu that drew over the screen; force full redraw
redraw = true;
drawMainBorder();
}
#endif

if (menuType == MENU_TYPE_REGULAR) {
Expand Down
11 changes: 7 additions & 4 deletions src/core/mykeyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,14 @@ keyStroke _getKeyPress() {
** location: mykeyboard.cpp
** runs a function called by the shortcut action
**********************************************************************/
void checkShortcutPress() {
bool checkShortcutPress() {
static JsonDocument shortcutsJson; // parsed only once
bool executed = false;

// lazy init
if (shortcutsJson.size() == 0) {
FS *fs;
if (!getFsStorage(fs)) return;
if (!getFsStorage(fs)) return false;
File file = fs->open("/shortcuts.json", FILE_READ);
if (!file) {
log_e("Shortcuts Config file not found. Using default values");
Expand All @@ -270,13 +271,13 @@ void checkShortcutPress() {
shortcuts["b"] = "loader open badusb";
shortcuts["w"] = "loader open webui";
shortcuts["f"] = "loader open files";
return;
return false;
}
// else
if (deserializeJson(shortcutsJson, file)) {
log_e("Failed to parse shortcuts.json");
file.close();
return;
return false;
}
file.close();
}
Expand All @@ -293,9 +294,11 @@ void checkShortcutPress() {
if (i == *shortcut_key) { // compare the 1st char of the key string
// execute the associated action
serialCli.parse(String(shortcut_value));
executed = true;
}
}
}
return executed;
}

/*********************************************************************
Expand Down
2 changes: 1 addition & 1 deletion src/core/mykeyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ keyStroke _getKeyPress(); // This function must be implemented in the interface.
// by using the flag HAS_KEYBOARD

// Core functions, depends on the implementation of the funtions above in the interface.h
void checkShortcutPress();
bool checkShortcutPress();
int checkNumberShortcutPress();
char checkLetterShortcutPress();