Bug 1498103: Select 'this firefox' page when selected runtime was removed. r=jdescottes
authorDaisuke Akatsuka <dakatsuka@mozilla.com>
Wed, 24 Oct 2018 06:21:11 +0000
changeset 491070 eca6ed1ae9ad1ef7a3c347741b1c85a948c61048
parent 491069 28ab0061c2ac1c13e4550117acf466509a6d2dcf
child 491071 8523f4a3ba87384698b64cb8bb0c6e3303952f9a
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersjdescottes
bugs1498103
milestone65.0a1
Bug 1498103: Select 'this firefox' page when selected runtime was removed. r=jdescottes Depends on D9469 Differential Revision: https://phabricator.services.mozilla.com/D9470
devtools/client/aboutdebugging-new/src/actions/runtimes.js
--- a/devtools/client/aboutdebugging-new/src/actions/runtimes.js
+++ b/devtools/client/aboutdebugging-new/src/actions/runtimes.js
@@ -210,17 +210,36 @@ function unwatchRuntime(id) {
       dispatch({ type: UNWATCH_RUNTIME_SUCCESS });
     } catch (e) {
       dispatch({ type: UNWATCH_RUNTIME_FAILURE, error: e.message });
     }
   };
 }
 
 function updateUSBRuntimes(runtimes) {
-  return { type: USB_RUNTIMES_UPDATED, runtimes };
+  return async (dispatch, getState) => {
+    const currentRuntime = getCurrentRuntime(getState().runtimes);
+
+    if (currentRuntime &&
+        currentRuntime.type === RUNTIMES.USB &&
+        !runtimes.find(runtime => currentRuntime.id === runtime.id)) {
+      // Since current USB runtime was invalid, move to this firefox page.
+      // This case is considered as followings and so on:
+      // * Remove ADB addon
+      // * (Physically) Disconnect USB runtime
+      //
+      // The reason why we call selectPage before USB_RUNTIMES_UPDATED was fired is below.
+      // Current runtime can not be retrieved after USB_RUNTIMES_UPDATED action, since
+      // that updates runtime state. So, before that we fire selectPage action so that to
+      // transact unwatchRuntime correctly.
+      await dispatch(Actions.selectPage(RUNTIMES.THIS_FIREFOX, RUNTIMES.THIS_FIREFOX));
+    }
+
+    dispatch({ type: USB_RUNTIMES_UPDATED, runtimes });
+  };
 }
 
 module.exports = {
   connectRuntime,
   disconnectRuntime,
   unwatchRuntime,
   updateConnectionPromptSetting,
   updateUSBRuntimes,