Interceptor.vue 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <template>
  2. <div class="flex flex-col p-4 space-y-4">
  3. <div class="flex flex-col">
  4. <h2 class="inline-flex pb-1 font-semibold text-secondaryDark">
  5. {{ t("settings.interceptor") }}
  6. </h2>
  7. <p class="inline-flex text-tiny">
  8. {{ t("settings.interceptor_description") }}
  9. </p>
  10. </div>
  11. <SmartRadioGroup v-model="interceptorSelection" :radios="interceptors" />
  12. <div
  13. v-if="interceptorSelection == 'EXTENSIONS_ENABLED' && !extensionVersion"
  14. class="flex space-x-2"
  15. >
  16. <ButtonSecondary
  17. to="https://chrome.google.com/webstore/detail/hoppscotch-browser-extens/amknoiejhlmhancpahfcfcfhllgkpbld"
  18. blank
  19. svg="brands/chrome"
  20. label="Chrome"
  21. outline
  22. class="!flex-1"
  23. />
  24. <ButtonSecondary
  25. to="https://addons.mozilla.org/en-US/firefox/addon/hoppscotch"
  26. blank
  27. svg="brands/firefox"
  28. label="Firefox"
  29. outline
  30. class="!flex-1"
  31. />
  32. </div>
  33. </div>
  34. </template>
  35. <script setup lang="ts">
  36. import { computed } from "@nuxtjs/composition-api"
  37. import { applySetting, toggleSetting, useSetting } from "~/newstore/settings"
  38. import { useI18n, useReadonlyStream } from "~/helpers/utils/composables"
  39. import { extensionStatus$ } from "~/newstore/HoppExtension"
  40. const t = useI18n()
  41. const PROXY_ENABLED = useSetting("PROXY_ENABLED")
  42. const EXTENSIONS_ENABLED = useSetting("EXTENSIONS_ENABLED")
  43. const currentExtensionStatus = useReadonlyStream(extensionStatus$, null)
  44. const extensionVersion = computed(() => {
  45. return currentExtensionStatus.value === "available"
  46. ? window.__POSTWOMAN_EXTENSION_HOOK__?.getVersion() ?? null
  47. : null
  48. })
  49. const interceptors = computed(() => [
  50. { value: "BROWSER_ENABLED" as const, label: t("state.none") },
  51. { value: "PROXY_ENABLED" as const, label: t("settings.proxy") },
  52. {
  53. value: "EXTENSIONS_ENABLED" as const,
  54. label:
  55. `${t("settings.extensions")}: ` +
  56. (extensionVersion.value !== null
  57. ? `v${extensionVersion.value.major}.${extensionVersion.value.minor}`
  58. : t("settings.extension_ver_not_reported")),
  59. },
  60. ])
  61. type InterceptorMode = typeof interceptors["value"][number]["value"]
  62. const interceptorSelection = computed<InterceptorMode>({
  63. get() {
  64. if (PROXY_ENABLED.value) return "PROXY_ENABLED"
  65. if (EXTENSIONS_ENABLED.value) return "EXTENSIONS_ENABLED"
  66. return "BROWSER_ENABLED"
  67. },
  68. set(val) {
  69. if (val === "EXTENSIONS_ENABLED") {
  70. applySetting("EXTENSIONS_ENABLED", true)
  71. if (PROXY_ENABLED.value) toggleSetting("PROXY_ENABLED")
  72. }
  73. if (val === "PROXY_ENABLED") {
  74. applySetting("PROXY_ENABLED", true)
  75. if (EXTENSIONS_ENABLED.value) toggleSetting("EXTENSIONS_ENABLED")
  76. }
  77. if (val === "BROWSER_ENABLED") {
  78. applySetting("PROXY_ENABLED", false)
  79. applySetting("EXTENSIONS_ENABLED", false)
  80. }
  81. },
  82. })
  83. </script>