Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cannot get account occasionally #516

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions src/components/CodemirrorEditor/EditorHeader/PostInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ const form = ref<Post>({
const allowPost = computed(() => extensionInstalled.value && form.value.accounts.some(a => a.checked))

async function prePost() {
if (extensionInstalled.value && allAccounts.value.length === 0) {
await getAccounts()
}

let auto: Post = {
thumb: ``,
title: ``,
Expand All @@ -32,7 +36,7 @@ async function prePost() {
markdown: ``,
accounts: [],
}
const accounts = allAccounts.value.filter(a => !['weixin', 'ipfs'].includes(a.type))
const accounts = allAccounts.value.filter(a => ![`weixin`, `ipfs`].includes(a.type))
try {
auto = {
thumb: document.querySelector<HTMLImageElement>(`#output img`)?.src ?? ``,
Expand Down Expand Up @@ -64,9 +68,12 @@ declare global {
}
}

async function getAccounts() {
await window.$syncer?.getAccounts((resp: PostAccount[]) => {
allAccounts.value = resp.map(a => ({ ...a, checked: true }))
async function getAccounts(): Promise<void> {
return new Promise((resolve) => {
window.$syncer?.getAccounts((resp: PostAccount[]) => {
allAccounts.value = resp.map(a => ({ ...a, checked: true }))
resolve()
})
})
}

Expand All @@ -90,10 +97,10 @@ function checkExtension() {

// 如果插件还没加载,5秒内每 500ms 检查一次
let count = 0
const timer = setInterval(() => {
const timer = setInterval(async () => {
if (window.$syncer !== undefined) {
extensionInstalled.value = true
getAccounts()
await getAccounts()
clearInterval(timer)
return
}
Expand Down
Loading