improvement
[apps/agl-service-homescreen.git] / src / hs-config.cpp
index 17b086a..f043d46 100644 (file)
@@ -22,6 +22,11 @@ const std::array<std::string, 3> HS_Config::keys_recover_type = {   // based on
     "default-lastmode",
     "normal-apps"
 };
+const std::string HS_Config::lastmode_json = "lastmode.json";
+const std::string HS_Config::key_appid = "appid";
+const std::string HS_Config::key_visibility = "visibility";
+const std::string HS_Config::key_after = "after";
+std::string HS_Config::root_dir = "";
 
 /**
  * read configuration file to memory
@@ -35,16 +40,16 @@ const std::array<std::string, 3> HS_Config::keys_recover_type = {   // based on
  */
 int HS_Config::readConfig(void)
 {
-    auto rootdir = std::string(getenv("AFM_APP_INSTALL_DIR"));
-    auto path = rootdir + "/etc/" + hs_conf_json;
+    root_dir = std::string(getenv("AFM_APP_INSTALL_DIR"));
+    auto path = root_dir + "/etc/" + hs_conf_json;
     if(readJsonFile(path.c_str(), &m_hs_conf) < 0) {
         AFB_ERROR("read %s failed.", hs_conf_json.c_str());
         return -1;
     }
 
-    path = rootdir + "/etc/" + lastmode_json;
+    path = root_dir + "/etc/" + lastmode_json;
     if(readJsonFile(path.c_str(), &m_lastmode) < 0) {
-        AFB_ERROR("read %s failed.", lastmode_json.c_str());
+        AFB_WARNING("read %s failed.", lastmode_json.c_str());
         m_lastmode = nullptr;
     }
 
@@ -100,6 +105,11 @@ int HS_Config::parseConfig(void)
     if(json_object_get_type(m_lastmode) == json_type_array ) {
         struct std::vector<recover_app_info> v_lastmode = std::move(getRecoverAppInfo(m_lastmode));
         if(!v_lastmode.empty()) {   // got saving lastmode isn't null, instead of default lastmode
+            for(auto &it : v_lastmode) {
+                if(it.after.empty() && !m_recover_map[keys_recover_type[1]].empty()) {
+                    it.after = m_recover_map[keys_recover_type[1]][0].after;
+                }
+            }
             m_recover_map[keys_recover_type[1]] = std::move(v_lastmode);
         }
     }
@@ -109,7 +119,7 @@ int HS_Config::parseConfig(void)
 
 /**
  * get recover application information
- * appid, visibility, display area
+ * appid, visibility
  *
  * #### Parameters
  *  - obj : application information
@@ -134,12 +144,6 @@ std::vector<struct recover_app_info> HS_Config::getRecoverAppInfo(struct json_ob
             v_app_info.clear();
             return v_app_info;
         }
-        if(json_object_object_get_ex(info_obj, key_area.c_str(), &value_obj)) {
-            info.area = json_object_get_string(value_obj);
-        }
-        else {
-            info.area = "normal.full";
-        }
         if(json_object_object_get_ex(info_obj, key_visibility.c_str(), &value_obj)) {
             std::string visibility = json_object_get_string(value_obj);
             info.visibility = (visibility == "visible") ? true:false;
@@ -147,6 +151,12 @@ std::vector<struct recover_app_info> HS_Config::getRecoverAppInfo(struct json_ob
         else {
             info.visibility = false;
         }
+        if(json_object_object_get_ex(info_obj, key_after.c_str(), &value_obj)) {
+            info.after = json_object_get_string(value_obj);
+        }
+        else {
+            info.after.clear();
+        }
         v_app_info.push_back(info);
     }