Less annoying PWA install prompts

Former-commit-id: 6afd8cb6ad6960d07eb7f739f1bc85715e4a02b2 [formerly b2a36741b16c26e1c3292355575104637ae4901d]
Former-commit-id: c5ee5ea4a9326bae3f9b3621dc538802e85aee3d
This commit is contained in:
Jaifroid 2020-03-01 15:10:09 +00:00
parent f6fa2b2da0
commit e4775e8278
2 changed files with 19 additions and 12 deletions

View File

@ -710,10 +710,19 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'utf8', 'images', 'cooki
$("#searchingArticles").hide();
$("#welcomeText").hide();
if (params.beforeinstallpromptFired) {
if (activeBtn !== 'btnConfigure' && !params.installLater)
document.getElementById('divInstall1').style.display = 'block';
else
document.getElementById('divInstall1').style.display = 'none';
var divInstall1 = document.getElementById('divInstall1');
if (activeBtn !== 'btnConfigure' && !params.installLater && (params.pagesLoaded === 3 || params.pagesLoaded === 9)) {
divInstall1.style.display = 'block';
setTimeout(function() {
// If installLater is now true, then the user clicked the Later button and the timeout in init.js will hide the display
if (!params.installLater) {
divInstall1.style.display = 'none';
resizeIFrame();
}
}, 9000);
} else {
divInstall1.style.display = 'none';
}
}
setTimeout(resizeIFrame, 100);
}
@ -2389,7 +2398,7 @@ define(['jquery', 'zimArchiveLoader', 'uiUtil', 'util', 'utf8', 'images', 'cooki
* @param {DirEntry} dirEntry The directory entry of the article to read
*/
function readArticle(dirEntry) {
params.pagesLoaded++;
if (dirEntry.isRedirect()) {
state.selectedArchive.resolveRedirect(dirEntry, readArticle);
} else {

View File

@ -81,6 +81,7 @@ params['printIntercept'] = false;
params['printInterception'] = false;
params['appIsLaunching'] = true; //Allows some routines to tell if the app has just been launched
params['PWAInstalled'] = decodeURIComponent(getCookie('PWAInstalled'));
params.pagesLoaded = 0; // Page counter used to show PWA Install Prompt only after user has played with the app for a while
//Prevent app boot loop with problematic pages that cause an app crash
if (getCookie('lastPageLoad') == 'failed') {
@ -182,16 +183,13 @@ window.addEventListener('beforeinstallprompt', function(e) {
if (!params.beforeinstallpromptFired && params.PWAInstalled !== params.version) {
params.beforeinstallpromptFired = true;
var config = document.getElementById('configuration');
if (config.style.display === 'none') {
divInstall1.style.display = 'block';
}
btnInstall1.addEventListener('click', installApp);
btnLater.addEventListener('click', function (e) {
e.preventDefault();
divInstall1.style.display = 'none';
if (config.style.display === 'none') {
alert('You can install this app later from Configuration');
}
divInstall1.innerHTML = '<b>You can install this app later from Configuration</b>';
setTimeout(function() {
divInstall1.style.display = 'none';
}, 4000);
params.installLater = true;
});
divInstall2.style.display = 'block';