Sfoglia il codice sorgente

fix(plugin): beforeunload call error if it not exist & bump libs version

charlie 4 anni fa
parent
commit
80e47bf829
3 ha cambiato i file con 5 aggiunte e 5 eliminazioni
  1. 1 1
      libs/package.json
  2. 2 1
      libs/src/LSPlugin.caller.ts
  3. 2 3
      libs/src/LSPlugin.user.ts

+ 1 - 1
libs/package.json

@@ -1,6 +1,6 @@
 {
   "name": "@logseq/libs",
-  "version": "0.0.1-alpha.18",
+  "version": "0.0.1-alpha.19",
   "description": "Logseq SDK libraries",
   "main": "dist/lsplugin.user.js",
   "typings": "index.d.ts",

+ 2 - 1
libs/src/LSPlugin.caller.ts

@@ -77,6 +77,7 @@ class LSPluginCaller extends EventEmitter {
       },
 
       [LSPMSG_BEFORE_UNLOAD]: async (e) => {
+        debugger
         const actor = deferred(10 * 1000)
         caller.emit('beforeunload', Object.assign({ actor }, e))
         await actor.promise
@@ -225,7 +226,7 @@ class LSPluginCaller extends EventEmitter {
 
         this._callUserModel = async (type, payload: any) => {
           if (type.startsWith(FLAG_AWAIT)) {
-            // TODO: attach payload
+            // TODO: attach payload with method call
             return await refChild.get(type.replace(FLAG_AWAIT, ''))
           } else {
             refChild.call(type, payload)

+ 2 - 3
libs/src/LSPlugin.user.ts

@@ -155,14 +155,13 @@ export class LSPluginUser extends EventEmitter<LSPluginUserEvents> implements IL
     _caller.on('beforeunload', async (payload) => {
       const { actor, ...rest } = payload
       const cb = this._beforeunloadCallback
-      if (!cb || !actor) return
 
       try {
         cb && await cb(rest)
-        actor.resolve(null)
+        actor?.resolve(null)
       } catch (e) {
         console.debug(`${_caller.debugTag} [beforeunload] `, e)
-        actor.reject(e)
+        actor?.reject(e)
       }
     })
   }