MOBILE-4081 core: Consolidate Platform services

main
Noel De Martin 2022-06-20 18:19:18 +02:00
parent f1f7ee02de
commit ed50d3d76a
37 changed files with 121 additions and 93 deletions

View File

@ -32,7 +32,7 @@ import { AddonCalendarEventDBRecord, AddonCalendarReminderDBRecord, EVENTS_TABLE
import { CoreCourses } from '@features/courses/services/courses';
import { ContextLevel, CoreConstants } from '@/core/constants';
import { CoreWSError } from '@classes/errors/wserror';
import { ApplicationInit, makeSingleton, Translate, Platform } from '@singletons';
import { ApplicationInit, makeSingleton, Translate } from '@singletons';
import { AddonCalendarOfflineEventDBRecord } from './database/calendar-offline';
import { AddonCalendarMainMenuHandlerService } from './handlers/mainmenu';
import { SafeUrl } from '@angular/platform-browser';
@ -41,6 +41,7 @@ import { AddonCalendarFilter } from './calendar-helper';
import { AddonCalendarSyncEvents, AddonCalendarSyncProvider } from './calendar-sync';
import { CoreEvents } from '@singletons/events';
import { CoreText } from '@singletons/text';
import { CorePlatform } from '@services/platform';
const ROOT_CACHE_KEY = 'mmaCalendar:';
@ -1429,7 +1430,7 @@ export class AddonCalendarProvider {
* @return Promise resolved when all the notifications have been scheduled.
*/
async scheduleAllSitesEventsNotifications(): Promise<void> {
await Platform.ready();
await CorePlatform.ready();
const notificationsEnabled = CoreLocalNotifications.isAvailable();

View File

@ -28,11 +28,12 @@ import { ActivatedRoute, Params } from '@angular/router';
import { CorePushNotificationsNotificationBasicData } from '@features/pushnotifications/services/pushnotifications';
import { CorePushNotificationsDelegate } from '@features/pushnotifications/services/push-delegate';
import { Subscription } from 'rxjs';
import { Translate, Platform } from '@singletons';
import { Translate } from '@singletons';
import { IonRefresher } from '@ionic/angular';
import { CoreNavigator } from '@services/navigator';
import { CoreScreen } from '@services/screen';
import { CoreMainMenuDeepLinkManager } from '@features/mainmenu/classes/deep-link-manager';
import { CorePlatform } from '@services/platform';
/**
* Page that displays the list of discussions.
@ -114,7 +115,7 @@ export class AddonMessagesDiscussions35Page implements OnInit, OnDestroy {
);
// Refresh the view when the app is resumed.
this.appResumeSubscription = Platform.resume.subscribe(() => {
this.appResumeSubscription = CorePlatform.resume.subscribe(() => {
if (!this.loaded) {
return;
}

View File

@ -29,7 +29,7 @@ import {
import { CoreDomUtils } from '@services/utils/dom';
import { CoreUser } from '@features/user/services/user';
import { CorePushNotificationsDelegate } from '@features/pushnotifications/services/push-delegate';
import { Platform, Translate } from '@singletons';
import { Translate } from '@singletons';
import { Subscription } from 'rxjs';
import { CorePushNotificationsNotificationBasicData } from '@features/pushnotifications/services/pushnotifications';
import { ActivatedRoute, Params } from '@angular/router';
@ -37,6 +37,7 @@ import { CoreUtils } from '@services/utils/utils';
import { CoreNavigator } from '@services/navigator';
import { CoreScreen } from '@services/screen';
import { CoreMainMenuDeepLinkManager } from '@features/mainmenu/classes/deep-link-manager';
import { CorePlatform } from '@services/platform';
/**
* Page that displays the list of conversations, including group conversations.
@ -176,7 +177,7 @@ export class AddonMessagesGroupConversationsPage implements OnInit, OnDestroy {
);
// Refresh the view when the app is resumed.
this.appResumeSubscription = Platform.resume.subscribe(() => {
this.appResumeSubscription = CorePlatform.resume.subscribe(() => {
if (!this.loaded) {
return;
}

View File

@ -16,9 +16,10 @@ import { Injectable } from '@angular/core';
import { CoreCourse } from '@features/course/services/course';
import { CoreCourseModuleData } from '@features/course/services/course-helper';
import { CorePlatform } from '@services/platform';
import { CoreSites } from '@services/sites';
import { CoreDomUtils } from '@services/utils/dom';
import { makeSingleton, Platform } from '@singletons';
import { makeSingleton } from '@singletons';
import { CoreEvents } from '@singletons/events';
import { AddonModLti, AddonModLtiLti } from './lti';
@ -38,7 +39,7 @@ export class AddonModLtiHelperProvider {
}
watchPendingCompletions(): void {
Platform.resume.subscribe(() => {
CorePlatform.resume.subscribe(() => {
// User went back to the app, check pending completions.
for (const moduleId in this.pendingCheckCompletion) {
const data = this.pendingCheckCompletion[moduleId];

View File

@ -19,9 +19,9 @@ import { CoreCourseContentsPage } from '@features/course/pages/contents/contents
import { IonContent } from '@ionic/angular';
import { CoreGroupInfo, CoreGroups } from '@services/groups';
import { CoreNavigator } from '@services/navigator';
import { CorePlatform } from '@services/platform';
import { CoreDomUtils } from '@services/utils/dom';
import { CoreUtils } from '@services/utils/utils';
import { Platform } from '@singletons';
import { CoreEventObserver, CoreEvents } from '@singletons/events';
import { Subscription } from 'rxjs';
import { AddonModWorkshopModuleHandlerService } from '../../services/handlers/module';
@ -119,7 +119,7 @@ export class AddonModWorkshopIndexComponent extends CoreCourseModuleMainActivity
}, this.siteId);
// Since most actions will take the user out of the app, we should refresh the view when the app is resumed.
this.appResumeSubscription = Platform.resume.subscribe(() => {
this.appResumeSubscription = CorePlatform.resume.subscribe(() => {
this.showLoadingAndRefresh(true);
});

View File

@ -19,7 +19,7 @@ import { BackButtonEvent, ScrollDetail } from '@ionic/core';
import { CoreLang } from '@services/lang';
import { CoreLoginHelper } from '@features/login/services/login-helper';
import { CoreEvents } from '@singletons/events';
import { NgZone, Platform, SplashScreen, Translate } from '@singletons';
import { NgZone, SplashScreen, Translate } from '@singletons';
import { CoreNetwork } from '@services/network';
import { CoreApp, CoreAppProvider } from '@services/app';
import { CoreSites } from '@services/sites';
@ -33,6 +33,7 @@ import { CoreConstants } from '@/core/constants';
import { CoreSitePlugins } from '@features/siteplugins/services/siteplugins';
import { CoreDomUtils } from '@services/utils/dom';
import { CoreDom } from '@singletons/dom';
import { CorePlatform } from '@services/platform';
const MOODLE_VERSION_PREFIX = 'version-';
const MOODLEAPP_VERSION_PREFIX = 'moodleapp-';
@ -181,7 +182,7 @@ export class AppComponent implements OnInit, AfterViewInit {
}
});
Platform.resume.subscribe(() => {
CorePlatform.resume.subscribe(() => {
// Wait a second before setting it to false since in iOS there could be some frozen WS calls.
setTimeout(() => {
if (CoreLoginHelper.isWaitingForBrowser()) {
@ -305,7 +306,7 @@ export class AppComponent implements OnInit, AfterViewInit {
* Async init function on platform ready.
*/
protected async onPlatformReady(): Promise<void> {
await Platform.ready();
await CorePlatform.ready();
// Refresh online status when changes.
CoreNetwork.onChange().subscribe(() => {

View File

@ -14,13 +14,13 @@
import { createAnimation } from '@ionic/angular';
import { Animation } from '@ionic/core';
import { Platform } from '@singletons';
import { CorePlatform } from '@services/platform';
/**
* Sliding transition for lateral modals.
*/
export function CoreModalLateralTransitionEnter(baseEl: HTMLElement): Animation {
const OFF_RIGHT = Platform.isRTL ? '-100%' : '100%';
const OFF_RIGHT = CorePlatform.isRTL ? '-100%' : '100%';
const otherAnimations: Animation[] = [];
@ -51,7 +51,7 @@ export function CoreModalLateralTransitionEnter(baseEl: HTMLElement): Animation
}
export function CoreModalLateralTransitionLeave(baseEl: HTMLElement): Animation {
const OFF_RIGHT = Platform.isRTL ? '-100%' : '100%';
const OFF_RIGHT = CorePlatform.isRTL ? '-100%' : '100%';
const otherAnimations: Animation[] = [];

View File

@ -14,9 +14,10 @@
import { SQLiteObject } from '@ionic-native/sqlite/ngx';
import { SQLite, Platform } from '@singletons';
import { SQLite } from '@singletons';
import { CoreError } from '@classes/errors/error';
import { CoreDB } from '@services/db';
import { CorePlatform } from '@services/platform';
type SQLiteDBColumnType = 'INTEGER' | 'REAL' | 'TEXT' | 'BLOB';
@ -1157,7 +1158,7 @@ export class SQLiteDB {
* @returns Database.
*/
protected async createDatabase(): Promise<SQLiteObject> {
await Platform.ready();
await CorePlatform.ready();
return SQLite.create({ name: this.name, location: 'default' });
}

View File

@ -29,7 +29,7 @@ import { IonSlides } from '@ionic/angular';
import { BackButtonEvent } from '@ionic/core';
import { Subscription } from 'rxjs';
import { Platform, Translate } from '@singletons';
import { Translate } from '@singletons';
import { CoreSettingsHelper } from '@features/settings/services/settings-helper';
import { CoreAriaRoleTab, CoreAriaRoleTabFindable } from './aria-role-tab';
import { CoreEventObserver } from '@singletons/events';
@ -39,6 +39,7 @@ import { CoreError } from './errors/error';
import { CorePromisedValue } from './promised-value';
import { AsyncComponent } from './async-component';
import { CoreComponentsRegistry } from '@singletons/components-registry';
import { CorePlatform } from '@services/platform';
/**
* Class to abstract some common code for tabs.
@ -105,12 +106,12 @@ export class CoreTabsBaseComponent<T extends CoreTabBase> implements OnInit, Aft
* @inheritdoc
*/
async ngOnInit(): Promise<void> {
this.direction = Platform.isRTL ? 'rtl' : 'ltr';
this.direction = CorePlatform.isRTL ? 'rtl' : 'ltr';
// Change the side when the language changes.
this.subscriptions.push(Translate.onLangChange.subscribe(() => {
setTimeout(() => {
this.direction = Platform.isRTL ? 'rtl' : 'ltr';
this.direction = CorePlatform.isRTL ? 'rtl' : 'ltr';
});
}));
}

View File

@ -13,7 +13,7 @@
// limitations under the License.
import { Component, Input } from '@angular/core';
import { Platform } from '@singletons';
import { CorePlatform } from '@services/platform';
const enum ScrollPosition {
START = 'start',
@ -89,14 +89,14 @@ export class CoreHorizontalScrollControlsComponent {
}
if (scrollLeft === 0) {
return Platform.isRTL ? ScrollPosition.END : ScrollPosition.START;
return CorePlatform.isRTL ? ScrollPosition.END : ScrollPosition.START;
}
if (!Platform.isRTL && this.target.scrollWidth - scrollLeft === this.target.clientWidth) {
if (!CorePlatform.isRTL && this.target.scrollWidth - scrollLeft === this.target.clientWidth) {
return ScrollPosition.END;
}
if (Platform.isRTL && this.target.scrollWidth + scrollLeft === this.target.clientWidth) {
if (CorePlatform.isRTL && this.target.scrollWidth + scrollLeft === this.target.clientWidth) {
return ScrollPosition.START;
}

View File

@ -34,7 +34,7 @@ import { CoreIframeUtils, CoreIframeUtilsProvider } from '@services/utils/iframe
import { CoreTextUtils } from '@services/utils/text';
import { CoreUtils } from '@services/utils/utils';
import { CoreSite } from '@classes/site';
import { NgZone, Platform, Translate } from '@singletons';
import { NgZone, Translate } from '@singletons';
import { CoreExternalContentDirective } from './external-content';
import { CoreLinkDirective } from './link';
import { CoreFilter, CoreFilterFilter, CoreFilterFormatTextOptions } from '@features/filter/services/filter';
@ -49,6 +49,7 @@ import { CoreText } from '@singletons/text';
import { CoreDom } from '@singletons/dom';
import { CoreEvents } from '@singletons/events';
import { CoreRefreshContext, CORE_REFRESH_CONTEXT } from '@/core/utils/refresh-context';
import { CorePlatform } from '@services/platform';
/**
* Directive to format text rendered. It renders the HTML and treats all links and media, using CoreLinkDirective
@ -615,7 +616,7 @@ export class CoreFormatTextDirective implements OnChanges, OnDestroy, AsyncCompo
if (refreshOnResume && this.refreshContext) {
// Refresh the context when the app is resumed.
CoreSubscriptions.once(Platform.resume, () => {
CoreSubscriptions.once(CorePlatform.resume, () => {
NgZone.run(async () => {
this.refreshContext?.refreshContext();
});

View File

@ -17,8 +17,9 @@ import { CoreSwipeNavigationItemsManager } from '@classes/items-management/swipe
import { CoreSwipeNavigationTourComponent } from '@components/swipe-navigation-tour/swipe-navigation-tour';
import { CoreUserTours } from '@features/usertours/services/user-tours';
import { Gesture, GestureDetail } from '@ionic/angular';
import { CorePlatform } from '@services/platform';
import { CoreScreen } from '@services/screen';
import { GestureController, Platform } from '@singletons';
import { GestureController } from '@singletons';
const ACTIVATION_THRESHOLD = 150;
const SWIPE_FRICTION = 0.6;
@ -105,7 +106,7 @@ export class CoreSwipeNavigationDirective implements AfterViewInit, OnDestroy {
return;
}
Platform.isRTL
CorePlatform.isRTL
? this.manager?.navigateToPreviousItem()
: this.manager?.navigateToNextItem();
}
@ -118,7 +119,7 @@ export class CoreSwipeNavigationDirective implements AfterViewInit, OnDestroy {
return;
}
Platform.isRTL
CorePlatform.isRTL
? this.manager?.navigateToNextItem()
: this.manager?.navigateToPreviousItem();
}
@ -131,7 +132,7 @@ export class CoreSwipeNavigationDirective implements AfterViewInit, OnDestroy {
return false;
}
return Platform.isRTL
return CorePlatform.isRTL
? await this.manager.hasNextItem()
: await this.manager.hasPreviousItem();
}
@ -144,7 +145,7 @@ export class CoreSwipeNavigationDirective implements AfterViewInit, OnDestroy {
return false;
}
return Platform.isRTL
return CorePlatform.isRTL
? await this.manager.hasPreviousItem()
: await this.manager.hasNextItem();
}

View File

@ -26,7 +26,6 @@ import {
} from '@angular/core';
import { JitCompilerFactory } from '@angular/platform-browser-dynamic';
import {
Platform,
ActionSheetController,
AlertController,
LoadingController,
@ -156,6 +155,7 @@ import { ADDON_PRIVATEFILES_SERVICES } from '@addons/privatefiles/privatefiles.m
import { AddonModAssignComponentsModule } from '@addons/mod/assign/components/components.module';
import { AddonModWorkshopComponentsModule } from '@addons/mod/workshop/components/components.module';
import { CorePromisedValue } from '@classes/promised-value';
import { CorePlatform } from '@services/platform';
/**
* Service to provide functionalities regarding compiling dynamic HTML and Javascript.
@ -168,7 +168,7 @@ export class CoreCompileProvider {
// Other Ionic/Angular providers that don't depend on where they are injected.
protected readonly OTHER_SERVICES: unknown[] = [
TranslateService, HttpClient, Platform, DomSanitizer, ActionSheetController, AlertController, LoadingController,
TranslateService, HttpClient, DomSanitizer, ActionSheetController, AlertController, LoadingController,
ModalController, PopoverController, ToastController, FormBuilder,
];
@ -345,9 +345,11 @@ export class CoreCompileProvider {
instance['moment'] = moment;
instance['Md5'] = Md5;
instance['Network'] = CoreNetwork.instance; // @deprecated on 4.1, plugins should use CoreNetworkService instead.
instance['Platform'] = CorePlatform.instance; // @deprecated on 4.1, plugins should use CorePlatform instead.
instance['CoreSyncBaseProvider'] = CoreSyncBaseProvider;
instance['CoreArray'] = CoreArray;
instance['CoreComponentsRegistry'] = CoreComponentsRegistry;
instance['CorePlatform'] = CorePlatform.instance;
instance['CoreDom'] = CoreDom;
instance['CoreForms'] = CoreForms;
instance['CoreText'] = CoreText;

View File

@ -30,7 +30,7 @@ import {
CoreCourseOptionsMenuHandlerToDisplay,
} from '@features/course/services/course-options-delegate';
import { CoreCourseHelper } from '@features/course/services/course-helper';
import { ActionSheetController, ModalController, NgZone, Platform, Translate } from '@singletons';
import { ActionSheetController, ModalController, NgZone, Translate } from '@singletons';
import { CoreCoursesSelfEnrolPasswordComponent } from '../../../courses/components/self-enrol-password/self-enrol-password';
import { CoreNavigator } from '@services/navigator';
import { CoreUtils } from '@services/utils/utils';
@ -39,6 +39,7 @@ import { Subscription } from 'rxjs';
import { CoreColors } from '@singletons/colors';
import { CoreText } from '@singletons/text';
import { CorePromisedValue } from '@classes/promised-value';
import { CorePlatform } from '@services/platform';
const ENROL_BROWSER_METHODS = ['fee', 'paypal'];
@ -84,7 +85,7 @@ export class CoreCourseSummaryPage implements OnInit, OnDestroy {
constructor() {
// Refresh the view when the app is resumed.
this.appResumeSubscription = Platform.resume.subscribe(() => {
this.appResumeSubscription = CorePlatform.resume.subscribe(() => {
if (!this.waitingForBrowserEnrol || !this.dataLoaded) {
return;
}

View File

@ -23,7 +23,7 @@ import { CoreTimeUtils } from '@services/utils/time';
import { CoreUtils } from '@services/utils/utils';
import { CoreSiteWSPreSets, CoreSite } from '@classes/site';
import { CoreConstants } from '@/core/constants';
import { makeSingleton, Platform, Translate } from '@singletons';
import { makeSingleton, Translate } from '@singletons';
import { CoreStatusWithWarningsWSResponse, CoreWSExternalFile, CoreWSExternalWarning } from '@services/ws';
import {
@ -52,6 +52,7 @@ import { asyncInstance, AsyncInstance } from '@/core/utils/async-instance';
import { CoreDatabaseTable } from '@classes/database/database-table';
import { CoreDatabaseCachingStrategy } from '@classes/database/database-table-proxy';
import { SQLiteDB } from '@classes/sqlitedb';
import { CorePlatform } from '@services/platform';
const ROOT_CACHE_KEY = 'mmCourse:';
@ -173,7 +174,7 @@ export class CoreCourseProvider {
* Initialize.
*/
initialize(): void {
Platform.resume.subscribe(() => {
CorePlatform.resume.subscribe(() => {
// Run the handler the app is open to keep user in online status.
setTimeout(() => {
CoreCronDelegate.forceCronHandlerExecution(CoreCourseLogCronHandler.name);

View File

@ -33,7 +33,7 @@ import { CoreFilepool } from '@services/filepool';
import { CoreDomUtils } from '@services/utils/dom';
import { CoreUrlUtils } from '@services/utils/url';
import { CoreUtils } from '@services/utils/utils';
import { Platform, Translate } from '@singletons';
import { Translate } from '@singletons';
import { CoreEventFormActionData, CoreEventObserver, CoreEvents } from '@singletons/events';
import { CoreEditorOffline } from '../../services/editor-offline';
import { CoreComponentsRegistry } from '@singletons/components-registry';
@ -155,7 +155,7 @@ export class CoreEditorRichTextEditorComponent implements OnInit, AfterViewInit,
this.canScanQR = CoreUtils.canScanQR();
this.isPhone = CoreScreen.isMobile;
this.toolbarHidden = this.isPhone;
this.direction = Platform.isRTL ? 'rtl' : 'ltr';
this.direction = CorePlatform.isRTL ? 'rtl' : 'ltr';
}
/**
@ -269,7 +269,7 @@ export class CoreEditorRichTextEditorComponent implements OnInit, AfterViewInit,
// Change the side when the language changes.
this.languageChangedSubscription = Translate.onLangChange.subscribe(() => {
setTimeout(() => {
this.direction = Platform.isRTL ? 'rtl' : 'ltr';
this.direction = CorePlatform.isRTL ? 'rtl' : 'ltr';
});
});
}

View File

@ -21,7 +21,7 @@ import { CoreFile, CoreFileProvider } from '@services/file';
import { CoreDomUtils } from '@services/utils/dom';
import { CoreMimetypeUtils } from '@services/utils/mimetype';
import { CoreTimeUtils } from '@services/utils/time';
import { Platform, ModalController, Media, Translate } from '@singletons';
import { ModalController, Media, Translate } from '@singletons';
import { CoreError } from '@classes/errors/error';
import { CoreCaptureError } from '@classes/errors/captureerror';
import { CoreCanceledError } from '@classes/errors/cancelederror';
@ -119,7 +119,7 @@ export class CoreEmulatorCaptureMediaComponent implements OnInit, OnDestroy {
this.isCordovaAudioCapture = CorePlatform.isMobile() && this.isAudio;
if (this.isCordovaAudioCapture) {
this.extension = Platform.is('ios') ? 'wav' : 'aac';
this.extension = CorePlatform.is('ios') ? 'wav' : 'aac';
this.returnDataUrl = false;
}
}
@ -153,7 +153,7 @@ export class CoreEmulatorCaptureMediaComponent implements OnInit, OnDestroy {
// Now create the media instance.
let absolutePath = CoreText.concatenatePaths(CoreFile.getBasePathInstant(), this.filePath);
if (Platform.is('ios')) {
if (CorePlatform.is('ios')) {
// In iOS we need to remove the file:// part.
absolutePath = absolutePath.replace(/^file:\/\//, '');
}

View File

@ -26,7 +26,7 @@ import { CoreDomUtils } from '@services/utils/dom';
import { CoreMimetypeUtils } from '@services/utils/mimetype';
import { CoreTextUtils } from '@services/utils/text';
import { CoreUtils } from '@services/utils/utils';
import { makeSingleton, Translate, Camera, Chooser, Platform, ActionSheetController } from '@singletons';
import { makeSingleton, Translate, Camera, Chooser, ActionSheetController } from '@singletons';
import { CoreLogger } from '@singletons/logger';
import { CoreCanceledError } from '@classes/errors/cancelederror';
import { CoreError } from '@classes/errors/error';
@ -644,8 +644,8 @@ export class CoreFileUploaderHelperProvider {
options.popoverOptions = {
x: 10,
y: 10,
width: Platform.width() - 200,
height: Platform.height() - 200,
width: CorePlatform.width() - 200,
height: CorePlatform.height() - 200,
arrowDir: Camera.PopoverArrowDirection.ARROW_ANY,
};

View File

@ -17,10 +17,11 @@ import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { CoreDomUtils } from '@services/utils/dom';
import { CoreLoginHelper } from '@features/login/services/login-helper';
import { Translate, Platform } from '@singletons';
import { Translate } from '@singletons';
import { CoreWSExternalWarning } from '@services/ws';
import { CoreNavigator } from '@services/navigator';
import { CoreForms } from '@singletons/form';
import { CorePlatform } from '@services/platform';
/**
* Page to recover a forgotten password.
@ -55,7 +56,7 @@ export class CoreLoginForgottenPasswordPage implements OnInit {
}
this.siteUrl = siteUrl;
this.autoFocus = Platform.is('tablet');
this.autoFocus = CorePlatform.is('tablet');
this.myForm = this.formBuilder.group({
field: ['username', Validators.required],
value: [CoreNavigator.getRouteParam<string>('username') || '', Validators.required],

View File

@ -25,7 +25,7 @@ import { CoreTextUtils } from '@services/utils/text';
import { CoreConfig } from '@services/config';
import { CoreConstants } from '@/core/constants';
import { CoreSite, CoreSiteInfo } from '@classes/site';
import { makeSingleton, Badge, Push, Device, Translate, Platform, ApplicationInit, NgZone } from '@singletons';
import { makeSingleton, Badge, Push, Device, Translate, ApplicationInit, NgZone } from '@singletons';
import { CoreLogger } from '@singletons/logger';
import { CoreEvents } from '@singletons/events';
import {
@ -153,7 +153,7 @@ export class CorePushNotificationsProvider {
* @return Promise resolved when done.
*/
protected async initializeDefaultChannel(): Promise<void> {
await Platform.ready();
await CorePlatform.ready();
// Create the default channel.
this.createDefaultChannel();

View File

@ -15,10 +15,10 @@
import { Component, OnInit } from '@angular/core';
import { CoreSitePlugins } from '@features/siteplugins/services/siteplugins';
import { CoreUserTours } from '@features/usertours/services/user-tours';
import { CorePlatform } from '@services/platform';
import { CoreSites } from '@services/sites';
import { CoreDomUtils } from '@services/utils/dom';
import { CoreUtils } from '@services/utils/utils';
import { Platform } from '@singletons';
/**
* Page that displays the developer options.
@ -45,7 +45,7 @@ export class CoreSettingsDevPage implements OnInit {
siteId: string | undefined;
async ngOnInit(): Promise<void> {
this.rtl = Platform.isRTL;
this.rtl = CorePlatform.isRTL;
this.RTLChanged();
this.forceSafeAreaMargins = document.documentElement.classList.contains('force-safe-area-margins');

View File

@ -16,7 +16,7 @@ import { CoreApp } from '@services/app';
import { Component, OnDestroy } from '@angular/core';
import { CoreConstants } from '@/core/constants';
import { CoreLocalNotifications } from '@services/local-notifications';
import { Device, Platform, Translate, NgZone } from '@singletons';
import { Device, Translate, NgZone } from '@singletons';
import { CoreLang } from '@services/lang';
import { CoreFile } from '@services/file';
import { CoreSites } from '@services/sites';
@ -110,7 +110,7 @@ export class CoreSettingsDeviceInfoPage implements OnDestroy {
}
if (CorePlatform.isMobile()) {
this.deviceInfo.deviceType = Platform.is('tablet') ? 'tablet' : 'phone';
this.deviceInfo.deviceType = CorePlatform.is('tablet') ? 'tablet' : 'phone';
if (CoreApp.isAndroid()) {
this.deviceInfo.deviceOs = 'android';
this.deviceOsTranslated = 'Android';

View File

@ -23,7 +23,7 @@ import { CoreFile } from '@services/file';
import { CoreNavigator } from '@services/navigator';
import { CoreSites } from '@services/sites';
import { CoreDomUtils } from '@services/utils/dom';
import { AlertController, ApplicationInit, makeSingleton, Platform, Translate } from '@singletons';
import { AlertController, ApplicationInit, makeSingleton, Translate } from '@singletons';
import { CoreEvents } from '@singletons/events';
import { CoreLogger } from '@singletons/logger';
import { CoreSharedFilesListModalComponent } from '../components/list-modal/list-modal';
@ -31,6 +31,7 @@ import { CoreSharedFiles } from './sharedfiles';
import { SHAREDFILES_PAGE_NAME } from '../sharedfiles.module';
import { CoreSharedFilesChooseSitePage } from '../pages/choose-site/choose-site';
import { CoreError } from '@classes/errors/error';
import { CorePlatform } from '@services/platform';
/**
* Helper service to share files with the app.
@ -57,7 +58,7 @@ export class CoreSharedFilesHelperProvider {
// Check if there are new files at app start and when the app is resumed.
this.searchIOSNewSharedFiles();
Platform.resume.subscribe(() => {
CorePlatform.resume.subscribe(() => {
// Wait a bit to make sure that APP_LAUNCHED_URL is treated before this callback.
setTimeout(() => {
if (Date.now() - lastCheck < 1000) {

View File

@ -13,7 +13,7 @@
// limitations under the License.
import { CoreStyles, renderInlineStyles } from '@/core/utils/style-helpers';
import { Platform } from '@singletons';
import { CorePlatform } from '@services/platform';
import { CoreUserToursAlignment, CoreUserToursSide } from '../services/user-tours';
const ARROW_HEIGHT = 22;
@ -54,8 +54,12 @@ export class CoreUserToursPopoverLayout {
[CoreUserToursSide.Bottom]: this.calculateWrapperBottomSideStyles,
[CoreUserToursSide.Right]: this.calculateWrapperRightSideStyles,
[CoreUserToursSide.Left]: this.calculateWrapperLeftSideStyles,
[CoreUserToursSide.Start]: Platform.isRTL ? this.calculateWrapperRightSideStyles : this.calculateWrapperLeftSideStyles,
[CoreUserToursSide.End]: Platform.isRTL ? this.calculateWrapperLeftSideStyles : this.calculateWrapperRightSideStyles,
[CoreUserToursSide.Start]: CorePlatform.isRTL
? this.calculateWrapperRightSideStyles
: this.calculateWrapperLeftSideStyles,
[CoreUserToursSide.End]: CorePlatform.isRTL
? this.calculateWrapperLeftSideStyles
: this.calculateWrapperRightSideStyles,
};
sideHandlers[this.side].call(this);
@ -69,11 +73,11 @@ export class CoreUserToursPopoverLayout {
*/
private calculateWrapperHorizontalAlignmentStyles(): void {
const horizontalAlignmentHandlers: Record<CoreUserToursAlignment, () => void> ={
[CoreUserToursAlignment.Start]: Platform.isRTL
[CoreUserToursAlignment.Start]: CorePlatform.isRTL
? this.calculateWrapperRightAlignmentStyles
: this.calculateWrapperLeftAlignmentStyles,
[CoreUserToursAlignment.Center]: this.calculateWrapperCenterHorizontalAlignmentStyles,
[CoreUserToursAlignment.End]: Platform.isRTL
[CoreUserToursAlignment.End]: CorePlatform.isRTL
? this.calculateWrapperLeftAlignmentStyles
: this.calculateWrapperRightAlignmentStyles,
};

View File

@ -13,14 +13,14 @@
// limitations under the License.
import { CorePlatform } from '@services/platform';
import { NativeHttp, Platform } from '@singletons';
import { NativeHttp } from '@singletons';
export default async function(): Promise<void> {
if (!CorePlatform.isMobile()) {
return;
}
await Platform.ready();
await CorePlatform.ready();
NativeHttp.setHeader('*', 'User-Agent', navigator.userAgent);
}

View File

@ -13,11 +13,11 @@
// limitations under the License.
import { CoreApp } from '@services/app';
import { CorePlatform } from '@services/platform';
import { CoreIframeUtils } from '@services/utils/iframe';
import { Platform } from '@singletons';
export default async function(): Promise<void> {
await Platform.ready();
await CorePlatform.ready();
if (!CoreApp.isIOS() || !('WKUserScript' in window)) {
return;

View File

@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { Platform } from '@singletons';
import { CorePlatform } from '@services/platform';
export default async function(): Promise<void> {
await Platform.ready();
await CorePlatform.ready();
if (!window.cordova?.InAppBrowser) {
return;

View File

@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { Platform } from '@singletons';
import { CorePlatform } from '@services/platform';
export default async function(): Promise<void> {
await Platform.ready();
await CorePlatform.ready();
}

View File

@ -18,7 +18,7 @@ import { CoreDB } from '@services/db';
import { CoreEvents } from '@singletons/events';
import { SQLiteDB, SQLiteDBTableSchema } from '@classes/sqlitedb';
import { makeSingleton, Keyboard, StatusBar, Platform, Device } from '@singletons';
import { makeSingleton, Keyboard, StatusBar, Device } from '@singletons';
import { CoreLogger } from '@singletons/logger';
import { CoreColors } from '@singletons/colors';
import { DBNAME, SCHEMA_VERSIONS_TABLE_NAME, SCHEMA_VERSIONS_TABLE_SCHEMA, SchemaVersionsDBEntry } from '@services/database/app';
@ -227,7 +227,7 @@ export class CoreAppProvider {
* @return Whether the app is running in an Android mobile or tablet device.
*/
isAndroid(): boolean {
return CorePlatform.isMobile() && Platform.is('android');
return CorePlatform.isMobile() && CorePlatform.is('android');
}
/**
@ -246,7 +246,7 @@ export class CoreAppProvider {
* @return Whether the app is running in an iOS mobile or tablet device.
*/
isIOS(): boolean {
return CorePlatform.isMobile() && !Platform.is('android');
return CorePlatform.isMobile() && !CorePlatform.is('android');
}
/**
@ -322,7 +322,7 @@ export class CoreAppProvider {
* @return Whether the app the current window is wider than a mobile.
*/
isWide(): boolean {
return Platform.width() > 768;
return CorePlatform.width() > 768;
}
/**
@ -490,7 +490,7 @@ export class CoreAppProvider {
deferred = null;
};
resumeSubscription = Platform.resume.subscribe(stopWaiting);
resumeSubscription = CorePlatform.resume.subscribe(stopWaiting);
timeoutId = timeout ? window.setTimeout(stopWaiting, timeout) : null;
await deferred;

View File

@ -17,8 +17,9 @@ import { Injectable } from '@angular/core';
import { SQLiteDB } from '@classes/sqlitedb';
import { SQLiteDBMock } from '@features/emulator/classes/sqlitedb';
import { CoreBrowser } from '@singletons/browser';
import { makeSingleton, SQLite, Platform } from '@singletons';
import { makeSingleton, SQLite } from '@singletons';
import { CoreAppProvider } from './app';
import { CorePlatform } from '@services/platform';
const tableNameRegex = new RegExp([
'^SELECT.*FROM ([^ ]+)',
@ -208,7 +209,7 @@ export class CoreDbProvider {
*/
getDB(name: string, forceNew?: boolean): SQLiteDB {
if (this.dbInstances[name] === undefined || forceNew) {
if (Platform.is('cordova')) {
if (CorePlatform.is('cordova')) {
this.dbInstances[name] = new SQLiteDB(name);
} else {
this.dbInstances[name] = new SQLiteDBMock(name);
@ -241,7 +242,7 @@ export class CoreDbProvider {
location: 'default',
});
}
} else if (Platform.is('cordova')) {
} else if (CorePlatform.is('cordova')) {
return SQLite.deleteDatabase({
name,
location: 'default',

View File

@ -24,7 +24,7 @@ import { CoreConstants } from '@/core/constants';
import { CoreError } from '@classes/errors/error';
import { CoreLogger } from '@singletons/logger';
import { makeSingleton, File, Zip, Platform, WebView } from '@singletons';
import { makeSingleton, File, Zip, WebView } from '@singletons';
import { CoreFileEntry } from '@services/file-helper';
import { CoreText } from '@singletons/text';
import { CorePlatform } from '@services/platform';
@ -137,7 +137,7 @@ export class CoreFileProvider {
return;
}
await Platform.ready();
await CorePlatform.ready();
if (CoreApp.isAndroid()) {
this.basePath = File.externalApplicationStorageDirectory || this.basePath;

View File

@ -19,10 +19,11 @@ import { LangChangeEvent } from '@ngx-translate/core';
import { CoreAppProvider } from '@services/app';
import { CoreConfig } from '@services/config';
import { CoreSubscriptions } from '@singletons/subscriptions';
import { makeSingleton, Translate, Platform, Http } from '@singletons';
import { makeSingleton, Translate, Http } from '@singletons';
import * as moment from 'moment';
import { CoreSite } from '../classes/site';
import { CorePlatform } from '@services/platform';
/*
* Service to handle language features, like changing the current language.
@ -57,7 +58,7 @@ export class CoreLangProvider {
* Init language.
*/
protected async initializeCurrentLanguage(): Promise<void> {
await Platform.ready();
await CorePlatform.ready();
let language: string;

View File

@ -24,7 +24,7 @@ import { SQLiteDB } from '@classes/sqlitedb';
import { CoreQueueRunner } from '@classes/queue-runner';
import { CoreError } from '@classes/errors/error';
import { CoreConstants } from '@/core/constants';
import { makeSingleton, NgZone, Platform, Translate, LocalNotifications, Push } from '@singletons';
import { makeSingleton, NgZone, Translate, LocalNotifications, Push } from '@singletons';
import { CoreLogger } from '@singletons/logger';
import {
APP_SCHEMA,
@ -34,6 +34,7 @@ import {
CodeRequestsQueueItem,
} from '@services/database/local-notifications';
import { CorePromisedValue } from '@classes/promised-value';
import { CorePlatform } from '@services/platform';
/**
* Service to handle local notifications.
@ -68,7 +69,7 @@ export class CoreLocalNotificationsProvider {
* Init some properties.
*/
async initialize(): Promise<void> {
await Platform.ready();
await CorePlatform.ready();
if (!this.isAvailable()) {
return;

View File

@ -13,13 +13,14 @@
// limitations under the License.
import { Injectable } from '@angular/core';
import { makeSingleton, Platform } from '@singletons';
import { Platform } from '@ionic/angular';
import { makeSingleton } from '@singletons';
/**
* Extend Ionic's Platform service.
*/
@Injectable({ providedIn: 'root' })
export class CorePlatformService {
export class CorePlatformService extends Platform {
/**
* Checks if the app is running in a mobile or tablet device (Cordova).
@ -27,7 +28,7 @@ export class CorePlatformService {
* @return Whether the app is running in a mobile or tablet device.
*/
isMobile(): boolean {
return Platform.is('cordova');
return this.is('cordova');
}
}

View File

@ -16,8 +16,9 @@ import { Injectable } from '@angular/core';
import { BehaviorSubject, Observable } from 'rxjs';
import { distinctUntilChanged, map } from 'rxjs/operators';
import { makeSingleton, Platform } from '@singletons';
import { makeSingleton } from '@singletons';
import { CoreEvents } from '@singletons/events';
import { CorePlatform } from '@services/platform';
/**
* Screen breakpoints.
@ -120,7 +121,7 @@ export class CoreScreenService {
* Watch orientation changes.
*/
async watchOrientation(): Promise<void> {
await Platform.ready();
await CorePlatform.ready();
screen.orientation.addEventListener('change', () => {
CoreEvents.trigger(CoreEvents.ORIENTATION_CHANGE, { orientation: this.orientation });

View File

@ -26,7 +26,6 @@ import { HttpClient } from '@angular/common/http';
import { DomSanitizer as DomSanitizerService } from '@angular/platform-browser';
import {
Platform as PlatformService,
AngularDelegate as AngularDelegateService,
AlertController as AlertControllerService,
LoadingController as LoadingControllerService,
@ -202,7 +201,6 @@ export const Device = makeSingleton(DeviceService);
// Convert some Angular and Ionic injectables to singletons.
export const NgZone = makeSingleton(NgZoneService);
export const Http = makeSingleton(HttpClient);
export const Platform = makeSingleton(PlatformService);
export const ActionSheetController = makeSingleton(ActionSheetControllerService);
export const AngularDelegate = makeSingleton(AngularDelegateService);
export const AlertController = makeSingleton(AlertControllerService);

View File

@ -19,12 +19,13 @@ import { Observable, Subject } from 'rxjs';
import { sep } from 'path';
import { CORE_SITE_SCHEMAS } from '@services/sites';
import { CoreSingletonProxy, Platform, Translate } from '@singletons';
import { CoreSingletonProxy, Translate } from '@singletons';
import { CoreTextUtilsProvider } from '@services/utils/text';
import { TranslatePipeStub } from './stubs/pipes/translate';
import { CoreExternalContentDirectiveStub } from './stubs/directives/core-external-content';
import { CoreNetwork } from '@services/network';
import { CorePlatform } from '@services/platform';
abstract class WrapperComponent<U> {
@ -37,7 +38,12 @@ type ServiceInjectionToken = AbstractType<unknown> | Type<unknown> | string;
let testBedInitialized = false;
const textUtils = new CoreTextUtilsProvider();
const DEFAULT_SERVICE_SINGLETON_MOCKS: [CoreSingletonProxy, Record<string, unknown>][] = [
[Platform, mock({ is: () => false, ready: () => Promise.resolve(), resume: new Subject<void>() })],
[CorePlatform, mock({
is: () => false,
isMobile: () => false,
ready: () => Promise.resolve(),
resume: new Subject<void>(),
})],
[CoreNetwork, { onChange: () => new Observable() }],
];