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

Commit

Permalink
Fix #2643, force onboarding when you visit /#hello
Browse files Browse the repository at this point in the history
  • Loading branch information
ianb committed Apr 21, 2017
1 parent a9c7f67 commit 48b37fe
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 0 deletions.
17 changes: 17 additions & 0 deletions addon/webextension/background/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ this.main = (function() {
});
}

function startSelectionWithOnboarding(tab) {
return analytics.refreshTelemetryPref().then(() => {
return selectorLoader.testIfLoaded(tab.id);
}).then((isLoaded) => {
if (!isLoaded) {
sendEvent("start-shot", "site-request");
setIconActive(true, tab.id);
selectorLoader.toggle(tab.id, false);
}
});
}

function shouldOpenMyShots(url) {
return /^about:(?:newtab|blank)/i.test(url) || /^resource:\/\/activity-streams\//i.test(url);
}
Expand Down Expand Up @@ -295,5 +307,10 @@ this.main = (function() {
return catcher.watchPromise(browser.tabs.create({url: "https://www.mozilla.org/privacy/firefox-cloud/"}));
});

// A Screenshots page wants us to start/force onboarding
communication.register("requestOnboarding", (sender) => {
return startSelectionWithOnboarding(sender.tab);
});

return exports;
})();
9 changes: 9 additions & 0 deletions addon/webextension/background/selectorLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ this.selectorLoader = (function() {
});
};

exports.testIfLoaded = function(tabId) {
return browser.tabs.executeScript(tabId, {
code: "!!this.selectorLoader",
runAt: "document_start"
}).then(result => {
return result && result[0];
});
};

exports.loadModules = function(tabId, hasSeenOnboarding) {
if (hasSeenOnboarding) {
return executeModules(tabId, standardScripts.concat(selectorScripts));
Expand Down
4 changes: 4 additions & 0 deletions addon/webextension/sitehelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ this.sitehelper = (function() {
}));
}));

document.addEventListener("request-onboarding", catcher.watchFunction((event) => {
callBackground("requestOnboarding");
}));

// Depending on the script loading order, the site might get the addon-present event,
// but probably won't - instead the site will ask for that event after it has loaded
document.addEventListener("request-addon-present", catcher.watchFunction(() => {
Expand Down
1 change: 1 addition & 0 deletions docs/METRICS.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ The primary change was in `server/src/pages/shot/share-buttons.js`
1. [x] Toggle shot button on `addon/start-shot/toolbar-button` (previous to 54 launch the label was `toolbar-pageshot-button`)
2. [ ] Use keyboard shortcut to start shot `addon/start-shot/keyboard-shortcut` (accel-alt-control-c) (FIXME: not yet implemented)
3. [x] Use the right-click context menu to start a shot `addon/start-shot/context-menu`
3. [x] Start shot with onboarding because the site requested it (typically a visit to `/#hello`) `addon/start-shot/site-request`
2. [x] Make a selection `addon/make-selection/selection-drag` with `cd2: {px width}, cd1: {px height}`
3. [x] Make a selection by clicking on an element `addon/make-selection/selection-click` with `cd2: {px width}, cd1: {px height}`
4. [x] Click but fail to find an element that can be selected `addon/no-selection/no-element-found` (error case, not sure when it happens)
Expand Down
8 changes: 8 additions & 0 deletions server/src/pages/homepage/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,12 @@ function render() {
page.render(model);
}

document.addEventListener("addon-present", () => {
if (location.hash === "#hello") {
document.dispatchEvent(new CustomEvent("request-onboarding"));
}
});

document.dispatchEvent(new CustomEvent("request-addon-present"));

window.controller = exports;

0 comments on commit 48b37fe

Please sign in to comment.