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..02db5c875 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'; @@ -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/core/editor/components/rich-text-editor/rich-text-editor.ts b/src/core/editor/components/rich-text-editor/rich-text-editor.ts index 648567082..1a887cf8b 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 @@ -236,7 +236,7 @@ export class CoreEditorRichTextEditorComponent implements AfterContentInit, OnDe if (this.platform.is('android')) { // 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..ae5aa372c 100644 --- a/src/core/fileuploader/providers/audio-handler.ts +++ b/src/core/fileuploader/providers/audio-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 { CoreUtilsProvider } from '@providers/utils/utils'; import { CoreFileUploaderHandler, CoreFileUploaderHandlerData } from './delegate'; import { CoreFileUploaderHelperProvider } from './helper'; @@ -26,8 +26,11 @@ 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 platform: Platform, + private uploaderHelper: CoreFileUploaderHelperProvider + ) { } /** * Whether or not the handler is enabled on a site level. @@ -35,7 +38,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,7 +48,7 @@ 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')) { diff --git a/src/core/fileuploader/providers/file-handler.ts b/src/core/fileuploader/providers/file-handler.ts index 54c689ebe..53a5e82b9 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, CoreAppProvider } from '@providers/app'; import { CoreDomUtilsProvider } from '@providers/utils/dom'; import { CoreTimeUtilsProvider } from '@providers/utils/time'; import { CoreFileUploaderHandler, CoreFileUploaderHandlerData } from './delegate'; @@ -45,7 +45,7 @@ export class CoreFileUploaderFileHandler implements CoreFileUploaderHandler { */ isEnabled(): boolean | Promise { return this.platform.is('android') || !this.appProvider.isMobile() || - (this.platform.is('ios') && this.platform.version().major >= 9); + (CoreApp.instance.isIOS() && this.platform.version().major >= 9); } /** @@ -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..c34c502ca 100644 --- a/src/core/fileuploader/providers/fileuploader.ts +++ b/src/core/fileuploader/providers/fileuploader.ts @@ -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. @@ -183,7 +184,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 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..a34b1e244 100644 --- a/src/core/fileuploader/providers/video-handler.ts +++ b/src/core/fileuploader/providers/video-handler.ts @@ -14,7 +14,7 @@ import { Injectable } from '@angular/core'; import { Platform } from 'ionic-angular'; -import { CoreAppProvider } from '@providers/app'; +import { CoreApp, CoreAppProvider } from '@providers/app'; import { CoreUtilsProvider } from '@providers/utils/utils'; import { CoreFileUploaderHandler, CoreFileUploaderHandlerData } from './delegate'; import { CoreFileUploaderHelperProvider } from './helper'; @@ -45,7 +45,7 @@ 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')) { diff --git a/src/core/login/providers/helper.ts b/src/core/login/providers/helper.ts index 8b2fcdf6a..85915be8f 100644 --- a/src/core/login/providers/helper.ts +++ b/src/core/login/providers/helper.ts @@ -16,7 +16,7 @@ import { Injectable } from '@angular/core'; import { Location } from '@angular/common'; import { Platform, AlertController, NavController, NavOptions } from 'ionic-angular'; import { TranslateService } from '@ngx-translate/core'; -import { CoreAppProvider, CoreStoreConfig } from '@providers/app'; +import { CoreApp, CoreAppProvider, CoreStoreConfig } from '@providers/app'; import { CoreConfigProvider } from '@providers/config'; import { CoreEventsProvider } from '@providers/events'; import { CoreInitDelegate } from '@providers/init'; @@ -1272,7 +1272,7 @@ export class CoreLoginHelperProvider { }); alert.present().then(() => { - const isDevice = this.platform.is('android') || this.platform.is('ios'); + const isDevice = this.platform.is('android') || CoreApp.instance.isIOS(); if (!isDevice) { // Treat all anchors so they don't override the app. const alertMessageEl: HTMLElement = alert.pageRef().nativeElement.querySelector('.alert-message'); 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/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/providers/app.ts b/src/providers/app.ts index 7c3827806..b8c038e17 100644 --- a/src/providers/app.ts +++ b/src/providers/app.ts @@ -568,7 +568,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,7 +797,7 @@ 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); @@ -808,7 +808,7 @@ export class CoreAppProvider { 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 { @@ -822,11 +822,11 @@ export class CoreAppProvider { */ resetStatusBarColor(): void { if (typeof CoreConfigConstants.statusbarbgremotetheme == 'string' && - ((typeof CoreConfigConstants.statusbarbgios == 'string' && this.platform.is('ios')) || + ((typeof CoreConfigConstants.statusbarbgios == 'string' && this.isIOS()) || (typeof CoreConfigConstants.statusbarbgandroid == 'string' && this.platform.is('android')) || 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..3878f0e9f 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 } from './app'; import { CoreLoggerProvider } from './logger'; import { CoreMimetypeUtilsProvider } from './utils/mimetype'; import { CoreTextUtilsProvider } from './utils/text'; @@ -75,7 +74,6 @@ export class CoreFileProvider { constructor(logger: CoreLoggerProvider, protected platform: Platform, protected file: File, - protected appProvider: CoreAppProvider, protected textUtils: CoreTextUtilsProvider, protected zip: Zip, protected mimeUtils: CoreMimetypeUtilsProvider) { @@ -180,7 +178,7 @@ export class CoreFileProvider { if (this.platform.is('android')) { 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 +473,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 +620,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 +743,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 +1250,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 +1260,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/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/utils.ts b/src/providers/utils/utils.ts index 2172f30f4..14dc6c59e 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'); } } @@ -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 = []; @@ -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)) { @@ -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.'); }