Merge pull request #494 from AndrewBastin/feat/firefox-strategy

Firefox Extension compatibility
This commit is contained in:
Andrew Bastin
2020-01-16 13:00:37 -05:00
committed by GitHub
4 changed files with 29 additions and 4 deletions

View File

@@ -1,12 +1,24 @@
import AxiosStrategy from "./strategies/AxiosStrategy";
import ProxyStrategy from "./strategies/ProxyStrategy";
import FirefoxStrategy from "./strategies/FirefoxStrategy";
const runAppropriateStrategy = (req, store) => {
// The firefox plugin injects a function to send requests through it
// If that is available, then we can use the FirefoxStrategy
if (window.firefoxExtSendRequest) {
return FirefoxStrategy(req, store);
}
const sendNetworkRequest = (req, store) => {
if (store.state.postwoman.settings.PROXY_ENABLED) {
return ProxyStrategy(req, store);
}
return AxiosStrategy(req, store);
};
}
const sendNetworkRequest = (req, store) =>
runAppropriateStrategy(req, store)
.finally(() => window.$nuxt.$loading.finish());
export { sendNetworkRequest };

View File

@@ -2,7 +2,6 @@ import axios from "axios";
const axiosStrategy = async (req, _store) => {
const res = await axios(req);
window.$nuxt.$loading.finish();
return res;
};

View File

@@ -0,0 +1,15 @@
const firefoxStrategy = (req, _store) => new Promise((resolve, reject) => {
const eventListener = (event) => {
window.removeEventListener("firefoxExtSendRequestComplete", eventListener);
if (event.detail.error) reject(JSON.parse(event.detail.error));
else resolve(JSON.parse(event.detail.response));
};
window.addEventListener("firefoxExtSendRequestComplete", eventListener);
window.firefoxExtSendRequest(req);
});
export default firefoxStrategy;

View File

@@ -6,7 +6,6 @@ const proxyStrategy = async (req, store) => {
"https://postwoman.apollotv.xyz/",
req
);
window.$nuxt.$loading.finish();
return data;
};