From 8b4c693bec110c036481f9866a8b409bab8dd741 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Thu, 16 Jul 2020 11:49:19 +0200 Subject: [PATCH] MOBILE-3488 android: Open HTML files in InAppBrowser --- src/providers/utils/utils.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/providers/utils/utils.ts b/src/providers/utils/utils.ts index 75a50620b..8ee4a2798 100644 --- a/src/providers/utils/utils.ts +++ b/src/providers/utils/utils.ts @@ -897,13 +897,20 @@ export class CoreUtilsProvider { * @param path The local path of the file to be open. * @return Promise resolved when done. */ - openFile(path: string): Promise { + async openFile(path: string): Promise { // Convert the path to a native path if needed. path = CoreFile.instance.unconvertFileSrc(path); const extension = this.mimetypeUtils.getFileExtension(path); const mimetype = this.mimetypeUtils.getMimeType(extension); + if (mimetype == 'text/html' && this.platform.is('android')) { + // Open HTML local files in InAppBrowser, in system browser some embedded files aren't loaded. + this.openInApp(path); + + return; + } + // Path needs to be decoded, the file won't be opened if the path has %20 instead of spaces and so. try { path = decodeURIComponent(path); @@ -911,7 +918,9 @@ export class CoreUtilsProvider { // Error, use the original path. } - return this.fileOpener.open(path, mimetype).catch((error) => { + try { + await this.fileOpener.open(path, mimetype); + } catch (error) { this.logger.error('Error opening file ' + path + ' with mimetype ' + mimetype); this.logger.error('Error: ', JSON.stringify(error)); @@ -922,8 +931,8 @@ export class CoreUtilsProvider { error = this.translate.instant('core.erroropenfilenoapp'); } - return Promise.reject(error); - }); + throw error; + } } /**