@@ -67,24 +67,27 @@ export default abstract class Patcher {
6767 plugin : Plugin ,
6868 object : T | undefined ,
6969 patches : FunctionPatchObject < T > ,
70+ uninstallers ?: Array < ( ) => void >
7071 ) : T | null {
71- Patcher . patch ( plugin , object , patches )
72- return Patcher . patchPrototype ( plugin , object , patches )
72+ Patcher . patch ( plugin , object , patches , false , uninstallers )
73+ return Patcher . patchPrototype ( plugin , object , patches , uninstallers )
7374 }
7475
7576 static patchPrototype < T > (
7677 plugin : Plugin ,
7778 target : T | undefined ,
78- patches : FunctionPatchObject < T >
79+ patches : FunctionPatchObject < T > ,
80+ uninstallers ?: Array < ( ) => void >
7981 ) : T | null {
80- return Patcher . patch ( plugin , target , patches , true )
82+ return Patcher . patch ( plugin , target , patches , true , uninstallers )
8183 }
8284
8385 static patch < T > (
8486 plugin : Plugin ,
8587 object : T | undefined ,
8688 patches : FunctionPatchObject < T > ,
87- prototype : boolean = false
89+ prototype : boolean = false ,
90+ uninstallers ?: Array < ( ) => void >
8891 ) : T | null {
8992 if ( ! object ) return null
9093 const target = prototype ? object . constructor . prototype : object
@@ -99,6 +102,7 @@ export default abstract class Patcher {
99102 }
100103
101104 const uninstaller = around ( target as any , patches )
105+ if ( uninstallers ) uninstallers . push ( uninstaller )
102106 plugin . register ( uninstaller )
103107
104108 return object
@@ -107,17 +111,18 @@ export default abstract class Patcher {
107111 static tryPatchWorkspacePrototype < T > (
108112 plugin : Plugin ,
109113 getTarget : ( ) => T | undefined ,
110- patches : FunctionPatchObject < T >
114+ patches : FunctionPatchObject < T > ,
115+ uninstallers ?: Array < ( ) => void >
111116 ) : Promise < T > {
112117 return new Promise ( ( resolve ) => {
113- const result = Patcher . patchPrototype ( plugin , getTarget ( ) , patches )
118+ const result = Patcher . patchPrototype ( plugin , getTarget ( ) , patches , uninstallers )
114119 if ( result ) {
115120 resolve ( result )
116121 return
117122 }
118123
119124 const listener = plugin . app . workspace . on ( 'layout-change' , ( ) => {
120- const result = Patcher . patchPrototype ( plugin , getTarget ( ) , patches )
125+ const result = Patcher . patchPrototype ( plugin , getTarget ( ) , patches , uninstallers )
121126
122127 if ( result ) {
123128 plugin . app . workspace . offref ( listener )
0 commit comments