mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-21 05:04:46 -07:00
* feat(Desktop): Directories support for keybinds - Adds *RIGHT* button select in the file browser dialogs and changing the `Open File` action to `Open File/Directory` in `Settings > Desktop > Keybinds Setup`. This adds the ability to open to any directory in the Archive app, in addition to the default behavior of opening a file in it's default app. * line order mixup * Main Menu: Allow adding JS files (or any file) - Normal files and directories are now able to be added to then main menu and are run in their appropriate apps. - e.g. .txt files shown in text viewer, .js files are run in the JS Runner app, and folders are navigated to by the Archive app. All similar to the desktop keybinds functionality. - Icons are also assigned appropriately based on the extensions, though more could probably be added to the `loader_menu_get_ext_icon` function. - Also replaced some of the long arduous is_dir checks and just used the `storage_dir_exists` function since its already there and does the same. * should be checking `ext` for NULL * Move select_right at end of structs for binary compatibility apps may blindly reach into these structs so need to keep the basics in same structure for DialogsFileBrowserOptions this is even in public api and after compilation this would be incompatible with other firmwares even without reaching into private structs * Select menu item / folder for directories too * Move api below too * Keep ofw order here too * Refactor starting archive into desktop, less FuriString passing around * Dont leave main menu when launching archive * Simplify/fix a few things * Handle folders in run_with_default_app() * Update App -> Item naming in MNTM settings * Fix build * Explain pressing right * Update changelog --------- Co-authored-by: WillyJL <me@willyjl.dev>
166 lines
5.5 KiB
C
166 lines
5.5 KiB
C
#include <furi.h>
|
|
#include <furi_hal.h>
|
|
#include <applications.h>
|
|
#include <assets_icons.h>
|
|
#include <loader/loader.h>
|
|
#include <toolbox/run_parallel.h>
|
|
|
|
#include "../desktop_i.h"
|
|
#include "../views/desktop_events.h"
|
|
#include "../views/desktop_view_main.h"
|
|
#include "desktop_scene.h"
|
|
|
|
#define TAG "DesktopSrv"
|
|
|
|
static void desktop_scene_main_new_idle_animation_callback(void* context) {
|
|
furi_assert(context);
|
|
Desktop* desktop = context;
|
|
view_dispatcher_send_custom_event(
|
|
desktop->view_dispatcher, DesktopAnimationEventNewIdleAnimation);
|
|
}
|
|
|
|
static void desktop_scene_main_check_animation_callback(void* context) {
|
|
furi_assert(context);
|
|
Desktop* desktop = context;
|
|
view_dispatcher_send_custom_event(
|
|
desktop->view_dispatcher, DesktopAnimationEventCheckAnimation);
|
|
}
|
|
|
|
static void desktop_scene_main_interact_animation_callback(void* context) {
|
|
furi_assert(context);
|
|
Desktop* desktop = context;
|
|
view_dispatcher_send_custom_event(
|
|
desktop->view_dispatcher, DesktopAnimationEventInteractAnimation);
|
|
}
|
|
|
|
#ifdef APP_ARCHIVE
|
|
static void desktop_switch_to_app(
|
|
Desktop* desktop,
|
|
const FlipperInternalApplication* flipper_app,
|
|
void* context) {
|
|
furi_assert(desktop);
|
|
furi_assert(flipper_app);
|
|
furi_assert(flipper_app->app);
|
|
furi_assert(flipper_app->name);
|
|
|
|
if(furi_thread_get_state(desktop->scene_thread) != FuriThreadStateStopped) {
|
|
FURI_LOG_E("Desktop", "Thread is already running");
|
|
return;
|
|
}
|
|
|
|
FuriHalRtcHeapTrackMode mode = furi_hal_rtc_get_heap_track_mode();
|
|
if(mode > FuriHalRtcHeapTrackModeNone) {
|
|
furi_thread_enable_heap_trace(desktop->scene_thread);
|
|
} else {
|
|
furi_thread_disable_heap_trace(desktop->scene_thread);
|
|
}
|
|
|
|
furi_thread_set_name(desktop->scene_thread, flipper_app->name);
|
|
furi_thread_set_stack_size(desktop->scene_thread, flipper_app->stack_size);
|
|
furi_thread_set_callback(desktop->scene_thread, flipper_app->app);
|
|
furi_thread_set_context(desktop->scene_thread, context);
|
|
|
|
furi_thread_start(desktop->scene_thread);
|
|
}
|
|
#endif
|
|
|
|
void desktop_scene_main_callback(DesktopEvent event, void* context) {
|
|
Desktop* desktop = (Desktop*)context;
|
|
if(desktop->in_transition) return;
|
|
view_dispatcher_send_custom_event(desktop->view_dispatcher, event);
|
|
}
|
|
|
|
void desktop_scene_main_on_enter(void* context) {
|
|
Desktop* desktop = (Desktop*)context;
|
|
DesktopMainView* main_view = desktop->main_view;
|
|
|
|
animation_manager_set_context(desktop->animation_manager, desktop);
|
|
animation_manager_set_new_idle_callback(
|
|
desktop->animation_manager, desktop_scene_main_new_idle_animation_callback);
|
|
animation_manager_set_check_callback(
|
|
desktop->animation_manager, desktop_scene_main_check_animation_callback);
|
|
animation_manager_set_interact_callback(
|
|
desktop->animation_manager, desktop_scene_main_interact_animation_callback);
|
|
|
|
desktop_main_set_callback(main_view, desktop_scene_main_callback, desktop);
|
|
|
|
view_dispatcher_switch_to_view(desktop->view_dispatcher, DesktopViewIdMain);
|
|
}
|
|
|
|
bool desktop_scene_main_on_event(void* context, SceneManagerEvent event) {
|
|
Desktop* desktop = (Desktop*)context;
|
|
bool consumed = false;
|
|
|
|
if(event.type == SceneManagerEventTypeCustom) {
|
|
switch(event.event) {
|
|
case DesktopMainEventOpenMenu: {
|
|
Loader* loader = furi_record_open(RECORD_LOADER);
|
|
loader_show_menu(loader);
|
|
furi_record_close(RECORD_LOADER);
|
|
consumed = true;
|
|
} break;
|
|
|
|
case DesktopMainEventLockKeypad:
|
|
desktop_lock(desktop, false);
|
|
consumed = true;
|
|
break;
|
|
|
|
case DesktopMainEventLockWithPin:
|
|
desktop_lock(desktop, true);
|
|
consumed = true;
|
|
break;
|
|
|
|
case DesktopMainEventOpenLockMenu:
|
|
scene_manager_next_scene(desktop->scene_manager, DesktopSceneLockMenu);
|
|
consumed = true;
|
|
break;
|
|
|
|
case DesktopMainEventOpenArchive:
|
|
#ifdef APP_ARCHIVE
|
|
desktop_switch_to_app(desktop, &FLIPPER_ARCHIVE, desktop->archive_dir);
|
|
#endif
|
|
consumed = true;
|
|
break;
|
|
|
|
case DesktopMainEventOpenPowerOff: {
|
|
// Workaround for shutdown when app can't be opened
|
|
run_parallel(desktop_shutdown, desktop, 512);
|
|
consumed = true;
|
|
break;
|
|
}
|
|
case DesktopAnimationEventCheckAnimation:
|
|
animation_manager_check_blocking_process(desktop->animation_manager);
|
|
consumed = true;
|
|
break;
|
|
case DesktopAnimationEventNewIdleAnimation:
|
|
animation_manager_new_idle_process(desktop->animation_manager);
|
|
consumed = true;
|
|
break;
|
|
case DesktopAnimationEventInteractAnimation:
|
|
if(!animation_manager_interact_process(desktop->animation_manager)) {
|
|
desktop_run_keybind(desktop, InputTypeShort, InputKeyRight);
|
|
}
|
|
consumed = true;
|
|
break;
|
|
case DesktopLockedEventUpdate:
|
|
desktop_view_locked_update(desktop->locked_view);
|
|
consumed = true;
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
return consumed;
|
|
}
|
|
|
|
void desktop_scene_main_on_exit(void* context) {
|
|
Desktop* desktop = (Desktop*)context;
|
|
|
|
animation_manager_set_new_idle_callback(desktop->animation_manager, NULL);
|
|
animation_manager_set_check_callback(desktop->animation_manager, NULL);
|
|
animation_manager_set_interact_callback(desktop->animation_manager, NULL);
|
|
animation_manager_set_context(desktop->animation_manager, desktop);
|
|
}
|