From 2258c1183b45f61e8ea81efedb7e963bb558f043 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Thu, 9 Feb 2023 10:33:33 +0100 Subject: [PATCH] MOBILE-4166 core: Move some CoreApp functions to CorePlatform --- .../mediaplugin/classes/videojs-ogvjs.ts | 6 +- .../data/fields/latlong/component/latlong.ts | 4 +- .../mod/resource/components/index/index.ts | 4 +- src/core/components/file/file.ts | 4 +- src/core/components/loading/loading.ts | 4 +- src/core/components/local-file/local-file.ts | 4 +- .../components/show-password/show-password.ts | 4 +- src/core/directives/external-content.ts | 4 +- .../services/fileuploader-helper.ts | 3 +- .../fileuploader/services/fileuploader.ts | 6 +- .../fileuploader/services/handlers/audio.ts | 4 +- .../fileuploader/services/handlers/file.ts | 5 +- .../fileuploader/services/handlers/video.ts | 4 +- .../login/pages/credentials/credentials.ts | 3 +- src/core/features/login/pages/site/site.ts | 3 +- src/core/features/mainmenu/pages/menu/menu.ts | 4 +- .../features/mainmenu/services/mainmenu.ts | 6 +- .../services/pushnotifications.ts | 4 +- .../classes/settings-sections-source.ts | 4 +- .../settings/pages/deviceinfo/deviceinfo.ts | 5 +- .../settings/pages/general/general.ts | 4 +- .../sharedfiles/services/handlers/settings.ts | 4 +- .../sharedfiles/services/handlers/upload.ts | 4 +- .../services/sharedfiles-helper.ts | 3 +- .../siteplugins/services/siteplugins.ts | 2 +- src/core/initializers/inject-ios-scripts.ts | 6 +- .../initializers/prepare-inapp-browser.ts | 7 +- src/core/services/app.ts | 37 +++------- src/core/services/file-helper.ts | 4 +- src/core/services/file.ts | 11 ++- src/core/services/geolocation.ts | 4 +- src/core/services/local-notifications.ts | 6 +- src/core/services/platform.ts | 51 ++++++++++++- src/core/services/tests/utils/text.test.ts | 8 +-- src/core/services/utils/dom.ts | 11 +-- src/core/services/utils/iframe.ts | 8 +-- src/core/services/utils/text.ts | 4 +- src/core/services/utils/utils.ts | 11 ++- src/core/singletons/dom.ts | 72 ------------------- src/testing/utils.ts | 2 + 40 files changed, 153 insertions(+), 191 deletions(-) diff --git a/src/addons/filter/mediaplugin/classes/videojs-ogvjs.ts b/src/addons/filter/mediaplugin/classes/videojs-ogvjs.ts index c86ad7531..16fc96e19 100644 --- a/src/addons/filter/mediaplugin/classes/videojs-ogvjs.ts +++ b/src/addons/filter/mediaplugin/classes/videojs-ogvjs.ts @@ -123,7 +123,7 @@ export class VideoJSOgvJS extends Tech { this.playerId = options.playerId; this.on('loadedmetadata', () => { - if (CoreApp.isIPhone()) { + if (CorePlatform.isIPhone()) { // iPhoneOS add some inline styles to the canvas, we need to remove it. const canvas = this.el_.getElementsByTagName('canvas')[0]; @@ -186,7 +186,7 @@ export class VideoJSOgvJS extends Tech { * @returns True if volume can be controlled. */ static canControlVolume(): boolean { - if (CoreApp.isIPhone()) { + if (CorePlatform.isIPhone()) { return false; } @@ -393,7 +393,7 @@ export class VideoJSOgvJS extends Tech { */ setVolume(percentAsDecimal: number): void { // eslint-disable-next-line no-prototype-builtins - if (!CoreApp.isIPhone() && this.el_.hasOwnProperty('volume')) { + if (!CorePlatform.isIPhone() && this.el_.hasOwnProperty('volume')) { this.el_.volume = percentAsDecimal; } } diff --git a/src/addons/mod/data/fields/latlong/component/latlong.ts b/src/addons/mod/data/fields/latlong/component/latlong.ts index 38398beae..17c7a4f18 100644 --- a/src/addons/mod/data/fields/latlong/component/latlong.ts +++ b/src/addons/mod/data/fields/latlong/component/latlong.ts @@ -18,8 +18,8 @@ import { Component } from '@angular/core'; import { FormBuilder } from '@angular/forms'; import { SafeUrl } from '@angular/platform-browser'; import { CoreAnyError } from '@classes/errors/error'; -import { CoreApp } from '@services/app'; import { CoreGeolocation, CoreGeolocationError, CoreGeolocationErrorReason } from '@services/geolocation'; +import { CorePlatform } from '@services/platform'; import { CoreDomUtils } from '@services/utils/dom'; import { DomSanitizer } from '@singletons'; @@ -73,7 +73,7 @@ export class AddonModDataFieldLatlongComponent extends AddonModDataFieldPluginBa const northFixed = north ? north.toFixed(4) : '0.0000'; const eastFixed = east ? east.toFixed(4) : '0.0000'; - if (CoreApp.isIOS()) { + if (CorePlatform.isIOS()) { url = 'http://maps.apple.com/?ll=' + northFixed + ',' + eastFixed + '&near=' + northFixed + ',' + eastFixed; } else { url = 'geo:' + northFixed + ',' + eastFixed; diff --git a/src/addons/mod/resource/components/index/index.ts b/src/addons/mod/resource/components/index/index.ts index 545082efc..1fb0ecfeb 100644 --- a/src/addons/mod/resource/components/index/index.ts +++ b/src/addons/mod/resource/components/index/index.ts @@ -19,7 +19,6 @@ import { CoreCourseModuleMainResourceComponent } from '@features/course/classes/ import { CoreCourseContentsPage } from '@features/course/pages/contents/contents'; import { CoreCourse } from '@features/course/services/course'; import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate'; -import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network'; import { CoreFileHelper } from '@services/file-helper'; import { CoreSites } from '@services/sites'; @@ -35,6 +34,7 @@ import { AddonModResourceProvider, } from '../../services/resource'; import { AddonModResourceHelper } from '../../services/resource-helper'; +import { CorePlatform } from '@services/platform'; /** * Component that displays a resource. @@ -79,7 +79,7 @@ export class AddonModResourceIndexComponent extends CoreCourseModuleMainResource async ngOnInit(): Promise { super.ngOnInit(); - this.isIOS = CoreApp.isIOS(); + this.isIOS = CorePlatform.isIOS(); this.isOnline = CoreNetwork.isOnline(); // Refresh online status when changes. diff --git a/src/core/components/file/file.ts b/src/core/components/file/file.ts index 12f2d2fb2..d15e5e9e4 100644 --- a/src/core/components/file/file.ts +++ b/src/core/components/file/file.ts @@ -13,7 +13,6 @@ // limitations under the License. import { Component, Input, Output, OnInit, OnDestroy, EventEmitter } from '@angular/core'; -import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network'; import { CoreFilepool } from '@services/filepool'; import { CoreFileHelper } from '@services/file-helper'; @@ -27,6 +26,7 @@ import { CoreTextUtils } from '@services/utils/text'; import { CoreConstants } from '@/core/constants'; import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { CoreWSFile } from '@services/ws'; +import { CorePlatform } from '@services/platform'; /** * Component to handle a remote file. Shows the file name, icon (depending on mimetype) and a button @@ -87,7 +87,7 @@ export class CoreFileComponent implements OnInit, OnDestroy { this.fileSize = this.file.filesize; this.fileName = this.file.filename || ''; - this.isIOS = CoreApp.isIOS(); + this.isIOS = CorePlatform.isIOS(); this.defaultIsOpenWithPicker = CoreFileHelper.defaultIsOpenWithPicker(); this.openButtonIcon = this.defaultIsOpenWithPicker ? 'fas-file' : 'fas-share-square'; this.openButtonLabel = this.defaultIsOpenWithPicker ? 'core.openfile' : 'core.openwith'; diff --git a/src/core/components/loading/loading.ts b/src/core/components/loading/loading.ts index 832853f95..df08396dc 100644 --- a/src/core/components/loading/loading.ts +++ b/src/core/components/loading/loading.ts @@ -21,7 +21,7 @@ import { Translate } from '@singletons'; import { CoreDirectivesRegistry } from '@singletons/directives-registry'; import { CorePromisedValue } from '@classes/promised-value'; import { AsyncDirective } from '@classes/async-directive'; -import { CoreApp } from '@services/app'; +import { CorePlatform } from '@services/platform'; /** * Component to show a loading spinner and message while data is being loaded. @@ -146,7 +146,7 @@ export class CoreLoadingComponent implements OnInit, OnChanges, AfterViewInit, A if (loaded) { this.onReadyPromise.resolve(); this.restoreScrollPosition(); - if (CoreApp.isIOS()) { + if (CorePlatform.isIOS()) { this.mutationObserver.observe(this.element, { childList: true }); } } else { diff --git a/src/core/components/local-file/local-file.ts b/src/core/components/local-file/local-file.ts index 8301fbad3..62de411c7 100644 --- a/src/core/components/local-file/local-file.ts +++ b/src/core/components/local-file/local-file.ts @@ -25,8 +25,8 @@ import { CoreTextUtils } from '@services/utils/text'; import { CoreTimeUtils } from '@services/utils/time'; import { CoreUtils, CoreUtilsOpenFileOptions, OpenFileAction } from '@services/utils/utils'; import { CoreForms } from '@singletons/form'; -import { CoreApp } from '@services/app'; import { CorePath } from '@singletons/path'; +import { CorePlatform } from '@services/platform'; /** * Component to handle a local file. Only files inside the app folder can be managed. @@ -83,7 +83,7 @@ export class CoreLocalFileComponent implements OnInit { this.timemodified = CoreTimeUtils.userDate(metadata.modificationTime.getTime(), 'core.strftimedatetimeshort'); - this.isIOS = CoreApp.isIOS(); + this.isIOS = CorePlatform.isIOS(); this.defaultIsOpenWithPicker = CoreFileHelper.defaultIsOpenWithPicker(); this.openButtonIcon = this.defaultIsOpenWithPicker ? 'fas-file' : 'fas-share-square'; this.openButtonLabel = this.defaultIsOpenWithPicker ? 'core.openfile' : 'core.openwith'; diff --git a/src/core/components/show-password/show-password.ts b/src/core/components/show-password/show-password.ts index 12289e0d7..3b61044bf 100644 --- a/src/core/components/show-password/show-password.ts +++ b/src/core/components/show-password/show-password.ts @@ -15,7 +15,7 @@ import { Component, OnInit, AfterViewInit, Input, ElementRef, ContentChild } from '@angular/core'; import { IonInput } from '@ionic/angular'; -import { CoreApp } from '@services/app'; +import { CorePlatform } from '@services/platform'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreUtils } from '@services/utils/utils'; @@ -121,7 +121,7 @@ export class CoreShowPasswordComponent implements OnInit, AfterViewInit { this.setData(this.input); // In Android, the keyboard is closed when the input type changes. Focus it again. - if (isFocused && CoreApp.isAndroid()) { + if (isFocused && CorePlatform.isAndroid()) { CoreDomUtils.focusElement(this.input); } } diff --git a/src/core/directives/external-content.ts b/src/core/directives/external-content.ts index dcf6977c1..a4cd4afa7 100644 --- a/src/core/directives/external-content.ts +++ b/src/core/directives/external-content.ts @@ -23,7 +23,6 @@ import { EventEmitter, OnDestroy, } from '@angular/core'; -import { CoreApp } from '@services/app'; import { CoreFile } from '@services/file'; import { CoreFilepool, CoreFilepoolFileActions, CoreFilepoolFileEventData } from '@services/filepool'; import { CoreSites } from '@services/sites'; @@ -39,6 +38,7 @@ import { Translate } from '@singletons'; import { AsyncDirective } from '@classes/async-directive'; import { CoreDirectivesRegistry } from '@singletons/directives-registry'; import { CorePromisedValue } from '@classes/promised-value'; +import { CorePlatform } from '@services/platform'; /** * Directive to handle external content. @@ -117,7 +117,7 @@ export class CoreExternalContentDirective implements AfterViewInit, OnChanges, O newSource.setAttribute('src', url); if (type) { - if (CoreApp.isAndroid() && type == 'video/quicktime') { + if (CorePlatform.isAndroid() && type == 'video/quicktime') { // Fix for VideoJS/Chrome bug https://github.com/videojs/video.js/issues/423 . newSource.setAttribute('type', 'video/mp4'); } else { diff --git a/src/core/features/fileuploader/services/fileuploader-helper.ts b/src/core/features/fileuploader/services/fileuploader-helper.ts index 30fe5ebf1..47b649a28 100644 --- a/src/core/features/fileuploader/services/fileuploader-helper.ts +++ b/src/core/features/fileuploader/services/fileuploader-helper.ts @@ -19,7 +19,6 @@ import { ChooserResult } from '@ionic-native/chooser/ngx'; import { FileEntry, IFile } from '@ionic-native/file/ngx'; import { MediaFile } from '@ionic-native/media-capture/ngx'; -import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network'; import { CoreFile, CoreFileProvider, CoreFileProgressEvent } from '@services/file'; import { CoreDomUtils } from '@services/utils/dom'; @@ -652,7 +651,7 @@ export class CoreFileUploaderHelperProvider { options.mediaType = Camera.MediaType.PICTURE; } else if (!imageSupported && videoSupported) { options.mediaType = Camera.MediaType.VIDEO; - } else if (CoreApp.isIOS()) { + } else if (CorePlatform.isIOS()) { // Only get all media in iOS because in Android using this option allows uploading any kind of file. options.mediaType = Camera.MediaType.ALLMEDIA; } diff --git a/src/core/features/fileuploader/services/fileuploader.ts b/src/core/features/fileuploader/services/fileuploader.ts index 4949c64ff..f40ee7490 100644 --- a/src/core/features/fileuploader/services/fileuploader.ts +++ b/src/core/features/fileuploader/services/fileuploader.ts @@ -18,7 +18,6 @@ import { FileEntry } from '@ionic-native/file/ngx'; import { MediaFile, CaptureError, CaptureAudioOptions, CaptureVideoOptions } from '@ionic-native/media-capture/ngx'; import { Subject } from 'rxjs'; -import { CoreApp } from '@services/app'; import { CoreFile, CoreFileProvider } from '@services/file'; import { CoreFilepool } from '@services/filepool'; import { CoreSites } from '@services/sites'; @@ -33,6 +32,7 @@ import { CoreError } from '@classes/errors/error'; import { CoreSite } from '@classes/site'; import { CoreFileEntry, CoreFileHelper } from '@services/file-helper'; import { CorePath } from '@singletons/path'; +import { CorePlatform } from '@services/platform'; /** * File upload options. @@ -236,7 +236,7 @@ export class CoreFileUploaderProvider { getCameraUploadOptions(uri: string, isFromAlbum?: boolean): CoreFileUploaderOptions { const extension = CoreMimetypeUtils.guessExtensionFromUrl(uri); const mimetype = CoreMimetypeUtils.getMimeType(extension); - const isIOS = CoreApp.isIOS(); + const isIOS = CorePlatform.isIOS(); const options: CoreFileUploaderOptions = { deleteAfterUpload: !isFromAlbum, mimeType: mimetype, @@ -259,7 +259,7 @@ export class CoreFileUploaderProvider { // If the file was picked from the album, delete it only if it was copied to the app's folder. options.deleteAfterUpload = CoreFile.isFileInAppFolder(uri); - if (CoreApp.isAndroid()) { + if (CorePlatform.isAndroid()) { // Picking an image from album in Android adds a timestamp at the end of the file. Delete it. options.fileName = options.fileName.replace(/(\.[^.]*)\?[^.]*$/, '$1'); } diff --git a/src/core/features/fileuploader/services/handlers/audio.ts b/src/core/features/fileuploader/services/handlers/audio.ts index 99c4030ed..cdce9f086 100644 --- a/src/core/features/fileuploader/services/handlers/audio.ts +++ b/src/core/features/fileuploader/services/handlers/audio.ts @@ -45,10 +45,10 @@ export class CoreFileUploaderAudioHandlerService implements CoreFileUploaderHand * @returns Supported mimetypes. */ getSupportedMimetypes(mimetypes: string[]): string[] { - if (CoreApp.isIOS()) { + if (CorePlatform.isIOS()) { // In iOS it's recorded as WAV. return CoreUtils.filterByRegexp(mimetypes, /^audio\/wav$/); - } else if (CoreApp.isAndroid()) { + } else if (CorePlatform.isAndroid()) { // In Android we don't know the format the audio will be recorded, so accept any audio mimetype. return CoreUtils.filterByRegexp(mimetypes, /^audio\//); } else { diff --git a/src/core/features/fileuploader/services/handlers/file.ts b/src/core/features/fileuploader/services/handlers/file.ts index 54407e387..0ed301042 100644 --- a/src/core/features/fileuploader/services/handlers/file.ts +++ b/src/core/features/fileuploader/services/handlers/file.ts @@ -14,7 +14,6 @@ import { Injectable } from '@angular/core'; -import { CoreApp } from '@services/app'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreFileUploaderHandler, CoreFileUploaderHandlerData, CoreFileUploaderHandlerResult } from '../fileuploader-delegate'; import { CoreFileUploaderHelper } from '../fileuploader-helper'; @@ -94,7 +93,7 @@ export class CoreFileUploaderFileHandlerService implements CoreFileUploaderHandl const input = document.createElement('input'); input.setAttribute('type', 'file'); input.classList.add('core-fileuploader-file-handler-input'); - if (mimetypes && mimetypes.length && (!CoreApp.isAndroid() || mimetypes.length == 1)) { + if (mimetypes && mimetypes.length && (!CorePlatform.isAndroid() || mimetypes.length == 1)) { // Don't use accept attribute in Android with several mimetypes, it's not supported. input.setAttribute('accept', mimetypes.join(', ')); } @@ -134,7 +133,7 @@ export class CoreFileUploaderFileHandlerService implements CoreFileUploaderHandl } }); - if (CoreApp.isIOS()) { + if (CorePlatform.isIOS()) { // In iOS, the click on the input stopped working for some reason. We need to put it 1 level higher. element.parentElement?.appendChild(input); diff --git a/src/core/features/fileuploader/services/handlers/video.ts b/src/core/features/fileuploader/services/handlers/video.ts index b22f0750f..0472f2248 100644 --- a/src/core/features/fileuploader/services/handlers/video.ts +++ b/src/core/features/fileuploader/services/handlers/video.ts @@ -45,10 +45,10 @@ export class CoreFileUploaderVideoHandlerService implements CoreFileUploaderHand * @returns Supported mimetypes. */ getSupportedMimetypes(mimetypes: string[]): string[] { - if (CoreApp.isIOS()) { + if (CorePlatform.isIOS()) { // In iOS it's recorded as MOV. return CoreUtils.filterByRegexp(mimetypes, /^video\/quicktime$/); - } else if (CoreApp.isAndroid()) { + } else if (CorePlatform.isAndroid()) { // In Android we don't know the format the video will be recorded, so accept any video mimetype. return CoreUtils.filterByRegexp(mimetypes, /^video\//); } else { diff --git a/src/core/features/login/pages/credentials/credentials.ts b/src/core/features/login/pages/credentials/credentials.ts index c5c69bfc3..5841c1e7e 100644 --- a/src/core/features/login/pages/credentials/credentials.ts +++ b/src/core/features/login/pages/credentials/credentials.ts @@ -32,6 +32,7 @@ import { CoreUserSupport } from '@features/user/services/support'; import { CoreUserSupportConfig } from '@features/user/classes/support/support-config'; import { CoreUserGuestSupportConfig } from '@features/user/classes/support/guest-support-config'; import { SafeHtml } from '@angular/platform-browser'; +import { CorePlatform } from '@services/platform'; /** * Page to enter the user credentials. @@ -108,7 +109,7 @@ export class CoreLoginCredentialsPage implements OnInit, OnDestroy { this.pageLoaded = true; } - if (CoreApp.isIOS()) { + if (CorePlatform.isIOS()) { // Make iOS auto-fill work. The field that isn't focused doesn't get updated, do it manually. // Debounce it to prevent triggering this function too often when the user is typing. this.valueChangeSubscription = this.credForm.valueChanges.pipe(debounceTime(1000)).subscribe((changes) => { diff --git a/src/core/features/login/pages/site/site.ts b/src/core/features/login/pages/site/site.ts index 7673fa6fc..4fb73cadf 100644 --- a/src/core/features/login/pages/site/site.ts +++ b/src/core/features/login/pages/site/site.ts @@ -45,6 +45,7 @@ import { CoreErrorInfoComponent } from '@components/error-info/error-info'; import { CoreUserSupportConfig } from '@features/user/classes/support/support-config'; import { CoreUserGuestSupportConfig } from '@features/user/classes/support/guest-support-config'; import { CoreLoginError } from '@classes/errors/loginerror'; +import { CorePlatform } from '@services/platform'; /** * Site (url) chooser when adding a new site. @@ -93,7 +94,7 @@ export class CoreLoginSitePage implements OnInit { // Load fixed sites if they're set. if (CoreLoginHelper.hasSeveralFixedSites()) { url = this.initSiteSelector(); - } else if (CoreConstants.CONFIG.enableonboarding && !CoreApp.isIOS()) { + } else if (CoreConstants.CONFIG.enableonboarding && !CorePlatform.isIOS()) { this.initOnboarding(); } diff --git a/src/core/features/mainmenu/pages/menu/menu.ts b/src/core/features/mainmenu/pages/menu/menu.ts index 39211bd1b..f75066f04 100644 --- a/src/core/features/mainmenu/pages/menu/menu.ts +++ b/src/core/features/mainmenu/pages/menu/menu.ts @@ -17,7 +17,6 @@ import { IonTabs } from '@ionic/angular'; import { BackButtonEvent } from '@ionic/core'; import { Subscription } from 'rxjs'; -import { CoreApp } from '@services/app'; import { CoreEvents, CoreEventObserver } from '@singletons/events'; import { CoreMainMenu, CoreMainMenuProvider } from '../../services/mainmenu'; import { CoreMainMenuDelegate, CoreMainMenuHandlerToDisplay } from '../../services/mainmenu-delegate'; @@ -31,6 +30,7 @@ import { trigger, state, style, transition, animate } from '@angular/animations' import { CoreSites } from '@services/sites'; import { CoreDom } from '@singletons/dom'; import { CoreLogger } from '@singletons/logger'; +import { CorePlatform } from '@services/platform'; const ANIMATION_DURATION = 500; @@ -135,7 +135,7 @@ export class CoreMainMenuPage implements OnInit, OnDestroy { }); document.addEventListener('ionBackButton', this.backButtonFunction); - if (CoreApp.isIOS()) { + if (CorePlatform.isIOS()) { // In iOS, the resize event is triggered before the keyboard is opened/closed and not triggered again once done. // Init handlers again once keyboard is closed since the resize event doesn't have the updated height. this.keyboardObserver = CoreEvents.on(CoreEvents.KEYBOARD_CHANGE, (kbHeight: number) => { diff --git a/src/core/features/mainmenu/services/mainmenu.ts b/src/core/features/mainmenu/services/mainmenu.ts index 39cd39869..583d6b0da 100644 --- a/src/core/features/mainmenu/services/mainmenu.ts +++ b/src/core/features/mainmenu/services/mainmenu.ts @@ -14,7 +14,6 @@ import { Injectable } from '@angular/core'; -import { CoreApp } from '@services/app'; import { CoreLang, CoreLangLanguage } from '@services/lang'; import { CoreSites } from '@services/sites'; import { CoreConstants } from '@/core/constants'; @@ -23,6 +22,7 @@ import { Device, makeSingleton } from '@singletons'; import { CoreArray } from '@singletons/array'; import { CoreTextUtils } from '@services/utils/text'; import { CoreScreen } from '@services/screen'; +import { CorePlatform } from '@services/platform'; declare module '@singletons/events' { @@ -196,9 +196,9 @@ export class CoreMainMenuProvider { osversion: Device.version, }; - if (CoreApp.isAndroid()) { + if (CorePlatform.isAndroid()) { replacements.devicetype = 'Android'; - } else if (CoreApp.isIOS()) { + } else if (CorePlatform.isIOS()) { replacements.devicetype = 'iPhone or iPad'; } else { replacements.devicetype = 'Other'; diff --git a/src/core/features/pushnotifications/services/pushnotifications.ts b/src/core/features/pushnotifications/services/pushnotifications.ts index 583f81451..417ee3849 100644 --- a/src/core/features/pushnotifications/services/pushnotifications.ts +++ b/src/core/features/pushnotifications/services/pushnotifications.ts @@ -228,7 +228,7 @@ export class CorePushNotificationsProvider { * @returns Promise resolved when done. */ protected async createDefaultChannel(): Promise { - if (!CoreApp.isAndroid()) { + if (!CorePlatform.isAndroid()) { return; } @@ -481,7 +481,7 @@ export class CorePushNotificationsProvider { text: notification.message, channel: 'PushPluginChannel', }; - const isAndroid = CoreApp.isAndroid(); + const isAndroid = CorePlatform.isAndroid(); const extraFeatures = CoreUtils.isTrueOrOne(data.extrafeatures); if (extraFeatures && isAndroid && CoreUtils.isFalseOrZero(data.notif)) { diff --git a/src/core/features/settings/classes/settings-sections-source.ts b/src/core/features/settings/classes/settings-sections-source.ts index d3bcd02c9..caf755488 100644 --- a/src/core/features/settings/classes/settings-sections-source.ts +++ b/src/core/features/settings/classes/settings-sections-source.ts @@ -16,7 +16,7 @@ import { CoreConstants } from '@/core/constants'; import { Params } from '@angular/router'; import { CoreRoutedItemsManagerSource } from '@classes/items-management/routed-items-manager-source'; import { SHAREDFILES_PAGE_NAME } from '@features/sharedfiles/sharedfiles.module'; -import { CoreApp } from '@services/app'; +import { CorePlatform } from '@services/platform'; /** * Provides a collection of setting sections. @@ -45,7 +45,7 @@ export class CoreSettingsSectionsSource extends CoreRoutedItemsManagerSource { - return CoreApp.isIOS(); + return CorePlatform.isIOS(); } /** diff --git a/src/core/features/sharedfiles/services/handlers/upload.ts b/src/core/features/sharedfiles/services/handlers/upload.ts index a32da22fd..c0ff37195 100644 --- a/src/core/features/sharedfiles/services/handlers/upload.ts +++ b/src/core/features/sharedfiles/services/handlers/upload.ts @@ -19,7 +19,7 @@ import { CoreFileUploaderHandlerData, CoreFileUploaderHandlerResult, } from '@features/fileuploader/services/fileuploader-delegate'; -import { CoreApp } from '@services/app'; +import { CorePlatform } from '@services/platform'; import { makeSingleton } from '@singletons'; import { CoreSharedFilesHelper } from '../sharedfiles-helper'; /** @@ -37,7 +37,7 @@ export class CoreSharedFilesUploadHandlerService implements CoreFileUploaderHand * @returns True or promise resolved with true if enabled. */ async isEnabled(): Promise { - return CoreApp.isIOS(); + return CorePlatform.isIOS(); } /** diff --git a/src/core/features/sharedfiles/services/sharedfiles-helper.ts b/src/core/features/sharedfiles/services/sharedfiles-helper.ts index c3ab8d4c3..4fa26d913 100644 --- a/src/core/features/sharedfiles/services/sharedfiles-helper.ts +++ b/src/core/features/sharedfiles/services/sharedfiles-helper.ts @@ -18,7 +18,6 @@ import { FileEntry } from '@ionic-native/file/ngx'; import { CoreCanceledError } from '@classes/errors/cancelederror'; import { CoreFileUploader } from '@features/fileuploader/services/fileuploader'; import { CoreFileUploaderHandlerResult } from '@features/fileuploader/services/fileuploader-delegate'; -import { CoreApp } from '@services/app'; import { CoreFile } from '@services/file'; import { CoreNavigator } from '@services/navigator'; import { CoreSites } from '@services/sites'; @@ -49,7 +48,7 @@ export class CoreSharedFilesHelperProvider { * Initialize. */ initialize(): void { - if (!CoreApp.isIOS()) { + if (!CorePlatform.isIOS()) { return; } diff --git a/src/core/features/siteplugins/services/siteplugins.ts b/src/core/features/siteplugins/services/siteplugins.ts index 6cc006cd4..77247e9b7 100644 --- a/src/core/features/siteplugins/services/siteplugins.ts +++ b/src/core/features/siteplugins/services/siteplugins.ts @@ -97,7 +97,7 @@ export class CoreSitePluginsProvider { }; if (args.appismobile) { - defaultArgs.appplatform = CoreApp.isIOS() ? 'ios' : 'android'; + defaultArgs.appplatform = CorePlatform.isIOS() ? 'ios' : 'android'; } return { diff --git a/src/core/initializers/inject-ios-scripts.ts b/src/core/initializers/inject-ios-scripts.ts index eac4cb3b6..36affed3f 100644 --- a/src/core/initializers/inject-ios-scripts.ts +++ b/src/core/initializers/inject-ios-scripts.ts @@ -12,14 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { CoreApp } from '@services/app'; import { CorePlatform } from '@services/platform'; import { CoreIframeUtils } from '@services/utils/iframe'; +/** + * Inject some scripts for iOS iframes. + */ export default async function(): Promise { await CorePlatform.ready(); - if (!CoreApp.isIOS() || !('WKUserScript' in window)) { + if (!CorePlatform.isIOS() || !('WKUserScript' in window)) { return; } diff --git a/src/core/initializers/prepare-inapp-browser.ts b/src/core/initializers/prepare-inapp-browser.ts index 026e6115c..18be057f6 100644 --- a/src/core/initializers/prepare-inapp-browser.ts +++ b/src/core/initializers/prepare-inapp-browser.ts @@ -16,7 +16,7 @@ import { CoreSiteError } from '@classes/errors/siteerror'; import { CoreLoginHelper } from '@features/login/services/login-helper'; import { CoreUserAuthenticatedSupportConfig } from '@features/user/classes/support/authenticated-support-config'; import { CoreUserNullSupportConfig } from '@features/user/classes/support/null-support-config'; -import { CoreApp } from '@services/app'; +import { CorePlatform } from '@services/platform'; import { CoreSites } from '@services/sites'; import { CoreCustomURLSchemes } from '@services/urlschemes'; import { CoreDomUtils } from '@services/utils/dom'; @@ -27,6 +27,9 @@ import { CoreEvents } from '@singletons/events'; let lastInAppUrl: string | null = null; +/** + * + */ export default function(): void { // Check URLs loaded in any InAppBrowser. CoreEvents.on(CoreEvents.IAB_LOAD_START, async (event) => { @@ -59,7 +62,7 @@ export default function(): void { return; } - if (!CoreApp.isAndroid()) { + if (!CorePlatform.isAndroid()) { return; } diff --git a/src/core/services/app.ts b/src/core/services/app.ts index 31bc790fc..56263b143 100644 --- a/src/core/services/app.ts +++ b/src/core/services/app.ts @@ -18,7 +18,7 @@ import { CoreDB } from '@services/db'; import { CoreEvents } from '@singletons/events'; import { SQLiteDB, SQLiteDBTableSchema } from '@classes/sqlitedb'; -import { makeSingleton, Keyboard, StatusBar, Device } from '@singletons'; +import { makeSingleton, Keyboard, StatusBar } from '@singletons'; import { CoreLogger } from '@singletons/logger'; import { CoreColors } from '@singletons/colors'; import { DBNAME, SCHEMA_VERSIONS_TABLE_NAME, SCHEMA_VERSIONS_TABLE_SCHEMA, SchemaVersionsDBEntry } from '@services/database/app'; @@ -204,7 +204,7 @@ export class CoreAppProvider { return 'itms-apps://itunes.apple.com/app/' + storesConfig.ios; } - if (this.isAndroid() && storesConfig.android) { + if (CorePlatform.isAndroid() && storesConfig.android) { return 'market://details?id=' + storesConfig.android; } @@ -219,13 +219,10 @@ export class CoreAppProvider { * Get platform major version number. * * @returns The platform major number. + * @deprecated since 4.1.1. Use CorePlatform.getPlatformMajorVersion instead. */ getPlatformMajorVersion(): number { - if (!CorePlatform.isMobile()) { - return 0; - } - - return Number(Device.version?.split('.')[0]); + return CorePlatform.getPlatformMajorVersion(); } /** @@ -242,9 +239,10 @@ export class CoreAppProvider { * Checks if the app is running in an Android mobile or tablet device. * * @returns Whether the app is running in an Android mobile or tablet device. + * @deprecated since 4.1.1. Use CorePlatform.isAndroid instead. */ isAndroid(): boolean { - return CorePlatform.isMobile() && CorePlatform.is('android'); + return CorePlatform.isAndroid(); } /** @@ -261,27 +259,10 @@ export class CoreAppProvider { * Checks if the app is running in an iOS mobile or tablet device. * * @returns Whether the app is running in an iOS mobile or tablet device. + * @deprecated since 4.1.1. Use CorePlatform.isIOS instead. */ isIOS(): boolean { - return CorePlatform.isMobile() && !CorePlatform.is('android'); - } - - /** - * Checks if the app is running in an iPad device. - * - * @returns Whether the app is running in an iPad device. - */ - isIPad(): boolean { - return CoreApp.isIOS() && CorePlatform.is('ipad'); - } - - /** - * Checks if the app is running in an iPhone device. - * - * @returns Whether the app is running in an iPhone device. - */ - isIPhone(): boolean { - return CoreApp.isIOS() && CorePlatform.is('iphone'); + return CorePlatform.isIOS(); } /** @@ -405,7 +386,7 @@ export class CoreAppProvider { */ openKeyboard(): void { // Open keyboard is not supported in desktop and in iOS. - if (this.isAndroid()) { + if (CorePlatform.isAndroid()) { Keyboard.show(); } } diff --git a/src/core/services/file-helper.ts b/src/core/services/file-helper.ts index 0d6404f01..93825ee38 100644 --- a/src/core/services/file-helper.ts +++ b/src/core/services/file-helper.ts @@ -15,7 +15,6 @@ import { Injectable } from '@angular/core'; import { FileEntry } from '@ionic-native/file/ngx'; -import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network'; import { CoreFile } from '@services/file'; import { CoreFilepool } from '@services/filepool'; @@ -31,6 +30,7 @@ import { CoreNetworkError } from '@classes/errors/network-error'; import { CoreConfig } from './config'; import { CoreCanceledError } from '@classes/errors/cancelederror'; import { CoreMimetypeUtils } from '@services/utils/mimetype'; +import { CorePlatform } from './platform'; /** * Provider to provide some helper functions regarding files and packages. @@ -44,7 +44,7 @@ export class CoreFileHelperProvider { * @returns Boolean. */ defaultIsOpenWithPicker(): boolean { - return CoreApp.isIOS() && CoreConstants.CONFIG.iOSDefaultOpenFileAction === OpenFileAction.OPEN_WITH; + return CorePlatform.isIOS() && CoreConstants.CONFIG.iOSDefaultOpenFileAction === OpenFileAction.OPEN_WITH; } /** diff --git a/src/core/services/file.ts b/src/core/services/file.ts index f03ac2e65..cc45ae0d2 100644 --- a/src/core/services/file.ts +++ b/src/core/services/file.ts @@ -16,7 +16,6 @@ import { Injectable } from '@angular/core'; import { FileEntry, DirectoryEntry, Entry, Metadata, IFile } from '@ionic-native/file/ngx'; -import { CoreApp } from '@services/app'; import { CoreMimetypeUtils } from '@services/utils/mimetype'; import { CoreTextUtils } from '@services/utils/text'; import { CoreUtils } from '@services/utils/utils'; @@ -140,9 +139,9 @@ export class CoreFileProvider { await CorePlatform.ready(); - if (CoreApp.isAndroid()) { + if (CorePlatform.isAndroid()) { this.basePath = File.externalApplicationStorageDirectory || this.basePath; - } else if (CoreApp.isIOS()) { + } else if (CorePlatform.isIOS()) { this.basePath = File.documentsDirectory || this.basePath; } else if (!this.isAvailable() || this.basePath === '') { this.logger.error('Error getting device OS.'); @@ -441,7 +440,7 @@ export class CoreFileProvider { */ calculateFreeSpace(): Promise { return File.getFreeDiskSpace().then((size) => { - if (CoreApp.isIOS()) { + if (CorePlatform.isIOS()) { // In iOS the size is in bytes. return Number(size); } @@ -717,7 +716,7 @@ export class CoreFileProvider { async getBasePathToDownload(): Promise { await this.init(); - if (CoreApp.isIOS()) { + if (CorePlatform.isIOS()) { // In iOS we want the internal URL (cdvfile://localhost/persistent/...). const dirEntry = await File.resolveDirectoryUrl(this.basePath); @@ -1263,7 +1262,7 @@ export class CoreFileProvider { return src; } - if (CoreApp.isIOS()) { + if (CorePlatform.isIOS()) { return src.replace(CoreConstants.CONFIG.ioswebviewscheme + '://localhost/_app_file_', 'file://'); } diff --git a/src/core/services/geolocation.ts b/src/core/services/geolocation.ts index bea6a4df5..e736cdba8 100644 --- a/src/core/services/geolocation.ts +++ b/src/core/services/geolocation.ts @@ -74,7 +74,7 @@ export class CoreGeolocationProvider { return; } - if (!CoreApp.isIOS()) { + if (!CorePlatform.isIOS()) { Diagnostic.switchToLocationSettings(); await CoreApp.waitForResume(30000); @@ -142,7 +142,7 @@ export class CoreGeolocationProvider { * Request and return the location authorization status for the application. */ protected async requestLocationAuthorization(): Promise { - if (!CoreApp.isIOS()) { + if (!CorePlatform.isIOS()) { await Diagnostic.requestLocationAuthorization(); return; diff --git a/src/core/services/local-notifications.ts b/src/core/services/local-notifications.ts index 7b9bc100a..2b3e9d820 100644 --- a/src/core/services/local-notifications.ts +++ b/src/core/services/local-notifications.ts @@ -186,7 +186,7 @@ export class CoreLocalNotificationsProvider { */ canDisableSound(): boolean { // Only allow disabling sound in Android 7 or lower. In iOS and Android 8+ it can easily be done with system settings. - return this.isAvailable() && CoreApp.isAndroid() && CoreApp.getPlatformMajorVersion() < 8; + return CorePlatform.isAndroid() && CorePlatform.getPlatformMajorVersion() < 8; } /** @@ -195,7 +195,7 @@ export class CoreLocalNotificationsProvider { * @returns Promise resolved when done. */ protected async createDefaultChannel(): Promise { - if (!CoreApp.isAndroid()) { + if (!CorePlatform.isAndroid()) { return; } @@ -583,7 +583,7 @@ export class CoreLocalNotificationsProvider { notification.data.component = component; notification.data.siteId = siteId; - if (CoreApp.isAndroid()) { + if (CorePlatform.isAndroid()) { notification.icon = notification.icon || 'res://icon'; notification.smallIcon = notification.smallIcon || 'res://smallicon'; notification.color = notification.color || CoreConstants.CONFIG.notificoncolor; diff --git a/src/core/services/platform.ts b/src/core/services/platform.ts index bb157d9f6..c00787d1b 100644 --- a/src/core/services/platform.ts +++ b/src/core/services/platform.ts @@ -14,7 +14,7 @@ import { Injectable } from '@angular/core'; import { Platform } from '@ionic/angular'; -import { makeSingleton } from '@singletons'; +import { Device, makeSingleton } from '@singletons'; /** * Extend Ionic's Platform service. @@ -22,6 +22,55 @@ import { makeSingleton } from '@singletons'; @Injectable({ providedIn: 'root' }) export class CorePlatformService extends Platform { + /** + * Get platform major version number. + * + * @returns The platform major number. + */ + getPlatformMajorVersion(): number { + if (!this.isMobile()) { + return 0; + } + + return Number(Device.version?.split('.')[0]); + } + + /** + * Checks if the app is running in an Android mobile or tablet device. + * + * @returns Whether the app is running in an Android mobile or tablet device. + */ + isAndroid(): boolean { + return this.isMobile() && this.is('android'); + } + + /** + * Checks if the app is running in an iOS mobile or tablet device. + * + * @returns Whether the app is running in an iOS mobile or tablet device. + */ + isIOS(): boolean { + return this.isMobile() && !this.is('android'); + } + + /** + * Checks if the app is running in an iPad device. + * + * @returns Whether the app is running in an iPad device. + */ + isIPad(): boolean { + return this.isIOS() && this.is('ipad'); + } + + /** + * Checks if the app is running in an iPhone device. + * + * @returns Whether the app is running in an iPhone device. + */ + isIPhone(): boolean { + return this.isIOS() && this.is('iphone'); + } + /** * Checks if the app is running in a mobile or tablet device (Cordova). * diff --git a/src/core/services/tests/utils/text.test.ts b/src/core/services/tests/utils/text.test.ts index 6d11a1050..67db67650 100644 --- a/src/core/services/tests/utils/text.test.ts +++ b/src/core/services/tests/utils/text.test.ts @@ -12,11 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { CoreApp } from '@services/app'; import { CoreTextUtilsProvider } from '@services/utils/text'; import { DomSanitizer } from '@singletons'; import { mockSingleton } from '@/testing/utils'; +import { CorePlatform } from '@services/platform'; describe('CoreTextUtilsProvider', () => { @@ -24,7 +24,7 @@ describe('CoreTextUtilsProvider', () => { let textUtils: CoreTextUtilsProvider; beforeEach(() => { - mockSingleton(CoreApp, [], { isAndroid: () => config.platform === 'android' }); + mockSingleton(CorePlatform, [], { isAndroid: () => config.platform === 'android' }); mockSingleton(DomSanitizer, [], { bypassSecurityTrustUrl: url => url }); textUtils = new CoreTextUtilsProvider(); @@ -57,7 +57,7 @@ describe('CoreTextUtilsProvider', () => { expect(url).toEqual('geo:0,0?q=Moodle%20Spain%20HQ'); expect(DomSanitizer.bypassSecurityTrustUrl).toHaveBeenCalled(); - expect(CoreApp.isAndroid).toHaveBeenCalled(); + expect(CorePlatform.isAndroid).toHaveBeenCalled(); }); it('builds address URL for non-Android platforms', () => { @@ -73,7 +73,7 @@ describe('CoreTextUtilsProvider', () => { expect(url).toEqual('http://maps.google.com?q=Moodle%20Spain%20HQ'); expect(DomSanitizer.bypassSecurityTrustUrl).toHaveBeenCalled(); - expect(CoreApp.isAndroid).toHaveBeenCalled(); + expect(CorePlatform.isAndroid).toHaveBeenCalled(); }); it('doesn\'t build address if it\'s already a URL', () => { diff --git a/src/core/services/utils/dom.ts b/src/core/services/utils/dom.ts index 33dad4c11..f91e453e4 100644 --- a/src/core/services/utils/dom.ts +++ b/src/core/services/utils/dom.ts @@ -57,6 +57,7 @@ import { CoreNetwork } from '@services/network'; import { CoreSiteError } from '@classes/errors/siteerror'; import { CoreUserSupport } from '@features/user/services/support'; import { CoreErrorInfoComponent } from '@components/error-info/error-info'; +import { CorePlatform } from '@services/platform'; /* * "Utils" service with helper functions for UI, DOM elements and HTML code. @@ -133,7 +134,7 @@ export class CoreDomUtilsProvider { const getAvailableBytes = async (): Promise => { const availableBytes = await CoreFile.calculateFreeSpace(); - if (CoreApp.isAndroid()) { + if (CorePlatform.isAndroid()) { return availableBytes; } else { // Space calculation is not accurate on iOS, but it gets more accurate when space is lower. @@ -152,7 +153,7 @@ export class CoreDomUtilsProvider { } else { const availableSize = CoreTextUtils.bytesToSize(availableBytes, 2); - if (CoreApp.isAndroid() && size.size > availableBytes - CoreConstants.MINIMUM_FREE_SPACE) { + if (CorePlatform.isAndroid() && size.size > availableBytes - CoreConstants.MINIMUM_FREE_SPACE) { throw new CoreError( Translate.instant( 'core.course.insufficientavailablespace', @@ -338,7 +339,7 @@ export class CoreDomUtilsProvider { if (focusElement === document.activeElement) { await CoreUtils.nextTick(); - if (CoreApp.isAndroid() && this.supportsInputKeyboard(focusElement)) { + if (CorePlatform.isAndroid() && this.supportsInputKeyboard(focusElement)) { // On some Android versions the keyboard doesn't open automatically. CoreApp.openKeyboard(); } @@ -1529,7 +1530,7 @@ export class CoreDomUtilsProvider { buttons: buttons, }); - const isDevice = CoreApp.isAndroid() || CoreApp.isIOS(); + const isDevice = CorePlatform.isAndroid() || CorePlatform.isIOS(); if (!isDevice) { // Treat all anchors so they don't override the app. const alertMessageEl: HTMLElement | null = alert.querySelector('.alert-message'); @@ -1989,7 +1990,7 @@ export class CoreDomUtilsProvider { * @returns Promise resolved when done. */ async waitForResizeDone(windowWidth?: number, windowHeight?: number, retries = 0): Promise { - if (!CoreApp.isIOS()) { + if (!CorePlatform.isIOS()) { return; // Only wait in iOS. } diff --git a/src/core/services/utils/iframe.ts b/src/core/services/utils/iframe.ts index fc3a05e25..1d79a73f0 100644 --- a/src/core/services/utils/iframe.ts +++ b/src/core/services/utils/iframe.ts @@ -16,7 +16,6 @@ import { Injectable } from '@angular/core'; import { WKUserScriptWindow } from 'cordova-plugin-wkuserscript'; import { WKWebViewCookiesWindow } from 'cordova-plugin-wkwebview-cookies'; -import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network'; import { CoreFile } from '@services/file'; import { CoreFileHelper } from '@services/file-helper'; @@ -32,6 +31,7 @@ import { CoreWindow } from '@singletons/window'; import { CoreContentLinksHelper } from '@features/contentlinks/services/contentlinks-helper'; import { CorePath } from '@singletons/path'; import { CorePromisedValue } from '@classes/promised-value'; +import { CorePlatform } from '@services/platform'; /** * Possible types of frame elements. @@ -531,7 +531,7 @@ export class CoreIframeUtilsProvider { } catch (error) { CoreDomUtils.showErrorModal(error); } - } else if (CoreApp.isIOS() && (!link.target || link.target == '_self') && element) { + } else if (CorePlatform.isIOS() && (!link.target || link.target == '_self') && element) { // In cordova ios 4.1.0 links inside iframes stopped working. We'll manually treat them. event && event.preventDefault(); if (element.tagName.toLowerCase() == 'object') { @@ -564,7 +564,7 @@ export class CoreIframeUtilsProvider { * @returns Promise resolved when done. */ async fixIframeCookies(url: string): Promise { - if (!CoreApp.isIOS() || !url || CoreUrlUtils.isLocalFileUrl(url)) { + if (!CorePlatform.isIOS() || !url || CoreUrlUtils.isLocalFileUrl(url)) { // No need to fix cookies. return; } @@ -593,7 +593,7 @@ export class CoreIframeUtilsProvider { * @returns Boolean. */ shouldDisplayHelp(): boolean { - return CoreApp.isIOS() && CoreApp.getPlatformMajorVersion() >= 14; + return CorePlatform.isIOS() && CorePlatform.getPlatformMajorVersion() >= 14; } /** diff --git a/src/core/services/utils/text.ts b/src/core/services/utils/text.ts index 24065d5cc..96fdce92a 100644 --- a/src/core/services/utils/text.ts +++ b/src/core/services/utils/text.ts @@ -16,7 +16,6 @@ import { Injectable } from '@angular/core'; import { SafeUrl } from '@angular/platform-browser'; import { ModalOptions } from '@ionic/core'; -import { CoreApp } from '@services/app'; import { CoreAnyError, CoreError } from '@classes/errors/error'; import { DomSanitizer, makeSingleton, Translate } from '@singletons'; import { CoreWSFile } from '@services/ws'; @@ -28,6 +27,7 @@ import { CoreText } from '@singletons/text'; import { CoreUrl } from '@singletons/url'; import { AlertButton } from '@ionic/angular'; import { CorePath } from '@singletons/path'; +import { CorePlatform } from '@services/platform'; /** * Different type of errors the app can treat. @@ -187,7 +187,7 @@ export class CoreTextUtilsProvider { return DomSanitizer.bypassSecurityTrustUrl(address); } - return DomSanitizer.bypassSecurityTrustUrl((CoreApp.isAndroid() ? 'geo:0,0?q=' : 'http://maps.google.com?q=') + + return DomSanitizer.bypassSecurityTrustUrl((CorePlatform.isAndroid() ? 'geo:0,0?q=' : 'http://maps.google.com?q=') + encodeURIComponent(address)); } diff --git a/src/core/services/utils/utils.ts b/src/core/services/utils/utils.ts index a55bd56ff..555b6eb14 100644 --- a/src/core/services/utils/utils.ts +++ b/src/core/services/utils/utils.ts @@ -17,7 +17,6 @@ import { InAppBrowserObject, InAppBrowserOptions } from '@ionic-native/in-app-br import { FileEntry } from '@ionic-native/file/ngx'; import { Subscription } from 'rxjs'; -import { CoreApp } from '@services/app'; import { CoreEvents } from '@singletons/events'; import { CoreFile } from '@services/file'; import { CoreLang } from '@services/lang'; @@ -995,12 +994,12 @@ export class CoreUtilsProvider { const extension = CoreMimetypeUtils.getFileExtension(path); const mimetype = extension && CoreMimetypeUtils.getMimeType(extension); - if (mimetype == 'text/html' && CoreApp.isAndroid()) { + if (mimetype == 'text/html' && CorePlatform.isAndroid()) { // Open HTML local files in InAppBrowser, in system browser some embedded files aren't loaded. this.openInApp(path); return; - } else if (extension === 'apk' && CoreApp.isAndroid()) { + } else if (extension === 'apk' && CorePlatform.isAndroid()) { const url = await CoreUtils.ignoreErrors( CoreFilepool.getFileUrlByPath(CoreSites.getCurrentSiteId(), CoreFile.removeBasePath(path)), ); @@ -1065,7 +1064,7 @@ export class CoreUtilsProvider { options.enableViewPortScale = options.enableViewPortScale ?? 'yes'; // Enable zoom on iOS by default. options.allowInlineMediaPlayback = options.allowInlineMediaPlayback ?? 'yes'; // Allow playing inline videos in iOS. - if (!options.location && CoreApp.isIOS() && url.indexOf('file://') === 0) { + if (!options.location && CorePlatform.isIOS() && url.indexOf('file://') === 0) { // The URL uses file protocol, don't show it on iOS. // In Android we keep it because otherwise we lose the whole toolbar. options.location = 'no'; @@ -1190,7 +1189,7 @@ export class CoreUtilsProvider { * @returns Promise resolved when opened. */ async openOnlineFile(url: string): Promise { - if (CoreApp.isAndroid()) { + if (CorePlatform.isAndroid()) { // In Android we need the mimetype to open it. const mimetype = await this.ignoreErrors(this.getMimeTypeFromUrl(url)); @@ -1823,7 +1822,7 @@ export class CoreUtilsProvider { shouldOpenWithDialog(options: CoreUtilsOpenFileOptions = {}): boolean { const openFileAction = options.iOSOpenFileAction ?? CoreConstants.CONFIG.iOSDefaultOpenFileAction; - return CoreApp.isIOS() && openFileAction == OpenFileAction.OPEN_WITH; + return CorePlatform.isIOS() && openFileAction == OpenFileAction.OPEN_WITH; } } diff --git a/src/core/singletons/dom.ts b/src/core/singletons/dom.ts index bfcbae0b1..9f74b584b 100644 --- a/src/core/singletons/dom.ts +++ b/src/core/singletons/dom.ts @@ -13,7 +13,6 @@ // limitations under the License. import { CoreCancellablePromise } from '@classes/cancellable-promise'; -import { CoreApp } from '@services/app'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreUtils } from '@services/utils/utils'; import { CoreEventObserver } from '@singletons/events'; @@ -568,77 +567,6 @@ export class CoreDom { } } -<<<<<<< HEAD - /** - * Get all source URLs and types for a video or audio. - * - * @param mediaElement Audio or video element. - * @returns List of sources. - */ - static getMediaSources(mediaElement: HTMLVideoElement | HTMLAudioElement): CoreMediaSource[] { - const sources = Array.from(mediaElement.querySelectorAll('source')).map(source => ({ - src: source.src || source.getAttribute('target-src') || '', - type: source.type, - })); - - if (mediaElement.src) { - sources.push({ - src: mediaElement.src, - type: '', - }); - } - - return sources; - } - - /** - * Check if a source needs to be converted to be able to reproduce it. - * - * @param source Source. - * @returns Whether needs conversion. - */ - static sourceNeedsConversion(source: CoreMediaSource): boolean { - if (!CoreApp.isIOS()) { - return false; - } - - let extension = source.type ? CoreMimetypeUtils.getExtension(source.type) : undefined; - if (!extension) { - extension = CoreMimetypeUtils.guessExtensionFromUrl(source.src); - } - - return !!extension && ['ogv', 'webm', 'oga', 'ogg'].includes(extension); - } - - /** - * Check if JS player should be used for a certain source. - * - * @param source Source. - * @returns Whether JS player should be used. - */ - static sourceUsesJavascriptPlayer(source: CoreMediaSource): boolean { - // For now, only use JS player if the source needs to be converted. - return CoreDom.sourceNeedsConversion(source); - } - - /** - * Check if JS player should be used for a certain audio or video. - * - * @param mediaElement Media element. - * @returns Whether JS player should be used. - */ - static mediaUsesJavascriptPlayer(mediaElement: HTMLVideoElement | HTMLAudioElement): boolean { - if (!CoreApp.isIOS()) { - return false; - } - - const sources = CoreDom.getMediaSources(mediaElement); - - return sources.some(source => CoreDom.sourceUsesJavascriptPlayer(source)); - } - -======= ->>>>>>> f42ea632ca (a) } /** diff --git a/src/testing/utils.ts b/src/testing/utils.ts index e790fff28..2a54ef674 100644 --- a/src/testing/utils.ts +++ b/src/testing/utils.ts @@ -62,6 +62,8 @@ const DEFAULT_SERVICE_SINGLETON_MOCKS: [CoreSingletonProxy, unknown][] = [ [CorePlatform, mock({ is: () => false, isMobile: () => false, + isAndroid: () => false, + isIOS: () => false, ready: () => Promise.resolve(), resume: new Subject(), })],