Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Wait for onboarding status. #4263

Merged
merged 1 commit into from
Mar 26, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 34 additions & 32 deletions addon/webextension/background/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ this.main = (function() {
const manifest = browser.runtime.getManifest();
let backend;

let hasSeenOnboarding;

browser.storage.local.get(["hasSeenOnboarding"]).then((result) => {
hasSeenOnboarding = !!result.hasSeenOnboarding;
if (!hasSeenOnboarding) {
let hasSeenOnboarding = browser.storage.local.get(["hasSeenOnboarding"]).then((result) => {
const onboarded = !!result.hasSeenOnboarding;
if (!onboarded) {
setIconActive(false, null);
// Note that the branded name 'Firefox Screenshots' is not localized:
startBackground.photonPageActionPort.postMessage({
type: "setProperties",
title: "Firefox Screenshots"
});
}
hasSeenOnboarding = Promise.resolve(onboarded);
return hasSeenOnboarding;
}).catch((error) => {
log.error("Error getting hasSeenOnboarding:", error);
});
Expand Down Expand Up @@ -93,34 +93,36 @@ this.main = (function() {

// This is called by startBackground.js, directly in response to clicks on the Photon page action
exports.onClicked = catcher.watchFunction((tab) => {
if (shouldOpenMyShots(tab.url)) {
if (!hasSeenOnboarding) {
catcher.watchPromise(hasSeenOnboarding.then(onboarded => {
if (shouldOpenMyShots(tab.url)) {
if (!onboarded) {
catcher.watchPromise(analytics.refreshTelemetryPref().then(() => {
sendEvent("goto-onboarding", "selection-button", {incognito: tab.incognito});
return forceOnboarding();
}));
return;
}
catcher.watchPromise(analytics.refreshTelemetryPref().then(() => {
sendEvent("goto-onboarding", "selection-button", {incognito: tab.incognito});
return forceOnboarding();
sendEvent("goto-myshots", "about-newtab", {incognito: tab.incognito});
}));
return;
catcher.watchPromise(
auth.authHeaders()
.then(() => browser.tabs.update({url: backend + "/shots"})));
} else {
catcher.watchPromise(
toggleSelector(tab)
.then(active => {
const event = active ? "start-shot" : "cancel-shot";
sendEvent(event, "toolbar-button", {incognito: tab.incognito});
}, (error) => {
if ((!onboarded) && error.popupMessage === "UNSHOOTABLE_PAGE") {
sendEvent("goto-onboarding", "selection-button", {incognito: tab.incognito});
return forceOnboarding();
}
throw error;
}));
}
catcher.watchPromise(analytics.refreshTelemetryPref().then(() => {
sendEvent("goto-myshots", "about-newtab", {incognito: tab.incognito});
}));
catcher.watchPromise(
auth.authHeaders()
.then(() => browser.tabs.update({url: backend + "/shots"})));
} else {
catcher.watchPromise(
toggleSelector(tab)
.then(active => {
const event = active ? "start-shot" : "cancel-shot";
sendEvent(event, "toolbar-button", {incognito: tab.incognito});
}, (error) => {
if ((!hasSeenOnboarding) && error.popupMessage === "UNSHOOTABLE_PAGE") {
sendEvent("goto-onboarding", "selection-button", {incognito: tab.incognito});
return forceOnboarding();
}
throw error;
}));
}
}));
});

function forceOnboarding() {
Expand Down Expand Up @@ -273,8 +275,8 @@ this.main = (function() {
});

communication.register("hasSeenOnboarding", () => {
hasSeenOnboarding = true;
catcher.watchPromise(browser.storage.local.set({hasSeenOnboarding}));
hasSeenOnboarding = Promise.resolve(true);
catcher.watchPromise(browser.storage.local.set({hasSeenOnboarding: true}));
setIconActive(false, null);
startBackground.photonPageActionPort.postMessage({
type: "setProperties",
Expand Down
36 changes: 19 additions & 17 deletions addon/webextension/background/selectorLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,24 +66,26 @@ this.selectorLoader = (function() {
const loadingTabs = new Set();

exports.loadModules = function(tabId, hasSeenOnboarding) {
loadingTabs.add(tabId);
let promise = downloadOnlyCheck(tabId);
if (hasSeenOnboarding) {
promise = promise.then(() => {
return executeModules(tabId, standardScripts.concat(selectorScripts));
});
} else {
promise = promise.then(() => {
return executeModules(tabId, standardScripts.concat(onboardingScripts).concat(selectorScripts));
catcher.watchPromise(hasSeenOnboarding.then(onboarded => {
loadingTabs.add(tabId);
let promise = downloadOnlyCheck(tabId);
if (onboarded) {
promise = promise.then(() => {
return executeModules(tabId, standardScripts.concat(selectorScripts));
});
} else {
promise = promise.then(() => {
return executeModules(tabId, standardScripts.concat(onboardingScripts).concat(selectorScripts));
});
}
return promise.then((result) => {
loadingTabs.delete(tabId);
return result;
}, (error) => {
loadingTabs.delete(tabId);
throw error;
});
}
return promise.then((result) => {
loadingTabs.delete(tabId);
return result;
}, (error) => {
loadingTabs.delete(tabId);
throw error;
});
}));
};

// TODO: since bootstrap communication is now required, would this function
Expand Down