[Addon] Update the logic to update addon package list 90/214590/4
authorhyunduk.kim <hyunduk.kim@samsung.com>
Tue, 24 Sep 2019 07:21:22 +0000 (16:21 +0900)
committerhyunduk.kim <hyunduk.kim@samsung.com>
Tue, 1 Oct 2019 06:50:16 +0000 (15:50 +0900)
This patch will :

  - Only collect package info when it receives 'addon-installed'
  - Update addon DB files when it receives 'wgt-checking-done'
  - Handle the case when an addon was uninstalled by Application Manager

It should work together with [1] of chromium-efl.

[1] https://review.tizen.org/gerrit/214586

Change-Id: Iae13e65abd03642801f7a047af4dd856166b55c6
Signed-off-by: hyunduk.kim <hyunduk.kim@samsung.com>
wrt_app/src/addon_manager.js
wrt_app/src/runtime.js

index 83696ccb479725fda25d00fbc687d91c1fe0753a..378cf4fd486b1407e191b0bade7ad3b1781b6856 100644 (file)
@@ -224,20 +224,21 @@ class AddonManager {
         return ADN_PATH;
     }
 
-    static isAddon(path) {
+    static checkAddon(path) {
         let tmpPath = require('path');
         let mani_path = tmpPath.join(path, MANIFEST_FILE);
-        let db_path = tmpPath.join(ADN_PATH, ADDONS_DB_FILE);
         let tmpfs = require('fs');
         let json;
+        let addon = null;
+
         try {
             json = JSON.parse(tmpfs.readFileSync(mani_path));
         } catch (e) {
             console.log('fail to read manifest');
-            return false;
+            return addon;
         }
 
-        let addon = new Object();
+        addon = new Object();
         addon.name = json.name;
         addon.version = json.version;
         addon.settings = json.settings;
@@ -255,6 +256,13 @@ class AddonManager {
         addon.type = 'WRT';
         addon.activate = true;
 
+        return addon;
+    }
+
+    static updateDB(adnPkgs) {
+        let tmpPath = require('path');
+        let db_path = tmpPath.join(ADN_PATH, ADDONS_DB_FILE);
+        let tmpfs = require('fs');
         let addon_list = [];
         try {
             addon_list = JSON.parse(tmpfs.readFileSync(db_path));
@@ -274,20 +282,17 @@ class AddonManager {
             }
         }
 
-        let allowPush = true;
-        if (addon_list) {
-            for (let i in addon_list) {
-                let tmpAddon = addon_list[i];
-                if (tmpAddon.name == addon.name) {
-                     console.log('already in db');
-                     allowPush = false;
-                     break;
+        for (let addon of adnPkgs) {
+            if (addon_list) {
+                for (let tmpAddon of addon_list) {
+                    if (tmpAddon.name == addon.name) {
+                         console.log('already in db');
+                         adnPkgs[adnPkgs.indexOf(addon)].activate =
+                             tmpAddon.activate;
+                    }
                 }
             }
         }
-        if (allowPush) {
-            addon_list.push(addon);
-        }
 
         var fd;
         try {
@@ -296,7 +301,7 @@ class AddonManager {
             console.log('db file open error');
             return false;
         }
-        fs.writeSync(fd, JSON.stringify(addon_list));
+        fs.writeSync(fd, JSON.stringify(adnPkgs));
         fs.closeSync(fd);
         fs.chmodSync(db_path, 0o666);
         return true;
index f39e244f82c8ed9e42d4a94c039433c49b6b62c4..a52789f95e2ed8b9793f41c846cb7d445a5453c3 100755 (executable)
@@ -32,6 +32,7 @@ class Runtime {
         this.inspectorEnabledByVconf = false;
         this.sandbox = [];
         this.webContents = null;
+        this.addonPkgs = [];
 
         var _this = this;
         app.on('before-quit', function(event) {
@@ -215,15 +216,20 @@ class Runtime {
                 event.preventDefault();
             }
         });
-        wrt.on('wgt-installed', function(event, path) {
-            console.log('wgt-installed at ' + path);
-            if (AddonManager.isAddon(path)) {
-                console.log('Addon is updated on DB');
+        wrt.on('addon-installed', function(event, path) {
+            console.log('addon-installed at ' + path);
+            let dbInfo = AddonManager.checkAddon(path);
+            if (dbInfo) {
+                _this.addonPkgs.push(dbInfo);
             }
         });
         wrt.on('addon-uninstalled', function(event, id) {
             console.log('addon-unistalled named ' + id);
         });
+        wrt.on('wgt-checking-done', function(event) {
+            console.log('wgt-checking-done');
+            AddonManager.updateDB(_this.addonPkgs);
+        });
         /* FIXME: will uncheck after chromium-efl released */
         if (wrt.getPlatformType() !== "product_tv") {
             wrt.getInstalledPkg();