Add support for lumino plugin deactivation#54
Add support for lumino plugin deactivation#54fcollonval wants to merge 2 commits intojupyterlab:mainfrom
Conversation
|
Thanks for submitting your first pull request! You are awesome! 🤗 |
|
y'all got any other breaking changes hidden up yer sleeve? |
|
(to be fair, many of these are very cool, but i'm really wondering about why these are being backported: every one of them reduces the chance that existing third-party extensions will work properly, which is going to lead to a lot of unhappy users on launch day) |
|
@bollwyvl we don't use the But for this project to work with a code like the one below, we need a proper way to deactivate the previous version. Otherwise reloading the plugin will fail due to the command ID being already registered. import {
JupyterFrontEnd,
JupyterFrontEndPlugin,
} from '@jupyterlab/application';
import {
DisposableSet
} from '@lumino/disposable';
const resources = new DisposableSet();
const plugin: JupyterFrontEndPlugin<void> = {
id: 'mydynamicplugin',
autoStart: true,
requires: ['@jupyterlab/apputils:ICommandPalette'],
activate: (app, palette) => {
console.log('Hello from a dynamically loaded plugin!');
// We can use `.app` here to do something with the JupyterLab
// app instance, such as adding a new command
let commandID = 'MySuperCoolDynamicCommand';
let toggle = true;
const cmd = app.commands.addCommand(commandID, {
label: 'My Super Cool Command',
isToggled: function () {
return toggle;
},
execute: function () {
console.log('Executed ' + commandID + 'uu');
toggle = !toggle;
}
});
resources.add(cmd);
const item = palette.addItem({
command: commandID,
// make it appear right at the top!
category: 'AAA',
args: {}
});
resources.add(item);
},
deactivate: () => {
resources.dispose();
resources.clear();
}
};
export default plugin;And incidentally this raises a good question, is it really easier to create a plugin for JupyterLab as it requires a |
|
Again, it's important that these things get improved... but on |
| } | ||
| this.app.deregisterPlugin(plugin.id, true); | ||
| } catch (reason) { | ||
| showErrorMessage('Deactivation of the old plugin failed', reason); |
There was a problem hiding this comment.
We should probably preserve compatibility with 3.x branch here. Below is a suggestion for one way to do so (though checking for this.app.deactivatePlugin/this.app.deregisterPlugin could be better).
| showErrorMessage('Deactivation of the old plugin failed', reason); | |
| try { | |
| if (plugin.deactivate) { | |
| plugin.deactivate() | |
| } | |
| delete (this.app as any)._pluginMap[plugin.id]; | |
| } catch (otherReason) { | |
| showErrorMessage('Deactivation of the old plugin failed', reason, otherReason); | |
| } |

This add the support for the plugin
deactivatemethod that will be support in JupyterLab 3.6.