Browse Source

P4TB-213: Fix iframe content switching and use browser.tabs.create() to open the tutorial with moz-extension: URL.

1.1.101
Jorg Knobloch 1 year ago
parent
commit
bb1882f882
4 changed files with 17 additions and 18 deletions
  1. +3
    -6
      addon/background.js
  2. +7
    -5
      addon/content/tutorial/tutorial.js
  3. +4
    -4
      addon/experiments.js
  4. +3
    -3
      addon/schema.json

+ 3
- 6
addon/background.js View File

@ -14,11 +14,8 @@ browser.runtime.onStartup.addListener(() => browser.windows.onCreated.addListene
function showTutorial() {
browser.windows.onCreated.removeListener(showTutorial);
browser.pEp4Tb.showTutorial();
// The following code also displays the tutorial, but for some reason, the
// iframe content doesn't get refreshed reliably.
// browser.tabs.create({
// url: "content/tutorial/tutorial.html",
// });
browser.pEp4Tb.shouldShowTutorial().then((doit) => {
if (doit) browser.tabs.create({ url: "content/tutorial/tutorial.html" });
});
}

+ 7
- 5
addon/content/tutorial/tutorial.js View File

@ -1,7 +1,7 @@
function updateButtons(iframeSrc) {
let backButton = document.getElementById("backButton");
let nextButton = document.getElementById("nextButton");
switch (iframeSrc.replace(/.*\//, "")) {
switch (iframeSrc) {
case "tutorial-1.html":
backButton.disabled = true;
nextButton.disabled = false;
@ -21,14 +21,16 @@ function updateButtons(iframeSrc) {
function back() {
let iframe = document.getElementById("theIframe");
iframe.src = iframe.src.replace("-2", "-1").replace("-3", "-2").replace("-4", "-3");
updateButtons(iframe.src);
let newSrc = iframe.src.replace(/.*\//, "").replace("-2", "-1").replace("-3", "-2").replace("-4", "-3");
iframe.src = newSrc;
updateButtons(newSrc);
}
function next() {
let iframe = document.getElementById("theIframe");
iframe.src = iframe.src.replace("-3", "-4").replace("-2", "-3").replace("-1", "-2");
updateButtons(iframe.src);
let newSrc = iframe.src.replace(/.*\//, "").replace("-3", "-4").replace("-2", "-3").replace("-1", "-2");
iframe.src = newSrc;
updateButtons(newSrc);
}
window.addEventListener("load", () => {


+ 4
- 4
addon/experiments.js View File

@ -174,14 +174,14 @@ var pEp4Tb = class extends ExtensionCommon.ExtensionAPI {
setVersion(version) {
pEp4Tb.localeMessagesMap.set("pepversion", version);
},
showTutorial() {
// Show the tutorial.
async shouldShowTutorial() {
// Should we launch the tutorial in a tab?
if (Services.prefs.getBoolPref("extensions.pEp.showTutorial", true)) {
let win = Services.wm.getMostRecentWindow("mail:3pane");
win.openContentTab("chrome://pEp4Tb/content/tutorial/tutorial.html", "tab");
// TODO: Don't show it again, so set pref to false.
// Services.prefs.setBoolPref("extensions.pEp.showTutorial", false);
return true;
}
return false;
},
},
};


+ 3
- 3
addon/schema.json View File

@ -30,10 +30,10 @@
]
},
{
"name": "showTutorial",
"name": "shouldShowTutorial",
"type": "function",
"description": "Launch the tutorial in chrome tab.",
"async": false,
"description": "Should we launch the tutorial in a tab?",
"async": true,
"parameters": []
}
]


Loading…
Cancel
Save