xremote_app.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*!
  2. * @file flipper-xremote/xremote_app.h
  3. @license This project is released under the GNU GPLv3 License
  4. * @copyright (c) 2023 Sandro Kalatozishvili (s.kalatoz@gmail.com)
  5. *
  6. * @brief Shared functionality and data types between the apps.
  7. */
  8. #pragma once
  9. #include <furi.h>
  10. #include <gui/gui.h>
  11. #include <gui/view.h>
  12. #include <gui/view_dispatcher.h>
  13. #include <gui/modules/submenu.h>
  14. #include <gui/modules/dialog_ex.h>
  15. #include <gui/modules/variable_item_list.h>
  16. #include <notification/notification.h>
  17. #include <notification/notification_messages.h>
  18. #include <flipper_format/flipper_format.h>
  19. #include <storage/storage.h>
  20. #include <dialogs/dialogs.h>
  21. #include "views/xremote_common_view.h"
  22. #include "xc_icons.h"
  23. #define XREMOTE_APP_EXTENSION ".ir"
  24. #define XREMOTE_APP_FOLDER ANY_PATH("infrared")
  25. #define xremote_app_assert_void(cond) if (!cond) return
  26. #define xremote_app_assert(cond, var) if (!cond) return var
  27. typedef enum {
  28. XRemoteAppExitPress,
  29. XRemoteAppExitHold
  30. } XRemoteAppExit;
  31. typedef struct {
  32. ViewOrientation orientation;
  33. XRemoteAppExit exit_behavior;
  34. uint32_t repeat_count;
  35. } XRemoteAppSettings;
  36. XRemoteAppSettings* xremote_app_settings_alloc();
  37. void xremote_app_settings_free(XRemoteAppSettings* settings);
  38. bool xremote_app_settings_store(XRemoteAppSettings* settings);
  39. bool xremote_app_settings_load(XRemoteAppSettings* settings);
  40. typedef struct {
  41. XRemoteAppSettings* app_settings;
  42. NotificationApp* notifications;
  43. ViewDispatcher* view_dispatcher;
  44. FuriString* file_path;
  45. void* app_argument;
  46. Gui* gui;
  47. } XRemoteAppContext;
  48. XRemoteAppContext* xremote_app_context_alloc(void* arg);
  49. void xremote_app_context_free(XRemoteAppContext* ctx);
  50. const char* xremote_app_context_get_exit_str(XRemoteAppContext* ctx);
  51. typedef XRemoteView* (*XRemoteViewAllocator)(void* app_ctx);
  52. typedef void (*XRemoteAppClearCallback)(void *context);
  53. typedef struct {
  54. XRemoteAppClearCallback on_clear;
  55. XRemoteAppContext* app_ctx;
  56. XRemoteViewID submenu_id;
  57. XRemoteViewID view_id;
  58. XRemoteView* view_ctx;
  59. Submenu* submenu;
  60. void *context;
  61. } XRemoteApp;
  62. void xremote_app_submenu_add(XRemoteApp* app, const char *name, uint32_t index, SubmenuItemCallback callback);
  63. void xremote_app_submenu_alloc(XRemoteApp* app, uint32_t index, ViewNavigationCallback prev_cb);
  64. void xremote_app_submenu_free(XRemoteApp *app);
  65. void xremote_app_view_alloc(XRemoteApp *app, uint32_t view_id, XRemoteViewAllocator allocator);
  66. void xremote_app_view_free(XRemoteApp* app);
  67. void xremote_app_view_set_previous_callback(XRemoteApp* app, ViewNavigationCallback callback);
  68. void xremote_app_set_view_context(XRemoteApp* app, void *context, XRemoteViewClearCallback on_clear);
  69. void xremote_app_set_user_context(XRemoteApp* app, void *context, XRemoteAppClearCallback on_clear);
  70. void xremote_app_user_context_free(XRemoteApp* app);
  71. bool xremote_app_has_view(XRemoteApp *app, uint32_t view_id);
  72. void xremote_app_switch_to_view(XRemoteApp *app, uint32_t view_id);
  73. void xremote_app_switch_to_submenu(XRemoteApp *app);
  74. XRemoteApp* xremote_app_alloc(XRemoteAppContext *ctx);
  75. void xremote_app_free(XRemoteApp* app);