From 82c6f6f6bc714b9c834540227bcc775c28135b94 Mon Sep 17 00:00:00 2001 From: Jesvin Jose Date: Fri, 17 Feb 2023 19:14:50 +0530 Subject: [PATCH] fix: response time for requests via extension has incorrect value (#2921) Co-authored-by: Andrew Bastin --- .../src/components/http/Request.vue | 7 +++++++ .../src/helpers/strategies/ExtensionStrategy.ts | 2 +- packages/hoppscotch-common/src/shims.d.ts | 12 ++---------- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/packages/hoppscotch-common/src/components/http/Request.vue b/packages/hoppscotch-common/src/components/http/Request.vue index 87637aedd..763f7db71 100644 --- a/packages/hoppscotch-common/src/components/http/Request.vue +++ b/packages/hoppscotch-common/src/components/http/Request.vue @@ -274,6 +274,10 @@ import { createShortcode } from "~/helpers/backend/mutations/Shortcode" import { runMutation } from "~/helpers/backend/GQLClient" import { UpdateRequestDocument } from "~/helpers/backend/graphql" import { getPlatformSpecialKey as getSpecialKey } from "~/helpers/platformutils" +import { + cancelRunningExtensionRequest, + hasExtensionInstalled, +} from "~/helpers/strategies/ExtensionStrategy" const t = useI18n() @@ -403,6 +407,9 @@ function isCURL(curl: string) { const cancelRequest = () => { loading.value = false + if (hasExtensionInstalled()) { + cancelRunningExtensionRequest() + } updateRESTResponse(null) } diff --git a/packages/hoppscotch-common/src/helpers/strategies/ExtensionStrategy.ts b/packages/hoppscotch-common/src/helpers/strategies/ExtensionStrategy.ts index 5d9cef4f4..5bb0b69df 100644 --- a/packages/hoppscotch-common/src/helpers/strategies/ExtensionStrategy.ts +++ b/packages/hoppscotch-common/src/helpers/strategies/ExtensionStrategy.ts @@ -16,7 +16,7 @@ export const hasFirefoxExtensionInstalled = () => hasExtensionInstalled() && browserIsFirefox() export const cancelRunningExtensionRequest = () => { - window.__POSTWOMAN_EXTENSION_HOOK__?.cancelRunningRequest() + window.__POSTWOMAN_EXTENSION_HOOK__?.cancelRequest() } export const defineSubscribableObject = (obj: T) => { diff --git a/packages/hoppscotch-common/src/shims.d.ts b/packages/hoppscotch-common/src/shims.d.ts index 84ea49fb5..3248a8527 100644 --- a/packages/hoppscotch-common/src/shims.d.ts +++ b/packages/hoppscotch-common/src/shims.d.ts @@ -8,7 +8,7 @@ interface PWExtensionHook { sendRequest: ( req: AxiosRequestConfig & { wantsBinary: boolean } ) => Promise - cancelRunningRequest: () => void + cancelRequest: () => void } type HoppExtensionStatusHook = { @@ -18,17 +18,9 @@ type HoppExtensionStatusHook = { } subscribe(prop: "status", func: (...args: any[]) => any): void } -declare global { +export declare global { interface Window { __POSTWOMAN_EXTENSION_HOOK__: PWExtensionHook | undefined __HOPP_EXTENSION_STATUS_PROXY__: HoppExtensionStatusHook | undefined } } - -// Vue builtins -declare module '*.vue' { - import type { DefineComponent } from 'vue' - // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types - const component: DefineComponent<{}, {}, any> - export default component -}