You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.5 KiB
57 lines
1.5 KiB
4 years ago
|
import extension from 'extensionizer';
|
||
|
import log from 'loglevel';
|
||
5 years ago
|
|
||
|
const returnToOnboardingInitiatorTab = async (onboardingInitiator) => {
|
||
4 years ago
|
const tab = await new Promise((resolve) => {
|
||
|
extension.tabs.update(
|
||
|
onboardingInitiator.tabId,
|
||
|
{ active: true },
|
||
|
// eslint-disable-next-line no-shadow
|
||
|
(tab) => {
|
||
|
if (tab) {
|
||
4 years ago
|
resolve(tab);
|
||
4 years ago
|
} else {
|
||
|
// silence console message about unchecked error
|
||
|
if (extension.runtime.lastError) {
|
||
4 years ago
|
log.debug(extension.runtime.lastError);
|
||
4 years ago
|
}
|
||
4 years ago
|
resolve();
|
||
5 years ago
|
}
|
||
4 years ago
|
},
|
||
4 years ago
|
);
|
||
|
});
|
||
5 years ago
|
|
||
4 years ago
|
if (tab) {
|
||
4 years ago
|
window.close();
|
||
4 years ago
|
} else {
|
||
5 years ago
|
// this case can happen if the tab was closed since being checked with `extension.tabs.get`
|
||
4 years ago
|
log.warn(
|
||
|
`Setting current tab to onboarding initiator has failed; falling back to redirect`,
|
||
4 years ago
|
);
|
||
|
window.location.assign(onboardingInitiator.location);
|
||
5 years ago
|
}
|
||
4 years ago
|
};
|
||
5 years ago
|
|
||
|
export const returnToOnboardingInitiator = async (onboardingInitiator) => {
|
||
4 years ago
|
const tab = await new Promise((resolve) => {
|
||
4 years ago
|
// eslint-disable-next-line no-shadow
|
||
5 years ago
|
extension.tabs.get(onboardingInitiator.tabId, (tab) => {
|
||
|
if (tab) {
|
||
4 years ago
|
resolve(tab);
|
||
5 years ago
|
} else {
|
||
|
// silence console message about unchecked error
|
||
|
if (extension.runtime.lastError) {
|
||
4 years ago
|
log.debug(extension.runtime.lastError);
|
||
5 years ago
|
}
|
||
4 years ago
|
resolve();
|
||
5 years ago
|
}
|
||
4 years ago
|
});
|
||
|
});
|
||
5 years ago
|
|
||
|
if (tab) {
|
||
4 years ago
|
await returnToOnboardingInitiatorTab(onboardingInitiator);
|
||
5 years ago
|
} else {
|
||
4 years ago
|
window.location.assign(onboardingInitiator.location);
|
||
5 years ago
|
}
|
||
4 years ago
|
};
|