xremote_app.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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_assert_void(cond) if (!cond) return
  24. #define xremote_app_assert(cond, var) if (!cond) return var
  25. typedef enum {
  26. XRemoteAppExitPress,
  27. XRemoteAppExitHold
  28. } XRemoteAppExit;
  29. typedef struct {
  30. ViewOrientation orientation;
  31. XRemoteAppExit exit_behavior;
  32. uint32_t repeat_count;
  33. } XRemoteAppSettings;
  34. XRemoteAppSettings* xremote_app_settings_alloc();
  35. void xremote_app_settings_free(XRemoteAppSettings* settings);
  36. bool xremote_app_settings_store(XRemoteAppSettings* settings);
  37. bool xremote_app_settings_load(XRemoteAppSettings* settings);
  38. typedef struct {
  39. XRemoteAppSettings* app_settings;
  40. NotificationApp* notifications;
  41. ViewDispatcher* view_dispatcher;
  42. void* app_argument;
  43. Gui* gui;
  44. } XRemoteAppContext;
  45. XRemoteAppContext* xremote_app_context_alloc(void* arg);
  46. void xremote_app_context_free(XRemoteAppContext* ctx);
  47. const char* xremote_app_context_get_exit_str(XRemoteAppContext* ctx);
  48. typedef XRemoteView* (*XRemoteViewAllocator)(void* app_ctx);
  49. typedef void (*XRemoteAppClearCallback)(void *context);
  50. typedef struct {
  51. XRemoteAppClearCallback on_clear;
  52. XRemoteAppContext* app_ctx;
  53. XRemoteViewID submenu_id;
  54. XRemoteViewID view_id;
  55. XRemoteView* view_ctx;
  56. Submenu* submenu;
  57. void *context;
  58. } XRemoteApp;
  59. void xremote_app_submenu_add(XRemoteApp* app, const char *name, uint32_t index, SubmenuItemCallback callback);
  60. void xremote_app_submenu_alloc(XRemoteApp* app, uint32_t index, ViewNavigationCallback prev_cb);
  61. void xremote_app_submenu_free(XRemoteApp *app);
  62. void xremote_app_view_alloc(XRemoteApp *app, uint32_t view_id, XRemoteViewAllocator allocator);
  63. void xremote_app_view_free(XRemoteApp* app);
  64. void xremote_app_view_set_previous_callback(XRemoteApp* app, ViewNavigationCallback callback);
  65. void xremote_app_set_view_context(XRemoteApp* app, void *context, XRemoteViewClearCallback on_clear);
  66. void xremote_app_set_user_context(XRemoteApp* app, void *context, XRemoteAppClearCallback on_clear);
  67. void xremote_app_user_context_free(XRemoteApp* app);
  68. bool xremote_app_has_view(XRemoteApp *app, uint32_t view_id);
  69. void xremote_app_switch_to_view(XRemoteApp *app, uint32_t view_id);
  70. void xremote_app_switch_to_submenu(XRemoteApp *app);
  71. XRemoteApp* xremote_app_alloc(XRemoteAppContext *ctx);
  72. void xremote_app_free(XRemoteApp* app);