Interceptor.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <template>
  2. <div class="flex flex-col space-y-4 p-4 items-start">
  3. <SmartToggle
  4. :on="PROXY_ENABLED"
  5. @change="toggleSettingKey('PROXY_ENABLED')"
  6. >
  7. {{ t("settings.proxy") }}
  8. </SmartToggle>
  9. <SmartToggle
  10. :on="EXTENSIONS_ENABLED"
  11. @change="toggleSettingKey('EXTENSIONS_ENABLED')"
  12. >
  13. {{ t("settings.extensions") }}:
  14. {{
  15. extensionVersion != null
  16. ? `v${extensionVersion.major}.${extensionVersion.minor}`
  17. : t("settings.extension_ver_not_reported")
  18. }}
  19. </SmartToggle>
  20. </div>
  21. </template>
  22. <script setup lang="ts">
  23. import { defineComponent } from "@nuxtjs/composition-api"
  24. import { KeysMatching } from "~/types/ts-utils"
  25. import { SettingsType, toggleSetting, useSetting } from "~/newstore/settings"
  26. import { hasExtensionInstalled } from "~/helpers/strategies/ExtensionStrategy"
  27. import { useI18n } from "~/helpers/utils/composables"
  28. const t = useI18n()
  29. const PROXY_ENABLED = useSetting("PROXY_ENABLED")
  30. const EXTENSIONS_ENABLED = useSetting("EXTENSIONS_ENABLED")
  31. const toggleSettingKey = <K extends KeysMatching<SettingsType, boolean>>(
  32. key: K
  33. ) => {
  34. if (key === "EXTENSIONS_ENABLED" && PROXY_ENABLED.value) {
  35. toggleSetting("PROXY_ENABLED")
  36. }
  37. if (key === "PROXY_ENABLED" && EXTENSIONS_ENABLED.value) {
  38. toggleSetting("EXTENSIONS_ENABLED")
  39. }
  40. toggleSetting(key)
  41. }
  42. </script>
  43. <script lang="ts">
  44. export default defineComponent({
  45. data() {
  46. return {
  47. extensionVersion: hasExtensionInstalled()
  48. ? window.__POSTWOMAN_EXTENSION_HOOK__.getVersion()
  49. : null,
  50. }
  51. },
  52. })
  53. </script>