Handle onMessage errors when client is not connected
Reviewed By: lblasa Differential Revision: D47397641 fbshipit-source-id: ac9c057050a3bac0c5149f5ce2998657fededb61
This commit is contained in:
committed by
Facebook GitHub Bot
parent
257003af42
commit
0345d7d533
@@ -218,30 +218,38 @@ export default abstract class AbstractClient extends EventEmitter {
|
|||||||
|
|
||||||
// get the plugins, and update the UI
|
// get the plugins, and update the UI
|
||||||
async refreshPlugins() {
|
async refreshPlugins() {
|
||||||
const oldBackgroundPlugins = this.backgroundPlugins;
|
try {
|
||||||
await this.loadPlugins('refresh');
|
const oldBackgroundPlugins = this.backgroundPlugins;
|
||||||
await Promise.all(
|
await this.loadPlugins('refresh');
|
||||||
[...this.plugins].map(async (pluginId) =>
|
await Promise.all(
|
||||||
this.startPluginIfNeeded(await this.getPlugin(pluginId)),
|
[...this.plugins].map(async (pluginId) =>
|
||||||
),
|
this.startPluginIfNeeded(await this.getPlugin(pluginId)),
|
||||||
);
|
),
|
||||||
const newBackgroundPlugins = await this.getBackgroundPlugins();
|
);
|
||||||
this.backgroundPlugins = new Set(newBackgroundPlugins);
|
const newBackgroundPlugins = await this.getBackgroundPlugins();
|
||||||
// diff the background plugin list, disconnect old, connect new ones
|
this.backgroundPlugins = new Set(newBackgroundPlugins);
|
||||||
oldBackgroundPlugins.forEach((plugin) => {
|
// diff the background plugin list, disconnect old, connect new ones
|
||||||
if (!this.backgroundPlugins.has(plugin)) {
|
oldBackgroundPlugins.forEach((plugin) => {
|
||||||
this.deinitPlugin(plugin);
|
if (!this.backgroundPlugins.has(plugin)) {
|
||||||
|
this.deinitPlugin(plugin);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
newBackgroundPlugins.forEach((plugin) => {
|
||||||
|
if (
|
||||||
|
!oldBackgroundPlugins.has(plugin) &&
|
||||||
|
this.shouldConnectAsBackgroundPlugin(plugin)
|
||||||
|
) {
|
||||||
|
this.initPlugin(plugin);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.emit('plugins-change');
|
||||||
|
} catch (e) {
|
||||||
|
if (this.connected) {
|
||||||
|
throw e;
|
||||||
|
} else {
|
||||||
|
console.warn(e);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
newBackgroundPlugins.forEach((plugin) => {
|
|
||||||
if (
|
|
||||||
!oldBackgroundPlugins.has(plugin) &&
|
|
||||||
this.shouldConnectAsBackgroundPlugin(plugin)
|
|
||||||
) {
|
|
||||||
this.initPlugin(plugin);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.emit('plugins-change');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onMessage(msg: string) {
|
onMessage(msg: string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user