refactor: move from network strategies to generic interceptor service (#3242)

This commit is contained in:
Andrew Bastin
2023-08-21 07:50:35 +05:30
committed by GitHub
parent d4d1e27ba9
commit 10bb68a538
33 changed files with 1470 additions and 1314 deletions

View File

@@ -0,0 +1,46 @@
import { InterceptorService } from "~/services/interceptor.service"
import { HoppModule } from "."
import { getService } from "./dioc"
import { platform } from "~/platform"
import { watch } from "vue"
import { applySetting } from "~/newstore/settings"
import { useSettingStatic } from "~/composables/settings"
export default <HoppModule>{
onVueAppInit() {
const interceptorService = getService(InterceptorService)
for (const interceptorDef of platform.interceptors.interceptors) {
if (interceptorDef.type === "standalone") {
interceptorService.registerInterceptor(interceptorDef.interceptor)
} else {
const service = getService(interceptorDef.service)
interceptorService.registerInterceptor(service)
}
}
interceptorService.currentInterceptorID.value =
platform.interceptors.default
watch(interceptorService.currentInterceptorID, (id) => {
applySetting(
"CURRENT_INTERCEPTOR_ID",
id ?? platform.interceptors.default
)
})
const [setting] = useSettingStatic("CURRENT_INTERCEPTOR_ID")
watch(
setting,
() => {
interceptorService.currentInterceptorID.value =
setting.value ?? platform.interceptors.default
},
{
immediate: true,
}
)
},
}