mirror of
https://github.com/doocs/md.git
synced 2025-01-22 20:04:39 +08:00
fix: cannot get account occasionally (#516)
This commit is contained in:
parent
49c3231012
commit
5b8b5496c2
@ -24,6 +24,10 @@ const form = ref<Post>({
|
|||||||
const allowPost = computed(() => extensionInstalled.value && form.value.accounts.some(a => a.checked))
|
const allowPost = computed(() => extensionInstalled.value && form.value.accounts.some(a => a.checked))
|
||||||
|
|
||||||
async function prePost() {
|
async function prePost() {
|
||||||
|
if (extensionInstalled.value && allAccounts.value.length === 0) {
|
||||||
|
await getAccounts()
|
||||||
|
}
|
||||||
|
|
||||||
let auto: Post = {
|
let auto: Post = {
|
||||||
thumb: ``,
|
thumb: ``,
|
||||||
title: ``,
|
title: ``,
|
||||||
@ -32,7 +36,7 @@ async function prePost() {
|
|||||||
markdown: ``,
|
markdown: ``,
|
||||||
accounts: [],
|
accounts: [],
|
||||||
}
|
}
|
||||||
const accounts = allAccounts.value.filter(a => !['weixin', 'ipfs'].includes(a.type))
|
const accounts = allAccounts.value.filter(a => ![`weixin`, `ipfs`].includes(a.type))
|
||||||
try {
|
try {
|
||||||
auto = {
|
auto = {
|
||||||
thumb: document.querySelector<HTMLImageElement>(`#output img`)?.src ?? ``,
|
thumb: document.querySelector<HTMLImageElement>(`#output img`)?.src ?? ``,
|
||||||
@ -64,9 +68,12 @@ declare global {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getAccounts() {
|
async function getAccounts(): Promise<void> {
|
||||||
await window.$syncer?.getAccounts((resp: PostAccount[]) => {
|
return new Promise((resolve) => {
|
||||||
allAccounts.value = resp.map(a => ({ ...a, checked: true }))
|
window.$syncer?.getAccounts((resp: PostAccount[]) => {
|
||||||
|
allAccounts.value = resp.map(a => ({ ...a, checked: true }))
|
||||||
|
resolve()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,10 +97,10 @@ function checkExtension() {
|
|||||||
|
|
||||||
// 如果插件还没加载,5秒内每 500ms 检查一次
|
// 如果插件还没加载,5秒内每 500ms 检查一次
|
||||||
let count = 0
|
let count = 0
|
||||||
const timer = setInterval(() => {
|
const timer = setInterval(async () => {
|
||||||
if (window.$syncer !== undefined) {
|
if (window.$syncer !== undefined) {
|
||||||
extensionInstalled.value = true
|
extensionInstalled.value = true
|
||||||
getAccounts()
|
await getAccounts()
|
||||||
clearInterval(timer)
|
clearInterval(timer)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user