Bug 1078797 - Wait for running state before emitting install. r=ochameau
authorJ. Ryan Stinnett <jryans@gmail.com>
Tue, 07 Oct 2014 12:06:00 +0200
changeset 209330 9637293b166a5eb2dbb08a78442f8052dfeb22e6
parent 209329 3efeefd11c1afbf0583ead0ead807930a7b7c065
child 209331 4bad24a306b29ee04a3dc9edece5ffc43cd57310
child 209394 4d0bb69c5a497835bbff7c93a1543dc63e6241f2
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersochameau
bugs1078797
milestone35.0a1
Bug 1078797 - Wait for running state before emitting install. r=ochameau
toolkit/devtools/apps/app-actor-front.js
--- a/toolkit/devtools/apps/app-actor-front.js
+++ b/toolkit/devtools/apps/app-actor-front.js
@@ -660,62 +660,65 @@ AppActorFront.prototype = {
     let request = {
       to: this.actor,
       type: "unwatchApps"
     };
     return this.client.request(request);
   },
 
   _clientListener: function (type, message) {
-
     let { manifestURL } = message;
 
     // Reset the app object to get a fresh copy when we (re)install the app.
     if (type == "appInstall" && this._apps && this._apps.has(manifestURL)) {
       this._apps.delete(manifestURL);
     }
 
     this._getApp(manifestURL).then((app) => {
       switch(type) {
         case "appOpen":
           app.running = true;
+          this._notifyListeners("appOpen", app);
           break;
         case "appClose":
           app.running = false;
+          this._notifyListeners("appClose", app);
           break;
         case "appInstall":
           // The call to _getApp is going to create App object
 
           // This app may have been running while being installed, so check the list
           // of running apps again to get the right answer.
           let request = {
             to: this.actor,
             type: "listRunningApps"
           };
           this.client.request(request)
               .then(res => {
                 if (res.apps.indexOf(manifestURL) !== -1) {
                   app.running = true;
+                  this._notifyListeners("appInstall", app);
                   this._notifyListeners("appOpen", app);
+                } else {
+                  this._notifyListeners("appInstall", app);
                 }
               });
           break;
         case "appUninstall":
           // Fake a appClose event if we didn't got one before uninstall
           if (app.running) {
             app.running = false;
             this._notifyListeners("appClose", app);
           }
           this._apps.delete(manifestURL);
+          this._notifyListeners("appUninstall", app);
           break;
         default:
           return;
       }
-      this._notifyListeners(type, app);
-
     });
   },
 
   _notifyListeners: function (type, app) {
     this._listeners.forEach(f => {
       f(type, app);
     });
   },