1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-26 22:41:17 +02:00

Mobile: Plugins: Fix event listener memory leak when disabling/uninstalling plugins (#10280)

Co-authored-by: Laurent Cozic <laurent22@users.noreply.github.com>
This commit is contained in:
Henry Heino
2024-04-11 01:04:47 -07:00
committed by GitHub
parent 1812587970
commit c0c3b4d23e
8 changed files with 125 additions and 15 deletions

View File

@@ -21,6 +21,8 @@ interface ContentScripts {
[type: string]: ContentScript[];
}
type OnUnloadListener = ()=> void;
export default class Plugin {
private baseDir_: string;
@@ -41,6 +43,7 @@ export default class Plugin {
private dataDir_: string;
private dataDirCreated_ = false;
private hasErrors_ = false;
private onUnloadListeners_: OnUnloadListener[] = [];
// eslint-disable-next-line @typescript-eslint/ban-types -- Old code before rule was applied
public constructor(baseDir: string, manifest: PluginManifest, scriptText: string, dispatch: Function, dataDir: string) {
@@ -205,7 +208,16 @@ export default class Plugin {
return this.contentScriptMessageListeners_[id](message);
}
public addOnUnloadListener(callback: OnUnloadListener) {
this.onUnloadListeners_.push(callback);
}
public onUnload() {
for (const callback of this.onUnloadListeners_) {
callback();
}
this.onUnloadListeners_ = [];
this.dispatch_({
type: 'PLUGIN_UNLOAD',
pluginId: this.id,