Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify Chrome and Firefox extensions #573

Merged
merged 2 commits into from
Feb 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions functions/network.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import AxiosStrategy from "./strategies/AxiosStrategy";
import ExtensionStrategy from "./strategies/ExtensionStrategy";
import FirefoxStrategy from "./strategies/FirefoxStrategy";
import ChromeStrategy, { hasChromeExtensionInstalled } from "./strategies/ChromeStrategy";

Expand All @@ -9,6 +10,12 @@ const isExtensionsAllowed = ({ state }) => {

const runAppropriateStrategy = (req, store) => {
if (isExtensionsAllowed(store)) {
if (typeof window.__POSTWOMAN_EXTENSION_HOOK__ !== 'undefined') {
return ExtensionStrategy(req, store);
}

// The following strategies are deprecated and kept to support older version of the extensions

// Chrome Provides a chrome object for scripts to access
// Check its availability to say whether you are in Google Chrome
if (window.chrome && hasChromeExtensionInstalled()) {
Expand Down
22 changes: 22 additions & 0 deletions functions/strategies/ExtensionStrategy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const extensionWithProxy = async (req, { state }) => {
const { data } = await window.__POSTWOMAN_EXTENSION_HOOK__.sendRequest({
method: "post",
url: state.postwoman.settings.PROXY_URL || "https://postwoman.apollotv.xyz/",
data: req
});
return data;
};

const extensionWithoutProxy = async (req, _store) => {
const res = await window.__POSTWOMAN_EXTENSION_HOOK__.sendRequest(req);
return res;
};

const extensionStrategy = (req, store) => {
if (store.state.postwoman.settings.PROXY_ENABLED) {
return extensionWithProxy(req, store);
}
return extensionWithoutProxy(req, store);
};

export default extensionStrategy;