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

master
Jorg Knobloch 2 years ago
parent 4f7364a68f
commit bb1882f882

@ -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" });
});
}

@ -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", () => {

@ -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;
},
},
};

@ -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