diff --git a/src/addons/messages/pages/settings/settings.page.ts b/src/addons/messages/pages/settings/settings.page.ts index 06b4902b1..c69841ece 100644 --- a/src/addons/messages/pages/settings/settings.page.ts +++ b/src/addons/messages/pages/settings/settings.page.ts @@ -20,7 +20,6 @@ import { AddonMessages, } from '../../services/messages'; import { CoreUser } from '@features/user/services/user'; -import { CoreApp } from '@services/app'; import { CoreConfig } from '@services/config'; import { CoreEvents } from '@singletons/events'; import { CoreSites } from '@services/sites'; @@ -28,6 +27,7 @@ import { CoreDomUtils } from '@services/utils/dom'; import { CoreConstants } from '@/core/constants'; import { IonRefresher } from '@ionic/angular'; import { AddonNotificationsPreferencesNotificationProcessorState } from '@addons/notifications/services/notifications'; +import { CorePlatform } from '@services/platform'; /** * Page that displays the messages settings page. @@ -66,7 +66,7 @@ export class AddonMessagesSettingsPage implements OnInit, OnDestroy { } protected async asyncInit(): Promise { - this.sendOnEnter = !!(await CoreConfig.get(CoreConstants.SETTINGS_SEND_ON_ENTER, !CoreApp.isMobile())); + this.sendOnEnter = !!(await CoreConfig.get(CoreConstants.SETTINGS_SEND_ON_ENTER, !CorePlatform.isMobile())); } /** diff --git a/src/addons/mod/lti/services/lti.ts b/src/addons/mod/lti/services/lti.ts index 72c658feb..81347f9f0 100644 --- a/src/addons/mod/lti/services/lti.ts +++ b/src/addons/mod/lti/services/lti.ts @@ -17,8 +17,8 @@ import { Injectable } from '@angular/core'; import { CoreError } from '@classes/errors/error'; import { CoreSite, CoreSiteWSPreSets } from '@classes/site'; import { CoreCourseLogHelper } from '@features/course/services/log-helper'; -import { CoreApp } from '@services/app'; import { CoreFile } from '@services/file'; +import { CorePlatform } from '@services/platform'; import { CoreSites, CoreSitesCommonWSOptions } from '@services/sites'; import { CoreTextUtils } from '@services/utils/text'; import { CoreUrlUtils } from '@services/utils/url'; @@ -251,7 +251,7 @@ export class AddonModLtiProvider { // Generate launcher and open it. const launcherUrl = await this.generateLauncher(url, params); - if (CoreApp.isMobile()) { + if (CorePlatform.isMobile()) { CoreUtils.openInApp(launcherUrl); } else { // In desktop open in browser, we found some cases where inapp caused JS issues. diff --git a/src/addons/mod/scorm/services/handlers/prefetch.ts b/src/addons/mod/scorm/services/handlers/prefetch.ts index 907622300..c4ffb9112 100644 --- a/src/addons/mod/scorm/services/handlers/prefetch.ts +++ b/src/addons/mod/scorm/services/handlers/prefetch.ts @@ -16,9 +16,9 @@ import { Injectable } from '@angular/core'; import { CoreError } from '@classes/errors/error'; import { CoreCourseActivityPrefetchHandlerBase } from '@features/course/classes/activity-prefetch-handler'; import { CoreCourse, CoreCourseAnyModuleData, CoreCourseCommonModWSOptions } from '@features/course/services/course'; -import { CoreApp } from '@services/app'; import { CoreFile } from '@services/file'; import { CoreFilepool } from '@services/filepool'; +import { CorePlatform } from '@services/platform'; import { CoreFileSizeSum } from '@services/plugin-file-delegate'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreUtils } from '@services/utils/utils'; @@ -394,7 +394,7 @@ export class AddonModScormPrefetchHandlerService extends CoreCourseActivityPrefe // Remove the unzipped folder. promises.push(CoreFile.removeDir(path).catch((error) => { - if (error && (error.code == 1 || !CoreApp.isMobile())) { + if (error && (error.code == 1 || !CorePlatform.isMobile())) { // Not found, ignore error. } else { throw error; diff --git a/src/addons/notifications/services/handlers/cron.ts b/src/addons/notifications/services/handlers/cron.ts index fc8ca5329..882978cc7 100644 --- a/src/addons/notifications/services/handlers/cron.ts +++ b/src/addons/notifications/services/handlers/cron.ts @@ -14,8 +14,8 @@ import { Injectable } from '@angular/core'; -import { CoreApp } from '@services/app'; import { CoreCronHandler } from '@services/cron'; +import { CorePlatform } from '@services/platform'; import { CoreSites } from '@services/sites'; import { makeSingleton } from '@singletons'; import { CoreEvents } from '@singletons/events'; @@ -35,7 +35,7 @@ export class AddonNotificationsCronHandlerService implements CoreCronHandler { * @return Time between consecutive executions (in ms). */ getInterval(): number { - return CoreApp.isMobile() ? 600000 : 60000; // 1 or 10 minutes. + return CorePlatform.isMobile() ? 600000 : 60000; // 1 or 10 minutes. } /** diff --git a/src/core/components/send-message-form/send-message-form.ts b/src/core/components/send-message-form/send-message-form.ts index a783732ad..fe624981c 100644 --- a/src/core/components/send-message-form/send-message-form.ts +++ b/src/core/components/send-message-form/send-message-form.ts @@ -13,7 +13,6 @@ // limitations under the License. import { Component, Input, Output, EventEmitter, OnInit, ViewChild, ElementRef } from '@angular/core'; -import { CoreApp } from '@services/app'; import { CoreConfig } from '@services/config'; import { CoreEvents } from '@singletons/events'; import { CoreSites } from '@services/sites'; @@ -21,6 +20,7 @@ import { CoreUtils } from '@services/utils/utils'; import { CoreTextUtils } from '@services/utils/text'; import { CoreConstants } from '@/core/constants'; import { CoreForms } from '@singletons/form'; +import { CorePlatform } from '@services/platform'; /** * Component to display a "send message form". @@ -55,7 +55,7 @@ export class CoreSendMessageFormComponent implements OnInit { this.onSubmit = new EventEmitter(); this.onResize = new EventEmitter(); - CoreConfig.get(CoreConstants.SETTINGS_SEND_ON_ENTER, !CoreApp.isMobile()).then((sendOnEnter) => { + CoreConfig.get(CoreConstants.SETTINGS_SEND_ON_ENTER, !CorePlatform.isMobile()).then((sendOnEnter) => { this.sendOnEnter = !!sendOnEnter; return; @@ -117,7 +117,7 @@ export class CoreSendMessageFormComponent implements OnInit { // Enter clicked, send the message. e.preventDefault(); e.stopPropagation(); - } else if (!this.sendOnEnter && !CoreApp.isMobile() && other == 'control') { + } else if (!this.sendOnEnter && !CorePlatform.isMobile() && other == 'control') { // Cmd+Enter or Ctrl+Enter, send message. e.preventDefault(); e.stopPropagation(); @@ -138,7 +138,7 @@ export class CoreSendMessageFormComponent implements OnInit { if (this.sendOnEnter && !other) { // Enter clicked, send the message. this.submitForm(e); - } else if (!this.sendOnEnter && !CoreApp.isMobile() && other == 'control') { + } else if (!this.sendOnEnter && !CorePlatform.isMobile() && other == 'control') { // Cmd+Enter or Ctrl+Enter, send message. this.submitForm(e); } diff --git a/src/core/features/editor/components/rich-text-editor/rich-text-editor.ts b/src/core/features/editor/components/rich-text-editor/rich-text-editor.ts index ab00db484..3c444a4ef 100644 --- a/src/core/features/editor/components/rich-text-editor/rich-text-editor.ts +++ b/src/core/features/editor/components/rich-text-editor/rich-text-editor.ts @@ -28,7 +28,6 @@ import { FormControl } from '@angular/forms'; import { IonTextarea, IonContent, IonSlides } from '@ionic/angular'; import { Subscription } from 'rxjs'; -import { CoreApp } from '@services/app'; import { CoreSites } from '@services/sites'; import { CoreFilepool } from '@services/filepool'; import { CoreDomUtils } from '@services/utils/dom'; @@ -42,6 +41,7 @@ import { CoreLoadingComponent } from '@components/loading/loading'; import { CoreScreen } from '@services/screen'; import { CoreCancellablePromise } from '@classes/cancellable-promise'; import { CoreDom } from '@singletons/dom'; +import { CorePlatform } from '@services/platform'; /** * Component to display a rich text editor if enabled. @@ -797,7 +797,7 @@ export class CoreEditorRichTextEditorComponent implements OnInit, AfterViewInit, const selection = window.getSelection()?.toString(); // When RTE is focused with a whole paragraph in desktop the stopBubble will not fire click. - if (CoreApp.isMobile() || !this.rteEnabled || document.activeElement != this.editorElement || selection == '') { + if (CorePlatform.isMobile() || !this.rteEnabled || document.activeElement != this.editorElement || selection == '') { this.stopBubble(event); } } diff --git a/src/core/features/emulator/components/capture-media/capture-media.ts b/src/core/features/emulator/components/capture-media/capture-media.ts index b226d5b61..8a158181c 100644 --- a/src/core/features/emulator/components/capture-media/capture-media.ts +++ b/src/core/features/emulator/components/capture-media/capture-media.ts @@ -17,7 +17,6 @@ import { MediaObject } from '@ionic-native/media/ngx'; import { FileEntry } from '@ionic-native/file/ngx'; import { MediaFile } from '@ionic-native/media-capture/ngx'; -import { CoreApp } from '@services/app'; import { CoreFile, CoreFileProvider } from '@services/file'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreMimetypeUtils } from '@services/utils/mimetype'; @@ -27,6 +26,7 @@ import { CoreError } from '@classes/errors/error'; import { CoreCaptureError } from '@classes/errors/captureerror'; import { CoreCanceledError } from '@classes/errors/cancelederror'; import { CoreText } from '@singletons/text'; +import { CorePlatform } from '@services/platform'; /** * Page to capture media in browser, or to capture audio in mobile devices. @@ -116,7 +116,7 @@ export class CoreEmulatorCaptureMediaComponent implements OnInit, OnDestroy { this.title = 'core.captureimage'; } - this.isCordovaAudioCapture = CoreApp.isMobile() && this.isAudio; + this.isCordovaAudioCapture = CorePlatform.isMobile() && this.isAudio; if (this.isCordovaAudioCapture) { this.extension = Platform.is('ios') ? 'wav' : 'aac'; diff --git a/src/core/features/fileuploader/services/fileuploader-helper.ts b/src/core/features/fileuploader/services/fileuploader-helper.ts index 2c3580fd3..44bd4e2e1 100644 --- a/src/core/features/fileuploader/services/fileuploader-helper.ts +++ b/src/core/features/fileuploader/services/fileuploader-helper.ts @@ -37,6 +37,7 @@ import { CoreWSUploadFileResult } from '@services/ws'; import { CoreSites } from '@services/sites'; import { CoreText } from '@singletons/text'; import { CorePromisedValue } from '@classes/promised-value'; +import { CorePlatform } from '@services/platform'; /** * Helper service to upload files. @@ -551,7 +552,7 @@ export class CoreFileUploaderHelperProvider { media = medias[0]; // We used limit 1, we only want 1 media. } catch (error) { - if (isAudio && this.isNoAppError(error) && CoreApp.isMobile()) { + if (isAudio && this.isNoAppError(error) && CorePlatform.isMobile()) { // No app to record audio, fallback to capture it ourselves. try { media = await CoreFileUploader.captureAudioInApp(); @@ -574,7 +575,7 @@ export class CoreFileUploaderHelperProvider { } // Make sure the path has the protocol. In iOS it doesn't. - if (CoreApp.isMobile() && path.indexOf('file://') == -1) { + if (CorePlatform.isMobile() && path.indexOf('file://') == -1) { path = 'file://' + path; } diff --git a/src/core/features/fileuploader/services/handlers/album.ts b/src/core/features/fileuploader/services/handlers/album.ts index 39add8537..86f422444 100644 --- a/src/core/features/fileuploader/services/handlers/album.ts +++ b/src/core/features/fileuploader/services/handlers/album.ts @@ -14,7 +14,7 @@ import { Injectable } from '@angular/core'; -import { CoreApp } from '@services/app'; +import { CorePlatform } from '@services/platform'; import { CoreUtils } from '@services/utils/utils'; import { makeSingleton } from '@singletons'; import { CoreFileUploaderHandler, CoreFileUploaderHandlerData, CoreFileUploaderHandlerResult } from '../fileuploader-delegate'; @@ -35,7 +35,7 @@ export class CoreFileUploaderAlbumHandlerService implements CoreFileUploaderHand * @return Promise resolved with true if enabled. */ async isEnabled(): Promise { - return CoreApp.isMobile(); + return CorePlatform.isMobile(); } /** diff --git a/src/core/features/fileuploader/services/handlers/audio.ts b/src/core/features/fileuploader/services/handlers/audio.ts index d151f8469..a39a77b85 100644 --- a/src/core/features/fileuploader/services/handlers/audio.ts +++ b/src/core/features/fileuploader/services/handlers/audio.ts @@ -15,6 +15,7 @@ import { Injectable } from '@angular/core'; import { CoreApp } from '@services/app'; +import { CorePlatform } from '@services/platform'; import { CoreUtils } from '@services/utils/utils'; import { makeSingleton } from '@singletons'; import { CoreFileUploaderHandler, CoreFileUploaderHandlerData, CoreFileUploaderHandlerResult } from '../fileuploader-delegate'; @@ -34,7 +35,7 @@ export class CoreFileUploaderAudioHandlerService implements CoreFileUploaderHand * @return Promise resolved with true if enabled. */ async isEnabled(): Promise { - return CoreApp.isMobile() || (CoreApp.canGetUserMedia() && CoreApp.canRecordMedia()); + return CorePlatform.isMobile() || (CoreApp.canGetUserMedia() && CoreApp.canRecordMedia()); } /** diff --git a/src/core/features/fileuploader/services/handlers/camera.ts b/src/core/features/fileuploader/services/handlers/camera.ts index 3590934fc..077487da0 100644 --- a/src/core/features/fileuploader/services/handlers/camera.ts +++ b/src/core/features/fileuploader/services/handlers/camera.ts @@ -15,6 +15,7 @@ import { Injectable } from '@angular/core'; import { CoreApp } from '@services/app'; +import { CorePlatform } from '@services/platform'; import { CoreUtils } from '@services/utils/utils'; import { makeSingleton } from '@singletons'; import { CoreFileUploaderHandler, CoreFileUploaderHandlerData, CoreFileUploaderHandlerResult } from '../fileuploader-delegate'; @@ -35,7 +36,7 @@ export class CoreFileUploaderCameraHandlerService implements CoreFileUploaderHan * @return Promise resolved with true if enabled. */ async isEnabled(): Promise { - return CoreApp.isMobile() || CoreApp.canGetUserMedia(); + return CorePlatform.isMobile() || CoreApp.canGetUserMedia(); } /** diff --git a/src/core/features/fileuploader/services/handlers/file.ts b/src/core/features/fileuploader/services/handlers/file.ts index f0aff4c39..a2326bced 100644 --- a/src/core/features/fileuploader/services/handlers/file.ts +++ b/src/core/features/fileuploader/services/handlers/file.ts @@ -20,6 +20,7 @@ import { CoreFileUploaderHandler, CoreFileUploaderHandlerData, CoreFileUploaderH import { CoreFileUploaderHelper } from '../fileuploader-helper'; import { CoreFileUploader } from '../fileuploader'; import { makeSingleton, Translate } from '@singletons'; +import { CorePlatform } from '@services/platform'; /** * Handler to upload any type of file. @@ -61,7 +62,7 @@ export class CoreFileUploaderFileHandlerService implements CoreFileUploaderHandl icon: 'folder', // Cannot use font-awesome in action sheet. }; - if (CoreApp.isMobile()) { + if (CorePlatform.isMobile()) { handler.action = async ( maxSize?: number, upload?: boolean, diff --git a/src/core/features/fileuploader/services/handlers/video.ts b/src/core/features/fileuploader/services/handlers/video.ts index 037e1a0ec..578070cd4 100644 --- a/src/core/features/fileuploader/services/handlers/video.ts +++ b/src/core/features/fileuploader/services/handlers/video.ts @@ -15,6 +15,7 @@ import { Injectable } from '@angular/core'; import { CoreApp } from '@services/app'; +import { CorePlatform } from '@services/platform'; import { CoreUtils } from '@services/utils/utils'; import { makeSingleton } from '@singletons'; import { CoreFileUploaderHandler, CoreFileUploaderHandlerData, CoreFileUploaderHandlerResult } from '../fileuploader-delegate'; @@ -34,7 +35,7 @@ export class CoreFileUploaderVideoHandlerService implements CoreFileUploaderHand * @return Promise resolved with true if enabled. */ async isEnabled(): Promise { - return CoreApp.isMobile() || (CoreApp.canGetUserMedia() && CoreApp.canRecordMedia()); + return CorePlatform.isMobile() || (CoreApp.canGetUserMedia() && CoreApp.canRecordMedia()); } /** diff --git a/src/core/features/pushnotifications/services/pushnotifications.ts b/src/core/features/pushnotifications/services/pushnotifications.ts index 394f86dc6..ddd86d114 100644 --- a/src/core/features/pushnotifications/services/pushnotifications.ts +++ b/src/core/features/pushnotifications/services/pushnotifications.ts @@ -46,6 +46,7 @@ import { CoreDatabaseTable } from '@classes/database/database-table'; import { CoreDatabaseCachingStrategy, CoreDatabaseTableProxy } from '@classes/database/database-table-proxy'; import { CoreObject } from '@singletons/object'; import { lazyMap, LazyMap } from '@/core/utils/lazy-map'; +import { CorePlatform } from '@services/platform'; /** * Service to handle push notifications. @@ -204,7 +205,7 @@ export class CorePushNotificationsProvider { * @return Whether the device can be registered in Moodle. */ canRegisterOnMoodle(): boolean { - return !!this.pushID && CoreApp.isMobile(); + return !!this.pushID && CorePlatform.isMobile(); } /** @@ -542,7 +543,7 @@ export class CorePushNotificationsProvider { * @return Promise resolved when device is unregistered. */ async unregisterDeviceOnMoodle(site: CoreSite): Promise { - if (!site || !CoreApp.isMobile()) { + if (!site || !CorePlatform.isMobile()) { throw new CoreError('Cannot unregister device'); } @@ -624,7 +625,7 @@ export class CorePushNotificationsProvider { const total = counters.reduce((previous, counter) => previous + counter, 0); - if (!CoreApp.isMobile()) { + if (!CorePlatform.isMobile()) { // Browser doesn't have an app badge, stop. return total; } diff --git a/src/core/features/settings/pages/deviceinfo/deviceinfo.ts b/src/core/features/settings/pages/deviceinfo/deviceinfo.ts index da72645ff..6b400a5f0 100644 --- a/src/core/features/settings/pages/deviceinfo/deviceinfo.ts +++ b/src/core/features/settings/pages/deviceinfo/deviceinfo.ts @@ -26,6 +26,7 @@ import { CorePushNotifications } from '@features/pushnotifications/services/push import { CoreConfig } from '@services/config'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreNavigator } from '@services/navigator'; +import { CorePlatform } from '@services/platform'; /** * Device Info to be shown and copied to clipboard. @@ -108,7 +109,7 @@ export class CoreSettingsDeviceInfoPage implements OnDestroy { ' (' + window.screen.width + 'x' + window.screen.height + ')'; } - if (appProvider.isMobile()) { + if (CorePlatform.isMobile()) { this.deviceInfo.deviceType = Platform.is('tablet') ? 'tablet' : 'phone'; if (appProvider.isAndroid()) { this.deviceInfo.deviceOs = 'android'; diff --git a/src/core/features/siteplugins/services/siteplugins.ts b/src/core/features/siteplugins/services/siteplugins.ts index 4d71118ca..b9bb33a80 100644 --- a/src/core/features/siteplugins/services/siteplugins.ts +++ b/src/core/features/siteplugins/services/siteplugins.ts @@ -30,6 +30,7 @@ import { CoreEvents } from '@singletons/events'; import { CoreLogger } from '@singletons/logger'; import { CoreSitePluginsModuleHandler } from '../classes/handlers/module-handler'; import { CorePromisedValue } from '@classes/promised-value'; +import { CorePlatform } from '@services/platform'; const ROOT_CACHE_KEY = 'CoreSitePlugins:'; @@ -90,7 +91,7 @@ export class CoreSitePluginsProvider { applang: lang, appcustomurlscheme: CoreConstants.CONFIG.customurlscheme, appisdesktop: false, - appismobile: CoreApp.isMobile(), + appismobile: CorePlatform.isMobile(), appiswide: CoreApp.isWide(), appplatform: 'browser', }; diff --git a/src/core/initializers/initialize-user-agent.ts b/src/core/initializers/initialize-user-agent.ts index 085341f36..f6e914d90 100644 --- a/src/core/initializers/initialize-user-agent.ts +++ b/src/core/initializers/initialize-user-agent.ts @@ -12,11 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { CoreApp } from '@services/app'; +import { CorePlatform } from '@services/platform'; import { NativeHttp, Platform } from '@singletons'; export default async function(): Promise { - if (!CoreApp.isMobile()) { + if (!CorePlatform.isMobile()) { return; } diff --git a/src/core/services/app.ts b/src/core/services/app.ts index 40a76b704..2eb93fa4f 100644 --- a/src/core/services/app.ts +++ b/src/core/services/app.ts @@ -29,6 +29,7 @@ import { asyncInstance } from '../utils/async-instance'; import { CoreDatabaseTable } from '@classes/database/database-table'; import { CorePromisedValue } from '@classes/promised-value'; import { Subscription } from 'rxjs'; +import { CorePlatform } from '@services/platform'; /** * Factory to provide some global functionalities, like access to the global app database. @@ -111,7 +112,7 @@ export class CoreAppProvider { * Closes the keyboard. */ closeKeyboard(): void { - if (this.isMobile()) { + if (CorePlatform.isMobile()) { Keyboard.hide(); } } @@ -192,7 +193,7 @@ export class CoreAppProvider { return 'market://details?id=' + storesConfig.android; } - if (this.isMobile() && storesConfig.mobile) { + if (CorePlatform.isMobile() && storesConfig.mobile) { return storesConfig.mobile; } @@ -203,7 +204,7 @@ export class CoreAppProvider { * Get platform major version number. */ getPlatformMajorVersion(): number { - if (!this.isMobile()) { + if (!CorePlatform.isMobile()) { return 0; } @@ -226,7 +227,7 @@ export class CoreAppProvider { * @return Whether the app is running in an Android mobile or tablet device. */ isAndroid(): boolean { - return this.isMobile() && Platform.is('android'); + return CorePlatform.isMobile() && Platform.is('android'); } /** @@ -245,7 +246,7 @@ export class CoreAppProvider { * @return Whether the app is running in an iOS mobile or tablet device. */ isIOS(): boolean { - return this.isMobile() && !Platform.is('android'); + return CorePlatform.isMobile() && !Platform.is('android'); } /** @@ -309,9 +310,10 @@ export class CoreAppProvider { * Checks if the app is running in a mobile or tablet device (Cordova). * * @return Whether the app is running in a mobile or tablet device. + * @deprecated since 4.1. use CorePlatform instead. */ isMobile(): boolean { - return Platform.is('cordova'); + return CorePlatform.isMobile(); } /** @@ -630,7 +632,7 @@ export class CoreAppProvider { * @param color RGB color to use as status bar background. If not set the css variable will be read. */ setStatusBarColor(color?: string): void { - if (!this.isMobile()) { + if (!CorePlatform.isMobile()) { return; } diff --git a/src/core/services/file.ts b/src/core/services/file.ts index ce592709e..5b5eea530 100644 --- a/src/core/services/file.ts +++ b/src/core/services/file.ts @@ -27,6 +27,7 @@ import { CoreLogger } from '@singletons/logger'; import { makeSingleton, File, Zip, Platform, WebView } from '@singletons'; import { CoreFileEntry } from '@services/file-helper'; import { CoreText } from '@singletons/text'; +import { CorePlatform } from '@services/platform'; /** * Progress event used when writing a file data into a file. @@ -1261,7 +1262,7 @@ export class CoreFileProvider { * @return Converted src. */ convertFileSrc(src: string): string { - return CoreApp.isMobile() ? WebView.convertFileSrc(src) : src; + return CorePlatform.isMobile() ? WebView.convertFileSrc(src) : src; } /** @@ -1271,7 +1272,7 @@ export class CoreFileProvider { * @return Unconverted src. */ unconvertFileSrc(src: string): string { - if (!CoreApp.isMobile()) { + if (!CorePlatform.isMobile()) { return src; } diff --git a/src/core/services/navigator.ts b/src/core/services/navigator.ts index a33abca58..746eb23b7 100644 --- a/src/core/services/navigator.ts +++ b/src/core/services/navigator.ts @@ -27,9 +27,9 @@ import { CoreUrlUtils } from '@services/utils/url'; import { CoreTextUtils } from '@services/utils/text'; import { makeSingleton, NavController, Router } from '@singletons'; import { CoreScreen } from './screen'; -import { CoreApp } from './app'; import { CoreError } from '@classes/errors/error'; import { CoreMainMenuDelegate } from '@features/mainmenu/services/mainmenu-delegate'; +import { CorePlatform } from '@services/platform'; /** * Redirect payload. @@ -318,7 +318,7 @@ export class CoreNavigatorService { // Remove the parameter from our map if it's in there. delete this.storedParams[value]; - if (!CoreApp.isMobile() && !storedParam) { + if (!CorePlatform.isMobile() && !storedParam) { // Try to retrieve the param from local storage in browser. const storageParam = localStorage.getItem(value); if (storageParam) { @@ -604,7 +604,7 @@ export class CoreNavigatorService { this.storedParams[id] = value; queryParams[name] = id; - if (!CoreApp.isMobile()) { + if (!CorePlatform.isMobile()) { // In browser, save the param in local storage to be able to retrieve it if the app is refreshed. localStorage.setItem(id, JSON.stringify(value)); } diff --git a/src/core/services/platform.ts b/src/core/services/platform.ts new file mode 100644 index 000000000..294a4859a --- /dev/null +++ b/src/core/services/platform.ts @@ -0,0 +1,35 @@ +// (C) Copyright 2015 Moodle Pty Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { Injectable } from '@angular/core'; +import { makeSingleton, Platform } from '@singletons'; + +/** + * Extend Ionic's Platform service. + */ +@Injectable({ providedIn: 'root' }) +export class CorePlatformService { + + /** + * Checks if the app is running in a mobile or tablet device (Cordova). + * + * @return Whether the app is running in a mobile or tablet device. + */ + isMobile(): boolean { + return Platform.is('cordova'); + } + +} + +export const CorePlatform = makeSingleton(CorePlatformService); diff --git a/src/core/services/utils/url.ts b/src/core/services/utils/url.ts index a75e8d911..282a1c4fc 100644 --- a/src/core/services/utils/url.ts +++ b/src/core/services/utils/url.ts @@ -19,9 +19,9 @@ import { CoreTextUtils } from '@services/utils/text'; import { CoreConstants } from '@/core/constants'; import { makeSingleton } from '@singletons'; import { CoreUrl } from '@singletons/url'; -import { CoreApp } from '@services/app'; import { CoreSites } from '@services/sites'; import { CoreText } from '@singletons/text'; +import { CorePlatform } from '@services/platform'; /* * "Utils" service with helper functions for URLs. @@ -461,7 +461,7 @@ export class CoreUrlUtilsProvider { scheme == 'file' || scheme == 'filesystem' || scheme == CoreConstants.CONFIG.ioswebviewscheme || - (CoreApp.isMobile() && scheme === 'http' && domain === 'localhost'); // @todo: Get served domain from ENV. + (CorePlatform.isMobile() && scheme === 'http' && domain === 'localhost'); // @todo: Get served domain from ENV. } /** diff --git a/src/core/services/utils/utils.ts b/src/core/services/utils/utils.ts index 44778e743..9de9a1b9e 100644 --- a/src/core/services/utils/utils.ts +++ b/src/core/services/utils/utils.ts @@ -35,6 +35,7 @@ import { CoreConstants } from '@/core/constants'; import { CoreWindow } from '@singletons/window'; import { CoreColors } from '@singletons/colors'; import { CorePromisedValue } from '@classes/promised-value'; +import { CorePlatform } from '@services/platform'; type TreeNode = T & { children: TreeNode[] }; @@ -1015,7 +1016,7 @@ export class CoreUtilsProvider { this.iabInstance = InAppBrowser.create(url, '_blank', options); - if (CoreApp.isMobile()) { + if (CorePlatform.isMobile()) { let loadStopSubscription; const loadStartUrls: string[] = []; @@ -1590,7 +1591,7 @@ export class CoreUtilsProvider { * @return Whether the app can scan QR codes. */ canScanQR(): boolean { - return CoreApp.isMobile(); + return CorePlatform.isMobile(); } /** @@ -1615,7 +1616,7 @@ export class CoreUtilsProvider { * @return Promise resolved with the QR string, rejected if error or cancelled. */ async startScanQR(): Promise { - if (!CoreApp.isMobile()) { + if (!CorePlatform.isMobile()) { return Promise.reject('QRScanner isn\'t available in browser.'); } diff --git a/src/core/services/ws.ts b/src/core/services/ws.ts index 306851383..7f532887c 100644 --- a/src/core/services/ws.ts +++ b/src/core/services/ws.ts @@ -38,6 +38,7 @@ import { CoreNetworkError } from '@classes/errors/network-error'; import { CoreSite } from '@classes/site'; import { CoreHttpError } from '@classes/errors/httperror'; import { CorePromisedValue } from '@classes/promised-value'; +import { CorePlatform } from '@services/platform'; /** * This service allows performing WS calls and download/upload files. @@ -994,7 +995,7 @@ export class CoreWSProvider { options.responseType = options.responseType || 'json'; options.timeout = options.timeout === undefined ? this.getRequestTimeout() : options.timeout; - if (CoreApp.isMobile()) { + if (CorePlatform.isMobile()) { // Use the cordova plugin. if (url.indexOf('file://') === 0) { // We cannot load local files using the http native plugin. Use file provider instead.