diff --git a/src/addon/mod/data/fields/latlong/component/latlong.ts b/src/addon/mod/data/fields/latlong/component/latlong.ts index 38a62df64..fb3d0b27e 100644 --- a/src/addon/mod/data/fields/latlong/component/latlong.ts +++ b/src/addon/mod/data/fields/latlong/component/latlong.ts @@ -17,7 +17,7 @@ import { DomSanitizer, SafeUrl } from '@angular/platform-browser'; import { Platform } from 'ionic-angular'; import { Geolocation, GeolocationOptions } from '@ionic-native/geolocation'; import { AddonModDataFieldPluginComponent } from '../../../classes/field-plugin-component'; -import { CoreAppProvider } from '@providers/app'; +import { CoreApp, CoreAppProvider } from '@providers/app'; import { CoreDomUtilsProvider } from '@providers/utils/dom'; /** @@ -38,10 +38,11 @@ export class AddonModDataFieldLatlongComponent extends AddonModDataFieldPluginCo protected geolocation: Geolocation, protected domUtils: CoreDomUtilsProvider, protected sanitizer: DomSanitizer, - protected appProvider: CoreAppProvider) { + appProvider: CoreAppProvider + ) { super(fb); - this.showGeolocation = !this.appProvider.isDesktop(); + this.showGeolocation = !appProvider.isDesktop(); } /** @@ -73,7 +74,7 @@ export class AddonModDataFieldLatlongComponent extends AddonModDataFieldPluginCo const eastFixed = east ? east.toFixed(4) : '0.0000'; let url; - if (this.platform.is('ios')) { + if (CoreApp.instance.isIOS()) { url = 'http://maps.apple.com/?ll=' + northFixed + ',' + eastFixed + '&near=' + northFixed + ',' + eastFixed; } else { url = 'geo:' + northFixed + ',' + eastFixed; diff --git a/src/app/app.component.ts b/src/app/app.component.ts index d743d1269..c87872880 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -15,7 +15,7 @@ import { Component, OnInit, NgZone } from '@angular/core'; import { Platform, IonicApp } from 'ionic-angular'; import { Network } from '@ionic-native/network'; -import { CoreAppProvider } from '@providers/app'; +import { CoreApp, CoreAppProvider } from '@providers/app'; import { CoreEventsProvider } from '@providers/events'; import { CoreLangProvider } from '@providers/lang'; import { CoreLoggerProvider } from '@providers/logger'; @@ -146,7 +146,7 @@ export class MoodleMobileApp implements OnInit { }); this.utils.closeInAppBrowser(false); - } else if (this.platform.is('android')) { + } else if (CoreApp.instance.isAndroid()) { // Check if the URL has a custom URL scheme. In Android they need to be opened manually. const urlScheme = this.urlUtils.getUrlProtocol(url); if (urlScheme && urlScheme !== 'file' && urlScheme !== 'cdvfile') { @@ -260,7 +260,7 @@ export class MoodleMobileApp implements OnInit { // Pause Youtube videos in Android when app is put in background or screen is locked. this.platform.pause.subscribe(() => { - if (!this.platform.is('android')) { + if (!CoreApp.instance.isAndroid()) { return; } @@ -285,7 +285,7 @@ export class MoodleMobileApp implements OnInit { // Detect orientation changes. this.screenOrientation.onChange().subscribe( () => { - if (this.platform.is('ios')) { + if (CoreApp.instance.isIOS()) { // Force ios to recalculate safe areas when rotating. // This can be erased when https://issues.apache.org/jira/browse/CB-13448 issue is solved or // After switching to WkWebview. diff --git a/src/components/iframe/iframe.ts b/src/components/iframe/iframe.ts index 14dc98c54..0bc3cabde 100644 --- a/src/components/iframe/iframe.ts +++ b/src/components/iframe/iframe.ts @@ -16,7 +16,7 @@ import { Component, Input, Output, ViewChild, ElementRef, EventEmitter, OnChanges, SimpleChange, Optional } from '@angular/core'; import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser'; -import { NavController, Platform } from 'ionic-angular'; +import { NavController } from 'ionic-angular'; import { CoreFile } from '@providers/file'; import { CoreLoggerProvider } from '@providers/logger'; import { CoreDomUtilsProvider } from '@providers/utils/dom'; @@ -25,6 +25,7 @@ import { CoreIframeUtilsProvider } from '@providers/utils/iframe'; import { CoreUtilsProvider } from '@providers/utils/utils'; import { CoreSplitViewComponent } from '@components/split-view/split-view'; import { CoreUrl } from '@singletons/url'; +import { CoreApp } from '@providers/app'; import { WKWebViewCookiesWindow } from 'cordova-plugin-wkwebview-cookies'; @Component({ @@ -54,7 +55,7 @@ export class CoreIframeComponent implements OnChanges { protected urlUtils: CoreUrlUtilsProvider, protected utils: CoreUtilsProvider, @Optional() protected svComponent: CoreSplitViewComponent, - protected platform: Platform) { + ) { this.logger = logger.getInstance('CoreIframe'); this.loaded = new EventEmitter(); @@ -106,7 +107,7 @@ export class CoreIframeComponent implements OnChanges { if (changes.src) { const url = this.urlUtils.getYoutubeEmbedUrl(changes.src.currentValue) || changes.src.currentValue; - if (this.platform.is('ios') && url && !this.urlUtils.isLocalFileUrl(url)) { + if (CoreApp.instance.isIOS() && url && !this.urlUtils.isLocalFileUrl(url)) { // Save a "fake" cookie for the iframe's domain to fix a bug in WKWebView. try { const win = window; diff --git a/src/components/show-password/show-password.ts b/src/components/show-password/show-password.ts index 6ccf84a05..3449268b0 100644 --- a/src/components/show-password/show-password.ts +++ b/src/components/show-password/show-password.ts @@ -15,7 +15,7 @@ import { Component, OnInit, AfterViewInit, Input, ElementRef } from '@angular/core'; import { CoreDomUtilsProvider } from '@providers/utils/dom'; import { CoreUtilsProvider } from '@providers/utils/utils'; -import { Platform } from 'ionic-angular'; +import { CoreApp } from '@providers/app'; /** * Component to allow showing and hiding a password. The affected input MUST have a name to identify it. @@ -47,8 +47,11 @@ export class CoreShowPasswordComponent implements OnInit, AfterViewInit { protected input: HTMLInputElement; // Input affected. protected element: HTMLElement; // Current element. - constructor(element: ElementRef, private utils: CoreUtilsProvider, private domUtils: CoreDomUtilsProvider, - private platform: Platform) { + constructor( + element: ElementRef, + private utils: CoreUtilsProvider, + private domUtils: CoreDomUtilsProvider + ) { this.element = element.nativeElement; } @@ -114,7 +117,7 @@ export class CoreShowPasswordComponent implements OnInit, AfterViewInit { this.shown = !this.shown; this.setData(); - if (isFocused && this.platform.is('android')) { + if (isFocused && CoreApp.instance.isAndroid()) { // In Android, the keyboard is closed when the input type changes. Focus it again. setTimeout(() => { this.domUtils.focusElement(this.input); diff --git a/src/core/editor/components/rich-text-editor/rich-text-editor.ts b/src/core/editor/components/rich-text-editor/rich-text-editor.ts index 648567082..2bc3fb491 100644 --- a/src/core/editor/components/rich-text-editor/rich-text-editor.ts +++ b/src/core/editor/components/rich-text-editor/rich-text-editor.ts @@ -218,7 +218,7 @@ export class CoreEditorRichTextEditorComponent implements AfterContentInit, OnDe setTimeout(() => { let contentVisibleHeight = this.domUtils.getContentHeight(this.content); - if (!this.platform.is('android')) { + if (!CoreApp.instance.isAndroid()) { // In Android we ignore the keyboard height because it is not part of the web view. contentVisibleHeight -= this.kbHeight; } @@ -233,10 +233,10 @@ export class CoreEditorRichTextEditorComponent implements AfterContentInit, OnDe // Editor is ready, adjust Height if needed. let height; - if (this.platform.is('android')) { + if (CoreApp.instance.isAndroid()) { // In Android we ignore the keyboard height because it is not part of the web view. height = this.domUtils.getContentHeight(this.content) - this.getSurroundingHeight(this.element); - } else if (this.platform.is('ios') && this.kbHeight > 0 && this.platform.version().major < 12) { + } else if (CoreApp.instance.isIOS() && this.kbHeight > 0 && this.platform.version().major < 12) { // Keyboard open in iOS 11 or previous. The window height changes when the keyboard is open. height = window.innerHeight - this.getSurroundingHeight(this.element); diff --git a/src/core/fileuploader/providers/audio-handler.ts b/src/core/fileuploader/providers/audio-handler.ts index 8e4ae96ed..a9e32b93e 100644 --- a/src/core/fileuploader/providers/audio-handler.ts +++ b/src/core/fileuploader/providers/audio-handler.ts @@ -13,8 +13,7 @@ // limitations under the License. import { Injectable } from '@angular/core'; -import { Platform } from 'ionic-angular'; -import { CoreAppProvider } from '@providers/app'; +import { CoreApp } from '@providers/app'; import { CoreUtilsProvider } from '@providers/utils/utils'; import { CoreFileUploaderHandler, CoreFileUploaderHandlerData } from './delegate'; import { CoreFileUploaderHelperProvider } from './helper'; @@ -26,8 +25,10 @@ export class CoreFileUploaderAudioHandler implements CoreFileUploaderHandler { name = 'CoreFileUploaderAudio'; priority = 1600; - constructor(private appProvider: CoreAppProvider, private utils: CoreUtilsProvider, private platform: Platform, - private uploaderHelper: CoreFileUploaderHelperProvider) { } + constructor( + private utils: CoreUtilsProvider, + private uploaderHelper: CoreFileUploaderHelperProvider + ) { } /** * Whether or not the handler is enabled on a site level. @@ -35,7 +36,7 @@ export class CoreFileUploaderAudioHandler implements CoreFileUploaderHandler { * @return True or promise resolved with true if enabled. */ isEnabled(): boolean | Promise { - return this.appProvider.isMobile() || (this.appProvider.canGetUserMedia() && this.appProvider.canRecordMedia()); + return CoreApp.instance.isMobile() || (CoreApp.instance.canGetUserMedia() && CoreApp.instance.canRecordMedia()); } /** @@ -45,10 +46,10 @@ export class CoreFileUploaderAudioHandler implements CoreFileUploaderHandler { * @return Supported mimetypes. */ getSupportedMimetypes(mimetypes: string[]): string[] { - if (this.platform.is('ios')) { + if (CoreApp.instance.isIOS()) { // In iOS it's recorded as WAV. return this.utils.filterByRegexp(mimetypes, /^audio\/wav$/); - } else if (this.platform.is('android')) { + } else if (CoreApp.instance.isAndroid()) { // In Android we don't know the format the audio will be recorded, so accept any audio mimetype. return this.utils.filterByRegexp(mimetypes, /^audio\//); } else { diff --git a/src/core/fileuploader/providers/file-handler.ts b/src/core/fileuploader/providers/file-handler.ts index 54c689ebe..01f93288b 100644 --- a/src/core/fileuploader/providers/file-handler.ts +++ b/src/core/fileuploader/providers/file-handler.ts @@ -14,7 +14,7 @@ import { Injectable } from '@angular/core'; import { Platform } from 'ionic-angular'; -import { CoreAppProvider } from '@providers/app'; +import { CoreApp } from '@providers/app'; import { CoreDomUtilsProvider } from '@providers/utils/dom'; import { CoreTimeUtilsProvider } from '@providers/utils/time'; import { CoreFileUploaderHandler, CoreFileUploaderHandlerData } from './delegate'; @@ -30,7 +30,7 @@ export class CoreFileUploaderFileHandler implements CoreFileUploaderHandler { name = 'CoreFileUploaderFile'; priority = 1200; - constructor(protected appProvider: CoreAppProvider, + constructor( protected platform: Platform, protected timeUtils: CoreTimeUtilsProvider, protected uploaderHelper: CoreFileUploaderHelperProvider, @@ -44,8 +44,8 @@ export class CoreFileUploaderFileHandler implements CoreFileUploaderHandler { * @return True or promise resolved with true if enabled. */ isEnabled(): boolean | Promise { - return this.platform.is('android') || !this.appProvider.isMobile() || - (this.platform.is('ios') && this.platform.version().major >= 9); + return CoreApp.instance.isAndroid() || !CoreApp.instance.isMobile() || + (CoreApp.instance.isIOS() && this.platform.version().major >= 9); } /** @@ -70,7 +70,7 @@ export class CoreFileUploaderFileHandler implements CoreFileUploaderHandler { icon: 'folder', }; - if (this.appProvider.isMobile()) { + if (CoreApp.instance.isMobile()) { handler.action = (maxSize?: number, upload?: boolean, allowOffline?: boolean, mimetypes?: string[]): Promise => { return this.uploaderHelper.chooseAndUploadFile(maxSize, upload, allowOffline, mimetypes).then((result) => { return { @@ -89,7 +89,7 @@ export class CoreFileUploaderFileHandler implements CoreFileUploaderHandler { const input = document.createElement('input'); input.setAttribute('type', 'file'); input.classList.add('core-fileuploader-file-handler-input'); - if (mimetypes && mimetypes.length && (!this.platform.is('android') || mimetypes.length == 1)) { + if (mimetypes && mimetypes.length && (!CoreApp.instance.isAndroid() || mimetypes.length == 1)) { // Don't use accept attribute in Android with several mimetypes, it's not supported. input.setAttribute('accept', mimetypes.join(', ')); } @@ -119,7 +119,7 @@ export class CoreFileUploaderFileHandler implements CoreFileUploaderHandler { }); }); - if (this.platform.is('ios')) { + if (CoreApp.instance.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/fileuploader/providers/fileuploader.ts b/src/core/fileuploader/providers/fileuploader.ts index 648a01947..2caac3c0c 100644 --- a/src/core/fileuploader/providers/fileuploader.ts +++ b/src/core/fileuploader/providers/fileuploader.ts @@ -13,7 +13,7 @@ // limitations under the License. import { Injectable } from '@angular/core'; -import { Platform, ModalController } from 'ionic-angular'; +import { ModalController } from 'ionic-angular'; import { Camera, CameraOptions } from '@ionic-native/camera'; import { MediaCapture, MediaFile, CaptureError, CaptureAudioOptions, CaptureVideoOptions } from '@ionic-native/media-capture'; import { TranslateService } from '@ngx-translate/core'; @@ -27,6 +27,7 @@ import { CoreTimeUtilsProvider } from '@providers/utils/time'; import { CoreUtilsProvider } from '@providers/utils/utils'; import { CoreWSFileUploadOptions } from '@providers/ws'; import { Subject } from 'rxjs'; +import { CoreApp } from '@providers/app'; /** * File upload options. @@ -61,7 +62,6 @@ export class CoreFileUploaderProvider { protected timeUtils: CoreTimeUtilsProvider, protected mimeUtils: CoreMimetypeUtilsProvider, protected filepoolProvider: CoreFilepoolProvider, - protected platform: Platform, protected translate: TranslateService, protected mediaCapture: MediaCapture, protected camera: Camera, @@ -183,7 +183,7 @@ export class CoreFileUploaderProvider { getCameraUploadOptions(uri: string, isFromAlbum?: boolean): CoreFileUploaderOptions { const extension = this.mimeUtils.guessExtensionFromUrl(uri); const mimetype = this.mimeUtils.getMimeType(extension); - const isIOS = this.platform.is('ios'); + const isIOS = CoreApp.instance.isIOS(); const options: CoreFileUploaderOptions = { deleteAfterUpload: !isFromAlbum, mimeType: mimetype @@ -206,7 +206,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 = this.fileProvider.isFileInAppFolder(uri); - if (this.platform.is('android')) { + if (CoreApp.instance.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/fileuploader/providers/helper.ts b/src/core/fileuploader/providers/helper.ts index 2b4325e2e..9a07a1a6a 100644 --- a/src/core/fileuploader/providers/helper.ts +++ b/src/core/fileuploader/providers/helper.ts @@ -18,7 +18,7 @@ import { MediaFile } from '@ionic-native/media-capture'; import { Camera, CameraOptions } from '@ionic-native/camera'; import { Chooser, ChooserResult } from '@ionic-native/chooser'; import { TranslateService } from '@ngx-translate/core'; -import { CoreAppProvider } from '@providers/app'; +import { CoreApp, CoreAppProvider } from '@providers/app'; import { CoreFileProvider, CoreFileProgressEvent } from '@providers/file'; import { CoreLoggerProvider } from '@providers/logger'; import { CoreDomUtilsProvider } from '@providers/utils/dom'; @@ -628,7 +628,7 @@ export class CoreFileUploaderHelperProvider { options.mediaType = this.camera.MediaType.PICTURE; } else if (!imageSupported && videoSupported) { options.mediaType = this.camera.MediaType.VIDEO; - } else if (this.platform.is('ios')) { + } else if (CoreApp.instance.isIOS()) { // Only get all media in iOS because in Android using this option allows uploading any kind of file. options.mediaType = this.camera.MediaType.ALLMEDIA; } diff --git a/src/core/fileuploader/providers/video-handler.ts b/src/core/fileuploader/providers/video-handler.ts index bc6f192b5..e7d9341d4 100644 --- a/src/core/fileuploader/providers/video-handler.ts +++ b/src/core/fileuploader/providers/video-handler.ts @@ -13,8 +13,7 @@ // limitations under the License. import { Injectable } from '@angular/core'; -import { Platform } from 'ionic-angular'; -import { CoreAppProvider } from '@providers/app'; +import { CoreApp } from '@providers/app'; import { CoreUtilsProvider } from '@providers/utils/utils'; import { CoreFileUploaderHandler, CoreFileUploaderHandlerData } from './delegate'; import { CoreFileUploaderHelperProvider } from './helper'; @@ -26,8 +25,10 @@ export class CoreFileUploaderVideoHandler implements CoreFileUploaderHandler { name = 'CoreFileUploaderVideo'; priority = 1400; - constructor(private appProvider: CoreAppProvider, private utils: CoreUtilsProvider, private platform: Platform, - private uploaderHelper: CoreFileUploaderHelperProvider) { } + constructor( + private utils: CoreUtilsProvider, + private uploaderHelper: CoreFileUploaderHelperProvider + ) { } /** * Whether or not the handler is enabled on a site level. @@ -35,7 +36,7 @@ export class CoreFileUploaderVideoHandler implements CoreFileUploaderHandler { * @return True or promise resolved with true if enabled. */ isEnabled(): boolean | Promise { - return this.appProvider.isMobile() || (this.appProvider.canGetUserMedia() && this.appProvider.canRecordMedia()); + return CoreApp.instance.isMobile() || (CoreApp.instance.canGetUserMedia() && CoreApp.instance.canRecordMedia()); } /** @@ -45,10 +46,10 @@ export class CoreFileUploaderVideoHandler implements CoreFileUploaderHandler { * @return Supported mimetypes. */ getSupportedMimetypes(mimetypes: string[]): string[] { - if (this.platform.is('ios')) { + if (CoreApp.instance.isIOS()) { // In iOS it's recorded as MOV. return this.utils.filterByRegexp(mimetypes, /^video\/quicktime$/); - } else if (this.platform.is('android')) { + } else if (CoreApp.instance.isAndroid()) { // In Android we don't know the format the video will be recorded, so accept any video mimetype. return this.utils.filterByRegexp(mimetypes, /^video\//); } else { diff --git a/src/core/login/providers/helper.ts b/src/core/login/providers/helper.ts index 8b2fcdf6a..9e5ea3630 100644 --- a/src/core/login/providers/helper.ts +++ b/src/core/login/providers/helper.ts @@ -14,9 +14,9 @@ import { Injectable } from '@angular/core'; import { Location } from '@angular/common'; -import { Platform, AlertController, NavController, NavOptions } from 'ionic-angular'; +import { AlertController, NavController, NavOptions } from 'ionic-angular'; import { TranslateService } from '@ngx-translate/core'; -import { CoreAppProvider, CoreStoreConfig } from '@providers/app'; +import { CoreApp, CoreStoreConfig } from '@providers/app'; import { CoreConfigProvider } from '@providers/config'; import { CoreEventsProvider } from '@providers/events'; import { CoreInitDelegate } from '@providers/init'; @@ -87,12 +87,23 @@ export class CoreLoginHelperProvider { protected isOpeningReconnect = false; waitingForBrowser = false; - constructor(logger: CoreLoggerProvider, private sitesProvider: CoreSitesProvider, private domUtils: CoreDomUtilsProvider, - private wsProvider: CoreWSProvider, private translate: TranslateService, private textUtils: CoreTextUtilsProvider, - private eventsProvider: CoreEventsProvider, private appProvider: CoreAppProvider, private utils: CoreUtilsProvider, - private urlUtils: CoreUrlUtilsProvider, private configProvider: CoreConfigProvider, private platform: Platform, - private initDelegate: CoreInitDelegate, private sitePluginsProvider: CoreSitePluginsProvider, - private location: Location, private alertCtrl: AlertController, private courseProvider: CoreCourseProvider) { + constructor( + logger: CoreLoggerProvider, + private sitesProvider: CoreSitesProvider, + private domUtils: CoreDomUtilsProvider, + private wsProvider: CoreWSProvider, + private translate: TranslateService, + private textUtils: CoreTextUtilsProvider, + private eventsProvider: CoreEventsProvider, + private utils: CoreUtilsProvider, + private urlUtils: CoreUrlUtilsProvider, + private configProvider: CoreConfigProvider, + private initDelegate: CoreInitDelegate, + private sitePluginsProvider: CoreSitePluginsProvider, + private location: Location, + private alertCtrl: AlertController, + private courseProvider: CoreCourseProvider + ) { this.logger = logger.getInstance('CoreLoginHelper'); this.eventsProvider.on(CoreEventsProvider.MAIN_MENU_OPEN, () => { @@ -149,17 +160,17 @@ export class CoreLoginHelperProvider { return false; } - if (this.appProvider.isSSOAuthenticationOngoing()) { + if (CoreApp.instance.isSSOAuthenticationOngoing()) { // Authentication ongoing, probably duplicated request. return true; } - if (this.appProvider.isDesktop()) { + if (CoreApp.instance.isDesktop()) { // In desktop, make sure InAppBrowser is closed. this.utils.closeInAppBrowser(true); } // App opened using custom URL scheme. Probably an SSO authentication. - this.appProvider.startSSOAuthentication(); + CoreApp.instance.startSSOAuthentication(); this.logger.debug('App launched by URL with an SSO'); // Delete the sso scheme from the URL. @@ -195,7 +206,7 @@ export class CoreLoginHelperProvider { }).then(() => { if (siteData.pageName) { // State defined, go to that state instead of site initial page. - this.appProvider.getRootNavController().push(siteData.pageName, siteData.pageParams); + CoreApp.instance.getRootNavController().push(siteData.pageName, siteData.pageParams); } else { this.goToSiteInitialPage(); } @@ -207,7 +218,7 @@ export class CoreLoginHelperProvider { } }).finally(() => { modal.dismiss(); - this.appProvider.finishSSOAuthentication(); + CoreApp.instance.finishSSOAuthentication(); }); return true; @@ -232,8 +243,8 @@ export class CoreLoginHelperProvider { * Function called when an SSO InAppBrowser is closed or the app is resumed. Check if user needs to be logged out. */ checkLogout(): void { - const navCtrl = this.appProvider.getRootNavController(); - if (!this.appProvider.isSSOAuthenticationOngoing() && this.sitesProvider.isLoggedIn() && + const navCtrl = CoreApp.instance.getRootNavController(); + if (!CoreApp.instance.isSSOAuthenticationOngoing() && this.sitesProvider.isLoggedIn() && this.sitesProvider.getCurrentSite().isLoggedOut() && navCtrl.getActive().name == 'CoreLoginReconnectPage') { // User must reauthenticate but he closed the InAppBrowser without doing so, logout him. this.sitesProvider.logout(); @@ -515,9 +526,9 @@ export class CoreLoginHelperProvider { } if (setRoot) { - return this.appProvider.getRootNavController().setRoot(pageName, params, { animate: false }); + return CoreApp.instance.getRootNavController().setRoot(pageName, params, { animate: false }); } else { - return this.appProvider.getRootNavController().push(pageName, params); + return CoreApp.instance.getRootNavController().push(pageName, params); } } @@ -530,7 +541,7 @@ export class CoreLoginHelperProvider { * @return Promise resolved when done. */ goToNoSitePage(navCtrl: NavController, page: string, params?: any): Promise { - navCtrl = navCtrl || this.appProvider.getRootNavController(); + navCtrl = navCtrl || CoreApp.instance.getRootNavController(); const currentPage = navCtrl && navCtrl.getActive().component.name; @@ -728,7 +739,7 @@ export class CoreLoginHelperProvider { * @return True if embedded browser, false othwerise. */ isSSOEmbeddedBrowser(code: number): boolean { - if (this.appProvider.isLinux()) { + if (CoreApp.instance.isLinux()) { // In Linux desktop app, always use embedded browser. return true; } @@ -755,7 +766,7 @@ export class CoreLoginHelperProvider { * @return Promise resolved when done. */ protected loadSiteAndPage(page: string, params: any, siteId: string): Promise { - const navCtrl = this.appProvider.getRootNavController(); + const navCtrl = CoreApp.instance.getRootNavController(); if (siteId == CoreConstants.NO_SITE_ID) { // Page doesn't belong to a site, just load the page. @@ -783,7 +794,7 @@ export class CoreLoginHelperProvider { * @param params Params to pass to the page. */ loadPageInMainMenu(page: string, params: any): void { - if (!this.appProvider.isMainMenuOpen()) { + if (!CoreApp.instance.isMainMenuOpen()) { // Main menu not open. Store the page to be loaded later. this.pageToLoad = { page: page, @@ -813,7 +824,7 @@ export class CoreLoginHelperProvider { * @return Promise resolved when done. */ protected openMainMenu(navCtrl: NavController, page: string, params: any, options?: NavOptions, url?: string): Promise { - navCtrl = navCtrl || this.appProvider.getRootNavController(); + navCtrl = navCtrl || CoreApp.instance.getRootNavController(); // Due to DeepLinker, we need to remove the path from the URL before going to main menu. // IonTabs checks the URL to determine which path to load for deep linking, so we clear the URL. @@ -857,7 +868,7 @@ export class CoreLoginHelperProvider { oauthsso: params.id, }); - if (this.appProvider.isLinux()) { + if (CoreApp.instance.isLinux()) { // In Linux desktop app, always use embedded browser. this.utils.openInApp(loginUrl); } else { @@ -974,7 +985,7 @@ export class CoreLoginHelperProvider { return; // Site that triggered the event is not current site. } - const rootNavCtrl = this.appProvider.getRootNavController(), + const rootNavCtrl = CoreApp.instance.getRootNavController(), activePage = rootNavCtrl.getActive(); // If current page is already change password, stop. @@ -1041,7 +1052,7 @@ export class CoreLoginHelperProvider { // Target page belongs to a different site. Change site. if (this.sitePluginsProvider.hasSitePluginsLoaded) { // The site has site plugins so the app will be restarted. Store the data and logout. - this.appProvider.storeRedirect(siteId, page, params); + CoreApp.instance.storeRedirect(siteId, page, params); return this.sitesProvider.logout(); } else { @@ -1056,7 +1067,7 @@ export class CoreLoginHelperProvider { if (siteId) { return this.loadSiteAndPage(page, params, siteId); } else { - return this.appProvider.getRootNavController().setRoot('CoreLoginSitesPage'); + return CoreApp.instance.getRootNavController().setRoot('CoreLoginSitesPage'); } } @@ -1113,7 +1124,7 @@ export class CoreLoginHelperProvider { if (this.isSSOLoginNeeded(result.code)) { // SSO. User needs to authenticate in a browser. Check if we need to display a message. - if (!this.appProvider.isSSOAuthenticationOngoing() && !this.isSSOConfirmShown && !this.waitingForBrowser) { + if (!CoreApp.instance.isSSOAuthenticationOngoing() && !this.isSSOConfirmShown && !this.waitingForBrowser) { this.isSSOConfirmShown = true; if (this.shouldShowSSOConfirm(result.code)) { @@ -1146,7 +1157,7 @@ export class CoreLoginHelperProvider { }); if (providerToUse) { - if (!this.appProvider.isSSOAuthenticationOngoing() && !this.isSSOConfirmShown && !this.waitingForBrowser) { + if (!CoreApp.instance.isSSOAuthenticationOngoing() && !this.isSSOConfirmShown && !this.waitingForBrowser) { // Open browser to perform the OAuth. this.isSSOConfirmShown = true; @@ -1173,7 +1184,7 @@ export class CoreLoginHelperProvider { const info = currentSite.getInfo(); if (typeof info != 'undefined' && typeof info.username != 'undefined' && !this.isOpeningReconnect) { - const rootNavCtrl = this.appProvider.getRootNavController(), + const rootNavCtrl = CoreApp.instance.getRootNavController(), activePage = rootNavCtrl.getActive(); // If current page is already reconnect, stop. @@ -1222,7 +1233,7 @@ export class CoreLoginHelperProvider { * @param message The warning message. */ protected showWorkplaceNoticeModal(message: string): void { - const link = this.appProvider.getAppStoreUrl({android: 'com.moodle.workplace', ios: 'id1470929705' }); + const link = CoreApp.instance.getAppStoreUrl({android: 'com.moodle.workplace', ios: 'id1470929705' }); this.showDownloadAppNoticeModal(message, link); } @@ -1238,7 +1249,7 @@ export class CoreLoginHelperProvider { storesConfig.mobile = 'https://download.moodle.org/mobile/'; storesConfig.default = 'https://download.moodle.org/mobile/'; - const link = this.appProvider.getAppStoreUrl(storesConfig); + const link = CoreApp.instance.getAppStoreUrl(storesConfig); this.showDownloadAppNoticeModal(message, link); } @@ -1272,7 +1283,7 @@ export class CoreLoginHelperProvider { }); alert.present().then(() => { - const isDevice = this.platform.is('android') || this.platform.is('ios'); + const isDevice = CoreApp.instance.isAndroid() || CoreApp.instance.isIOS(); if (!isDevice) { // Treat all anchors so they don't override the app. const alertMessageEl: HTMLElement = alert.pageRef().nativeElement.querySelector('.alert-message'); @@ -1358,7 +1369,7 @@ export class CoreLoginHelperProvider { return; } - const rootNavCtrl = this.appProvider.getRootNavController(), + const rootNavCtrl = CoreApp.instance.getRootNavController(), activePage = rootNavCtrl.getActive(); // If current page is already site policy, stop. diff --git a/src/core/mainmenu/pages/menu/menu.ts b/src/core/mainmenu/pages/menu/menu.ts index 067689bba..bdf1cdbd4 100644 --- a/src/core/mainmenu/pages/menu/menu.ts +++ b/src/core/mainmenu/pages/menu/menu.ts @@ -13,8 +13,8 @@ // limitations under the License. import { Component, OnDestroy, ViewChild, ChangeDetectorRef } from '@angular/core'; -import { IonicPage, NavController, NavParams, Platform } from 'ionic-angular'; -import { CoreAppProvider } from '@providers/app'; +import { IonicPage, NavController, NavParams } from 'ionic-angular'; +import { CoreApp } from '@providers/app'; import { CoreSitesProvider } from '@providers/sites'; import { CoreEventsProvider } from '@providers/events'; import { CoreIonTabsComponent } from '@components/ion-tabs/ion-tabs'; @@ -58,10 +58,9 @@ export class CoreMainMenuPage implements OnDestroy { protected mainMenuProvider: CoreMainMenuProvider, protected linksDelegate: CoreContentLinksDelegate, protected linksHelper: CoreContentLinksHelperProvider, - protected appProvider: CoreAppProvider, - protected platform: Platform) { + ) { - this.mainMenuId = this.appProvider.getMainMenuId(); + this.mainMenuId = CoreApp.instance.getMainMenuId(); // Check if the menu was loaded with a redirect. const redirectPage = navParams.get('redirectPage'); @@ -118,7 +117,7 @@ export class CoreMainMenuPage implements OnDestroy { window.addEventListener('resize', this.initHandlers.bind(this)); - if (this.platform.is('ios')) { + if (CoreApp.instance.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 = this.eventsProvider.on(CoreEventsProvider.KEYBOARD_CHANGE, (kbHeight) => { @@ -133,7 +132,7 @@ export class CoreMainMenuPage implements OnDestroy { }); } - this.appProvider.setMainMenuOpen(this.mainMenuId, true); + CoreApp.instance.setMainMenuOpen(this.mainMenuId, true); } /** @@ -243,7 +242,7 @@ export class CoreMainMenuPage implements OnDestroy { this.subscription && this.subscription.unsubscribe(); this.redirectObs && this.redirectObs.off(); window.removeEventListener('resize', this.initHandlers.bind(this)); - this.appProvider.setMainMenuOpen(this.mainMenuId, false); + CoreApp.instance.setMainMenuOpen(this.mainMenuId, false); this.keyboardObserver && this.keyboardObserver.off(); } } diff --git a/src/core/pushnotifications/providers/pushnotifications.ts b/src/core/pushnotifications/providers/pushnotifications.ts index 28cd94d28..76b2faa73 100644 --- a/src/core/pushnotifications/providers/pushnotifications.ts +++ b/src/core/pushnotifications/providers/pushnotifications.ts @@ -18,7 +18,7 @@ import { Badge } from '@ionic-native/badge'; import { Push, PushObject, PushOptions } from '@ionic-native/push'; import { Device } from '@ionic-native/device'; import { TranslateService } from '@ngx-translate/core'; -import { CoreAppProvider, CoreAppSchema } from '@providers/app'; +import { CoreApp, CoreAppProvider, CoreAppSchema } from '@providers/app'; import { CoreInitDelegate } from '@providers/init'; import { CoreLoggerProvider } from '@providers/logger'; import { CoreSitesProvider, CoreSiteSchema } from '@providers/sites'; @@ -178,13 +178,26 @@ export class CorePushNotificationsProvider { ], }; - constructor(logger: CoreLoggerProvider, protected appProvider: CoreAppProvider, private initDelegate: CoreInitDelegate, - protected pushNotificationsDelegate: CorePushNotificationsDelegate, protected sitesProvider: CoreSitesProvider, - private badge: Badge, private localNotificationsProvider: CoreLocalNotificationsProvider, - private utils: CoreUtilsProvider, private textUtils: CoreTextUtilsProvider, private push: Push, - private configProvider: CoreConfigProvider, private device: Device, private zone: NgZone, - private translate: TranslateService, private platform: Platform, private sitesFactory: CoreSitesFactoryProvider, - private filterProvider: CoreFilterProvider, private filterDelegate: CoreFilterDelegate) { + constructor( + logger: CoreLoggerProvider, + private initDelegate: CoreInitDelegate, + protected pushNotificationsDelegate: CorePushNotificationsDelegate, + protected sitesProvider: CoreSitesProvider, + private badge: Badge, + private localNotificationsProvider: CoreLocalNotificationsProvider, + private utils: CoreUtilsProvider, + private textUtils: CoreTextUtilsProvider, + private push: Push, + private configProvider: CoreConfigProvider, + private device: Device, + private zone: NgZone, + private translate: TranslateService, + platform: Platform, + appProvider: CoreAppProvider, + private sitesFactory: CoreSitesFactoryProvider, + private filterProvider: CoreFilterProvider, + private filterDelegate: CoreFilterDelegate + ) { this.logger = logger.getInstance('CorePushNotificationsProvider'); this.appDB = appProvider.getDB(); this.dbReady = appProvider.createTablesFromSchema(this.appTablesSchema).catch(() => { @@ -209,7 +222,7 @@ export class CorePushNotificationsProvider { * @return Whether the device can be registered in Moodle. */ canRegisterOnMoodle(): boolean { - return this.pushID && this.appProvider.isMobile(); + return this.pushID && CoreApp.instance.isMobile(); } /** @@ -234,7 +247,7 @@ export class CorePushNotificationsProvider { * @return Promise resolved when done. */ protected createDefaultChannel(): Promise { - if (!this.platform.is('android')) { + if (!CoreApp.instance.isAndroid()) { return Promise.resolve(); } @@ -467,7 +480,7 @@ export class CorePushNotificationsProvider { instanceId: 0, filter: true }, - isAndroid = this.platform.is('android'), + isAndroid = CoreApp.instance.isAndroid(), extraFeatures = this.utils.isTrueOrOne(data.extrafeatures); // Get the filters to apply to text and message. Don't use FIlterHelper to prevent circular dependencies. @@ -544,7 +557,7 @@ export class CorePushNotificationsProvider { * @return Promise resolved when device is unregistered. */ async unregisterDeviceOnMoodle(site: CoreSite): Promise { - if (!site || !this.appProvider.isMobile()) { + if (!site || !CoreApp.instance.isMobile()) { return Promise.reject(null); } @@ -632,7 +645,7 @@ export class CorePushNotificationsProvider { return previous + parseInt(counter, 10); }, 0); - if (!this.appProvider.isDesktop() && !this.appProvider.isMobile()) { + if (!CoreApp.instance.isDesktop() && !CoreApp.instance.isMobile()) { // Browser doesn't have an app badge, stop. return total; } diff --git a/src/core/settings/pages/app/app.ts b/src/core/settings/pages/app/app.ts index e459cd241..e0a5058dc 100644 --- a/src/core/settings/pages/app/app.ts +++ b/src/core/settings/pages/app/app.ts @@ -13,8 +13,9 @@ // limitations under the License. import { Component, ViewChild } from '@angular/core'; -import { IonicPage, NavParams, Platform } from 'ionic-angular'; +import { IonicPage, NavParams } from 'ionic-angular'; import { CoreSplitViewComponent } from '@components/split-view/split-view'; +import { CoreApp } from '@providers/app'; /** * Page that displays the list of app settings pages. @@ -30,9 +31,8 @@ export class CoreAppSettingsPage { isIOS: boolean; selectedPage: string; - constructor(platorm: Platform, - navParams: NavParams) { - this.isIOS = platorm.is('ios'); + constructor(navParams: NavParams) { + this.isIOS = CoreApp.instance.isIOS(); this.selectedPage = navParams.get('page') || false; } diff --git a/src/core/settings/pages/site/site.ts b/src/core/settings/pages/site/site.ts index 4f35c7feb..01e88ed56 100644 --- a/src/core/settings/pages/site/site.ts +++ b/src/core/settings/pages/site/site.ts @@ -13,7 +13,7 @@ // limitations under the License. import { Component, ViewChild } from '@angular/core'; -import { IonicPage, NavParams, Platform } from 'ionic-angular'; +import { IonicPage, NavParams } from 'ionic-angular'; import { TranslateService } from '@ngx-translate/core'; import { CoreSettingsDelegate, CoreSettingsHandlerData } from '../../providers/delegate'; import { CoreEventsProvider } from '@providers/events'; @@ -22,6 +22,7 @@ import { CoreDomUtilsProvider } from '@providers/utils/dom'; import { CoreSplitViewComponent } from '@components/split-view/split-view'; import { CoreSharedFilesProvider } from '@core/sharedfiles/providers/sharedfiles'; import { CoreSettingsHelper, CoreSiteSpaceUsage } from '../../providers/helper'; +import { CoreApp } from '@providers/app'; /** * Page that displays the list of site settings pages. @@ -57,11 +58,10 @@ export class CoreSitePreferencesPage { protected eventsProvider: CoreEventsProvider, protected sharedFilesProvider: CoreSharedFilesProvider, protected translate: TranslateService, - platorm: Platform, navParams: NavParams, ) { - this.isIOS = platorm.is('ios'); + this.isIOS = CoreApp.instance.isIOS(); this.selectedPage = navParams.get('page') || false; diff --git a/src/core/sharedfiles/providers/upload-handler.ts b/src/core/sharedfiles/providers/upload-handler.ts index 61a73efc9..0ae2f82e7 100644 --- a/src/core/sharedfiles/providers/upload-handler.ts +++ b/src/core/sharedfiles/providers/upload-handler.ts @@ -13,7 +13,7 @@ // limitations under the License. import { Injectable } from '@angular/core'; -import { Platform } from 'ionic-angular'; +import { CoreApp } from '@providers/app'; import { CoreFileUploaderHandler, CoreFileUploaderHandlerData } from '@core/fileuploader/providers/delegate'; import { CoreSharedFilesHelperProvider } from './helper'; /** @@ -24,7 +24,7 @@ export class CoreSharedFilesUploadHandler implements CoreFileUploaderHandler { name = 'CoreSharedFilesUpload'; priority = 1300; - constructor(private sharedFilesHelper: CoreSharedFilesHelperProvider, private platform: Platform) { } + constructor(private sharedFilesHelper: CoreSharedFilesHelperProvider) { } /** * Whether or not the handler is enabled on a site level. @@ -32,7 +32,7 @@ export class CoreSharedFilesUploadHandler implements CoreFileUploaderHandler { * @return True or promise resolved with true if enabled. */ isEnabled(): boolean | Promise { - return this.platform.is('ios'); + return CoreApp.instance.isIOS(); } /** diff --git a/src/core/sharedfiles/sharedfiles.module.ts b/src/core/sharedfiles/sharedfiles.module.ts index 09ebb0d4b..c31accbad 100644 --- a/src/core/sharedfiles/sharedfiles.module.ts +++ b/src/core/sharedfiles/sharedfiles.module.ts @@ -19,6 +19,7 @@ import { CoreSharedFilesHelperProvider } from './providers/helper'; import { CoreSharedFilesUploadHandler } from './providers/upload-handler'; import { CoreFileUploaderDelegate } from '@core/fileuploader/providers/delegate'; import { CoreEventsProvider } from '@providers/events'; +import { CoreAppProvider } from '@providers/app'; // List of providers (without handlers). export const CORE_SHAREDFILES_PROVIDERS: any[] = [ @@ -38,12 +39,17 @@ export const CORE_SHAREDFILES_PROVIDERS: any[] = [ ] }) export class CoreSharedFilesModule { - constructor(platform: Platform, delegate: CoreFileUploaderDelegate, handler: CoreSharedFilesUploadHandler, - helper: CoreSharedFilesHelperProvider, eventsProvider: CoreEventsProvider) { + constructor(platform: Platform, + delegate: CoreFileUploaderDelegate, + handler: CoreSharedFilesUploadHandler, + helper: CoreSharedFilesHelperProvider, + appsProvider: CoreAppProvider, + eventsProvider: CoreEventsProvider + ) { // Register the handler. delegate.registerHandler(handler); - if (platform.is('ios')) { + if (appsProvider.isIOS()) { let lastCheck = 0; // Check if there are new files at app start and when the app is resumed. diff --git a/src/core/siteplugins/providers/siteplugins.ts b/src/core/siteplugins/providers/siteplugins.ts index 18a38b374..e3f8beade 100644 --- a/src/core/siteplugins/providers/siteplugins.ts +++ b/src/core/siteplugins/providers/siteplugins.ts @@ -13,8 +13,7 @@ // limitations under the License. import { Injectable } from '@angular/core'; -import { Platform } from 'ionic-angular'; -import { CoreAppProvider } from '@providers/app'; +import { CoreApp } from '@providers/app'; import { CoreFilepoolProvider } from '@providers/filepool'; import { CoreLangProvider } from '@providers/lang'; import { CoreLoggerProvider } from '@providers/logger'; @@ -67,10 +66,15 @@ export class CoreSitePluginsProvider { hasSitePluginsLoaded = false; sitePluginsFinishedLoading = false; - constructor(logger: CoreLoggerProvider, private sitesProvider: CoreSitesProvider, private utils: CoreUtilsProvider, - private langProvider: CoreLangProvider, private appProvider: CoreAppProvider, private platform: Platform, - private filepoolProvider: CoreFilepoolProvider, private coursesProvider: CoreCoursesProvider, - private textUtils: CoreTextUtilsProvider, private eventsProvider: CoreEventsProvider) { + constructor(logger: CoreLoggerProvider, + private sitesProvider: CoreSitesProvider, + private utils: CoreUtilsProvider, + private langProvider: CoreLangProvider, + private filepoolProvider: CoreFilepoolProvider, + private coursesProvider: CoreCoursesProvider, + private textUtils: CoreTextUtilsProvider, + private eventsProvider: CoreEventsProvider + ) { this.logger = logger.getInstance('CoreUserProvider'); const observer = this.eventsProvider.on(CoreEventsProvider.SITE_PLUGINS_LOADED, () => { @@ -107,20 +111,20 @@ export class CoreSitePluginsProvider { argsToSend.appversionname = CoreConfigConstants.versionname; argsToSend.applang = lang; argsToSend.appcustomurlscheme = CoreConfigConstants.customurlscheme; - argsToSend.appisdesktop = this.appProvider.isDesktop(); - argsToSend.appismobile = this.appProvider.isMobile(); - argsToSend.appiswide = this.appProvider.isWide(); + argsToSend.appisdesktop = CoreApp.instance.isDesktop(); + argsToSend.appismobile = CoreApp.instance.isMobile(); + argsToSend.appiswide = CoreApp.instance.isWide(); if (argsToSend.appisdevice) { - if (this.platform.is('ios')) { + if (CoreApp.instance.isIOS()) { argsToSend.appplatform = 'ios'; } else { argsToSend.appplatform = 'android'; } } else if (argsToSend.appisdesktop) { - if (this.appProvider.isMac()) { + if (CoreApp.instance.isMac()) { argsToSend.appplatform = 'mac'; - } else if (this.appProvider.isLinux()) { + } else if (CoreApp.instance.isLinux()) { argsToSend.appplatform = 'linux'; } else { argsToSend.appplatform = 'windows'; diff --git a/src/directives/back-button.ts b/src/directives/back-button.ts index 0a14f881c..1ece9e765 100644 --- a/src/directives/back-button.ts +++ b/src/directives/back-button.ts @@ -14,8 +14,9 @@ import { Directive, OnInit, OnDestroy } from '@angular/core'; import { TranslateService } from '@ngx-translate/core'; -import { Navbar, Platform } from 'ionic-angular'; +import { Navbar } from 'ionic-angular'; import { CoreEventsProvider } from '@providers/events'; +import { CoreApp } from '@providers/app'; /** * Directive to tramslate the back button of navigation bars in iOS. @@ -30,8 +31,10 @@ import { CoreEventsProvider } from '@providers/events'; export class CoreBackButtonDirective implements OnInit, OnDestroy { protected languageObserver: any; - constructor(private host: Navbar, private platform: Platform, - private translate: TranslateService, private eventsProvider: CoreEventsProvider) {} + constructor(private host: Navbar, + private translate: TranslateService, + private eventsProvider: CoreEventsProvider + ) {} /** * Component being initialized. @@ -56,7 +59,7 @@ export class CoreBackButtonDirective implements OnInit, OnDestroy { * Set the trasnlated back button text in iOS. */ protected setTranslatedBackButtonText(): void { - if (this.host && this.platform.is('ios')) { + if (this.host && CoreApp.instance.isIOS()) { this.host.setBackButtonText(this.translate.instant('core.back')); } } diff --git a/src/directives/external-content.ts b/src/directives/external-content.ts index c425c9d8c..04aa19982 100644 --- a/src/directives/external-content.ts +++ b/src/directives/external-content.ts @@ -14,7 +14,7 @@ import { Directive, Input, AfterViewInit, ElementRef, OnChanges, SimpleChange, Output, EventEmitter } from '@angular/core'; import { Platform } from 'ionic-angular'; -import { CoreAppProvider } from '@providers/app'; +import { CoreApp } from '@providers/app'; import { CoreLoggerProvider } from '@providers/logger'; import { CoreFile } from '@providers/file'; import { CoreFilepoolProvider } from '@providers/filepool'; @@ -60,7 +60,6 @@ export class CoreExternalContentDirective implements AfterViewInit, OnChanges { protected sitesProvider: CoreSitesProvider, protected domUtils: CoreDomUtilsProvider, protected urlUtils: CoreUrlUtilsProvider, - protected appProvider: CoreAppProvider, protected utils: CoreUtilsProvider) { this.element = element.nativeElement; @@ -104,7 +103,7 @@ export class CoreExternalContentDirective implements AfterViewInit, OnChanges { newSource.setAttribute('src', url); if (type) { - if (this.platform.is('android') && type == 'video/quicktime') { + if (CoreApp.instance.isAndroid() && type == 'video/quicktime') { // Fix for VideoJS/Chrome bug https://github.com/videojs/video.js/issues/423 . newSource.setAttribute('type', 'video/mp4'); } else { @@ -198,7 +197,7 @@ export class CoreExternalContentDirective implements AfterViewInit, OnChanges { const track = event.track; if (track) { track.oncuechange = (): void => { - const line = this.platform.is('tablet') || this.platform.is('android') ? 90 : 80; + const line = this.platform.is('tablet') || CoreApp.instance.isAndroid() ? 90 : 80; // Position all subtitles to a percentage of video height. Array.from(track.cues).forEach((cue: any) => { cue.snapToLines = false; @@ -281,7 +280,7 @@ export class CoreExternalContentDirective implements AfterViewInit, OnChanges { clickableEl.addEventListener(eventName, () => { // User played media or opened a downloadable link. // Download the file if in wifi and it hasn't been downloaded already (for big files). - if (this.appProvider.isWifi()) { + if (CoreApp.instance.isWifi()) { // We aren't using the result, so it doesn't matter which of the 2 functions we call. this.filepoolProvider.getUrlByUrl(siteId, url, this.component, this.componentId, 0, false); } diff --git a/src/directives/format-text.ts b/src/directives/format-text.ts index 9b3563629..6cc11c983 100644 --- a/src/directives/format-text.ts +++ b/src/directives/format-text.ts @@ -17,7 +17,6 @@ import { } from '@angular/core'; import { Platform, NavController, Content } from 'ionic-angular'; import { TranslateService } from '@ngx-translate/core'; -import { CoreAppProvider } from '@providers/app'; import { CoreEventsProvider } from '@providers/events'; import { CoreFilepoolProvider } from '@providers/filepool'; import { CoreLoggerProvider } from '@providers/logger'; @@ -84,7 +83,6 @@ export class CoreFormatTextDirective implements OnChanges { protected urlUtils: CoreUrlUtilsProvider, protected loggerProvider: CoreLoggerProvider, protected filepoolProvider: CoreFilepoolProvider, - protected appProvider: CoreAppProvider, protected contentLinksHelper: CoreContentLinksHelperProvider, @Optional() protected navCtrl: NavController, @Optional() protected content: Content, @Optional() @@ -124,7 +122,7 @@ export class CoreFormatTextDirective implements OnChanges { protected addExternalContent(element: Element): CoreExternalContentDirective { // Angular 2 doesn't let adding directives dynamically. Create the CoreExternalContentDirective manually. const extContent = new CoreExternalContentDirective(new ElementRef(element), this.loggerProvider, this.filepoolProvider, - this.platform, this.sitesProvider, this.domUtils, this.urlUtils, this.appProvider, this.utils); + this.platform, this.sitesProvider, this.domUtils, this.urlUtils, this.utils); extContent.component = this.component; extContent.componentId = this.componentId; diff --git a/src/providers/app.ts b/src/providers/app.ts index 7c3827806..8ad693772 100644 --- a/src/providers/app.ts +++ b/src/providers/app.ts @@ -17,6 +17,7 @@ import { Platform, App, NavController, MenuController } from 'ionic-angular'; import { Keyboard } from '@ionic-native/keyboard'; import { Network } from '@ionic-native/network'; import { StatusBar } from '@ionic-native/status-bar'; +import { Device } from '@ionic-native/device'; import { CoreDbProvider } from './db'; import { CoreLoggerProvider } from './logger'; @@ -178,6 +179,7 @@ export class CoreAppProvider { zone: NgZone, private menuCtrl: MenuController, private statusBar: StatusBar, + private device: Device, appRef: ApplicationRef) { this.logger = logger.getInstance('CoreAppProvider'); @@ -390,7 +392,7 @@ export class CoreAppProvider { * @return Whether the app is running in an Android mobile or tablet device. */ isAndroid(): boolean { - return this.platform.is('android'); + return this.isMobile() && this.device.platform.toLowerCase() == 'android'; } /** @@ -410,7 +412,7 @@ export class CoreAppProvider { * @return Whether the app is running in an iOS mobile or tablet device. */ isIOS(): boolean { - return this.platform.is('ios'); + return this.isMobile() && this.device.platform.toLowerCase() == 'ios'; } /** @@ -568,7 +570,7 @@ export class CoreAppProvider { */ openKeyboard(): void { // Open keyboard is not supported in desktop and in iOS. - if (this.isMobile() && !this.platform.is('ios')) { + if (this.isMobile() && !this.isIOS()) { this.keyboard.show(); } } @@ -797,23 +799,23 @@ export class CoreAppProvider { * Set StatusBar color depending on platform. */ setStatusBarColor(): void { - if (typeof CoreConfigConstants.statusbarbgios == 'string' && this.platform.is('ios')) { + if (typeof CoreConfigConstants.statusbarbgios == 'string' && this.isIOS()) { // IOS Status bar properties. this.statusBar.overlaysWebView(false); this.statusBar.backgroundColorByHexString(CoreConfigConstants.statusbarbgios); CoreConfigConstants.statusbarlighttextios ? this.statusBar.styleLightContent() : this.statusBar.styleDefault(); - } else if (typeof CoreConfigConstants.statusbarbgandroid == 'string' && this.platform.is('android')) { + } else if (typeof CoreConfigConstants.statusbarbgandroid == 'string' && this.isAndroid()) { // Android Status bar properties. this.statusBar.backgroundColorByHexString(CoreConfigConstants.statusbarbgandroid); CoreConfigConstants.statusbarlighttextandroid ? this.statusBar.styleLightContent() : this.statusBar.styleDefault(); } else if (typeof CoreConfigConstants.statusbarbg == 'string') { // Generic Status bar properties. - this.platform.is('ios') && this.statusBar.overlaysWebView(false); + this.isIOS() && this.statusBar.overlaysWebView(false); this.statusBar.backgroundColorByHexString(CoreConfigConstants.statusbarbg); CoreConfigConstants.statusbarlighttext ? this.statusBar.styleLightContent() : this.statusBar.styleDefault(); } else { // Default Status bar properties. - this.platform.is('android') ? this.statusBar.styleLightContent() : this.statusBar.styleDefault(); + this.isAndroid() ? this.statusBar.styleLightContent() : this.statusBar.styleDefault(); } } @@ -822,11 +824,11 @@ export class CoreAppProvider { */ resetStatusBarColor(): void { if (typeof CoreConfigConstants.statusbarbgremotetheme == 'string' && - ((typeof CoreConfigConstants.statusbarbgios == 'string' && this.platform.is('ios')) || - (typeof CoreConfigConstants.statusbarbgandroid == 'string' && this.platform.is('android')) || + ((typeof CoreConfigConstants.statusbarbgios == 'string' && this.isIOS()) || + (typeof CoreConfigConstants.statusbarbgandroid == 'string' && this.isAndroid()) || typeof CoreConfigConstants.statusbarbg == 'string')) { // If the status bar has been overriden and there's a fallback color for remote themes, use it now. - this.platform.is('ios') && this.statusBar.overlaysWebView(false); + this.isIOS() && this.statusBar.overlaysWebView(false); this.statusBar.backgroundColorByHexString(CoreConfigConstants.statusbarbgremotetheme); CoreConfigConstants.statusbarlighttextremotetheme ? this.statusBar.styleLightContent() : this.statusBar.styleDefault(); diff --git a/src/providers/file.ts b/src/providers/file.ts index dad6b1c8f..98df61923 100644 --- a/src/providers/file.ts +++ b/src/providers/file.ts @@ -15,8 +15,7 @@ import { Injectable } from '@angular/core'; import { Platform } from 'ionic-angular'; import { File, FileEntry, DirectoryEntry, Entry, Metadata } from '@ionic-native/file'; - -import { CoreAppProvider } from './app'; +import { CoreApp, CoreAppProvider } from './app'; import { CoreLoggerProvider } from './logger'; import { CoreMimetypeUtilsProvider } from './utils/mimetype'; import { CoreTextUtilsProvider } from './utils/text'; @@ -73,16 +72,16 @@ export class CoreFileProvider { protected isHTMLAPI = false; constructor(logger: CoreLoggerProvider, + appProvider: CoreAppProvider, protected platform: Platform, protected file: File, - protected appProvider: CoreAppProvider, protected textUtils: CoreTextUtilsProvider, protected zip: Zip, protected mimeUtils: CoreMimetypeUtilsProvider) { this.logger = logger.getInstance('CoreFileProvider'); - if (platform.is('android') && !Object.getOwnPropertyDescriptor(FileReader.prototype, 'onloadend')) { + if (appProvider.isAndroid() && !Object.getOwnPropertyDescriptor(FileReader.prototype, 'onloadend')) { // Cordova File plugin creates some getters and setter for FileReader, but Ionic's polyfills override them in Android. // Create the getters and setters again. This code comes from FileReader.js in cordova-plugin-file. this.defineGetterSetter(FileReader.prototype, 'readyState', function(): any { @@ -178,9 +177,9 @@ export class CoreFileProvider { return this.platform.ready().then(() => { - if (this.platform.is('android')) { + if (CoreApp.instance.isAndroid()) { this.basePath = this.file.externalApplicationStorageDirectory || this.basePath; - } else if (this.platform.is('ios')) { + } else if (CoreApp.instance.isIOS()) { this.basePath = this.file.documentsDirectory || this.basePath; } else if (!this.isAvailable() || this.basePath === '') { this.logger.error('Error getting device OS.'); @@ -475,7 +474,7 @@ export class CoreFileProvider { */ calculateFreeSpace(): Promise { return this.file.getFreeDiskSpace().then((size) => { - if (this.platform.is('ios')) { + if (CoreApp.instance.isIOS()) { // In iOS the size is in bytes. return Number(size); } @@ -622,7 +621,7 @@ export class CoreFileProvider { // Create file (and parent folders) to prevent errors. return this.createFile(path).then((fileEntry) => { - if (this.isHTMLAPI && !this.appProvider.isDesktop() && + if (this.isHTMLAPI && !CoreApp.instance.isDesktop() && (typeof data == 'string' || data.toString() == '[object ArrayBuffer]')) { // We need to write Blobs. const type = this.mimeUtils.getMimeType(this.mimeUtils.getFileExtension(path)); @@ -745,7 +744,7 @@ export class CoreFileProvider { */ getBasePathToDownload(): Promise { return this.init().then(() => { - if (this.platform.is('ios')) { + if (CoreApp.instance.isIOS()) { // In iOS we want the internal URL (cdvfile://localhost/persistent/...). return this.file.resolveDirectoryUrl(this.basePath).then((dirEntry) => { return dirEntry.toInternalURL(); @@ -1252,7 +1251,7 @@ export class CoreFileProvider { * @return Converted src. */ convertFileSrc(src: string): string { - return this.appProvider.isIOS() ? ( window).Ionic.WebView.convertFileSrc(src) : src; + return CoreApp.instance.isIOS() ? ( window).Ionic.WebView.convertFileSrc(src) : src; } /** @@ -1262,7 +1261,7 @@ export class CoreFileProvider { * @return Unconverted src. */ unconvertFileSrc(src: string): string { - if (!this.appProvider.isIOS()) { + if (!CoreApp.instance.isIOS()) { return src; } diff --git a/src/providers/local-notifications.ts b/src/providers/local-notifications.ts index c75391606..c2ea096c2 100644 --- a/src/providers/local-notifications.ts +++ b/src/providers/local-notifications.ts @@ -17,7 +17,7 @@ import { Platform, Alert, AlertController } from 'ionic-angular'; import { LocalNotifications, ILocalNotification } from '@ionic-native/local-notifications'; import { Push } from '@ionic-native/push'; import { TranslateService } from '@ngx-translate/core'; -import { CoreAppProvider, CoreAppSchema } from './app'; +import { CoreApp, CoreAppProvider, CoreAppSchema } from './app'; import { CoreConfigProvider } from './config'; import { CoreEventsProvider } from './events'; import { CoreLoggerProvider } from './logger'; @@ -115,10 +115,19 @@ export class CoreLocalNotificationsProvider { protected updateSubscription: Subscription; protected queueRunner: CoreQueueRunner; // Queue to decrease the number of concurrent calls to the plugin (see MOBILE-3477). - constructor(logger: CoreLoggerProvider, private localNotifications: LocalNotifications, private platform: Platform, - private appProvider: CoreAppProvider, private utils: CoreUtilsProvider, private configProvider: CoreConfigProvider, - private textUtils: CoreTextUtilsProvider, private translate: TranslateService, private alertCtrl: AlertController, - eventsProvider: CoreEventsProvider, private push: Push, private zone: NgZone) { + constructor( + logger: CoreLoggerProvider, + private localNotifications: LocalNotifications, + private platform: Platform, + private utils: CoreUtilsProvider, + private configProvider: CoreConfigProvider, + private textUtils: CoreTextUtilsProvider, + private translate: TranslateService, + private alertCtrl: AlertController, + eventsProvider: CoreEventsProvider, + appProvider: CoreAppProvider, + private push: Push, + private zone: NgZone) { this.logger = logger.getInstance('CoreLocalNotificationsProvider'); this.queueRunner = new CoreQueueRunner(10); @@ -228,7 +237,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() && !this.appProvider.isDesktop() && this.platform.is('android') && + return this.isAvailable() && !CoreApp.instance.isDesktop() && CoreApp.instance.isAndroid() && this.platform.version().major < 8; } @@ -238,7 +247,7 @@ export class CoreLocalNotificationsProvider { * @return Promise resolved when done. */ protected createDefaultChannel(): Promise { - if (!this.platform.is('android')) { + if (!CoreApp.instance.isAndroid()) { return Promise.resolve(); } @@ -368,7 +377,7 @@ export class CoreLocalNotificationsProvider { isAvailable(): boolean { const win = window; - return this.appProvider.isDesktop() || !!(win.cordova && win.cordova.plugins && win.cordova.plugins.notification && + return CoreApp.instance.isDesktop() || !!(win.cordova && win.cordova.plugins && win.cordova.plugins.notification && win.cordova.plugins.notification.local); } @@ -609,7 +618,7 @@ export class CoreLocalNotificationsProvider { notification.data.component = component; notification.data.siteId = siteId; - if (this.platform.is('android')) { + if (CoreApp.instance.isAndroid()) { notification.icon = notification.icon || 'res://icon'; notification.smallIcon = notification.smallIcon || 'res://smallicon'; notification.color = notification.color || CoreConfigConstants.notificoncolor; diff --git a/src/providers/utils/dom.ts b/src/providers/utils/dom.ts index 1a7291ed6..5be93dddb 100644 --- a/src/providers/utils/dom.ts +++ b/src/providers/utils/dom.ts @@ -14,13 +14,13 @@ import { Injectable, SimpleChange, ElementRef } from '@angular/core'; import { - LoadingController, Loading, ToastController, Toast, AlertController, Alert, Platform, Content, PopoverController, + LoadingController, Loading, ToastController, Toast, AlertController, Alert, Content, PopoverController, ModalController, AlertButton, AlertOptions } from 'ionic-angular'; import { DomSanitizer } from '@angular/platform-browser'; import { TranslateService } from '@ngx-translate/core'; import { CoreTextUtilsProvider } from './text'; -import { CoreAppProvider } from '../app'; +import { CoreApp } from '../app'; import { CoreConfigProvider } from '../config'; import { CoreEventsProvider } from '../events'; import { CoreLoggerProvider } from '../logger'; @@ -71,8 +71,6 @@ export class CoreDomUtilsProvider { protected toastCtrl: ToastController, protected alertCtrl: AlertController, protected textUtils: CoreTextUtilsProvider, - protected appProvider: CoreAppProvider, - protected platform: Platform, protected configProvider: CoreConfigProvider, protected urlUtils: CoreUrlUtilsProvider, protected modalCtrl: ModalController, @@ -147,12 +145,12 @@ export class CoreDomUtilsProvider { const readableSize = this.textUtils.bytesToSize(size.size, 2); const getAvailableBytes = new Promise((resolve): void => { - if (this.appProvider.isDesktop()) { + if (CoreApp.instance.isDesktop()) { // Free space calculation is not supported on desktop. resolve(null); } else { this.fileProvider.calculateFreeSpace().then((availableBytes) => { - if (this.platform.is('android')) { + if (CoreApp.instance.isAndroid()) { return availableBytes; } else { // Space calculation is not accurate on iOS, but it gets more accurate when space is lower. @@ -174,7 +172,7 @@ export class CoreDomUtilsProvider { return ''; } else { const availableSize = this.textUtils.bytesToSize(availableBytes, 2); - if (this.platform.is('android') && size.size > availableBytes - CoreConstants.MINIMUM_FREE_SPACE) { + if (CoreApp.instance.isAndroid() && size.size > availableBytes - CoreConstants.MINIMUM_FREE_SPACE) { return Promise.reject(this.translate.instant('core.course.insufficientavailablespace', { size: readableSize })); } @@ -187,7 +185,7 @@ export class CoreDomUtilsProvider { limitedThreshold = typeof limitedThreshold == 'undefined' ? CoreConstants.DOWNLOAD_THRESHOLD : limitedThreshold; let wifiPrefix = ''; - if (this.appProvider.isNetworkAccessLimited()) { + if (CoreApp.instance.isNetworkAccessLimited()) { wifiPrefix = this.translate.instant('core.course.confirmlimiteddownload'); } @@ -202,7 +200,7 @@ export class CoreDomUtilsProvider { return this.showConfirm(wifiPrefix + this.translate.instant('core.course.confirmpartialdownloadsize', { size: readableSize, availableSpace: availableSpace })); } else if (alwaysConfirm || size.size >= wifiThreshold || - (this.appProvider.isNetworkAccessLimited() && size.size >= limitedThreshold)) { + (CoreApp.instance.isNetworkAccessLimited() && size.size >= limitedThreshold)) { message = message || (size.size === 0 ? 'core.course.confirmdownloadzerosize' : 'core.course.confirmdownload'); return this.showConfirm(wifiPrefix + this.translate.instant(message, @@ -377,9 +375,9 @@ export class CoreDomUtilsProvider { focusElement(el: HTMLElement): void { if (el && el.focus) { el.focus(); - if (this.platform.is('android') && this.supportsInputKeyboard(el)) { + if (CoreApp.instance.isAndroid() && this.supportsInputKeyboard(el)) { // On some Android versions the keyboard doesn't open automatically. - this.appProvider.openKeyboard(); + CoreApp.instance.openKeyboard(); } } } @@ -1562,7 +1560,7 @@ export class CoreDomUtilsProvider { event.stopPropagation(); // We cannot use CoreDomUtilsProvider.openInBrowser due to circular dependencies. - if (this.appProvider.isDesktop()) { + if (CoreApp.instance.isDesktop()) { // It's a desktop app, use Electron shell library to open the browser. const shell = require('electron').shell; if (!shell.openExternal(href)) { diff --git a/src/providers/utils/iframe.ts b/src/providers/utils/iframe.ts index 29aad5859..7eb0edf2f 100644 --- a/src/providers/utils/iframe.ts +++ b/src/providers/utils/iframe.ts @@ -16,7 +16,7 @@ import { Injectable, NgZone } from '@angular/core'; import { Config, Platform, NavController } from 'ionic-angular'; import { TranslateService } from '@ngx-translate/core'; import { Network } from '@ionic-native/network'; -import { CoreAppProvider } from '../app'; +import { CoreApp } from '../app'; import { CoreFileProvider } from '../file'; import { CoreLoggerProvider } from '../logger'; import { CoreSitesProvider } from '../sites'; @@ -39,16 +39,24 @@ export class CoreIframeUtilsProvider { protected logger; - constructor(logger: CoreLoggerProvider, private fileProvider: CoreFileProvider, private sitesProvider: CoreSitesProvider, - private urlUtils: CoreUrlUtilsProvider, private textUtils: CoreTextUtilsProvider, private utils: CoreUtilsProvider, - private domUtils: CoreDomUtilsProvider, private platform: Platform, private appProvider: CoreAppProvider, - private translate: TranslateService, private network: Network, private zone: NgZone, private config: Config, - private contentLinksHelper: CoreContentLinksHelperProvider) { + constructor(logger: CoreLoggerProvider, + private fileProvider: CoreFileProvider, + private sitesProvider: CoreSitesProvider, + private urlUtils: CoreUrlUtilsProvider, + private textUtils: CoreTextUtilsProvider, + private utils: CoreUtilsProvider, + private domUtils: CoreDomUtilsProvider, + platform: Platform, + private translate: TranslateService, + private network: Network, private zone: NgZone, + private config: Config, + private contentLinksHelper: CoreContentLinksHelperProvider + ) { this.logger = logger.getInstance('CoreUtilsProvider'); const win = window; - if (platform.is('ios') && win.WKUserScript) { + if (CoreApp.instance.isIOS() && win.WKUserScript) { platform.ready().then(() => { // Inject code to the iframes because we cannot access the online ones. const wwwPath = fileProvider.getWWWAbsolutePath(); @@ -78,7 +86,7 @@ export class CoreIframeUtilsProvider { checkOnlineFrameInOffline(element: any, isSubframe?: boolean): boolean { const src = element.src || element.data; - if (src && src != 'about:blank' && !this.urlUtils.isLocalFileUrl(src) && !this.appProvider.isOnline()) { + if (src && src != 'about:blank' && !this.urlUtils.isLocalFileUrl(src) && !CoreApp.instance.isOnline()) { if (element.classList.contains('core-iframe-offline-disabled')) { // Iframe already hidden, stop. return true; @@ -444,7 +452,7 @@ export class CoreIframeUtilsProvider { this.utils.openFile(link.href).catch((error) => { this.domUtils.showErrorModal(error); }); - } else if (this.platform.is('ios') && (!link.target || link.target == '_self') && element) { + } else if (CoreApp.instance.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') { diff --git a/src/providers/utils/text.ts b/src/providers/utils/text.ts index 9d005530f..af83ced3b 100644 --- a/src/providers/utils/text.ts +++ b/src/providers/utils/text.ts @@ -14,10 +14,11 @@ import { Injectable } from '@angular/core'; import { DomSanitizer, SafeUrl } from '@angular/platform-browser'; -import { ModalController, Platform } from 'ionic-angular'; +import { ModalController } from 'ionic-angular'; import { TranslateService } from '@ngx-translate/core'; import { CoreLangProvider } from '../lang'; import { makeSingleton } from '@singletons/core.singletons'; +import { CoreApp } from '../app'; /** * Different type of errors the app can treat. @@ -84,8 +85,12 @@ export class CoreTextUtilsProvider { protected template = document.createElement('template'); // A template element to convert HTML to element. - constructor(private translate: TranslateService, private langProvider: CoreLangProvider, private modalCtrl: ModalController, - private sanitizer: DomSanitizer, private platform: Platform) { } + constructor( + private translate: TranslateService, + private langProvider: CoreLangProvider, + private modalCtrl: ModalController, + private sanitizer: DomSanitizer + ) { } /** * Add ending slash from a path or URL. @@ -139,7 +144,7 @@ export class CoreTextUtilsProvider { * @return URL to view the address. */ buildAddressURL(address: string): SafeUrl { - return this.sanitizer.bypassSecurityTrustUrl((this.platform.is('android') ? 'geo:0,0?q=' : 'http://maps.google.com?q=') + + return this.sanitizer.bypassSecurityTrustUrl((CoreApp.instance.isAndroid() ? 'geo:0,0?q=' : 'http://maps.google.com?q=') + encodeURIComponent(address)); } diff --git a/src/providers/utils/utils.ts b/src/providers/utils/utils.ts index 2172f30f4..8b87c1b93 100644 --- a/src/providers/utils/utils.ts +++ b/src/providers/utils/utils.ts @@ -19,7 +19,7 @@ import { Clipboard } from '@ionic-native/clipboard'; import { FileOpener } from '@ionic-native/file-opener'; import { WebIntent } from '@ionic-native/web-intent'; import { QRScanner } from '@ionic-native/qr-scanner'; -import { CoreAppProvider } from '../app'; +import { CoreApp } from '../app'; import { CoreDomUtilsProvider } from './dom'; import { CoreMimetypeUtilsProvider } from './mimetype'; import { CoreTextUtilsProvider } from './text'; @@ -68,7 +68,6 @@ export class CoreUtilsProvider { protected qrScanData: {deferred: PromiseDefer, observable: Subscription}; constructor(protected iab: InAppBrowser, - protected appProvider: CoreAppProvider, protected clipboard: Clipboard, protected domUtils: CoreDomUtilsProvider, logger: CoreLoggerProvider, @@ -285,7 +284,7 @@ export class CoreUtilsProvider { closeInAppBrowser(closeAll?: boolean): void { if (this.iabInstance) { this.iabInstance.close(); - if (closeAll && this.appProvider.isDesktop()) { + if (closeAll && CoreApp.instance.isDesktop()) { require('electron').ipcRenderer.send('closeSecondaryWindows'); } } @@ -904,7 +903,7 @@ export class CoreUtilsProvider { const extension = this.mimetypeUtils.getFileExtension(path); const mimetype = this.mimetypeUtils.getMimeType(extension); - if (mimetype == 'text/html' && this.platform.is('android')) { + if (mimetype == 'text/html' && CoreApp.instance.isAndroid()) { // Open HTML local files in InAppBrowser, in system browser some embedded files aren't loaded. this.openInApp(path); @@ -959,7 +958,7 @@ export class CoreUtilsProvider { options.allowInlineMediaPlayback = 'yes'; // Allow playing inline videos in iOS. } - if (!options.location && this.platform.is('ios') && url.indexOf('file://') === 0) { + if (!options.location && CoreApp.instance.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'; @@ -967,7 +966,7 @@ export class CoreUtilsProvider { this.iabInstance = this.iab.create(url, '_blank', options); - if (this.appProvider.isDesktop() || this.appProvider.isMobile()) { + if (CoreApp.instance.isDesktop() || CoreApp.instance.isMobile()) { let loadStopSubscription; const loadStartUrls = []; @@ -985,7 +984,7 @@ export class CoreUtilsProvider { }); }); - if (this.platform.is('android')) { + if (CoreApp.instance.isAndroid()) { // Load stop is needed with InAppBrowser v3. Custom URL schemes no longer trigger load start, simulate it. loadStopSubscription = this.iabInstance.on('loadstop').subscribe((event) => { // Execute the callback in the Angular zone, so change detection doesn't stop working. @@ -1019,7 +1018,7 @@ export class CoreUtilsProvider { * @param url The URL to open. */ openInBrowser(url: string): void { - if (this.appProvider.isDesktop()) { + if (CoreApp.instance.isDesktop()) { // It's a desktop app, use Electron shell library to open the browser. const shell = require('electron').shell; if (!shell.openExternal(url)) { @@ -1039,7 +1038,7 @@ export class CoreUtilsProvider { * @return Promise resolved when opened. */ openOnlineFile(url: string): Promise { - if (this.platform.is('android')) { + if (CoreApp.instance.isAndroid()) { // In Android we need the mimetype to open it. return this.getMimeTypeFromUrl(url).catch(() => { // Error getting mimetype, return undefined. @@ -1471,7 +1470,7 @@ export class CoreUtilsProvider { * @return Whether the app can scan QR codes. */ canScanQR(): boolean { - return this.appProvider.isMobile(); + return CoreApp.instance.isMobile(); } /** @@ -1500,7 +1499,7 @@ export class CoreUtilsProvider { * @return Promise resolved with the QR string, rejected if error or cancelled. */ startScanQR(): Promise { - if (!this.appProvider.isMobile()) { + if (!CoreApp.instance.isMobile()) { return Promise.reject('QRScanner isn\'t available in desktop apps.'); }