Просмотр исходного кода

Update libs/src/LSPlugin.user.ts

Co-authored-by: Peng Xiao <[email protected]>
Charlie 3 лет назад
Родитель
Сommit
9885dc64e0
1 измененных файлов с 14 добавлено и 8 удалено
  1. 14 8
      libs/src/LSPlugin.user.ts

+ 14 - 8
libs/src/LSPlugin.user.ts

@@ -586,15 +586,21 @@ export class LSPluginUser
               const handler = args[0]
               caller[f](type, handler)
 
-              if (!isOff) {
-                that.App._installPluginHook(pid, type)
-              }
+  const unlisten = () => {
+    caller.off(type, handler)
+    if (!caller.listenerCount(type)) {
+      that.App._uninstallPluginHook(pid, type)
+    }
+  }
+  
+  if (!isOff) {
+    that.App._installPluginHook(pid, type)
+  } else {
+    unlisten()
+    return
+  }
 
-              return () => {
-                caller.off(type, handler)
-                if (!caller.listenerCount(type)) {
-                  that.App._uninstallPluginHook(pid, type)
-                }
+  return unlisten
               }
             }
           }