mirror of https://github.com/logseq/logseq
fix(plugin): beforeunload call error if it not exist & bump libs version
parent
a7cc751269
commit
80e47bf829
|
@ -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",
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue