feat: stop extension status polling when a status is resolved
This commit is contained in:
@@ -164,16 +164,29 @@ export function useColorMode() {
|
|||||||
|
|
||||||
export function usePolled<T>(
|
export function usePolled<T>(
|
||||||
pollDurationMS: number,
|
pollDurationMS: number,
|
||||||
pollFunc: () => T
|
pollFunc: (stopPolling: () => void) => T
|
||||||
): Ref<T> {
|
): Ref<T> {
|
||||||
const result = shallowRef(pollFunc())
|
let polling = true
|
||||||
|
let handle: ReturnType<typeof setInterval> | undefined
|
||||||
|
|
||||||
const handle = setInterval(() => {
|
const stopPolling = () => {
|
||||||
result.value = pollFunc()
|
if (handle) {
|
||||||
}, pollDurationMS)
|
clearInterval(handle)
|
||||||
|
handle = undefined
|
||||||
|
polling = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = shallowRef(pollFunc(stopPolling))
|
||||||
|
|
||||||
|
if (polling) {
|
||||||
|
handle = setInterval(() => {
|
||||||
|
result.value = pollFunc(stopPolling)
|
||||||
|
}, pollDurationMS)
|
||||||
|
}
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
clearInterval(handle)
|
if (polling) stopPolling()
|
||||||
})
|
})
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|||||||
@@ -57,11 +57,8 @@ import { logPageView } from "~/helpers/fb/analytics"
|
|||||||
import { hookKeybindingsListener } from "~/helpers/keybindings"
|
import { hookKeybindingsListener } from "~/helpers/keybindings"
|
||||||
import { defineActionHandler } from "~/helpers/actions"
|
import { defineActionHandler } from "~/helpers/actions"
|
||||||
import useWindowSize from "~/helpers/utils/useWindowSize"
|
import useWindowSize from "~/helpers/utils/useWindowSize"
|
||||||
<<<<<<< HEAD
|
|
||||||
import { useSentry } from "~/helpers/sentry"
|
import { useSentry } from "~/helpers/sentry"
|
||||||
=======
|
|
||||||
import { useColorMode } from "~/helpers/utils/composables"
|
import { useColorMode } from "~/helpers/utils/composables"
|
||||||
>>>>>>> refactor: update color-mode usage to new composable
|
|
||||||
|
|
||||||
function appLayout() {
|
function appLayout() {
|
||||||
const rightSidebar = useSetting("SIDEBAR")
|
const rightSidebar = useSetting("SIDEBAR")
|
||||||
|
|||||||
@@ -249,6 +249,7 @@ import {
|
|||||||
hasFirefoxExtensionInstalled,
|
hasFirefoxExtensionInstalled,
|
||||||
} from "~/helpers/strategies/ExtensionStrategy"
|
} from "~/helpers/strategies/ExtensionStrategy"
|
||||||
import { getLocalConfig } from "~/newstore/localpersistence"
|
import { getLocalConfig } from "~/newstore/localpersistence"
|
||||||
|
import { browserIsChrome, browserIsFirefox } from "~/helpers/utils/userAgent"
|
||||||
|
|
||||||
const t = useI18n()
|
const t = useI18n()
|
||||||
const toast = useToast()
|
const toast = useToast()
|
||||||
@@ -262,19 +263,30 @@ const EXPAND_NAVIGATION = useSetting("EXPAND_NAVIGATION")
|
|||||||
const SIDEBAR_ON_LEFT = useSetting("SIDEBAR_ON_LEFT")
|
const SIDEBAR_ON_LEFT = useSetting("SIDEBAR_ON_LEFT")
|
||||||
const ZEN_MODE = useSetting("ZEN_MODE")
|
const ZEN_MODE = useSetting("ZEN_MODE")
|
||||||
|
|
||||||
const extensionVersion = usePolled(5000, () =>
|
const extensionVersion = usePolled(5000, (stopPolling) => {
|
||||||
hasExtensionInstalled()
|
const result = hasExtensionInstalled()
|
||||||
? window.__POSTWOMAN_EXTENSION_HOOK__.getVersion()
|
? window.__POSTWOMAN_EXTENSION_HOOK__.getVersion()
|
||||||
: null
|
: null
|
||||||
)
|
|
||||||
|
|
||||||
const hasChromeExtInstalled = usePolled(5000, () =>
|
// We don't need to poll anymore after we get value
|
||||||
hasChromeExtensionInstalled()
|
if (result) stopPolling()
|
||||||
)
|
|
||||||
|
|
||||||
const hasFirefoxExtInstalled = usePolled(5000, () =>
|
return result
|
||||||
hasFirefoxExtensionInstalled()
|
})
|
||||||
)
|
|
||||||
|
const hasChromeExtInstalled = usePolled(5000, (stopPolling) => {
|
||||||
|
// If not Chrome, we don't need to worry about this value changing
|
||||||
|
if (!browserIsChrome()) stopPolling()
|
||||||
|
|
||||||
|
return hasChromeExtensionInstalled()
|
||||||
|
})
|
||||||
|
|
||||||
|
const hasFirefoxExtInstalled = usePolled(5000, (stopPolling) => {
|
||||||
|
// If not Chrome, we don't need to worry about this value changing
|
||||||
|
if (!browserIsFirefox()) stopPolling()
|
||||||
|
|
||||||
|
return hasFirefoxExtensionInstalled()
|
||||||
|
})
|
||||||
|
|
||||||
const clearIcon = ref("rotate-ccw")
|
const clearIcon = ref("rotate-ccw")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user