MOBILE-4166 core: Move some CoreApp functions to CorePlatform

main
Dani Palou 2023-02-09 10:33:33 +01:00
parent 884827afb6
commit 2258c1183b
40 changed files with 153 additions and 191 deletions

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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<void> {
super.ngOnInit();
this.isIOS = CoreApp.isIOS();
this.isIOS = CorePlatform.isIOS();
this.isOnline = CoreNetwork.isOnline();
// Refresh online status when changes.

View File

@ -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';

View File

@ -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 {

View File

@ -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';

View File

@ -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);
}
}

View File

@ -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 {

View File

@ -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;
}

View File

@ -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');
}

View File

@ -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 {

View File

@ -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);

View File

@ -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 {

View File

@ -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) => {

View File

@ -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();
}

View File

@ -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) => {

View File

@ -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';

View File

@ -228,7 +228,7 @@ export class CorePushNotificationsProvider {
* @returns Promise resolved when done.
*/
protected async createDefaultChannel(): Promise<void> {
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)) {

View File

@ -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<Cor
},
];
if (CoreApp.isIOS()) {
if (CorePlatform.isIOS()) {
sections.push({
name: 'core.sharedfiles.sharedfiles',
path: SHAREDFILES_PAGE_NAME + '/list/root',

View File

@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { CoreApp } from '@services/app';
import { Component, OnDestroy } from '@angular/core';
import { CoreConstants } from '@/core/constants';
import { CoreLocalNotifications } from '@services/local-notifications';
@ -111,10 +110,10 @@ export class CoreSettingsDeviceInfoPage implements OnDestroy {
if (CorePlatform.isMobile()) {
this.deviceInfo.deviceType = CorePlatform.is('tablet') ? 'tablet' : 'phone';
if (CoreApp.isAndroid()) {
if (CorePlatform.isAndroid()) {
this.deviceInfo.deviceOs = 'android';
this.deviceOsTranslated = 'Android';
} else if (CoreApp.isIOS()) {
} else if (CorePlatform.isIOS()) {
this.deviceInfo.deviceOs = 'ios';
this.deviceOsTranslated = 'iOS';
} else {

View File

@ -20,13 +20,13 @@ import { CoreLang } from '@services/lang';
import { CoreDomUtils } from '@services/utils/dom';
import { CorePushNotifications } from '@features/pushnotifications/services/pushnotifications';
import { CoreSettingsHelper, CoreColorScheme, CoreZoomLevel } from '../../services/settings-helper';
import { CoreApp } from '@services/app';
import { CoreIframeUtils } from '@services/utils/iframe';
import { Diagnostic, Translate } from '@singletons';
import { CoreSites } from '@services/sites';
import { CoreUtils } from '@services/utils/utils';
import { AlertButton } from '@ionic/angular';
import { CoreNavigator } from '@services/navigator';
import { CorePlatform } from '@services/platform';
/**
* Page that displays the general settings.
@ -81,7 +81,7 @@ export class CoreSettingsGeneralPage {
this.colorSchemes.push(CoreColorScheme.LIGHT);
this.selectedScheme = this.colorSchemes[0];
} else {
this.isAndroid = CoreApp.isAndroid();
this.isAndroid = CorePlatform.isAndroid();
this.colorSchemes = CoreSettingsHelper.getAllowedColorSchemes();
this.selectedScheme = await CoreConfig.get(CoreConstants.SETTINGS_COLOR_SCHEME, CoreColorScheme.LIGHT);
}

View File

@ -15,7 +15,7 @@
import { Injectable } from '@angular/core';
import { CoreSettingsHandler, CoreSettingsHandlerData } from '@features/settings/services/settings-delegate';
import { SHAREDFILES_PAGE_NAME } from '@features/sharedfiles/sharedfiles.module';
import { CoreApp } from '@services/app';
import { CorePlatform } from '@services/platform';
import { makeSingleton } from '@singletons';
/**
@ -33,7 +33,7 @@ export class CoreSharedFilesSettingsHandlerService implements CoreSettingsHandle
* @returns Whether or not the handler is enabled on a site level.
*/
async isEnabled(): Promise<boolean> {
return CoreApp.isIOS();
return CorePlatform.isIOS();
}
/**

View File

@ -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<boolean> {
return CoreApp.isIOS();
return CorePlatform.isIOS();
}
/**

View File

@ -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;
}

View File

@ -97,7 +97,7 @@ export class CoreSitePluginsProvider {
};
if (args.appismobile) {
defaultArgs.appplatform = CoreApp.isIOS() ? 'ios' : 'android';
defaultArgs.appplatform = CorePlatform.isIOS() ? 'ios' : 'android';
}
return {

View File

@ -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<void> {
await CorePlatform.ready();
if (!CoreApp.isIOS() || !('WKUserScript' in window)) {
if (!CorePlatform.isIOS() || !('WKUserScript' in window)) {
return;
}

View File

@ -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;
}

View File

@ -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();
}
}

View File

@ -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;
}
/**

View File

@ -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<number> {
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<string> {
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://');
}

View File

@ -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<void> {
if (!CoreApp.isIOS()) {
if (!CorePlatform.isIOS()) {
await Diagnostic.requestLocationAuthorization();
return;

View File

@ -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<void> {
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;

View File

@ -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).
*

View File

@ -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', () => {

View File

@ -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<number | null> => {
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<void> {
if (!CoreApp.isIOS()) {
if (!CorePlatform.isIOS()) {
return; // Only wait in iOS.
}

View File

@ -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<void> {
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;
}
/**

View File

@ -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));
}

View File

@ -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<void> {
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;
}
}

View File

@ -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)
}
/**

View File

@ -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<void>(),
})],