fix: try solve no tree at startup
This commit is contained in:
parent
9df80afe38
commit
b13fcf9742
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "logseq-plugin-favorite-tree",
|
"name": "logseq-plugin-favorite-tree",
|
||||||
"version": "1.0.5",
|
"version": "1.0.6",
|
||||||
"main": "dist/index.html",
|
"main": "dist/index.html",
|
||||||
"logseq": {
|
"logseq": {
|
||||||
"id": "_sethyuan-logseq-favorite-tree",
|
"id": "_sethyuan-logseq-favorite-tree",
|
||||||
|
|||||||
@ -89,6 +89,23 @@ export async function queryForSubItems(name: string) {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function waitForEl(selector: string, timeout: number) {
|
||||||
|
const start = Date.now()
|
||||||
|
|
||||||
|
function tryFindEl(resolve: (el: Element | null) => void) {
|
||||||
|
const el = parent.document.querySelector(selector)
|
||||||
|
if (el != null) {
|
||||||
|
resolve(el)
|
||||||
|
} else if (Date.now() - start <= timeout) {
|
||||||
|
setTimeout(() => tryFindEl(resolve), 100)
|
||||||
|
} else {
|
||||||
|
resolve(null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Promise(tryFindEl)
|
||||||
|
}
|
||||||
|
|
||||||
async function getQuickFilters(name: string) {
|
async function getQuickFilters(name: string) {
|
||||||
const [{ uuid: blockUUID }, { uuid: pageUUID }] = (
|
const [{ uuid: blockUUID }, { uuid: pageUUID }] = (
|
||||||
await logseq.DB.datascriptQuery(
|
await logseq.DB.datascriptQuery(
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import { setup, t } from "logseq-l10n"
|
|||||||
import { render } from "preact"
|
import { render } from "preact"
|
||||||
import { throttle } from "rambdax"
|
import { throttle } from "rambdax"
|
||||||
import FavList from "./comps/FavList"
|
import FavList from "./comps/FavList"
|
||||||
import { hash, queryForSubItems, setLanguage } from "./libs/utils"
|
import { hash, queryForSubItems, setLanguage, waitForEl } from "./libs/utils"
|
||||||
import zhCN from "./translations/zh-CN.json"
|
import zhCN from "./translations/zh-CN.json"
|
||||||
|
|
||||||
let dragHandle: HTMLElement | null = null
|
let dragHandle: HTMLElement | null = null
|
||||||
@ -81,6 +81,7 @@ async function main() {
|
|||||||
|
|
||||||
const graphOff = logseq.App.onCurrentGraphChanged(adjustLeftBarWidth)
|
const graphOff = logseq.App.onCurrentGraphChanged(adjustLeftBarWidth)
|
||||||
|
|
||||||
|
await waitForEl("#left-sidebar .favorite-item", 1000)
|
||||||
await processFavorites()
|
await processFavorites()
|
||||||
await adjustLeftBarWidth()
|
await adjustLeftBarWidth()
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user