You've already forked joplin
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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user