2020-02-24 18:44:50 +00:00
|
|
|
import AxiosStrategy from './strategies/AxiosStrategy'
|
|
|
|
|
import ExtensionStrategy, { hasExtensionInstalled } from './strategies/ExtensionStrategy'
|
|
|
|
|
import FirefoxStrategy from './strategies/FirefoxStrategy'
|
|
|
|
|
import ChromeStrategy, { hasChromeExtensionInstalled } from './strategies/ChromeStrategy'
|
2020-01-16 06:25:43 +00:00
|
|
|
|
2020-02-20 03:22:42 +00:00
|
|
|
const isExtensionsAllowed = ({ state }) =>
|
2020-02-24 18:44:50 +00:00
|
|
|
typeof state.postwoman.settings.EXTENSIONS_ENABLED === 'undefined' ||
|
|
|
|
|
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-02-04 18:13:20 +00:00
|
|
|
if (isExtensionsAllowed(store)) {
|
2020-02-20 18:36:30 +00:00
|
|
|
if (hasExtensionInstalled()) {
|
2020-02-24 18:44:50 +00:00
|
|
|
return ExtensionStrategy(req, store)
|
2020-02-16 14:48:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The following strategies are deprecated and kept to support older version of the extensions
|
|
|
|
|
|
2020-02-04 18:13:20 +00:00
|
|
|
// Chrome Provides a chrome object for scripts to access
|
|
|
|
|
// Check its availability to say whether you are in Google Chrome
|
|
|
|
|
if (window.chrome && hasChromeExtensionInstalled()) {
|
2020-02-24 18:44:50 +00:00
|
|
|
return ChromeStrategy(req, store)
|
2020-02-04 18:13:20 +00:00
|
|
|
}
|
|
|
|
|
// The firefox plugin injects a function to send requests through it
|
|
|
|
|
// If that is available, then we can use the FirefoxStrategy
|
|
|
|
|
if (window.firefoxExtSendRequest) {
|
2020-02-24 18:44:50 +00:00
|
|
|
return FirefoxStrategy(req, store)
|
2020-02-04 18:13:20 +00:00
|
|
|
}
|
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 }
|