зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1497448: Update usb devices when the debugger client of usb was closed. r=jdescottes
Depends on D9889 Differential Revision: https://phabricator.services.mozilla.com/D9890 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
4a4b56f77f
Коммит
b3905b1d5b
|
@ -93,6 +93,13 @@ async function getRuntimeInfo(runtime, client) {
|
|||
};
|
||||
}
|
||||
|
||||
function onUSBDebuggerClientClosed() {
|
||||
// After scanUSBRuntimes action, updateUSBRuntimes action is called.
|
||||
// The closed runtime will be unwatched and disconnected explicitly in the action
|
||||
// if needed.
|
||||
window.AboutDebugging.store.dispatch(Actions.scanUSBRuntimes());
|
||||
}
|
||||
|
||||
function connectRuntime(id) {
|
||||
return async (dispatch, getState) => {
|
||||
dispatch({ type: CONNECT_RUNTIME_START });
|
||||
|
@ -105,6 +112,12 @@ function connectRuntime(id) {
|
|||
await preferenceFront.getBoolPref(RUNTIME_PREFERENCE.CONNECTION_PROMPT);
|
||||
const runtimeDetails = { connectionPromptEnabled, client, info, transportDetails };
|
||||
|
||||
if (runtime.type === RUNTIMES.USB) {
|
||||
// `closed` event will be emitted when disabling remote debugging
|
||||
// on the connected USB runtime.
|
||||
client.addOneTimeListener("closed", onUSBDebuggerClientClosed);
|
||||
}
|
||||
|
||||
dispatch({
|
||||
type: CONNECT_RUNTIME_SUCCESS,
|
||||
runtime: {
|
||||
|
@ -126,8 +139,15 @@ function disconnectRuntime(id) {
|
|||
const runtime = findRuntimeById(id, getState().runtimes);
|
||||
const client = runtime.runtimeDetails.client;
|
||||
|
||||
if (runtime.type === RUNTIMES.USB) {
|
||||
client.removeListener("closed", onUSBDebuggerClientClosed);
|
||||
}
|
||||
|
||||
await client.close();
|
||||
DebuggerServer.destroy();
|
||||
|
||||
if (runtime.type === RUNTIMES.THIS_FIREFOX) {
|
||||
DebuggerServer.destroy();
|
||||
}
|
||||
|
||||
dispatch({
|
||||
type: DISCONNECT_RUNTIME_SUCCESS,
|
||||
|
@ -232,6 +252,13 @@ function updateUSBRuntimes(runtimes) {
|
|||
await dispatch(Actions.selectPage(RUNTIMES.THIS_FIREFOX, RUNTIMES.THIS_FIREFOX));
|
||||
}
|
||||
|
||||
// Disconnect runtimes that were no longer valid
|
||||
const invalidRuntimes =
|
||||
getState().runtimes.usbRuntimes.filter(r => !runtimes.includes(r));
|
||||
for (const invalidRuntime of invalidRuntimes) {
|
||||
await dispatch(disconnectRuntime(invalidRuntime.id));
|
||||
}
|
||||
|
||||
dispatch({ type: USB_RUNTIMES_UPDATED, runtimes });
|
||||
};
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче