2019-11-22 18:03:51 +01:00
|
|
|
import extension from 'extensionizer'
|
|
|
|
import log from 'loglevel'
|
|
|
|
|
|
|
|
const returnToOnboardingInitiatorTab = async (onboardingInitiator) => {
|
|
|
|
const tab = await (new Promise((resolve) => {
|
2020-08-18 18:36:45 +02:00
|
|
|
// eslint-disable-next-line no-shadow
|
2019-11-22 18:03:51 +01:00
|
|
|
extension.tabs.update(onboardingInitiator.tabId, { active: true }, (tab) => {
|
|
|
|
if (tab) {
|
|
|
|
resolve(tab)
|
|
|
|
} else {
|
|
|
|
// silence console message about unchecked error
|
|
|
|
if (extension.runtime.lastError) {
|
|
|
|
log.debug(extension.runtime.lastError)
|
|
|
|
}
|
|
|
|
resolve()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}))
|
|
|
|
|
2020-08-14 13:47:43 +02:00
|
|
|
if (tab) {
|
|
|
|
window.close()
|
|
|
|
} else {
|
2019-11-22 18:03:51 +01:00
|
|
|
// this case can happen if the tab was closed since being checked with `extension.tabs.get`
|
2020-07-20 19:02:49 +02:00
|
|
|
log.warn(`Setting current tab to onboarding initiator has failed; falling back to redirect`)
|
2019-11-22 18:03:51 +01:00
|
|
|
window.location.assign(onboardingInitiator.location)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const returnToOnboardingInitiator = async (onboardingInitiator) => {
|
|
|
|
const tab = await (new Promise((resolve) => {
|
2020-08-18 18:36:45 +02:00
|
|
|
// eslint-disable-next-line no-shadow
|
2019-11-22 18:03:51 +01:00
|
|
|
extension.tabs.get(onboardingInitiator.tabId, (tab) => {
|
|
|
|
if (tab) {
|
|
|
|
resolve(tab)
|
|
|
|
} else {
|
|
|
|
// silence console message about unchecked error
|
|
|
|
if (extension.runtime.lastError) {
|
|
|
|
log.debug(extension.runtime.lastError)
|
|
|
|
}
|
|
|
|
resolve()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}))
|
|
|
|
|
|
|
|
if (tab) {
|
|
|
|
await returnToOnboardingInitiatorTab(onboardingInitiator)
|
|
|
|
} else {
|
|
|
|
window.location.assign(onboardingInitiator.location)
|
|
|
|
}
|
|
|
|
}
|