Kaynağa Gözat

Remember last opened file or directory

Sandro Kalatozishvili 2 yıl önce
ebeveyn
işleme
95aeb2bb30
4 değiştirilmiş dosya ile 14 ekleme ve 12 silme
  1. 1 1
      xremote.h
  2. 5 0
      xremote_app.c
  3. 4 0
      xremote_app.h
  4. 4 11
      xremote_control.c

+ 1 - 1
xremote.h

@@ -10,6 +10,6 @@
 
 #define XREMOTE_VERSION_MAJOR  0
 #define XREMOTE_VERSION_MINOR  9
-#define XREMOTE_BUILD_NUMBER   21
+#define XREMOTE_BUILD_NUMBER   22
 
 void xremote_get_version(char *version, size_t length);

+ 5 - 0
xremote_app.c

@@ -103,6 +103,10 @@ XRemoteAppContext* xremote_app_context_alloc(void *arg)
     ctx->app_settings = xremote_app_settings_alloc();
     xremote_app_settings_load(ctx->app_settings);
 
+    /* Last opened file or directory path */
+    ctx->file_path = furi_string_alloc();
+    furi_string_set(ctx->file_path, XREMOTE_APP_FOLDER);
+
     /* Allocate and setup view dispatcher */
     ctx->view_dispatcher = view_dispatcher_alloc();
     view_dispatcher_enable_queue(ctx->view_dispatcher);
@@ -118,6 +122,7 @@ void xremote_app_context_free(XRemoteAppContext* ctx)
     view_dispatcher_free(ctx->view_dispatcher);
     furi_record_close(RECORD_NOTIFICATION);
     furi_record_close(RECORD_GUI);
+    furi_string_free(ctx->file_path);
     free(ctx);
 }
 

+ 4 - 0
xremote_app.h

@@ -26,6 +26,9 @@
 #include "views/xremote_common_view.h"
 #include "xc_icons.h"
 
+#define XREMOTE_APP_EXTENSION   ".ir"
+#define XREMOTE_APP_FOLDER      ANY_PATH("infrared")
+
 #define xremote_app_assert_void(cond) if (!cond) return
 #define xremote_app_assert(cond, var) if (!cond) return var
 
@@ -50,6 +53,7 @@ typedef struct {
     XRemoteAppSettings* app_settings;
     NotificationApp* notifications;
     ViewDispatcher* view_dispatcher;
+    FuriString* file_path;
     void* app_argument;
     Gui* gui;
 } XRemoteAppContext;

+ 4 - 11
xremote_control.c

@@ -15,9 +15,6 @@
 #include "views/xremote_player_view.h"
 #include "views/xremote_custom_view.h"
 
-#define XREMOTE_APP_EXTENSION   ".ir"
-#define XREMOTE_APP_FOLDER      ANY_PATH("infrared")
-
 static uint32_t xremote_control_submenu_exit_callback(void* context)
 {
     UNUSED(context);
@@ -61,13 +58,11 @@ static void xremote_control_submenu_callback(void* context, uint32_t index)
     }
 }
 
-InfraredRemote* xremote_load_ir_buttons()
+static InfraredRemote* xremote_load_ir_buttons(XRemoteAppContext* app_ctx)
 {
     DialogsApp* dialogs = furi_record_open(RECORD_DIALOGS);
     Storage* storage = furi_record_open(RECORD_STORAGE);
 
-    FuriString* file_path = furi_string_alloc();
-    furi_string_set(file_path, XREMOTE_APP_FOLDER);
     storage_simply_mkdir(storage, XREMOTE_APP_FOLDER);
 
     /* Open file browser (view and dialogs are managed by the browser itself) */
@@ -76,22 +71,20 @@ InfraredRemote* xremote_load_ir_buttons()
     browser.base_path = XREMOTE_APP_FOLDER;
 
     /* Show file selection dialog (returns selected file path with variable file_path) */
-    if(!dialog_file_browser_show(dialogs, file_path, file_path, &browser))
+    if(!dialog_file_browser_show(dialogs, app_ctx->file_path, app_ctx->file_path, &browser))
     {
         furi_record_close(RECORD_STORAGE);
         furi_record_close(RECORD_DIALOGS);
-        furi_string_free(file_path);
         return NULL;
     }
 
     /* Load buttons from the selected path */
     InfraredRemote* remote = infrared_remote_alloc();
-    bool success = infrared_remote_load(remote, file_path);
+    bool success = infrared_remote_load(remote, app_ctx->file_path);
 
     /* Cleanup file loading context */
     furi_record_close(RECORD_STORAGE);
     furi_record_close(RECORD_DIALOGS);
-    furi_string_free(file_path);
 
     if (!success)
     {
@@ -105,7 +98,7 @@ InfraredRemote* xremote_load_ir_buttons()
 XRemoteApp* xremote_control_alloc(XRemoteAppContext* app_ctx)
 {
     /* Open file browser and load buttons from selected file */
-    InfraredRemote* remote = xremote_load_ir_buttons();
+    InfraredRemote* remote = xremote_load_ir_buttons(app_ctx);
     xremote_app_assert(remote, NULL);
 
     /* Allocate remote controller app with submenu */