send showWindow event when app start over
authorwang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com>
Wed, 24 Apr 2019 11:22:44 +0000 (19:22 +0800)
committerwang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com>
Wed, 24 Apr 2019 11:22:44 +0000 (19:22 +0800)
Change-Id: I2ced5f48f0c377cdc4261b5bb19ac6f9c40760ea

src/homescreen.cpp
src/hs-apprecover.cpp
src/hs-apprecover.h
src/hs-clientmanager.cpp
src/hs-clientmanager.h

index 2a0ee77..142007f 100644 (file)
@@ -305,6 +305,7 @@ static void tap_shortcut (afb_req_t request)
         AFB_INFO("request appid = %s.", value);
         ret = g_hs_instance->client_manager->handleRequest(request, __FUNCTION__, value);
         if(ret == AFB_REQ_NOT_STARTED_APPLICATION) {
+            g_hs_instance->client_manager->setStartupAppid(std::string(value));
             std::string id = g_hs_instance->app_info->getAppProperty(value, _keyId);
             HS_AfmMainProxy afm_proxy;
             afm_proxy.start(request->api, id);
@@ -462,6 +463,7 @@ static void showWindow(afb_req_t request)
     if (value) {
         ret = g_hs_instance->client_manager->handleRequest(request, __FUNCTION__, value);
         if(ret == AFB_REQ_NOT_STARTED_APPLICATION) {
+            g_hs_instance->client_manager->setStartupAppid(std::string(value));
             std::string id = g_hs_instance->app_info->getAppProperty(value, _keyId);
             HS_AfmMainProxy afm_proxy;
             afm_proxy.start(request->api, id);
index cedf751..5ccd039 100644 (file)
@@ -115,13 +115,15 @@ void HS_AppRecover::startRecovery(afb_api_t api, recover_map &map)
  *  - appid : application id liked "dashboard"
  *
  * #### Return
- * None
+ * false : not recover app
+ * true : recover app
  * 
  */
-void HS_AppRecover::registerRecoveredApp(const std::string &appid)
+bool HS_AppRecover::registerRecoveredApp(const std::string &appid)
 {
+    bool ret = false;
     if(m_recovering_set.empty()) {
-        return;
+        return ret;
     }
 
     auto it = m_recovering_set.find(appid);
@@ -132,7 +134,9 @@ void HS_AppRecover::registerRecoveredApp(const std::string &appid)
         && ip->second.visibility) {
             HS_ClientManager::instance()->pushEvent("showWindow", nullptr, appid);
         }
+        ret = true;
     }
+    return ret;
 }
 
 /**
index 3a0f8d5..701ec5f 100644 (file)
@@ -38,7 +38,7 @@ public:
     static HS_AppRecover* instance(void);
     int init(afb_api_t api);
     void startRecovery(afb_api_t api, recover_map &map);
-    void registerRecoveredApp(const std::string &appid);
+    bool registerRecoveredApp(const std::string &appid);
     void screenUpdated(struct json_object *obj);
 
 private:
index 1128b01..89b0ae2 100644 (file)
@@ -188,7 +188,7 @@ int HS_ClientManager::handleRequest(afb_req_t request, const char *verb, const c
                 appid2ctxt[appid] = createClientCtxt(request, appid);
                 HS_Client* client = addClient(request, appid);
                 ret = client->handleRequest(request, "subscribe");
-                HS_AppRecover::instance()->registerRecoveredApp(std::string(appid));
+                checkRegisterApp(std::string(appid));
             }
             else {
                 AFB_NOTICE("not exist session");
@@ -233,4 +233,27 @@ int HS_ClientManager::pushEvent(const char *event, struct json_object *param, st
     }
 
     return 0;
+}
+
+/**
+ * check register application
+ *
+ * #### Parameters
+ *  - appid : register application's id
+ *
+ * #### Return
+ * None
+ *
+ */
+void HS_ClientManager::checkRegisterApp(const std::string &appid)
+{
+    if(HS_AppRecover::instance()->registerRecoveredApp(appid)) {
+        AFB_NOTICE("register recover application.");
+        return;
+    }
+
+    if(startup_appid == appid) {
+        startup_appid.clear();
+        pushEvent("showWindow", nullptr, appid);
+    }
 }
\ No newline at end of file
index efc36de..54283c2 100644 (file)
@@ -48,17 +48,20 @@ public:
     int handleRequest(afb_req_t request, const char *verb, const char *appid = nullptr);
     int pushEvent(const char *event, struct json_object *param, std::string appid = "");
     void removeClientCtxt(void *data);  // don't use, internal only
+    void setStartupAppid(const std::string &appid) {startup_appid = appid;}
 
 private:
     HS_ClientCtxt* createClientCtxt(afb_req_t req, std::string appid);
     HS_Client* addClient(afb_req_t req, std::string appid);
     void removeClient(std::string appid);
+    void checkRegisterApp(const std::string &appid);
 
 private:
     static HS_ClientManager* me;
     std::unordered_map<std::string, HS_Client*> client_list;
     std::unordered_map<std::string, HS_ClientCtxt*> appid2ctxt;
     std::mutex mtx;
+    std::string startup_appid;
 };
 
 #endif // HOMESCREEN_CLIENTMANAGER_H
\ No newline at end of file