mirror of
https://github.com/snachodog/tok-to-insta-follower-bridge.git
synced 2025-04-23 20:12:22 -06:00
🐛 fix connection error
This commit is contained in:
parent
dad5f4a6b8
commit
34ba5a3628
@ -33,3 +33,5 @@ export const BSKY_USER_MATCH_TYPE = {
|
|||||||
DESCRIPTION: "description",
|
DESCRIPTION: "description",
|
||||||
NONE: "none",
|
NONE: "none",
|
||||||
} as const
|
} as const
|
||||||
|
|
||||||
|
export const MAX_RELOAD_COUNT = 1
|
||||||
|
@ -7,6 +7,7 @@ import { sendToContentScript } from "@plasmohq/messaging"
|
|||||||
import { useStorage } from "@plasmohq/storage/hook"
|
import { useStorage } from "@plasmohq/storage/hook"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
MAX_RELOAD_COUNT,
|
||||||
MESSAGE_NAMES,
|
MESSAGE_NAMES,
|
||||||
MESSAGE_TYPE,
|
MESSAGE_TYPE,
|
||||||
STORAGE_KEYS,
|
STORAGE_KEYS,
|
||||||
@ -14,11 +15,13 @@ import {
|
|||||||
} from "~lib/constants"
|
} from "~lib/constants"
|
||||||
|
|
||||||
import { debugLog } from "./lib/utils"
|
import { debugLog } from "./lib/utils"
|
||||||
|
import { ReloadButton } from "~lib/components/ReloadBtn"
|
||||||
|
|
||||||
function IndexPopup() {
|
function IndexPopup() {
|
||||||
const [isLoading, setIsLoading] = useState(false)
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
const [password, setPassword] = useStorage(STORAGE_KEYS.BSKY_PASSWORD, "")
|
const [password, setPassword] = useStorage(STORAGE_KEYS.BSKY_PASSWORD, "")
|
||||||
const [userId, setUserId] = useStorage(STORAGE_KEYS.BSKY_USER_ID, "")
|
const [userId, setUserId] = useStorage(STORAGE_KEYS.BSKY_USER_ID, "")
|
||||||
|
const [reloadCount, setReloadCount] = useState(0)
|
||||||
const [message, setMessage] = useState<null | {
|
const [message, setMessage] = useState<null | {
|
||||||
type: (typeof MESSAGE_TYPE)[keyof typeof MESSAGE_TYPE]
|
type: (typeof MESSAGE_TYPE)[keyof typeof MESSAGE_TYPE]
|
||||||
message: string
|
message: string
|
||||||
@ -31,8 +34,18 @@ function IndexPopup() {
|
|||||||
setMessage({ type: MESSAGE_TYPE.ERROR, message })
|
setMessage({ type: MESSAGE_TYPE.ERROR, message })
|
||||||
}
|
}
|
||||||
|
|
||||||
const searchBskyUser = async (e: FormEvent) => {
|
const reloadActiveTab = async () => {
|
||||||
e.preventDefault()
|
const [{ id: tabId }] = await chrome.tabs.query({
|
||||||
|
active: true,
|
||||||
|
currentWindow: true
|
||||||
|
})
|
||||||
|
await chrome.tabs.reload(tabId)
|
||||||
|
}
|
||||||
|
|
||||||
|
const searchBskyUser = async (e?: FormEvent) => {
|
||||||
|
if(e) {
|
||||||
|
e.preventDefault()
|
||||||
|
}
|
||||||
|
|
||||||
const [{ url: currentUrl }] = await chrome.tabs.query({
|
const [{ url: currentUrl }] = await chrome.tabs.query({
|
||||||
active: true,
|
active: true,
|
||||||
@ -82,10 +95,17 @@ function IndexPopup() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setErrorMessage(
|
if(e.message && e.message.includes("Could not establish connection") && reloadCount < MAX_RELOAD_COUNT) {
|
||||||
"Error: Something went wrong. Please reload the web page and try again."
|
setReloadCount((prev) => prev + 1)
|
||||||
)
|
await reloadActiveTab()
|
||||||
console.error(e)
|
await new Promise(r => setTimeout(r, 3000))
|
||||||
|
await searchBskyUser()
|
||||||
|
} else {
|
||||||
|
setErrorMessage(
|
||||||
|
"Error: Something went wrong. Please reload the web page and try again."
|
||||||
|
)
|
||||||
|
console.error(e)
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
setIsLoading(false)
|
setIsLoading(false)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user