Remove support for legacy extensions
This commit is contained in:
@@ -1,30 +1,13 @@
|
||||
import AxiosStrategy from "./strategies/AxiosStrategy"
|
||||
import ExtensionStrategy, { hasExtensionInstalled } from "./strategies/ExtensionStrategy"
|
||||
import FirefoxStrategy from "./strategies/FirefoxStrategy"
|
||||
import ChromeStrategy, { hasChromeExtensionInstalled } from "./strategies/ChromeStrategy"
|
||||
|
||||
const isExtensionsAllowed = ({ state }) =>
|
||||
typeof state.postwoman.settings.EXTENSIONS_ENABLED === "undefined" ||
|
||||
state.postwoman.settings.EXTENSIONS_ENABLED
|
||||
|
||||
const runAppropriateStrategy = (req, store) => {
|
||||
if (isExtensionsAllowed(store)) {
|
||||
if (hasExtensionInstalled()) {
|
||||
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()) {
|
||||
return ChromeStrategy(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)
|
||||
}
|
||||
if (isExtensionsAllowed(store) && hasExtensionInstalled()) {
|
||||
return ExtensionStrategy(req, store)
|
||||
}
|
||||
|
||||
return AxiosStrategy(req, store)
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
const EXTENSION_ID = "amknoiejhlmhancpahfcfcfhllgkpbld"
|
||||
|
||||
// Check if the Chrome Extension is present
|
||||
// The Chrome extension injects an empty span to help detection.
|
||||
// Also check for the presence of window.chrome object to confirm smooth operations
|
||||
export const hasChromeExtensionInstalled = () =>
|
||||
document.getElementById("chromePWExtensionDetect") !== null
|
||||
|
||||
const chromeWithoutProxy = (req, _store) =>
|
||||
new Promise((resolve, reject) => {
|
||||
chrome.runtime.sendMessage(
|
||||
EXTENSION_ID,
|
||||
{
|
||||
messageType: "send-req",
|
||||
data: {
|
||||
config: req,
|
||||
},
|
||||
},
|
||||
({ data }) => {
|
||||
if (data.error) {
|
||||
reject(data.error)
|
||||
} else {
|
||||
resolve(data.response)
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
const chromeWithProxy = (req, { state }) =>
|
||||
new Promise((resolve, reject) => {
|
||||
chrome.runtime.sendMessage(
|
||||
EXTENSION_ID,
|
||||
{
|
||||
messageType: "send-req",
|
||||
data: {
|
||||
config: {
|
||||
method: "post",
|
||||
url:
|
||||
state.postwoman.settings.PROXY_URL ||
|
||||
"https://postwoman.apollosoftware.xyz/",
|
||||
data: req
|
||||
}
|
||||
}
|
||||
},
|
||||
({ data }) => {
|
||||
if (data.error) {
|
||||
reject(error)
|
||||
} else {
|
||||
resolve(data.response.data)
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
const chromeStrategy = (req, store) => {
|
||||
if (store.state.postwoman.settings.PROXY_ENABLED) {
|
||||
return chromeWithProxy(req, store)
|
||||
} else {
|
||||
return chromeWithoutProxy(req, store)
|
||||
}
|
||||
}
|
||||
|
||||
export default chromeStrategy
|
||||
@@ -1,47 +0,0 @@
|
||||
const firefoxWithProxy = (req, { state }) =>
|
||||
new Promise((resolve, reject) => {
|
||||
const eventListener = event => {
|
||||
window.removeEventListener("firefoxExtSendRequestComplete", event)
|
||||
|
||||
if (event.detail.error) {
|
||||
reject(JSON.parse(event.detail.error))
|
||||
} else {
|
||||
resolve(JSON.parse(event.detail.response).data)
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener("firefoxExtSendRequestComplete", eventListener)
|
||||
|
||||
window.firefoxExtSendRequest({
|
||||
method: "post",
|
||||
url:
|
||||
state.postwoman.settings.PROXY_URL || "https://postwoman.apollosoftware.xyz/",
|
||||
data: req
|
||||
});
|
||||
});
|
||||
|
||||
const firefoxWithoutProxy = (req, _store) =>
|
||||
new Promise((resolve, reject) => {
|
||||
const eventListener = ({ detail }) => {
|
||||
window.removeEventListener("firefoxExtSendRequestComplete", eventListener)
|
||||
|
||||
if (detail.error) {
|
||||
reject(JSON.parse(detail.error))
|
||||
} else {
|
||||
resolve(JSON.parse(detail.response))
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener("firefoxExtSendRequestComplete", eventListener)
|
||||
|
||||
window.firefoxExtSendRequest(req)
|
||||
})
|
||||
|
||||
const firefoxStrategy = (req, store) => {
|
||||
if (store.state.postwoman.settings.PROXY_ENABLED) {
|
||||
return firefoxWithProxy(req, store)
|
||||
}
|
||||
return firefoxWithoutProxy(req, store)
|
||||
}
|
||||
|
||||
export default firefoxStrategy
|
||||
Reference in New Issue
Block a user