2020-02-25 02:06:23 +00:00
|
|
|
import AxiosStrategy from "./strategies/AxiosStrategy"
|
|
|
|
|
import ExtensionStrategy, { hasExtensionInstalled } from "./strategies/ExtensionStrategy"
|
2020-01-16 06:25:43 +00:00
|
|
|
|
2020-02-20 03:22:42 +00:00
|
|
|
const isExtensionsAllowed = ({ state }) =>
|
2020-02-25 02:06:23 +00:00
|
|
|
typeof state.postwoman.settings.EXTENSIONS_ENABLED === "undefined" ||
|
2020-02-24 18:44:50 +00:00
|
|
|
state.postwoman.settings.EXTENSIONS_ENABLED
|
2020-02-04 18:13:20 +00:00
|
|
|
|
2020-01-16 06:25:43 +00:00
|
|
|
const runAppropriateStrategy = (req, store) => {
|
2020-04-08 10:19:13 +00:00
|
|
|
if (isExtensionsAllowed(store) && hasExtensionInstalled()) {
|
|
|
|
|
return ExtensionStrategy(req, store)
|
2020-01-16 06:26:25 +00:00
|
|
|
}
|
2020-01-14 04:47:28 +00:00
|
|
|
|
2020-02-24 18:44:50 +00:00
|
|
|
return AxiosStrategy(req, store)
|
|
|
|
|
}
|
2020-01-16 06:25:43 +00:00
|
|
|
|
2020-02-04 19:01:26 +00:00
|
|
|
const sendNetworkRequest = (req, store) =>
|
2020-02-24 18:44:50 +00:00
|
|
|
runAppropriateStrategy(req, store).finally(() => window.$nuxt.$loading.finish())
|
2020-01-14 04:47:28 +00:00
|
|
|
|
2020-02-24 18:44:50 +00:00
|
|
|
export { sendNetworkRequest }
|