diff --git a/app/lib/utils/plugins.js b/app/lib/utils/plugins.js index 2d67f9a4..3ccb00f6 100644 --- a/app/lib/utils/plugins.js +++ b/app/lib/utils/plugins.js @@ -28,6 +28,11 @@ let termPropsDecorators; const { path, localPath } = plugins.getBasePaths(); const clearModulesCache = () => { + // trigger unload hooks + modules.forEach((mod) => { + if (mod.onRendererUnload) mod.onRendererUnload(window); + }); + // clear require cache for (const entry in window.require.cache) { if (entry.indexOf(path) === 0 || entry.indexOf(localPath) === 0) { @@ -132,6 +137,10 @@ const loadModules = () => { tabsPropsDecorators.push(mod.getTabsProps); } + if (mod.onRendererWindow) { + mod.onRendererWindow(window); + } + return mod; }) .filter((mod) => !!mod); @@ -360,7 +369,9 @@ function getDecorated (parent, name) { return decorated[name]; } -// for each component, we return the `react-proxy`d component +// for each component, we return a higher-order component +// that wraps with the higher-order components +// exposed by plugins export function decorate (Component, name) { return class extends React.Component { render () { diff --git a/plugins.js b/plugins.js index 5e6593cb..b55dd39b 100644 --- a/plugins.js +++ b/plugins.js @@ -115,6 +115,12 @@ function getPluginVersions () { } function clearCache (mod) { + // trigger unload hooks + modules.forEach((mod) => { + if (mod.onUnload) mod.onUnload(); + }); + + // clear require cache for (const entry in require.cache) { if (entry.indexOf(path) === 0 || entry.indexOf(localPath) === 0) { delete require.cache[entry];