Interceptor.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <template>
  2. <div class="flex p-4 space-y-4 items-start flex-col">
  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. const PROXY_ENABLED = useSetting("PROXY_ENABLED")
  28. const EXTENSIONS_ENABLED = useSetting("EXTENSIONS_ENABLED")
  29. const toggleSettingKey = <K extends KeysMatching<SettingsType, boolean>>(
  30. key: K
  31. ) => {
  32. if (key === "EXTENSIONS_ENABLED" && PROXY_ENABLED.value) {
  33. toggleSetting("PROXY_ENABLED")
  34. }
  35. if (key === "PROXY_ENABLED" && EXTENSIONS_ENABLED.value) {
  36. toggleSetting("EXTENSIONS_ENABLED")
  37. }
  38. toggleSetting(key)
  39. }
  40. </script>
  41. <script lang="ts">
  42. export default defineComponent({
  43. data() {
  44. return {
  45. extensionVersion: hasExtensionInstalled()
  46. ? window.__POSTWOMAN_EXTENSION_HOOK__.getVersion()
  47. : null,
  48. }
  49. },
  50. })
  51. </script>