MOBILE-3897 link: Wait for download to finish before open file
parent
43ce384da8
commit
e91e5d1cce
|
@ -364,7 +364,7 @@ export class CoreExternalContentDirective implements AfterViewInit, OnChanges, O
|
|||
finalUrl = CoreFile.convertFileSrc(finalUrl);
|
||||
}
|
||||
|
||||
if (!CoreUrlUtils.isLocalFileUrl(finalUrl) && !finalUrl.includes('#')) {
|
||||
if (!CoreUrlUtils.isLocalFileUrl(finalUrl) && !finalUrl.includes('#') && tagName !== 'A') {
|
||||
/* In iOS, if we use the same URL in embedded file and background download then the download only
|
||||
downloads a few bytes (cached ones). Add an anchor to the URL so both URLs are different.
|
||||
Don't add this anchor if the URL already has an anchor, otherwise other anchors might not work.
|
||||
|
|
|
@ -26,6 +26,7 @@ import { CoreConstants } from '@/core/constants';
|
|||
import { CoreContentLinksHelper } from '@features/contentlinks/services/contentlinks-helper';
|
||||
import { CoreCustomURLSchemes } from '@services/urlschemes';
|
||||
import { DomSanitizer } from '@singletons';
|
||||
import { CoreFilepool } from '@services/filepool';
|
||||
|
||||
/**
|
||||
* Directive to open a link in external browser or in the app.
|
||||
|
@ -218,6 +219,26 @@ export class CoreLinkDirective implements OnInit {
|
|||
}
|
||||
}
|
||||
|
||||
if (currentSite.isSitePluginFileUrl(href)) {
|
||||
// It's a site file. Check if it's being downloaded right now.
|
||||
const isDownloading = await CoreFilepool.isFileDownloadingByUrl(currentSite.getId(), href);
|
||||
|
||||
if (isDownloading) {
|
||||
// Wait for the download to finish before opening the file to prevent downloading it twice.
|
||||
const modal = await CoreDomUtils.showModalLoading();
|
||||
|
||||
try {
|
||||
const path = await CoreFilepool.downloadUrl(currentSite.getId(), href);
|
||||
|
||||
return this.openLocalFile(path);
|
||||
} catch {
|
||||
// Error downloading, just open the original URL.
|
||||
} finally {
|
||||
modal.dismiss();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.autoLogin == 'yes') {
|
||||
if (this.inApp) {
|
||||
await currentSite.openInAppWithAutoLogin(href);
|
||||
|
|
|
@ -457,13 +457,10 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
|
|||
size += fileSize;
|
||||
} catch {
|
||||
// Error getting size. Check if the file is being downloaded.
|
||||
try {
|
||||
await CoreFilepool.isFileDownloadingByUrl(siteId, CoreFileHelper.getFileUrl(file));
|
||||
|
||||
const isDownloading = await CoreFilepool.isFileDownloadingByUrl(siteId, CoreFileHelper.getFileUrl(file));
|
||||
if (isDownloading) {
|
||||
// If downloading, count as downloaded.
|
||||
size += file.filesize || 0;
|
||||
} catch {
|
||||
// Not downloading and not found in disk, don't add any size
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
|
|
@ -2280,13 +2280,19 @@ export class CoreFilepoolProvider {
|
|||
*
|
||||
* @param siteId The site ID.
|
||||
* @param fileUrl File URL.
|
||||
* @param Promise resolved if file is downloading, rejected otherwise.
|
||||
* @param Promise resolved with boolean: whether the file is downloading.
|
||||
*/
|
||||
async isFileDownloadingByUrl(siteId: string, fileUrl: string): Promise<void> {
|
||||
async isFileDownloadingByUrl(siteId: string, fileUrl: string): Promise<boolean> {
|
||||
const file = await this.fixPluginfileURL(siteId, fileUrl);
|
||||
const fileId = this.getFileIdByUrl(CoreFileHelper.getFileUrl(file));
|
||||
|
||||
try {
|
||||
await this.hasFileInQueue(siteId, fileId);
|
||||
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -8,6 +8,7 @@ information provided here is intended especially for developers.
|
|||
Now you have to pass all items and 3 optional params have been added.
|
||||
- CoreCourseModulePrefetchDelegate.getPrefetchHandlerFor now admits module name instead of full module object.
|
||||
- CoreCourse.getModuleBasicInfoByInstance and CoreCourse.getModuleBasicInfo have been modified to accept an "options" parameter instead of only siteId.
|
||||
- The function CoreFilepool.isFileDownloadingByUrl now returns Promise<boolean> instead of relying on resolve/reject.
|
||||
|
||||
=== 3.9.5 ===
|
||||
|
||||
|
|
Loading…
Reference in New Issue