mirror of
https://github.com/kiwix/kiwix-js-pwa.git
synced 2025-09-09 04:06:27 -04:00
Use Operations Panel for long-running processes
This commit is contained in:
parent
84e35492be
commit
0728a6ff27
@ -1337,8 +1337,8 @@ archiveFilesLegacy.addEventListener('change', function (files) {
|
||||
'Add to OPFS', true, null, 'Add to OPFS').then(function (confirmed) {
|
||||
if (!confirmed) return;
|
||||
// User has chosen a file or files to store in the Origin Private File System
|
||||
// This operation can take a long time, so show the spinner
|
||||
uiUtil.pollSpinner('<b>Please wait</b><br />Importing files to OPFS...', true);
|
||||
// This operation can take a long time, so show opsPanel
|
||||
uiUtil.pollOpsPanel('<b>Please wait:</b> Importing files to OPFS...', true);
|
||||
return cache.importOPFSEntries(filesArray).then(function () {
|
||||
uiUtil.systemAlert('<p>The selected files were successfully added to the OPFS!</p><p><b>We will now reload the app, so that the file(s) can be accessed at full speed.</b></p>')
|
||||
.then(function () {
|
||||
@ -1346,7 +1346,7 @@ archiveFilesLegacy.addEventListener('change', function (files) {
|
||||
settingsStore.setItem('lastSelectedArchive', filesArray[0].name, Infinity);
|
||||
window.location.reload();
|
||||
});
|
||||
uiUtil.clearSpinner();
|
||||
uiUtil.pollOpsPanel();
|
||||
processNativeDirHandle(params.pickedFolder);
|
||||
cache.populateOPFSStorageQuota();
|
||||
}).catch(function (err) {
|
||||
@ -1354,7 +1354,7 @@ archiveFilesLegacy.addEventListener('change', function (files) {
|
||||
var message = '<p>We could not import the selected files to the OPFS!</p><p>Reason: ' + err.message + '</p>';
|
||||
if (/iOS/.test(params.appType)) message = '<p>Unfortunately, iOS does not currently support importing files into the OPFS. Please disable the OPFS and use other file selection options.</p><p>Error message: ' + err.message + '</p>';
|
||||
uiUtil.systemAlert(message, 'OPFS import error');
|
||||
uiUtil.clearSpinner();
|
||||
uiUtil.pollOpsPanel();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -795,9 +795,9 @@ function importOPFSEntries (files) {
|
||||
return Promise.all(files.map(function (file) {
|
||||
return params.pickedFolder.getFileHandle(file.name, { create: true }).then(function (fileHandle) {
|
||||
return fileHandle.createWritable().then(function (writer) {
|
||||
uiUtil.pollSpinner('<b>Please wait</b><br />Importing ' + file.name.substring(0, 20) + '...', true);
|
||||
uiUtil.pollOpsPanel('<b>Please wait:</b> Importing ' + file.name + '...', true);
|
||||
return writer.write(file).then(function () {
|
||||
uiUtil.pollSpinner('<b>Please wait</b><br />Imported ' + file.name.substring(0, 20) + '...', true);
|
||||
uiUtil.pollOpsPanel('<b>Please wait:</b> Imported ' + file.name + '...', true);
|
||||
return writer.close();
|
||||
});
|
||||
});
|
||||
|
@ -611,9 +611,9 @@ function requestXhttpData (URL, lang, subj, kiwixDate) {
|
||||
var archiveName = e.target.href.replace(/^.*\/([^/]+)$/, '$1');
|
||||
var downloadArchiveWithFSA = function () {
|
||||
downloadSize = megabytes;
|
||||
uiUtil.pollSpinner('<b>Please wait</b><br />Downloading archive... 0%', true);
|
||||
uiUtil.pollOpsPanel('<b>Please wait:</b> Downloading archive... 0%', true);
|
||||
return cache.downloadArchiveToPickedFolder(archiveName, archiveUrl, reportDownloadProgress).then(function () {
|
||||
uiUtil.clearSpinner();
|
||||
uiUtil.pollOpsPanel();
|
||||
return uiUtil.systemAlert('<p>The archive ' + archiveName + ' has been downloaded to your device.</p>' +
|
||||
(params.useOPFS ? '<p><b>Reloading to activate new ZIM...</b></p>' : ''), 'Download complete').then(function () {
|
||||
if (params.useOPFS) {
|
||||
@ -634,21 +634,14 @@ function requestXhttpData (URL, lang, subj, kiwixDate) {
|
||||
});
|
||||
}
|
||||
if (megabytes > 1000) {
|
||||
if (params.useOPFS) {
|
||||
uiUtil.systemAlert('<p>Do you wish to download the <b>large</b> archive <b><i>' + archiveName + '</i> (' + megabytes$ + ' MB)</b> directly into the Origin Private File System?</p>' +
|
||||
'<p><b>If you proceed, do not close the app during the download.</b><p>' +
|
||||
'<p>If you prefer to download in the background, use a browser-managed download link instead, and afterwards import the file into the OPFS using the "Add file(s)" button.</p>',
|
||||
'Download large archive to OPFS?', true).then(function (result) {
|
||||
if (result) downloadArchiveWithFSA();
|
||||
});
|
||||
} else {
|
||||
uiUtil.systemAlert('<p>Do you wish to download the <b>large</b> archive <b><i>' + archiveName + '</i> (' + megabytes$ + ' MB)</b> to the current ZIM folder?</p>' +
|
||||
'<p><b>If you proceed, do not close the app during the download.</b></p>' +
|
||||
'<p>If you prefer to download in the background, use a browser-managed download link instead, and then move the file manually into your ZIM folder.</p>',
|
||||
'Download large archive to folder?', true).then(function (result) {
|
||||
if (result) downloadArchiveWithFSA();
|
||||
});
|
||||
}
|
||||
var message = '<p>Do you wish to download the following <b>large</b> archive ' + (params.useOPFS ? 'directly into the Origin Private File System' : 'to the current ZIM folder') +
|
||||
'?</p><ul><li><i>' + archiveName + '</i> (<b>' + megabytes$ + ' MB</b>)</li></ul><p><b><i>If you proceed, do not close the app during the download.</i></b><p>' +
|
||||
'<p>If you prefer to download in the background, use a browser-managed download link instead, and ' + (params.useOPFS
|
||||
? 'afterwards import the file into the OPFS using the "Add file(s)" button' : 'then move the file manually into your ZIM folder') + '.</p>';
|
||||
var messageTitle = 'Download large archive to ' + (params.useOPFS ? 'OPFS?' : 'folder?');
|
||||
uiUtil.systemAlert(message, messageTitle, true, 'Cancel', 'Download').then(function (result) {
|
||||
if (result) downloadArchiveWithFSA();
|
||||
});
|
||||
} else {
|
||||
downloadArchiveWithFSA();
|
||||
}
|
||||
@ -1057,19 +1050,19 @@ function reportDownloadProgress (data) {
|
||||
} else {
|
||||
var dataMB = (data / 1024 / 1024).toFixed(2);
|
||||
// console.debug('dataMB: ' + dataMB + '; data: ' + data);
|
||||
if (downloadSize > 0) {
|
||||
var percentageData = Math.floor(dataMB / downloadSize * 100);
|
||||
if (percentageData > percentageComplete) {
|
||||
percentageComplete = percentageData;
|
||||
uiUtil.pollSpinner('<b>Please wait</b><br />Downloading archive... ' + percentageComplete + '%', true);
|
||||
}
|
||||
}
|
||||
// If data is greater than 1GB, convert to GB
|
||||
if (data > 1073741824) {
|
||||
formattedData = (dataMB / 1024).toFixed(2) + ' GB';
|
||||
} else {
|
||||
formattedData = dataMB + ' MB';
|
||||
}
|
||||
if (downloadSize > 0) {
|
||||
var percentageData = Math.floor(dataMB / downloadSize * 100);
|
||||
if (percentageData > percentageComplete) {
|
||||
percentageComplete = percentageData;
|
||||
uiUtil.pollOpsPanel('<b>Do not quit app:</b> Downloading archive... ' + percentageComplete + '% (' + formattedData + ')', true);
|
||||
}
|
||||
}
|
||||
}
|
||||
serverResponse.innerHTML = 'Download progress: ' + formattedData;
|
||||
if (data === 'completed') {
|
||||
|
Loading…
x
Reference in New Issue
Block a user