From 73ee4df1ec2402ebca2d02d2ec32564cbeaebe10 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Wed, 11 May 2022 14:06:42 +0200 Subject: [PATCH] MOBILE-3321 core: Decouple Network from App --- .../calendar/components/calendar/calendar.ts | 4 +- src/addons/calendar/pages/day/day.page.ts | 8 +- src/addons/calendar/pages/event/event.page.ts | 6 +- src/addons/calendar/pages/index/index.page.ts | 6 +- src/addons/calendar/services/calendar-sync.ts | 4 +- src/addons/calendar/services/calendar.ts | 8 +- .../messages/services/messages-offline.ts | 6 +- src/addons/messages/services/messages-sync.ts | 6 +- src/addons/messages/services/messages.ts | 6 +- .../components/submission/submission.ts | 4 +- src/addons/mod/assign/services/assign-sync.ts | 4 +- src/addons/mod/assign/services/assign.ts | 8 +- .../mod/book/pages/contents/contents.ts | 4 +- .../components/users-modal/users-modal.ts | 6 +- src/addons/mod/chat/pages/chat/chat.ts | 5 +- src/addons/mod/choice/services/choice-sync.ts | 4 +- src/addons/mod/choice/services/choice.ts | 6 +- src/addons/mod/data/services/data-sync.ts | 4 +- src/addons/mod/data/services/data.ts | 14 +-- src/addons/mod/feedback/pages/form/form.ts | 6 +- .../mod/feedback/services/feedback-sync.ts | 4 +- src/addons/mod/feedback/services/feedback.ts | 4 +- .../post-options-menu/post-options-menu.ts | 6 +- .../forum/pages/discussion/discussion.page.ts | 6 +- src/addons/mod/forum/services/forum-helper.ts | 4 +- src/addons/mod/forum/services/forum-sync.ts | 8 +- src/addons/mod/forum/services/forum.ts | 6 +- .../mod/glossary/services/glossary-sync.ts | 4 +- src/addons/mod/glossary/services/glossary.ts | 4 +- .../mod/h5pactivity/components/index/index.ts | 6 +- .../h5pactivity/services/h5pactivity-sync.ts | 4 +- src/addons/mod/imscp/pages/view/view.ts | 4 +- src/addons/mod/imscp/services/imscp.ts | 4 +- .../mod/lesson/pages/player/player.page.ts | 6 +- src/addons/mod/lesson/services/lesson-sync.ts | 6 +- src/addons/mod/quiz/services/quiz-sync.ts | 4 +- .../mod/resource/components/index/index.ts | 5 +- .../mod/resource/services/resource-helper.ts | 4 +- src/addons/mod/survey/services/survey-sync.ts | 4 +- src/addons/mod/survey/services/survey.ts | 4 +- src/addons/mod/wiki/components/index/index.ts | 6 +- src/addons/mod/wiki/services/wiki-sync.ts | 4 +- src/addons/mod/wiki/services/wiki.ts | 4 +- .../mod/workshop/services/workshop-sync.ts | 4 +- src/addons/mod/workshop/services/workshop.ts | 14 +-- src/addons/notes/services/notes-sync.ts | 4 +- src/addons/notes/services/notes.ts | 6 +- src/addons/privatefiles/pages/index/index.ts | 4 +- src/app/app.component.ts | 5 +- src/core/classes/base-sync.ts | 4 +- src/core/classes/site.ts | 9 +- .../components/attachments/attachments.ts | 4 +- src/core/components/file/file.ts | 3 +- .../components/user-avatar/user-avatar.ts | 4 +- src/core/directives/external-content.ts | 3 +- .../comments/pages/viewer/viewer.page.ts | 5 +- .../comments/services/comments-sync.ts | 4 +- .../features/comments/services/comments.ts | 6 +- .../classes/activity-prefetch-handler.ts | 4 +- .../course/classes/main-resource-component.ts | 4 +- .../classes/resource-prefetch-handler.ts | 4 +- .../module-summary/module-summary.ts | 6 +- .../features/course/services/course-helper.ts | 8 +- src/core/features/course/services/course.ts | 6 +- .../features/course/services/log-helper.ts | 4 +- src/core/features/course/services/sync.ts | 4 +- .../services/fileuploader-helper.ts | 9 +- .../features/filter/services/filter-helper.ts | 4 +- src/core/features/filter/services/filter.ts | 4 +- .../h5p/components/h5p-player/h5p-player.ts | 6 +- .../login/pages/credentials/credentials.ts | 3 +- .../login/pages/reconnect/reconnect.ts | 3 +- src/core/features/login/pages/site/site.ts | 3 +- .../features/rating/services/rating-sync.ts | 4 +- src/core/features/rating/services/rating.ts | 4 +- .../settings/pages/deviceinfo/deviceinfo.ts | 7 +- .../settings/services/settings-helper.ts | 5 +- src/core/features/user/services/user.ts | 6 +- src/core/features/xapi/services/xapi.ts | 4 +- src/core/services/app.ts | 43 ++------- src/core/services/cron.ts | 5 +- src/core/services/file-helper.ts | 5 +- src/core/services/filepool.ts | 15 +-- src/core/services/network.ts | 92 +++++++++++++++++++ src/core/services/sites.ts | 5 +- src/core/services/utils/dom.ts | 5 +- src/core/services/utils/iframe.ts | 3 +- src/core/services/ws.ts | 14 +-- 88 files changed, 343 insertions(+), 255 deletions(-) create mode 100644 src/core/services/network.ts diff --git a/src/addons/calendar/components/calendar/calendar.ts b/src/addons/calendar/components/calendar/calendar.ts index f60aff1ce..82a1fc81f 100644 --- a/src/addons/calendar/components/calendar/calendar.ts +++ b/src/addons/calendar/components/calendar/calendar.ts @@ -41,7 +41,7 @@ import { import { AddonCalendarFilter, AddonCalendarHelper } from '../../services/calendar-helper'; import { AddonCalendarOffline } from '../../services/calendar-offline'; import { CoreCategoryData, CoreCourses } from '@features/courses/services/courses'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreSwipeSlidesComponent } from '@components/swipe-slides/swipe-slides'; import { CoreSwipeSlidesDynamicItem, @@ -498,7 +498,7 @@ class AddonCalendarMonthSlidesItemsManagerSource extends CoreSwipeSlidesDynamicI // Don't pass courseId and categoryId, we'll filter them locally. result = await AddonCalendar.getMonthlyEvents(year, monthNumber); } catch (error) { - if (!CoreApp.isOnline()) { + if (!CoreNetwork.isOnline()) { // Allow navigating to non-cached months in offline (behave as if using emergency cache). result = await AddonCalendarHelper.getOfflineMonthWeeks(year, monthNumber); } else { diff --git a/src/addons/calendar/pages/day/day.page.ts b/src/addons/calendar/pages/day/day.page.ts index f8e013549..5efb9dfa2 100644 --- a/src/addons/calendar/pages/day/day.page.ts +++ b/src/addons/calendar/pages/day/day.page.ts @@ -14,7 +14,7 @@ import { Component, OnInit, OnDestroy, ViewChild } from '@angular/core'; import { IonRefresher } from '@ionic/angular'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { CoreSites } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; @@ -183,7 +183,7 @@ export class AddonCalendarDayPage implements OnInit, OnDestroy { this.onlineObserver = Network.onChange().subscribe(() => { // Execute the callback in the Angular zone, so change detection doesn't stop working. NgZone.run(() => { - this.isOnline = CoreApp.isOnline(); + this.isOnline = CoreNetwork.isOnline(); }); }); } @@ -237,7 +237,7 @@ export class AddonCalendarDayPage implements OnInit, OnDestroy { */ async fetchData(sync?: boolean): Promise { this.syncIcon = CoreConstants.ICON_LOADING; - this.isOnline = CoreApp.isOnline(); + this.isOnline = CoreNetwork.isOnline(); if (sync) { await this.sync(); @@ -674,7 +674,7 @@ class AddonCalendarDaySlidesItemsManagerSource extends CoreSwipeSlidesDynamicIte ); } catch (error) { // Allow navigating to non-cached days in offline (behave as if using emergency cache). - if (CoreApp.isOnline()) { + if (CoreNetwork.isOnline()) { throw error; } } diff --git a/src/addons/calendar/pages/event/event.page.ts b/src/addons/calendar/pages/event/event.page.ts index e032a0247..95c35dccd 100644 --- a/src/addons/calendar/pages/event/event.page.ts +++ b/src/addons/calendar/pages/event/event.page.ts @@ -23,7 +23,7 @@ import { import { AddonCalendarEventReminder, AddonCalendarHelper } from '../../services/calendar-helper'; import { AddonCalendarOffline } from '../../services/calendar-offline'; import { AddonCalendarSync, AddonCalendarSyncEvents, AddonCalendarSyncProvider } from '../../services/calendar-sync'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreTextUtils } from '@services/utils/text'; @@ -126,7 +126,7 @@ export class AddonCalendarEventPage implements OnInit, OnDestroy { this.onlineObserver = Network.onChange().subscribe(() => { // Execute the callback in the Angular zone, so change detection doesn't stop working. NgZone.run(() => { - this.isOnline = CoreApp.isOnline(); + this.isOnline = CoreNetwork.isOnline(); }); }); @@ -184,7 +184,7 @@ export class AddonCalendarEventPage implements OnInit, OnDestroy { * @return Promise resolved when done. */ async fetchEvent(sync = false, showErrors = false): Promise { - this.isOnline = CoreApp.isOnline(); + this.isOnline = CoreNetwork.isOnline(); if (sync) { const deleted = await this.syncEvents(showErrors); diff --git a/src/addons/calendar/pages/index/index.page.ts b/src/addons/calendar/pages/index/index.page.ts index 9b9fd080b..cac6d7fde 100644 --- a/src/addons/calendar/pages/index/index.page.ts +++ b/src/addons/calendar/pages/index/index.page.ts @@ -14,7 +14,7 @@ import { Component, OnInit, OnDestroy, ViewChild } from '@angular/core'; import { IonRefresher } from '@ionic/angular'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { CoreSites } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; @@ -156,7 +156,7 @@ export class AddonCalendarIndexPage implements OnInit, OnDestroy { this.onlineObserver = Network.onChange().subscribe(() => { // Execute the callback in the Angular zone, so change detection doesn't stop working. NgZone.run(() => { - this.isOnline = CoreApp.isOnline(); + this.isOnline = CoreNetwork.isOnline(); }); }); } @@ -193,7 +193,7 @@ export class AddonCalendarIndexPage implements OnInit, OnDestroy { async fetchData(sync?: boolean, showErrors?: boolean): Promise { this.syncIcon = CoreConstants.ICON_LOADING; - this.isOnline = CoreApp.isOnline(); + this.isOnline = CoreNetwork.isOnline(); if (sync) { // Try to synchronize offline events. diff --git a/src/addons/calendar/services/calendar-sync.ts b/src/addons/calendar/services/calendar-sync.ts index 12d26e5bb..97bb81eae 100644 --- a/src/addons/calendar/services/calendar-sync.ts +++ b/src/addons/calendar/services/calendar-sync.ts @@ -14,7 +14,7 @@ import { Injectable } from '@angular/core'; import { CoreSyncBaseProvider, CoreSyncBlockedError } from '@classes/base-sync'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreEvents } from '@singletons/events'; import { CoreSites } from '@services/sites'; import { CoreUtils } from '@services/utils/utils'; @@ -134,7 +134,7 @@ export class AddonCalendarSyncProvider extends CoreSyncBaseProvider 0) { - if (!CoreApp.isOnline()) { + if (!CoreNetwork.isOnline()) { // Cannot sync in offline. throw new CoreNetworkError(); } diff --git a/src/addons/calendar/services/calendar.ts b/src/addons/calendar/services/calendar.ts index 6877b54c3..fe6166ed9 100644 --- a/src/addons/calendar/services/calendar.ts +++ b/src/addons/calendar/services/calendar.ts @@ -15,7 +15,7 @@ import { Injectable } from '@angular/core'; import { CoreSites } from '@services/sites'; import { CoreSite, CoreSiteWSPreSets } from '@classes/site'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreTextUtils } from '@services/utils/text'; import { CoreTimeUtils } from '@services/utils/time'; import { CoreUrlUtils } from '@services/utils/url'; @@ -241,7 +241,7 @@ export class AddonCalendarProvider { const storeOffline = (): Promise => AddonCalendarOffline.markDeleted(eventId, name, deleteAll, siteId).then(() => false); - if (forceOffline || !CoreApp.isOnline()) { + if (forceOffline || !CoreNetwork.isOnline()) { // App is offline, store the action. return storeOffline(); } @@ -1074,7 +1074,7 @@ export class AddonCalendarProvider { }); // Store starting week day preference, we need it in offline to show months that are not in cache. - if (CoreApp.isOnline()) { + if (CoreNetwork.isOnline()) { CoreConfig.set(AddonCalendarProvider.STARTING_WEEK_DAY, response.daynames[0].dayno); } @@ -1707,7 +1707,7 @@ export class AddonCalendarProvider { return { sent: false, event }; }; - if (options.forceOffline || !CoreApp.isOnline()) { + if (options.forceOffline || !CoreNetwork.isOnline()) { // App is offline, store the event. return storeOffline(); } diff --git a/src/addons/messages/services/messages-offline.ts b/src/addons/messages/services/messages-offline.ts index 949e4f87e..1e0942776 100644 --- a/src/addons/messages/services/messages-offline.ts +++ b/src/addons/messages/services/messages-offline.ts @@ -14,7 +14,7 @@ import { Injectable } from '@angular/core'; import { CoreSites } from '@services/sites'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreTextUtils } from '@services/utils/text'; import { AddonMessagesOfflineConversationMessagesDBRecord, @@ -283,7 +283,7 @@ export class AddonMessagesOfflineProvider { conversationid: conversation.id, text: message, timecreated: Date.now(), - deviceoffline: CoreApp.isOnline() ? 0 : 1, + deviceoffline: CoreNetwork.isOnline() ? 0 : 1, conversation: JSON.stringify({ name: conversation.name || '', subname: conversation.subname || '', @@ -314,7 +314,7 @@ export class AddonMessagesOfflineProvider { useridfrom: site.getUserId(), smallmessage: message, timecreated: new Date().getTime(), - deviceoffline: CoreApp.isOnline() ? 0 : 1, + deviceoffline: CoreNetwork.isOnline() ? 0 : 1, }; await site.getDb().insertRecord(MESSAGES_TABLE, entry); diff --git a/src/addons/messages/services/messages-sync.ts b/src/addons/messages/services/messages-sync.ts index 64edaf6df..85fdfe689 100644 --- a/src/addons/messages/services/messages-sync.ts +++ b/src/addons/messages/services/messages-sync.ts @@ -26,7 +26,7 @@ import { CoreEvents } from '@singletons/events'; import { CoreUtils } from '@services/utils/utils'; import { makeSingleton, Translate } from '@singletons'; import { CoreSites } from '@services/sites'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreConstants } from '@/core/constants'; import { CoreUser } from '@features/user/services/user'; import { CoreError } from '@classes/errors/error'; @@ -193,7 +193,7 @@ export class AddonMessagesSyncProvider extends CoreSyncBaseProvider { // Execute the callback in the Angular zone, so change detection doesn't stop working. NgZone.run(() => { - this.isOnline = CoreApp.isOnline(); + this.isOnline = CoreNetwork.isOnline(); }); }); } diff --git a/src/addons/mod/chat/pages/chat/chat.ts b/src/addons/mod/chat/pages/chat/chat.ts index 595287512..47bde10f6 100644 --- a/src/addons/mod/chat/pages/chat/chat.ts +++ b/src/addons/mod/chat/pages/chat/chat.ts @@ -18,6 +18,7 @@ import { CoreSendMessageFormComponent } from '@components/send-message-form/send import { CanLeave } from '@guards/can-leave'; import { IonContent } from '@ionic/angular'; import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreNavigator } from '@services/navigator'; import { CoreSites } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; @@ -65,11 +66,11 @@ export class AddonModChatChatPage implements OnInit, OnDestroy, CanLeave { constructor() { this.currentUserId = CoreSites.getCurrentSiteUserId(); - this.isOnline = CoreApp.isOnline(); + this.isOnline = CoreNetwork.isOnline(); this.onlineSubscription = Network.onChange().subscribe(() => { // Execute the callback in the Angular zone, so change detection doesn't stop working. NgZone.run(() => { - this.isOnline = CoreApp.isOnline(); + this.isOnline = CoreNetwork.isOnline(); }); }); } diff --git a/src/addons/mod/choice/services/choice-sync.ts b/src/addons/mod/choice/services/choice-sync.ts index 44f78056a..fc34da090 100644 --- a/src/addons/mod/choice/services/choice-sync.ts +++ b/src/addons/mod/choice/services/choice-sync.ts @@ -17,7 +17,7 @@ import { CoreNetworkError } from '@classes/errors/network-error'; import { CoreCourseActivitySyncBaseProvider } from '@features/course/classes/activity-sync'; import { CoreCourse } from '@features/course/services/course'; import { CoreCourseLogHelper } from '@features/course/services/log-helper'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreSites } from '@services/sites'; import { CoreUtils } from '@services/utils/utils'; import { makeSingleton } from '@singletons'; @@ -160,7 +160,7 @@ export class AddonModChoiceSyncProvider extends CoreCourseActivitySyncBaseProvid return result; } - if (!CoreApp.isOnline()) { + if (!CoreNetwork.isOnline()) { // Cannot sync in offline. throw new CoreNetworkError(); } diff --git a/src/addons/mod/choice/services/choice.ts b/src/addons/mod/choice/services/choice.ts index 8074f2459..284d88109 100644 --- a/src/addons/mod/choice/services/choice.ts +++ b/src/addons/mod/choice/services/choice.ts @@ -18,7 +18,7 @@ import { CoreWSError } from '@classes/errors/wserror'; import { CoreSite, CoreSiteWSPreSets } from '@classes/site'; import { CoreCourseCommonModWSOptions } from '@features/course/services/course'; import { CoreCourseLogHelper } from '@features/course/services/log-helper'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreFilepool } from '@services/filepool'; import { CoreSites, CoreSitesCommonWSOptions } from '@services/sites'; import { CoreUtils } from '@services/utils/utils'; @@ -90,7 +90,7 @@ export class AddonModChoiceProvider { return false; }; - if (!CoreApp.isOnline()) { + if (!CoreNetwork.isOnline()) { // App is offline, store the action. return storeOffline(); } @@ -407,7 +407,7 @@ export class AddonModChoiceProvider { return false; }; - if (!CoreApp.isOnline()) { + if (!CoreNetwork.isOnline()) { // App is offline, store the action. return storeOffline(); } diff --git a/src/addons/mod/data/services/data-sync.ts b/src/addons/mod/data/services/data-sync.ts index 1549bf5f9..b4548616d 100644 --- a/src/addons/mod/data/services/data-sync.ts +++ b/src/addons/mod/data/services/data-sync.ts @@ -21,7 +21,7 @@ import { CoreCourseCommonModWSOptions } from '@features/course/services/course'; import { CoreCourseLogHelper } from '@features/course/services/log-helper'; import { CoreFileUploaderStoreFilesResult } from '@features/fileuploader/services/fileuploader'; import { CoreRatingSync } from '@features/rating/services/rating-sync'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreFileEntry } from '@services/file-helper'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreSync } from '@services/sync'; @@ -184,7 +184,7 @@ export class AddonModDataSyncProvider extends CoreCourseActivitySyncBaseProvider return result; } - if (!CoreApp.isOnline()) { + if (!CoreNetwork.isOnline()) { // Cannot sync in offline. throw new CoreNetworkError(); } diff --git a/src/addons/mod/data/services/data.ts b/src/addons/mod/data/services/data.ts index 297f4204e..dde8919c8 100644 --- a/src/addons/mod/data/services/data.ts +++ b/src/addons/mod/data/services/data.ts @@ -19,7 +19,7 @@ import { CoreCourseCommonModWSOptions } from '@features/course/services/course'; import { CoreCourseLogHelper } from '@features/course/services/log-helper'; import { CoreRatingInfo } from '@features/rating/services/rating'; import { CoreTagItem } from '@features/tag/services/tag'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreFileEntry } from '@services/file-helper'; import { CoreFilepool } from '@services/filepool'; import { CoreSites, CoreSitesCommonWSOptions, CoreSitesReadingStrategy } from '@services/sites'; @@ -136,7 +136,7 @@ export class AddonModDataProvider { }; // Checks to store offline. - if (!CoreApp.isOnline() || forceOffline) { + if (!CoreNetwork.isOnline() || forceOffline) { const notifications = this.checkFields(fields, contents); if (notifications.length > 0) { return { fieldnotifications: notifications }; @@ -147,7 +147,7 @@ export class AddonModDataProvider { await this.deleteEntryOfflineAction(dataId, entryId, AddonModDataAction.ADD, siteId); // App is offline, store the action. - if (!CoreApp.isOnline() || forceOffline) { + if (!CoreNetwork.isOnline() || forceOffline) { return storeOffline(); } @@ -234,7 +234,7 @@ export class AddonModDataProvider { return; } - if (!CoreApp.isOnline()) { + if (!CoreNetwork.isOnline()) { // App is offline, store the action. return storeOffline(); } @@ -333,7 +333,7 @@ export class AddonModDataProvider { return; } - if (!CoreApp.isOnline()) { + if (!CoreNetwork.isOnline()) { // App is offline, store the action. return storeOffline(); } @@ -436,7 +436,7 @@ export class AddonModDataProvider { }; }; - if (!CoreApp.isOnline() || forceOffline) { + if (!CoreNetwork.isOnline() || forceOffline) { const notifications = this.checkFields(fields, contents); if (notifications.length > 0) { return { fieldnotifications: notifications }; @@ -446,7 +446,7 @@ export class AddonModDataProvider { // Remove unnecessary not synced actions. await this.deleteEntryOfflineAction(dataId, entryId, AddonModDataAction.EDIT, siteId); - if (!CoreApp.isOnline() || forceOffline) { + if (!CoreNetwork.isOnline() || forceOffline) { // App is offline, store the action. return storeOffline(); } diff --git a/src/addons/mod/feedback/pages/form/form.ts b/src/addons/mod/feedback/pages/form/form.ts index 8134221a6..7ef9df00a 100644 --- a/src/addons/mod/feedback/pages/form/form.ts +++ b/src/addons/mod/feedback/pages/form/form.ts @@ -19,7 +19,7 @@ import { CoreCourse, CoreCourseCommonModWSOptions } from '@features/course/servi import { CoreCourseModuleData } from '@features/course/services/course-helper'; import { CanLeave } from '@guards/can-leave'; import { IonContent } from '@ionic/angular'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreNavigator } from '@services/navigator'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; @@ -83,7 +83,7 @@ export class AddonModFeedbackFormPage implements OnInit, OnDestroy, CanLeave { this.onlineObserver = Network.onChange().subscribe(() => { // Execute the callback in the Angular zone, so change detection doesn't stop working. NgZone.run(() => { - this.offline = !CoreApp.isOnline(); + this.offline = !CoreNetwork.isOnline(); }); }); } @@ -160,7 +160,7 @@ export class AddonModFeedbackFormPage implements OnInit, OnDestroy, CanLeave { try { this.module = await CoreCourse.getModule(this.cmId, this.courseId, undefined, true, false, this.currentSite.getId()); - this.offline = !CoreApp.isOnline(); + this.offline = !CoreNetwork.isOnline(); const options = { cmId: this.cmId, readingStrategy: this.offline ? CoreSitesReadingStrategy.PREFER_CACHE : CoreSitesReadingStrategy.ONLY_NETWORK, diff --git a/src/addons/mod/feedback/services/feedback-sync.ts b/src/addons/mod/feedback/services/feedback-sync.ts index c7042e15f..bdfe3d355 100644 --- a/src/addons/mod/feedback/services/feedback-sync.ts +++ b/src/addons/mod/feedback/services/feedback-sync.ts @@ -18,7 +18,7 @@ import { CoreNetworkError } from '@classes/errors/network-error'; import { CoreCourseActivitySyncBaseProvider } from '@features/course/classes/activity-sync'; import { CoreCourse, CoreCourseAnyModuleData } from '@features/course/services/course'; import { CoreCourseLogHelper } from '@features/course/services/log-helper'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreSync } from '@services/sync'; import { CoreUtils } from '@services/utils/utils'; @@ -174,7 +174,7 @@ export class AddonModFeedbackSyncProvider extends CoreCourseActivitySyncBaseProv return result; } - if (!CoreApp.isOnline()) { + if (!CoreNetwork.isOnline()) { // Cannot sync in offline. throw new CoreNetworkError(); } diff --git a/src/addons/mod/feedback/services/feedback.ts b/src/addons/mod/feedback/services/feedback.ts index 814640e9f..aac5fc65f 100644 --- a/src/addons/mod/feedback/services/feedback.ts +++ b/src/addons/mod/feedback/services/feedback.ts @@ -17,7 +17,7 @@ import { CoreError } from '@classes/errors/error'; import { CoreSite, CoreSiteWSPreSets } from '@classes/site'; import { CoreCourseCommonModWSOptions } from '@features/course/services/course'; import { CoreCourseLogHelper } from '@features/course/services/log-helper'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreFilepool } from '@services/filepool'; import { CoreSites, CoreSitesCommonWSOptions, CoreSitesReadingStrategy } from '@services/sites'; import { CoreUtils } from '@services/utils/utils'; @@ -1187,7 +1187,7 @@ export class AddonModFeedbackProvider { return response; }; - if (!CoreApp.isOnline()) { + if (!CoreNetwork.isOnline()) { // App is offline, store the action. return storeOffline(); } diff --git a/src/addons/mod/forum/components/post-options-menu/post-options-menu.ts b/src/addons/mod/forum/components/post-options-menu/post-options-menu.ts index 02015d077..f5e147ae8 100644 --- a/src/addons/mod/forum/components/post-options-menu/post-options-menu.ts +++ b/src/addons/mod/forum/components/post-options-menu/post-options-menu.ts @@ -14,7 +14,7 @@ import { Component, Input, OnInit } from '@angular/core'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { AddonModForum, AddonModForumPost } from '@addons/mod/forum/services/forum'; import { PopoverController } from '@singletons'; import { CoreDomUtils } from '@services/utils/dom'; @@ -101,7 +101,7 @@ export class AddonModForumPostOptionsMenuComponent implements OnInit { */ deletePost(): void { if (!this.offlinePost) { - if (!CoreApp.isOnline()) { + if (!CoreNetwork.isOnline()) { CoreDomUtils.showErrorModal(new CoreNetworkError()); return; @@ -117,7 +117,7 @@ export class AddonModForumPostOptionsMenuComponent implements OnInit { * Edit a post. */ editPost(): void { - if (!this.offlinePost && !CoreApp.isOnline()) { + if (!this.offlinePost && !CoreNetwork.isOnline()) { CoreDomUtils.showErrorModal(new CoreNetworkError()); return; diff --git a/src/addons/mod/forum/pages/discussion/discussion.page.ts b/src/addons/mod/forum/pages/discussion/discussion.page.ts index 2b422913e..39af8c389 100644 --- a/src/addons/mod/forum/pages/discussion/discussion.page.ts +++ b/src/addons/mod/forum/pages/discussion/discussion.page.ts @@ -24,7 +24,7 @@ import { CoreRatingSyncProvider } from '@features/rating/services/rating-sync'; import { CoreUser } from '@features/user/services/user'; import { CanLeave } from '@guards/can-leave'; import { IonContent, IonRefresher } from '@ionic/angular'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreNavigator } from '@services/navigator'; import { CoreScreen } from '@services/screen'; import { CoreSites } from '@services/sites'; @@ -164,12 +164,12 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes return; } - this.isOnline = CoreApp.isOnline(); + this.isOnline = CoreNetwork.isOnline(); this.externalUrl = CoreSites.getCurrentSite()?.createSiteUrl('/mod/forum/discuss.php', { d: this.discussionId.toString() }); this.onlineObserver = Network.onChange().subscribe(() => { // Execute the callback in the Angular zone, so change detection doesn't stop working. NgZone.run(() => { - this.isOnline = CoreApp.isOnline(); + this.isOnline = CoreNetwork.isOnline(); }); }); diff --git a/src/addons/mod/forum/services/forum-helper.ts b/src/addons/mod/forum/services/forum-helper.ts index a9c26c9f5..020a9498d 100644 --- a/src/addons/mod/forum/services/forum-helper.ts +++ b/src/addons/mod/forum/services/forum-helper.ts @@ -16,7 +16,7 @@ import { Injectable } from '@angular/core'; import { FileEntry } from '@ionic-native/file/ngx'; import { CoreFileUploader, CoreFileUploaderStoreFilesResult } from '@features/fileuploader/services/fileuploader'; import { CoreUser } from '@features/user/services/user'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreFile } from '@services/file'; import { CoreSites } from '@services/sites'; import { CoreTimeUtils } from '@services/utils/time'; @@ -124,7 +124,7 @@ export class AddonModForumHelperProvider { await AddonModForumOffline.deleteNewDiscussion(forumId, timeCreated, siteId); } - if (saveOffline || !CoreApp.isOnline()) { + if (saveOffline || !CoreNetwork.isOnline()) { await storeOffline(); return null; diff --git a/src/addons/mod/forum/services/forum-sync.ts b/src/addons/mod/forum/services/forum-sync.ts index f522dc34f..f08542f5b 100644 --- a/src/addons/mod/forum/services/forum-sync.ts +++ b/src/addons/mod/forum/services/forum-sync.ts @@ -18,7 +18,7 @@ import { CoreCourseActivitySyncBaseProvider } from '@features/course/classes/act import { CoreCourseLogHelper } from '@features/course/services/log-helper'; import { CoreFileUploader } from '@features/fileuploader/services/fileuploader'; import { CoreRatingSync } from '@features/rating/services/rating-sync'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreGroups } from '@services/groups'; import { CoreSites } from '@services/sites'; import { CoreSync } from '@services/sync'; @@ -230,7 +230,7 @@ export class AddonModForumSyncProvider extends CoreCourseActivitySyncBaseProvide [] as AddonModForumOfflineDiscussion[], ); - if (discussions.length !== 0 && !CoreApp.isOnline()) { + if (discussions.length !== 0 && !CoreNetwork.isOnline()) { throw new Error('cannot sync in offline'); } @@ -369,7 +369,7 @@ export class AddonModForumSyncProvider extends CoreCourseActivitySyncBaseProvide if (!replies.length) { // Nothing to sync. return { warnings: [], updated: false }; - } else if (!CoreApp.isOnline()) { + } else if (!CoreNetwork.isOnline()) { // Cannot sync in offline. return Promise.reject(null); } @@ -458,7 +458,7 @@ export class AddonModForumSyncProvider extends CoreCourseActivitySyncBaseProvide [] as AddonModForumOfflineReply[], ); - if (replies.length !== 0 && !CoreApp.isOnline()) { + if (replies.length !== 0 && !CoreNetwork.isOnline()) { throw new Error('Cannot sync in offline'); } diff --git a/src/addons/mod/forum/services/forum.ts b/src/addons/mod/forum/services/forum.ts index fb1b53bbd..dc8d60079 100644 --- a/src/addons/mod/forum/services/forum.ts +++ b/src/addons/mod/forum/services/forum.ts @@ -20,7 +20,7 @@ import { CoreCourseLogHelper } from '@features/course/services/log-helper'; import { CoreRatingInfo } from '@features/rating/services/rating'; import { CoreTagItem } from '@features/tag/services/tag'; import { CoreUser } from '@features/user/services/user'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreFileEntry } from '@services/file-helper'; import { CoreGroups } from '@services/groups'; import { CoreSitesCommonWSOptions, CoreSites, CoreSitesReadingStrategy } from '@services/sites'; @@ -756,7 +756,7 @@ export class AddonModForumProvider { } catch (error) { // Try to get the data from cache stored with the old WS method. if ( - CoreApp.isOnline() || + CoreNetwork.isOnline() || method !== 'mod_forum_get_forum_discussions' || options.sortOrder !== AddonModForumProvider.SORTORDER_LASTPOST_DESC ) { @@ -1065,7 +1065,7 @@ export class AddonModForumProvider { return false; }; - if (!CoreApp.isOnline() && allowOffline) { + if (!CoreNetwork.isOnline() && allowOffline) { // App is offline, store the action. return storeOffline(); } diff --git a/src/addons/mod/glossary/services/glossary-sync.ts b/src/addons/mod/glossary/services/glossary-sync.ts index 8d0844cb4..941adca6d 100644 --- a/src/addons/mod/glossary/services/glossary-sync.ts +++ b/src/addons/mod/glossary/services/glossary-sync.ts @@ -19,7 +19,7 @@ import { CoreNetworkError } from '@classes/errors/network-error'; import { CoreCourseActivitySyncBaseProvider } from '@features/course/classes/activity-sync'; import { CoreCourseLogHelper } from '@features/course/services/log-helper'; import { CoreRatingSync } from '@features/rating/services/rating-sync'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreSites } from '@services/sites'; import { CoreSync } from '@services/sync'; import { CoreUtils } from '@services/utils/utils'; @@ -189,7 +189,7 @@ export class AddonModGlossarySyncProvider extends CoreCourseActivitySyncBaseProv await CoreUtils.ignoreErrors(this.setSyncTime(syncId, siteId)); return result; - } else if (!CoreApp.isOnline()) { + } else if (!CoreNetwork.isOnline()) { // Cannot sync in offline. throw new CoreNetworkError(); } diff --git a/src/addons/mod/glossary/services/glossary.ts b/src/addons/mod/glossary/services/glossary.ts index eeb8ec937..f85c300de 100644 --- a/src/addons/mod/glossary/services/glossary.ts +++ b/src/addons/mod/glossary/services/glossary.ts @@ -20,7 +20,7 @@ import { CoreCourseLogHelper } from '@features/course/services/log-helper'; import { CoreFileUploaderStoreFilesResult } from '@features/fileuploader/services/fileuploader'; import { CoreRatingInfo } from '@features/rating/services/rating'; import { CoreTagItem } from '@features/tag/services/tag'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreSites, CoreSitesCommonWSOptions, CoreSitesReadingStrategy } from '@services/sites'; import { CoreUtils } from '@services/utils/utils'; import { CoreWSExternalFile, CoreWSExternalWarning } from '@services/ws'; @@ -898,7 +898,7 @@ export class AddonModGlossaryProvider { return false; }; - if (!CoreApp.isOnline() && otherOptions.allowOffline) { + if (!CoreNetwork.isOnline() && otherOptions.allowOffline) { // App is offline, store the action. return storeOffline(); } diff --git a/src/addons/mod/h5pactivity/components/index/index.ts b/src/addons/mod/h5pactivity/components/index/index.ts index 217675e4d..901f1b104 100644 --- a/src/addons/mod/h5pactivity/components/index/index.ts +++ b/src/addons/mod/h5pactivity/components/index/index.ts @@ -24,7 +24,7 @@ import { CoreH5PHelper } from '@features/h5p/classes/helper'; import { CoreH5P } from '@features/h5p/services/h5p'; import { CoreXAPIOffline } from '@features/xapi/services/offline'; import { CoreXAPI } from '@features/xapi/services/xapi'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreFilepool } from '@services/filepool'; import { CoreNavigator } from '@services/navigator'; import { CoreSites } from '@services/sites'; @@ -149,7 +149,7 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv // Cannot download the file or already downloaded, play the package directly. this.play(); - } else if ((this.state == CoreConstants.NOT_DOWNLOADED || this.state == CoreConstants.OUTDATED) && CoreApp.isOnline() && + } else if ((this.state == CoreConstants.NOT_DOWNLOADED || this.state == CoreConstants.OUTDATED) && CoreNetwork.isOnline() && this.deployedFile?.filesize && CoreFilepool.shouldDownload(this.deployedFile.filesize)) { // Package is small, download it automatically. Don't block this function for this. this.downloadAutomatically(); @@ -280,7 +280,7 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv return; } - if (!CoreApp.isOnline()) { + if (!CoreNetwork.isOnline()) { CoreDomUtils.showErrorModal('core.networkerrormsg', true); return; diff --git a/src/addons/mod/h5pactivity/services/h5pactivity-sync.ts b/src/addons/mod/h5pactivity/services/h5pactivity-sync.ts index 95b5748ca..48d2f172c 100644 --- a/src/addons/mod/h5pactivity/services/h5pactivity-sync.ts +++ b/src/addons/mod/h5pactivity/services/h5pactivity-sync.ts @@ -19,7 +19,7 @@ import { CoreCourseActivitySyncBaseProvider } from '@features/course/classes/act import { CoreCourseLogHelper } from '@features/course/services/log-helper'; import { CoreXAPIOffline } from '@features/xapi/services/offline'; import { CoreXAPI } from '@features/xapi/services/xapi'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreSites } from '@services/sites'; import { CoreUtils } from '@services/utils/utils'; import { makeSingleton } from '@singletons'; @@ -103,7 +103,7 @@ export class AddonModH5PActivitySyncProvider extends CoreCourseActivitySyncBaseP syncActivity(contextId: number, siteId?: string): Promise { siteId = siteId || CoreSites.getCurrentSiteId(); - if (!CoreApp.isOnline()) { + if (!CoreNetwork.isOnline()) { // Cannot sync in offline. throw new CoreNetworkError(); } diff --git a/src/addons/mod/imscp/pages/view/view.ts b/src/addons/mod/imscp/pages/view/view.ts index 18da77400..e491daf2e 100644 --- a/src/addons/mod/imscp/pages/view/view.ts +++ b/src/addons/mod/imscp/pages/view/view.ts @@ -21,7 +21,7 @@ import { CoreCourse } from '@features/course/services/course'; import { CoreCourseModuleData } from '@features/course/services/course-helper'; import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate'; import { IonRefresher } from '@ionic/angular'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreNavigator } from '@services/navigator'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreTextUtils } from '@services/utils/text'; @@ -189,7 +189,7 @@ export class AddonModImscpViewPage implements OnInit { if (!module.contents?.length || (refresh && !contentsAlreadyLoaded)) { // Try to load the contents. - const ignoreCache = refresh && CoreApp.isOnline(); + const ignoreCache = refresh && CoreNetwork.isOnline(); try { await CoreCourse.loadModuleContents(module, undefined, undefined, false, ignoreCache); diff --git a/src/addons/mod/imscp/services/imscp.ts b/src/addons/mod/imscp/services/imscp.ts index 824dbb33f..7175ae599 100644 --- a/src/addons/mod/imscp/services/imscp.ts +++ b/src/addons/mod/imscp/services/imscp.ts @@ -18,7 +18,7 @@ import { CoreSite, CoreSiteWSPreSets } from '@classes/site'; import { CoreCourse, CoreCourseModuleContentFile } from '@features/course/services/course'; import { CoreCourseModuleData } from '@features/course/services/course-helper'; import { CoreCourseLogHelper } from '@features/course/services/log-helper'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreFilepool } from '@services/filepool'; import { CoreSitesCommonWSOptions, CoreSites } from '@services/sites'; import { CoreTextUtils } from '@services/utils/text'; @@ -181,7 +181,7 @@ export class AddonModImscpProvider { return CoreText.concatenatePaths(dirPath, itemHref); } catch (error) { // Error getting directory, there was an error downloading or we're in browser. Return online URL if connected. - if (CoreApp.isOnline()) { + if (CoreNetwork.isOnline()) { const contents = await CoreCourse.getModuleContents(module); const indexUrl = this.getFileUrlFromContents(contents, itemHref); diff --git a/src/addons/mod/lesson/pages/player/player.page.ts b/src/addons/mod/lesson/pages/player/player.page.ts index e0c4f251d..1eab60f21 100644 --- a/src/addons/mod/lesson/pages/player/player.page.ts +++ b/src/addons/mod/lesson/pages/player/player.page.ts @@ -18,7 +18,7 @@ import { IonContent } from '@ionic/angular'; import { CoreError } from '@classes/errors/error'; import { CanLeave } from '@guards/can-leave'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreNavigator } from '@services/navigator'; import { CoreSites, CoreSitesCommonWSOptions, CoreSitesReadingStrategy } from '@services/sites'; import { CoreSync } from '@services/sync'; @@ -280,7 +280,7 @@ export class AddonModLessonPlayerPage implements OnInit, OnDestroy, CanLeave { // If lesson has offline data already, use offline mode. this.offline = await AddonModLessonOffline.hasOfflineData(this.lesson.id); - if (!this.offline && !CoreApp.isOnline() && AddonModLesson.isLessonOffline(this.lesson) && !this.review) { + if (!this.offline && !CoreNetwork.isOnline() && AddonModLesson.isLessonOffline(this.lesson) && !this.review) { // Lesson doesn't have offline data, but it allows offline and the device is offline. Use offline mode. this.offline = true; } @@ -375,7 +375,7 @@ export class AddonModLessonPlayerPage implements OnInit, OnDestroy, CanLeave { protected async finishRetake(outOfTime?: boolean): Promise { this.messages = []; - if (this.offline && CoreApp.isOnline()) { + if (this.offline && CoreNetwork.isOnline()) { // Offline mode but the app is online. Try to sync the data. const result = await CoreUtils.ignoreErrors( AddonModLessonSync.syncLesson(this.lesson!.id, true, true), diff --git a/src/addons/mod/lesson/services/lesson-sync.ts b/src/addons/mod/lesson/services/lesson-sync.ts index 9ad52a558..ef2c6923e 100644 --- a/src/addons/mod/lesson/services/lesson-sync.ts +++ b/src/addons/mod/lesson/services/lesson-sync.ts @@ -19,7 +19,7 @@ import { CoreNetworkError } from '@classes/errors/network-error'; import { CoreCourseActivitySyncBaseProvider } from '@features/course/classes/activity-sync'; import { CoreCourse } from '@features/course/services/course'; import { CoreCourseLogHelper } from '@features/course/services/log-helper'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreSync } from '@services/sync'; import { CoreTimeUtils } from '@services/utils/time'; @@ -275,7 +275,7 @@ export class AddonModLessonSyncProvider extends CoreCourseActivitySyncBaseProvid if (!attempts.length) { return; - } else if (!CoreApp.isOnline()) { + } else if (!CoreNetwork.isOnline()) { // Cannot sync in offline. throw new CoreNetworkError(); } @@ -420,7 +420,7 @@ export class AddonModLessonSyncProvider extends CoreCourseActivitySyncBaseProvid await AddonModLessonOffline.deleteRetake(lessonId, siteId); return; - } else if (!CoreApp.isOnline()) { + } else if (!CoreNetwork.isOnline()) { // Cannot sync in offline. throw new CoreNetworkError(); } diff --git a/src/addons/mod/quiz/services/quiz-sync.ts b/src/addons/mod/quiz/services/quiz-sync.ts index 4f4aed5d0..84abd5e4b 100644 --- a/src/addons/mod/quiz/services/quiz-sync.ts +++ b/src/addons/mod/quiz/services/quiz-sync.ts @@ -21,7 +21,7 @@ import { CoreCourseLogHelper } from '@features/course/services/log-helper'; import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate'; import { CoreQuestion, CoreQuestionQuestionParsed } from '@features/question/services/question'; import { CoreQuestionDelegate } from '@features/question/services/question-delegate'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreSync } from '@services/sync'; import { CoreUtils } from '@services/utils/utils'; @@ -311,7 +311,7 @@ export class AddonModQuizSyncProvider extends CoreCourseActivitySyncBaseProvider return this.finishSync(siteId, quiz, courseId, warnings); } - if (!CoreApp.isOnline()) { + if (!CoreNetwork.isOnline()) { // Cannot sync in offline. throw new CoreError(Translate.instant('core.cannotconnect')); } diff --git a/src/addons/mod/resource/components/index/index.ts b/src/addons/mod/resource/components/index/index.ts index a582ed675..e8ca58c9c 100644 --- a/src/addons/mod/resource/components/index/index.ts +++ b/src/addons/mod/resource/components/index/index.ts @@ -20,6 +20,7 @@ import { CoreCourseContentsPage } from '@features/course/pages/contents/contents import { CoreCourse } from '@features/course/services/course'; import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate'; import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreFileHelper } from '@services/file-helper'; import { CoreSites } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; @@ -79,13 +80,13 @@ export class AddonModResourceIndexComponent extends CoreCourseModuleMainResource super.ngOnInit(); this.isIOS = CoreApp.isIOS(); - this.isOnline = CoreApp.isOnline(); + this.isOnline = CoreNetwork.isOnline(); // Refresh online status when changes. this.onlineObserver = Network.onChange().subscribe(() => { // Execute the callback in the Angular zone, so change detection doesn't stop working. NgZone.run(() => { - this.isOnline = CoreApp.isOnline(); + this.isOnline = CoreNetwork.isOnline(); }); }); diff --git a/src/addons/mod/resource/services/resource-helper.ts b/src/addons/mod/resource/services/resource-helper.ts index 41e4eec84..d0f5c7557 100644 --- a/src/addons/mod/resource/services/resource-helper.ts +++ b/src/addons/mod/resource/services/resource-helper.ts @@ -17,7 +17,7 @@ import { Injectable } from '@angular/core'; import { CoreError } from '@classes/errors/error'; import { CoreCourse, CoreCourseAnyModuleData } from '@features/course/services/course'; import { CoreCourseHelper, CoreCourseModuleData } from '@features/course/services/course-helper'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreFile } from '@services/file'; import { CoreFileHelper } from '@services/file-helper'; import { CoreFilepool } from '@services/filepool'; @@ -80,7 +80,7 @@ export class AddonModResourceHelperProvider { return CoreText.concatenatePaths(dirPath, mainFilePath); } catch (e) { // Error getting directory, there was an error downloading or we're in browser. Return online URL. - if (CoreApp.isOnline() && mainFile.fileurl) { + if (CoreNetwork.isOnline() && mainFile.fileurl) { // This URL is going to be injected in an iframe, we need this to make it work. return CoreSites.getRequiredCurrentSite().checkAndFixPluginfileURL(mainFile.fileurl); } diff --git a/src/addons/mod/survey/services/survey-sync.ts b/src/addons/mod/survey/services/survey-sync.ts index 4ed43f0dd..f3389b3db 100644 --- a/src/addons/mod/survey/services/survey-sync.ts +++ b/src/addons/mod/survey/services/survey-sync.ts @@ -17,7 +17,7 @@ import { CoreNetworkError } from '@classes/errors/network-error'; import { CoreCourseActivitySyncBaseProvider } from '@features/course/classes/activity-sync'; import { CoreCourse } from '@features/course/services/course'; import { CoreCourseLogHelper } from '@features/course/services/log-helper'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreSites } from '@services/sites'; import { CoreUtils } from '@services/utils/utils'; import { makeSingleton } from '@singletons'; @@ -168,7 +168,7 @@ export class AddonModSurveySyncProvider extends CoreCourseActivitySyncBaseProvid } if (answersNumber > 0 && data) { - if (!CoreApp.isOnline()) { + if (!CoreNetwork.isOnline()) { // Cannot sync in offline. throw new CoreNetworkError(); } diff --git a/src/addons/mod/survey/services/survey.ts b/src/addons/mod/survey/services/survey.ts index 0278684aa..4a77075d5 100644 --- a/src/addons/mod/survey/services/survey.ts +++ b/src/addons/mod/survey/services/survey.ts @@ -17,7 +17,7 @@ import { CoreError } from '@classes/errors/error'; import { CoreSite, CoreSiteWSPreSets } from '@classes/site'; import { CoreCourseCommonModWSOptions } from '@features/course/services/course'; import { CoreCourseLogHelper } from '@features/course/services/log-helper'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreFilepool } from '@services/filepool'; import { CoreSites, CoreSitesCommonWSOptions } from '@services/sites'; import { CoreUtils } from '@services/utils/utils'; @@ -257,7 +257,7 @@ export class AddonModSurveyProvider { siteId = siteId || CoreSites.getCurrentSiteId(); - if (!CoreApp.isOnline()) { + if (!CoreNetwork.isOnline()) { // App is offline, store the message. return storeOffline(); } diff --git a/src/addons/mod/wiki/components/index/index.ts b/src/addons/mod/wiki/components/index/index.ts index fac51cd87..0a88f7cdb 100644 --- a/src/addons/mod/wiki/components/index/index.ts +++ b/src/addons/mod/wiki/components/index/index.ts @@ -21,7 +21,7 @@ import { CoreCourse } from '@features/course/services/course'; import { CoreTag, CoreTagItem } from '@features/tag/services/tag'; import { CoreUser } from '@features/user/services/user'; import { IonContent } from '@ionic/angular'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreGroup, CoreGroups } from '@services/groups'; import { CoreNavigator } from '@services/navigator'; import { CoreSites } from '@services/sites'; @@ -116,13 +116,13 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp ) { super('AddonModLessonIndexComponent', content, courseContentsPage); - this.isOnline = CoreApp.isOnline(); + this.isOnline = CoreNetwork.isOnline(); // Refresh online status when changes. this.onlineSubscription = Network.onChange().subscribe(() => { // Execute the callback in the Angular zone, so change detection doesn't stop working. NgZone.run(() => { - this.isOnline = CoreApp.isOnline(); + this.isOnline = CoreNetwork.isOnline(); }); }); } diff --git a/src/addons/mod/wiki/services/wiki-sync.ts b/src/addons/mod/wiki/services/wiki-sync.ts index da3d9ae21..7cc5b4c8e 100644 --- a/src/addons/mod/wiki/services/wiki-sync.ts +++ b/src/addons/mod/wiki/services/wiki-sync.ts @@ -16,7 +16,7 @@ import { Injectable } from '@angular/core'; import { CoreSyncBaseProvider, CoreSyncBlockedError } from '@classes/base-sync'; import { CoreNetworkError } from '@classes/errors/network-error'; import { CoreCourseLogHelper } from '@features/course/services/log-helper'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreGroups } from '@services/groups'; import { CoreSites } from '@services/sites'; import { CoreSync } from '@services/sync'; @@ -224,7 +224,7 @@ export class AddonModWikiSyncProvider extends CoreSyncBaseProvider { - if (!CoreApp.isOnline()) { + if (!CoreNetwork.isOnline()) { CoreDomUtils.showErrorModal('core.fileuploader.errormustbeonlinetoupload', true); return; diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 63fade7ba..594733fe0 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -32,6 +32,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 { CoreNetwork } from '@services/network'; const MOODLE_VERSION_PREFIX = 'version-'; const MOODLEAPP_VERSION_PREFIX = 'moodleapp-'; @@ -310,7 +311,7 @@ export class AppComponent implements OnInit, AfterViewInit { Network.onChange().subscribe(() => { // Execute the callback in the Angular zone, so change detection doesn't stop working. NgZone.run(() => { - const isOnline = CoreApp.isOnline(); + const isOnline = CoreNetwork.isOnline(); const hadOfflineMessage = document.body.classList.contains('core-offline'); document.body.classList.toggle('core-offline', !isOnline); @@ -327,7 +328,7 @@ export class AppComponent implements OnInit, AfterViewInit { }); }); - const isOnline = CoreApp.isOnline(); + const isOnline = CoreNetwork.isOnline(); document.body.classList.toggle('core-offline', !isOnline); // Set StatusBar properties. diff --git a/src/core/classes/base-sync.ts b/src/core/classes/base-sync.ts index 417b03ff6..27de5e84e 100644 --- a/src/core/classes/base-sync.ts +++ b/src/core/classes/base-sync.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreSites } from '@services/sites'; import { CoreSync } from '@services/sync'; import { CoreTextUtils } from '@services/utils/text'; @@ -272,7 +272,7 @@ export class CoreSyncBaseProvider { * @return Resolved with siteIds selected. Rejected if offline. */ async syncOnSites(syncFunctionLog: string, syncFunction: (siteId: string) => void, siteId?: string): Promise { - if (!CoreApp.isOnline()) { + if (!CoreNetwork.isOnline()) { const message = `Cannot sync '${syncFunctionLog}' because device is offline.`; this.logger.debug(message); diff --git a/src/core/classes/site.ts b/src/core/classes/site.ts index 3aa0626b0..8afc08b21 100644 --- a/src/core/classes/site.ts +++ b/src/core/classes/site.ts @@ -16,6 +16,7 @@ import { InAppBrowserObject, InAppBrowserOptions } from '@ionic-native/in-app-br import { Md5 } from 'ts-md5/dist/md5'; import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreDB } from '@services/db'; import { CoreEvents } from '@singletons/events'; import { CoreFile } from '@services/file'; @@ -537,7 +538,7 @@ export class CoreSite { const initialToken = this.token || ''; data = data || {}; - if (!CoreApp.isOnline() && this.offlineDisabled) { + if (!CoreNetwork.isOnline() && this.offlineDisabled) { throw new CoreError(Translate.instant('core.errorofflinedisabled')); } @@ -995,7 +996,7 @@ export class CoreSite { const now = Date.now(); let expirationTime: number | undefined; - preSets.omitExpires = preSets.omitExpires || preSets.forceOffline || !CoreApp.isOnline(); + preSets.omitExpires = preSets.omitExpires || preSets.forceOffline || !CoreNetwork.isOnline(); if (!preSets.omitExpires) { expirationTime = entry.expirationTime + this.getExpirationDelay(preSets.updateFrequency); @@ -1987,7 +1988,7 @@ export class CoreSite { updateFrequency = updateFrequency || CoreSite.FREQUENCY_USUALLY; let expirationDelay = this.UPDATE_FREQUENCIES[updateFrequency] || this.UPDATE_FREQUENCIES[CoreSite.FREQUENCY_USUALLY]; - if (CoreApp.isNetworkAccessLimited()) { + if (CoreNetwork.isNetworkAccessLimited()) { // Not WiFi, increase the expiration delay a 50% to decrease the data usage in this case. expirationDelay *= 1.5; } @@ -2011,7 +2012,7 @@ export class CoreSite { } else if (this.tokenPluginFileWorksPromise) { // Check ongoing, use the same promise. return this.tokenPluginFileWorksPromise; - } else if (!CoreApp.isOnline()) { + } else if (!CoreNetwork.isOnline()) { // Not online, cannot check it. Assume it's working, but don't save the result. return Promise.resolve(true); } diff --git a/src/core/components/attachments/attachments.ts b/src/core/components/attachments/attachments.ts index d8e1c6fa0..df9a9dbfc 100644 --- a/src/core/components/attachments/attachments.ts +++ b/src/core/components/attachments/attachments.ts @@ -19,7 +19,7 @@ import { CoreFileUploader, CoreFileUploaderTypeList } from '@features/fileupload import { CoreSites } from '@services/sites'; import { CoreTextUtils } from '@services/utils/text'; import { Translate } from '@singletons'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreFileUploaderHelper } from '@features/fileuploader/services/fileuploader-helper'; import { CoreFileEntry } from '@services/file-helper'; @@ -132,7 +132,7 @@ export class CoreAttachmentsComponent implements OnInit { async add(): Promise { const allowOffline = !!this.allowOffline && this.allowOffline !== 'false'; - if (!allowOffline && !CoreApp.isOnline()) { + if (!allowOffline && !CoreNetwork.isOnline()) { CoreDomUtils.showErrorModal('core.fileuploader.errormustbeonlinetoupload', true); return; diff --git a/src/core/components/file/file.ts b/src/core/components/file/file.ts index a2b6b183d..cb3306990 100644 --- a/src/core/components/file/file.ts +++ b/src/core/components/file/file.ts @@ -14,6 +14,7 @@ import { Component, Input, Output, OnInit, OnDestroy, EventEmitter } from '@angular/core'; import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreFilepool } from '@services/filepool'; import { CoreFileHelper } from '@services/file-helper'; import { CorePluginFileDelegate } from '@services/plugin-file-delegate'; @@ -197,7 +198,7 @@ export class CoreFileComponent implements OnInit, OnDestroy { return; } - if (!CoreApp.isOnline() && (!openAfterDownload || (openAfterDownload && + if (!CoreNetwork.isOnline() && (!openAfterDownload || (openAfterDownload && !CoreFileHelper.isStateDownloaded(this.state)))) { CoreDomUtils.showErrorModal('core.networkerrormsg', true); diff --git a/src/core/components/user-avatar/user-avatar.ts b/src/core/components/user-avatar/user-avatar.ts index e192d15af..220a58bc3 100644 --- a/src/core/components/user-avatar/user-avatar.ts +++ b/src/core/components/user-avatar/user-avatar.ts @@ -14,12 +14,12 @@ import { Component, Input, OnInit, OnChanges, OnDestroy, SimpleChange } from '@angular/core'; -import { CoreApp } from '@services/app'; import { CoreSites } from '@services/sites'; import { CoreUtils } from '@services/utils/utils'; import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { CoreUserProvider, CoreUserBasicData } from '@features/user/services/user'; import { CoreNavigator } from '@services/navigator'; +import { CoreNetwork } from '@services/network'; /** * Component to display a "user avatar". @@ -119,7 +119,7 @@ export class CoreUserAvatarComponent implements OnInit, OnChanges, OnDestroy { return this.user.lastaccess * 1000 >= time; } else { // You have to have Internet access first. - return !!this.user.isonline && CoreApp.isOnline(); + return !!this.user.isonline && CoreNetwork.isOnline(); } } diff --git a/src/core/directives/external-content.ts b/src/core/directives/external-content.ts index 53272d158..4663b44d7 100644 --- a/src/core/directives/external-content.ts +++ b/src/core/directives/external-content.ts @@ -34,6 +34,7 @@ import { CoreError } from '@classes/errors/error'; import { CoreSite } from '@classes/site'; import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { CoreConstants } from '../constants'; +import { CoreNetwork } from '@services/network'; /** * Directive to handle external content. @@ -427,7 +428,7 @@ export class CoreExternalContentDirective implements AfterViewInit, OnChanges, O clickableEl.addEventListener(eventName, () => { // User played media or opened a downloadable link. // Download the file if in wifi and it hasn't been downloaded already (for big files). - if (state !== CoreConstants.DOWNLOADED && state !== CoreConstants.DOWNLOADING && CoreApp.isWifi()) { + if (state !== CoreConstants.DOWNLOADED && state !== CoreConstants.DOWNLOADING && CoreNetwork.isWifi()) { // We aren't using the result, so it doesn't matter which of the 2 functions we call. CoreFilepool.getUrlByUrl(site.getId(), url, this.component, this.componentId, 0, false); } diff --git a/src/core/features/comments/pages/viewer/viewer.page.ts b/src/core/features/comments/pages/viewer/viewer.page.ts index 038983c2f..6c92436e0 100644 --- a/src/core/features/comments/pages/viewer/viewer.page.ts +++ b/src/core/features/comments/pages/viewer/viewer.page.ts @@ -40,6 +40,7 @@ import { CoreCommentsOffline } from '@features/comments/services/comments-offlin import { CoreCommentsDBRecord } from '@features/comments/services/database/comments'; import { CoreTimeUtils } from '@services/utils/time'; import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import moment from 'moment'; import { Subscription } from 'rxjs'; @@ -108,11 +109,11 @@ export class CoreCommentsViewerPage implements OnInit, OnDestroy { } }, CoreSites.getCurrentSiteId()); - this.isOnline = CoreApp.isOnline(); + this.isOnline = CoreNetwork.isOnline(); this.onlineObserver = Network.onChange().subscribe(() => { // Execute the callback in the Angular zone, so change detection doesn't stop working. NgZone.run(() => { - this.isOnline = CoreApp.isOnline(); + this.isOnline = CoreNetwork.isOnline(); }); }); } diff --git a/src/core/features/comments/services/comments-sync.ts b/src/core/features/comments/services/comments-sync.ts index 277c7e651..cf19944cf 100644 --- a/src/core/features/comments/services/comments-sync.ts +++ b/src/core/features/comments/services/comments-sync.ts @@ -19,7 +19,7 @@ import { CoreEvents } from '@singletons/events'; import { makeSingleton, Translate } from '@singletons'; import { CoreCommentsOffline } from './comments-offline'; import { CoreSites } from '@services/sites'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreUtils } from '@services/utils/utils'; import { CoreNetworkError } from '@classes/errors/network-error'; import { CoreCommentsDBRecord, CoreCommentsDeletedDBRecord } from './database/comments'; @@ -204,7 +204,7 @@ export class CoreCommentsSyncProvider extends CoreSyncBaseProvider { siteId = siteId || CoreSites.getCurrentSiteId(); - if (!CoreApp.isOnline()) { + if (!CoreNetwork.isOnline()) { // Cannot prefetch in offline. throw new CoreNetworkError(); } diff --git a/src/core/features/course/classes/main-resource-component.ts b/src/core/features/course/classes/main-resource-component.ts index 9e995d682..3b720dec3 100644 --- a/src/core/features/course/classes/main-resource-component.ts +++ b/src/core/features/course/classes/main-resource-component.ts @@ -16,7 +16,7 @@ import { CoreConstants } from '@/core/constants'; import { OnInit, OnDestroy, Input, Output, EventEmitter, Component, Optional, Inject } from '@angular/core'; import { CoreAnyError } from '@classes/errors/error'; import { IonRefresher } from '@ionic/angular'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreSites } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; @@ -354,7 +354,7 @@ export class CoreCourseModuleMainResourceComponent implements OnInit, OnDestroy, if (!this.module.contents?.length || (refresh && !contentsAlreadyLoaded)) { // Try to load the contents. - const ignoreCache = refresh && CoreApp.isOnline(); + const ignoreCache = refresh && CoreNetwork.isOnline(); try { await CoreCourse.loadModuleContents(this.module, undefined, undefined, false, ignoreCache); diff --git a/src/core/features/course/classes/resource-prefetch-handler.ts b/src/core/features/course/classes/resource-prefetch-handler.ts index c7549df91..a7cde627d 100644 --- a/src/core/features/course/classes/resource-prefetch-handler.ts +++ b/src/core/features/course/classes/resource-prefetch-handler.ts @@ -14,7 +14,7 @@ import { CoreNetworkError } from '@classes/errors/network-error'; import { CoreFilterHelper } from '@features/filter/services/filter-helper'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreFilepool } from '@services/filepool'; import { CoreSites } from '@services/sites'; import { CoreWSFile } from '@services/ws'; @@ -57,7 +57,7 @@ export class CoreCourseResourcePrefetchHandlerBase extends CoreCourseModulePrefe * @return Promise resolved when all content is downloaded. */ async downloadOrPrefetch(module: CoreCourseModuleData, courseId: number, prefetch?: boolean, dirPath?: string): Promise { - if (!CoreApp.isOnline()) { + if (!CoreNetwork.isOnline()) { // Cannot download in offline. throw new CoreNetworkError(); } diff --git a/src/core/features/course/components/module-summary/module-summary.ts b/src/core/features/course/components/module-summary/module-summary.ts index 0fed98fd1..1cc0e43db 100644 --- a/src/core/features/course/components/module-summary/module-summary.ts +++ b/src/core/features/course/components/module-summary/module-summary.ts @@ -23,7 +23,7 @@ import { CoreCourseModuleDelegate } from '@features/course/services/module-deleg import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate'; import { CoreCourses, CoreEnrolledCourseData } from '@features/courses/services/courses'; import { CoreGradesFormattedRow, CoreGradesFormattedTableRow, CoreGradesHelper } from '@features/grades/services/grades-helper'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreFilepool } from '@services/filepool'; import { CoreNavigator } from '@services/navigator'; import { CoreSites } from '@services/sites'; @@ -79,13 +79,13 @@ export class CoreCourseModuleSummaryComponent implements OnInit, OnDestroy { constructor() { this.siteId = CoreSites.getCurrentSiteId(); - this.isOnline = CoreApp.isOnline(); + this.isOnline = CoreNetwork.isOnline(); // Refresh online status when changes. this.onlineSubscription = Network.onChange().subscribe(() => { // Execute the callback in the Angular zone, so change detection doesn't stop working. NgZone.run(() => { - this.isOnline = CoreApp.isOnline(); + this.isOnline = CoreNetwork.isOnline(); }); }); } diff --git a/src/core/features/course/services/course-helper.ts b/src/core/features/course/services/course-helper.ts index 422d4e3a6..ea53b8900 100644 --- a/src/core/features/course/services/course-helper.ts +++ b/src/core/features/course/services/course-helper.ts @@ -58,7 +58,7 @@ import { } from './module-prefetch-delegate'; import { CoreFileSizeSum } from '@services/plugin-file-delegate'; import { CoreFileHelper } from '@services/file-helper'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreSite } from '@classes/site'; import { CoreFile } from '@services/file'; import { CoreUrlUtils } from '@services/utils/url'; @@ -798,7 +798,7 @@ export class CoreCourseHelperProvider { files?: CoreCourseModuleContentFile[], options: CoreUtilsOpenFileOptions = {}, ): Promise { - if (!CoreApp.isOnline()) { + if (!CoreNetwork.isOnline()) { // Not online, get the offline file. It will fail if not found. let path: string | undefined; try { @@ -950,7 +950,7 @@ export class CoreCourseHelperProvider { ): Promise { siteId = siteId || CoreSites.getCurrentSiteId(); - const isOnline = CoreApp.isOnline(); + const isOnline = CoreNetwork.isOnline(); const mainFile = files[0]; const timemodified = mainFile.timemodified || 0; @@ -969,7 +969,7 @@ export class CoreCourseHelperProvider { } // Start the download if in wifi, but return the URL right away so the file is opened. - if (CoreApp.isWifi()) { + if (CoreNetwork.isWifi()) { this.downloadModule(module, courseId, component, componentId, files, siteId); } diff --git a/src/core/features/course/services/course.ts b/src/core/features/course/services/course.ts index 3d29c793b..67cd03a3e 100644 --- a/src/core/features/course/services/course.ts +++ b/src/core/features/course/services/course.ts @@ -15,7 +15,7 @@ import { Injectable } from '@angular/core'; import { Params } from '@angular/router'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreEvents } from '@singletons/events'; import { CoreLogger } from '@singletons/logger'; import { CoreSitesCommonWSOptions, CoreSites, CoreSitesReadingStrategy } from '@services/sites'; @@ -554,7 +554,7 @@ export class CoreCourseProvider { return sections; } catch { // The module might still be cached by a request with different parameters. - if (!ignoreCache && !CoreApp.isOnline()) { + if (!ignoreCache && !CoreNetwork.isOnline()) { if (includeStealth) { // Older versions didn't include the includestealthmodules option. return doRequest(site, courseId, moduleId, modName, false, true); @@ -1168,7 +1168,7 @@ export class CoreCourseProvider { CoreCourseOffline.markCompletedManually(cmId, completed, courseId, undefined, siteId); // The offline function requires a courseId and it could be missing because it's a calculated field. - if (!CoreApp.isOnline()) { + if (!CoreNetwork.isOnline()) { // App is offline, store the action. return storeOffline(); } diff --git a/src/core/features/course/services/log-helper.ts b/src/core/features/course/services/log-helper.ts index f7d8cbbc0..72124ffc1 100644 --- a/src/core/features/course/services/log-helper.ts +++ b/src/core/features/course/services/log-helper.ts @@ -14,7 +14,7 @@ import { Injectable } from '@angular/core'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreSites } from '@services/sites'; import { CoreTextUtils } from '@services/utils/text'; import { CoreTimeUtils } from '@services/utils/time'; @@ -134,7 +134,7 @@ export class CoreCourseLogHelperProvider { async log(ws: string, data: Record, component: string, componentId: number, siteId?: string): Promise { const site = await CoreSites.getSite(siteId); - if (!CoreApp.isOnline()) { + if (!CoreNetwork.isOnline()) { // App is offline, store the action. return this.storeOffline(ws, data, component, componentId, site.getId()); } diff --git a/src/core/features/course/services/sync.ts b/src/core/features/course/services/sync.ts index 9d3899dba..ab604bb89 100644 --- a/src/core/features/course/services/sync.ts +++ b/src/core/features/course/services/sync.ts @@ -17,7 +17,7 @@ import { Injectable } from '@angular/core'; import { CoreSyncBaseProvider } from '@classes/base-sync'; import { CoreSites } from '@services/sites'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreUtils } from '@services/utils/utils'; import { CoreTextUtils } from '@services/utils/text'; import { CoreCourseOffline } from './course-offline'; @@ -167,7 +167,7 @@ export class CoreCourseSyncProvider extends CoreSyncBaseProvider= wifiThreshold || (CoreApp.isNetworkAccessLimited() && size >= limitedThreshold)) { + } else if (size >= wifiThreshold || (CoreNetwork.isNetworkAccessLimited() && size >= limitedThreshold)) { const readableSize = CoreTextUtils.bytesToSize(size, 2); return CoreDomUtils.showConfirm( @@ -365,7 +366,7 @@ export class CoreFileUploaderHelperProvider { return false; } - if (!allowOffline && !CoreApp.isOnline()) { + if (!allowOffline && !CoreNetwork.isOnline()) { // Not allowed, show error. CoreDomUtils.showErrorModal('core.fileuploader.errormustbeonlinetoupload', true); @@ -796,7 +797,7 @@ export class CoreFileUploaderHelperProvider { return this.uploadFile(path, maxSize, checkSize, options, siteId); }; - if (!CoreApp.isOnline()) { + if (!CoreNetwork.isOnline()) { return errorUploading(Translate.instant('core.fileuploader.errormustbeonlinetoupload')); } diff --git a/src/core/features/filter/services/filter-helper.ts b/src/core/features/filter/services/filter-helper.ts index bc6ed652e..6467f1b67 100644 --- a/src/core/features/filter/services/filter-helper.ts +++ b/src/core/features/filter/services/filter-helper.ts @@ -14,7 +14,7 @@ import { Injectable } from '@angular/core'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreSites } from '@services/sites'; import { CoreFilterDelegate } from './filter-delegate'; import { @@ -299,7 +299,7 @@ export class CoreFilterHelperProvider { const cachedData = this.moduleContextsCache[siteId][courseId][contextLevel]; - if (!CoreApp.isOnline() || Date.now() <= cachedData.time + site.getExpirationDelay(CoreSite.FREQUENCY_RARELY)) { + if (!CoreNetwork.isOnline() || Date.now() <= cachedData.time + site.getExpirationDelay(CoreSite.FREQUENCY_RARELY)) { // We can use cache, return the filters if found. return cachedData.contexts[contextLevel] && cachedData.contexts[contextLevel][instanceId]; } diff --git a/src/core/features/filter/services/filter.ts b/src/core/features/filter/services/filter.ts index e413084d5..321748b32 100644 --- a/src/core/features/filter/services/filter.ts +++ b/src/core/features/filter/services/filter.ts @@ -14,7 +14,7 @@ import { Injectable } from '@angular/core'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreSites } from '@services/sites'; import { CoreSite } from '@classes/site'; import { CoreWSExternalWarning } from '@services/ws'; @@ -338,7 +338,7 @@ export class CoreFilterProvider { // Check if we have the contexts in the memory cache. const siteContexts = this.contextsCache[site.getId()]; - const isOnline = CoreApp.isOnline(); + const isOnline = CoreNetwork.isOnline(); const result: CoreFilterClassifiedFilters = {}; let allFound = true; diff --git a/src/core/features/h5p/components/h5p-player/h5p-player.ts b/src/core/features/h5p/components/h5p-player/h5p-player.ts index a8664a1d8..1ec717856 100644 --- a/src/core/features/h5p/components/h5p-player/h5p-player.ts +++ b/src/core/features/h5p/components/h5p-player/h5p-player.ts @@ -14,7 +14,7 @@ import { Component, Input, ElementRef, OnInit, OnDestroy, OnChanges, SimpleChange } from '@angular/core'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreFilepool } from '@services/filepool'; import { CoreSites } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; @@ -111,7 +111,7 @@ export class CoreH5PPlayerComponent implements OnInit, OnChanges, OnDestroy { * @return Promise resolved when done. */ async download(): Promise { - if (!CoreApp.isOnline()) { + if (!CoreNetwork.isOnline()) { CoreDomUtils.showErrorModal('core.networkerrormsg', true); return; @@ -144,7 +144,7 @@ export class CoreH5PPlayerComponent implements OnInit, OnChanges, OnDestroy { */ protected async attemptDownloadInBg(): Promise { if (!this.urlParams || !this.src || !this.siteCanDownload || !CoreH5P.canGetTrustedH5PFileInSite() || - !CoreApp.isOnline()) { + !CoreNetwork.isOnline()) { return; } diff --git a/src/core/features/login/pages/credentials/credentials.ts b/src/core/features/login/pages/credentials/credentials.ts index 6e805abe7..9c7ab916e 100644 --- a/src/core/features/login/pages/credentials/credentials.ts +++ b/src/core/features/login/pages/credentials/credentials.ts @@ -18,6 +18,7 @@ import { Subscription } from 'rxjs'; import { debounceTime } from 'rxjs/operators'; import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreSites } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreLoginHelper } from '@features/login/services/login-helper'; @@ -244,7 +245,7 @@ export class CoreLoginCredentialsPage implements OnInit, OnDestroy { return; } - if (!CoreApp.isOnline()) { + if (!CoreNetwork.isOnline()) { CoreDomUtils.showErrorModal('core.networkerrormsg', true); return; diff --git a/src/core/features/login/pages/reconnect/reconnect.ts b/src/core/features/login/pages/reconnect/reconnect.ts index c8a8acf37..0c5ca4c23 100644 --- a/src/core/features/login/pages/reconnect/reconnect.ts +++ b/src/core/features/login/pages/reconnect/reconnect.ts @@ -16,6 +16,7 @@ import { Component, OnInit, OnDestroy, ViewChild, ElementRef } from '@angular/co import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreUtils } from '@services/utils/utils'; @@ -201,7 +202,7 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy { return; } - if (!CoreApp.isOnline()) { + if (!CoreNetwork.isOnline()) { CoreDomUtils.showErrorModal('core.networkerrormsg', true); return; diff --git a/src/core/features/login/pages/site/site.ts b/src/core/features/login/pages/site/site.ts index a00117db3..902fbd16c 100644 --- a/src/core/features/login/pages/site/site.ts +++ b/src/core/features/login/pages/site/site.ts @@ -16,6 +16,7 @@ import { Component, OnInit, ViewChild, ElementRef } from '@angular/core'; import { FormBuilder, FormGroup, ValidatorFn, AbstractControl, ValidationErrors } from '@angular/forms'; import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreConfig } from '@services/config'; import { CoreSites, CoreSiteCheckResponse, CoreLoginSiteInfo, CoreSitesDemoSiteData } from '@services/sites'; import { CoreUtils } from '@services/utils/utils'; @@ -242,7 +243,7 @@ export class CoreLoginSitePage implements OnInit { return; } - if (!CoreApp.isOnline()) { + if (!CoreNetwork.isOnline()) { CoreDomUtils.showErrorModal('core.networkerrormsg', true); return; diff --git a/src/core/features/rating/services/rating-sync.ts b/src/core/features/rating/services/rating-sync.ts index 09f1af9c2..ad04f754e 100644 --- a/src/core/features/rating/services/rating-sync.ts +++ b/src/core/features/rating/services/rating-sync.ts @@ -16,7 +16,7 @@ import { ContextLevel } from '@/core/constants'; import { Injectable } from '@angular/core'; import { CoreSyncBaseProvider } from '@classes/base-sync'; import { CoreNetworkError } from '@classes/errors/network-error'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreSites } from '@services/sites'; import { CoreTextUtils } from '@services/utils/text'; import { CoreUtils } from '@services/utils/utils'; @@ -202,7 +202,7 @@ export class CoreRatingSyncProvider extends CoreSyncBaseProvider { // Execute the callback in the Angular zone, so change detection doesn't stop working. NgZone.run(() => { - this.deviceInfo.networkStatus = appProvider.isOnline() ? 'online' : 'offline'; + this.deviceInfo.networkStatus = CoreNetwork.isOnline() ? 'online' : 'offline'; }); }); diff --git a/src/core/features/settings/services/settings-helper.ts b/src/core/features/settings/services/settings-helper.ts index dacb346ed..1d1ee82ea 100644 --- a/src/core/features/settings/services/settings-helper.ts +++ b/src/core/features/settings/services/settings-helper.ts @@ -14,6 +14,7 @@ import { Injectable } from '@angular/core'; import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreCronDelegate } from '@services/cron'; import { CoreEvents } from '@singletons/events'; import { CoreFilepool } from '@services/filepool'; @@ -262,10 +263,10 @@ export class CoreSettingsHelperProvider { if (site.isLoggedOut()) { // Cannot sync logged out sites. throw new CoreError(Translate.instant('core.settings.cannotsyncloggedout')); - } else if (hasSyncHandlers && !CoreApp.isOnline()) { + } else if (hasSyncHandlers && !CoreNetwork.isOnline()) { // We need connection to execute sync. throw new CoreError(Translate.instant('core.settings.cannotsyncoffline')); - } else if (hasSyncHandlers && syncOnlyOnWifi && CoreApp.isNetworkAccessLimited()) { + } else if (hasSyncHandlers && syncOnlyOnWifi && CoreNetwork.isNetworkAccessLimited()) { throw new CoreError(Translate.instant('core.settings.cannotsyncwithoutwifi')); } diff --git a/src/core/features/user/services/user.ts b/src/core/features/user/services/user.ts index 72dfc469e..ed0b956ee 100644 --- a/src/core/features/user/services/user.ts +++ b/src/core/features/user/services/user.ts @@ -14,7 +14,7 @@ import { Injectable } from '@angular/core'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreFilepool } from '@services/filepool'; import { CoreSites } from '@services/sites'; import { CoreUtils } from '@services/utils/utils'; @@ -401,7 +401,7 @@ export class CoreUserProvider { const preference = await CoreUtils.ignoreErrors(CoreUserOffline.getPreference(name, siteId)); - if (preference && !CoreApp.isOnline()) { + if (preference && !CoreNetwork.isOnline()) { // Offline, return stored value. return preference.value; } @@ -760,7 +760,7 @@ export class CoreUserProvider { async setUserPreference(name: string, value: string, siteId?: string): Promise { siteId = siteId || CoreSites.getCurrentSiteId(); - if (!CoreApp.isOnline()) { + if (!CoreNetwork.isOnline()) { // Offline, just update the preference. return CoreUserOffline.setPreference(name, value); } diff --git a/src/core/features/xapi/services/xapi.ts b/src/core/features/xapi/services/xapi.ts index 8f6a6e75f..769a477fc 100644 --- a/src/core/features/xapi/services/xapi.ts +++ b/src/core/features/xapi/services/xapi.ts @@ -14,7 +14,7 @@ import { Injectable } from '@angular/core'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreSites } from '@services/sites'; import { CoreUtils } from '@services/utils/utils'; import { CoreSite } from '@classes/site'; @@ -94,7 +94,7 @@ export class CoreXAPIProvider { return false; }; - if (!CoreApp.isOnline() || options.offline) { + if (!CoreNetwork.isOnline() || options.offline) { // App is offline, store the action. return storeOffline(); } diff --git a/src/core/services/app.ts b/src/core/services/app.ts index 2eb93fa4f..69222deff 100644 --- a/src/core/services/app.ts +++ b/src/core/services/app.ts @@ -18,7 +18,7 @@ import { CoreDB } from '@services/db'; import { CoreEvents } from '@singletons/events'; import { SQLiteDB, SQLiteDBTableSchema } from '@classes/sqlitedb'; -import { makeSingleton, Keyboard, Network, StatusBar, Platform, Device } from '@singletons'; +import { makeSingleton, Keyboard, StatusBar, Platform, 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'; @@ -30,6 +30,7 @@ import { CoreDatabaseTable } from '@classes/database/database-table'; import { CorePromisedValue } from '@classes/promised-value'; import { Subscription } from 'rxjs'; import { CorePlatform } from '@services/platform'; +import { CoreNetwork } from '@services/network'; /** * Factory to provide some global functionalities, like access to the global app database. @@ -53,7 +54,6 @@ export class CoreAppProvider { protected isKeyboardShown = false; protected keyboardOpening = false; protected keyboardClosing = false; - protected forceOffline = false; protected redirect?: CoreRedirectData; protected schemaVersionsTable = asyncInstance>(); @@ -329,54 +329,30 @@ export class CoreAppProvider { * Returns whether we are online. * * @return Whether the app is online. + * @deprecated since 4.1.0. Use CoreNetwork instead. */ isOnline(): boolean { - if (this.forceOffline) { - return false; - } - - if (!this.isMobile()) { - return navigator.onLine; - } - - let online = Network.type !== null && Network.type != Network.Connection.NONE && - Network.type != Network.Connection.UNKNOWN; - - // Double check we are not online because we cannot rely 100% in Cordova APIs. - if (!online && navigator.onLine) { - online = true; - } - - return online; + return CoreNetwork.isOnline(); } /** * Check if device uses a limited connection. * * @return Whether the device uses a limited connection. + * @deprecated since 4.1.0. Use CoreNetwork instead. */ isNetworkAccessLimited(): boolean { - if (!this.isMobile()) { - return false; - } - - const limited = [ - Network.Connection.CELL_2G, - Network.Connection.CELL_3G, - Network.Connection.CELL_4G, - Network.Connection.CELL, - ]; - - return limited.indexOf(Network.type) > -1; + return CoreNetwork.isNetworkAccessLimited(); } /** * Check if device uses a wifi connection. * * @return Whether the device uses a wifi connection. + * @deprecated since 4.1.0. Use CoreNetwork instead. */ isWifi(): boolean { - return this.isOnline() && !this.isNetworkAccessLimited(); + return CoreNetwork.isWifi(); } /** @@ -668,9 +644,10 @@ export class CoreAppProvider { * Set value of forceOffline flag. If true, the app will think the device is offline. * * @param value Value to set. + * @deprecated since 4.1.0. Use CoreNetwork instead. */ setForceOffline(value: boolean): void { - this.forceOffline = !!value; + CoreNetwork.setForceOffline(value); } /** diff --git a/src/core/services/cron.ts b/src/core/services/cron.ts index eca0b1447..df6ec5e33 100644 --- a/src/core/services/cron.ts +++ b/src/core/services/cron.ts @@ -15,6 +15,7 @@ import { Injectable } from '@angular/core'; import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreConfig } from '@services/config'; import { CoreUtils } from '@services/utils/utils'; import { CoreConstants } from '@/core/constants'; @@ -89,7 +90,7 @@ export class CoreCronDelegateService { const usesNetwork = this.handlerUsesNetwork(name); const isSync = !force && this.isHandlerSync(name); - if (usesNetwork && !CoreApp.isOnline()) { + if (usesNetwork && !CoreNetwork.isOnline()) { // Offline, stop executing. const message = `Cannot execute handler because device is offline: ${name}`; this.logger.debug(message); @@ -102,7 +103,7 @@ export class CoreCronDelegateService { // Check network connection. const syncOnlyOnWifi = await CoreConfig.get(CoreConstants.SETTINGS_SYNC_ONLY_ON_WIFI, false); - if (syncOnlyOnWifi && !CoreApp.isWifi()) { + if (syncOnlyOnWifi && !CoreNetwork.isWifi()) { // Cannot execute in this network connection, retry soon. const message = `Cannot execute handler because device is using limited connection: ${name}`; this.logger.debug(message); diff --git a/src/core/services/file-helper.ts b/src/core/services/file-helper.ts index 136d1291e..cb5da9e8d 100644 --- a/src/core/services/file-helper.ts +++ b/src/core/services/file-helper.ts @@ -16,6 +16,7 @@ import { Injectable } from '@angular/core'; import { FileEntry } from '@ionic-native/file/ngx'; import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreFile } from '@services/file'; import { CoreFilepool } from '@services/filepool'; import { CoreSites } from '@services/sites'; @@ -167,8 +168,8 @@ export class CoreFileHelperProvider { } // The file system is available. - const isWifi = CoreApp.isWifi(); - const isOnline = CoreApp.isOnline(); + const isWifi = CoreNetwork.isWifi(); + const isOnline = CoreNetwork.isOnline(); if (state == CoreConstants.DOWNLOADED) { // File is downloaded, get the local file URL. diff --git a/src/core/services/filepool.ts b/src/core/services/filepool.ts index 87d88974c..3de5be814 100644 --- a/src/core/services/filepool.ts +++ b/src/core/services/filepool.ts @@ -16,6 +16,7 @@ import { Injectable } from '@angular/core'; import { Md5 } from 'ts-md5/dist/md5'; import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreEventPackageStatusChanged, CoreEvents } from '@singletons/events'; import { CoreFile } from '@services/file'; import { CorePluginFileDelegate } from '@services/plugin-file-delegate'; @@ -506,7 +507,7 @@ export class CoreFilepoolProvider { if (this.sizeCache[fileUrl] !== undefined) { size = this.sizeCache[fileUrl]; } else { - if (!CoreApp.isOnline()) { + if (!CoreNetwork.isOnline()) { // Cannot check size in offline, stop. throw new CoreError(Translate.instant('core.cannotconnect')); } @@ -515,7 +516,7 @@ export class CoreFilepoolProvider { } // Calculate the size of the file. - const isWifi = CoreApp.isWifi(); + const isWifi = CoreNetwork.isWifi(); const sizeUnknown = size <= 0; if (!sizeUnknown) { @@ -550,7 +551,7 @@ export class CoreFilepoolProvider { * is not accessible. Also, this will have no effect if the queue is already running. */ protected checkQueueProcessing(): void { - if (!CoreFile.isAvailable() || !CoreApp.isOnline()) { + if (!CoreFile.isAvailable() || !CoreNetwork.isOnline()) { this.queueState = CoreFilepoolProvider.QUEUE_PAUSED; return; @@ -1053,7 +1054,7 @@ export class CoreFilepoolProvider { if (!fileObject || this.isFileOutdated(fileObject, options.revision, options.timemodified) && - CoreApp.isOnline() && + CoreNetwork.isOnline() && !ignoreStale ) { throw new CoreError('Needs to be downloaded'); @@ -1597,7 +1598,7 @@ export class CoreFilepoolProvider { throw new CoreError('File not downloaded.'); } - if (this.isFileOutdated(entry, revision, timemodified) && CoreApp.isOnline()) { + if (this.isFileOutdated(entry, revision, timemodified) && CoreNetwork.isOnline()) { throw new CoreError('File is outdated'); } } catch (error) { @@ -2497,7 +2498,7 @@ export class CoreFilepoolProvider { if (this.queueState !== CoreFilepoolProvider.QUEUE_RUNNING) { // Silently ignore, the queue is on pause. throw CoreFilepoolProvider.ERR_QUEUE_ON_PAUSE; - } else if (!CoreFile.isAvailable() || !CoreApp.isOnline()) { + } else if (!CoreFile.isAvailable() || !CoreNetwork.isOnline()) { throw CoreFilepoolProvider.ERR_FS_OR_NETWORK_UNAVAILABLE; } @@ -2817,7 +2818,7 @@ export class CoreFilepoolProvider { */ shouldDownload(size: number): boolean { return size <= CoreFilepoolProvider.DOWNLOAD_THRESHOLD || - (CoreApp.isWifi() && size <= CoreFilepoolProvider.WIFI_DOWNLOAD_THRESHOLD); + (CoreNetwork.isWifi() && size <= CoreFilepoolProvider.WIFI_DOWNLOAD_THRESHOLD); } /** diff --git a/src/core/services/network.ts b/src/core/services/network.ts new file mode 100644 index 000000000..7673e2007 --- /dev/null +++ b/src/core/services/network.ts @@ -0,0 +1,92 @@ +// (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 { CorePlatform } from '@services/platform'; +import { makeSingleton, Network } from '@singletons'; + +/** + * Service to manage network information. + */ +@Injectable({ providedIn: 'root' }) +export class CoreNetworkService { + + protected forceOffline = false; + + /** + * Set value of forceOffline flag. If true, the app will think the device is offline. + * + * @param value Value to set. + */ + setForceOffline(value: boolean): void { + this.forceOffline = !!value; + } + + /** + * Returns whether we are online. + * + * @return Whether the app is online. + */ + isOnline(): boolean { + if (this.forceOffline) { + return false; + } + + if (!CorePlatform.isMobile()) { + return navigator.onLine; + } + + let online = Network.type !== null && Network.type != Network.Connection.NONE && + Network.type != Network.Connection.UNKNOWN; + + // Double check we are not online because we cannot rely 100% in Cordova APIs. + if (!online && navigator.onLine) { + online = true; + } + + return online; + } + + /** + * Check if device uses a limited connection. + * + * @return Whether the device uses a limited connection. + */ + isNetworkAccessLimited(): boolean { + if (!CorePlatform.isMobile()) { + return false; + } + + const limited = [ + Network.Connection.CELL_2G, + Network.Connection.CELL_3G, + Network.Connection.CELL_4G, + Network.Connection.CELL, + ]; + + return limited.indexOf(Network.type) > -1; + } + + /** + * Check if device uses a wifi connection. + * + * @return Whether the device uses a wifi connection. + */ + isWifi(): boolean { + return this.isOnline() && !this.isNetworkAccessLimited(); + } + +} + +export const CoreNetwork = makeSingleton(CoreNetworkService); diff --git a/src/core/services/sites.ts b/src/core/services/sites.ts index c27c1783a..642564033 100644 --- a/src/core/services/sites.ts +++ b/src/core/services/sites.ts @@ -60,6 +60,7 @@ import { CoreDatabaseConfiguration, CoreDatabaseTable } from '@classes/database/ import { CoreDatabaseCachingStrategy, CoreDatabaseTableProxy } from '@classes/database/database-table-proxy'; import { asyncInstance, AsyncInstance } from '../utils/async-instance'; import { CoreConfig } from './config'; +import { CoreNetwork } from '@services/network'; export const CORE_SITE_SCHEMAS = new InjectionToken('CORE_SITE_SCHEMAS'); export const CORE_SITE_CURRENT_SITE_ID_CONFIG = 'current_site_id'; @@ -216,7 +217,7 @@ export class CoreSitesProvider { if (!CoreUrlUtils.isHttpURL(siteUrl)) { throw new CoreError(Translate.instant('core.login.invalidsite')); - } else if (!CoreApp.isOnline()) { + } else if (!CoreNetwork.isOnline()) { throw new CoreNetworkError(); } @@ -429,7 +430,7 @@ export class CoreSitesProvider { service?: string, retry?: boolean, ): Promise { - if (!CoreApp.isOnline()) { + if (!CoreNetwork.isOnline()) { throw new CoreNetworkError(); } diff --git a/src/core/services/utils/dom.ts b/src/core/services/utils/dom.ts index 8a8ea8def..014196466 100644 --- a/src/core/services/utils/dom.ts +++ b/src/core/services/utils/dom.ts @@ -54,6 +54,7 @@ import { filter } from 'rxjs/operators'; import { Subscription } from 'rxjs'; import { CoreComponentsRegistry } from '@singletons/components-registry'; import { CoreDom } from '@singletons/dom'; +import { CoreNetwork } from '@services/network'; /* * "Utils" service with helper functions for UI, DOM elements and HTML code. @@ -170,7 +171,7 @@ export class CoreDomUtilsProvider { limitedThreshold = limitedThreshold === undefined ? CoreConstants.DOWNLOAD_THRESHOLD : limitedThreshold; let wifiPrefix = ''; - if (CoreApp.isNetworkAccessLimited()) { + if (CoreNetwork.isNetworkAccessLimited()) { wifiPrefix = Translate.instant('core.course.confirmlimiteddownload'); } @@ -194,7 +195,7 @@ export class CoreDomUtilsProvider { ), ); } else if (alwaysConfirm || size.size >= wifiThreshold || - (CoreApp.isNetworkAccessLimited() && size.size >= limitedThreshold)) { + (CoreNetwork.isNetworkAccessLimited() && size.size >= limitedThreshold)) { message = message || (size.size === 0 ? 'core.course.confirmdownloadzerosize' : 'core.course.confirmdownload'); return this.showConfirm( diff --git a/src/core/services/utils/iframe.ts b/src/core/services/utils/iframe.ts index 4805a657a..2cbd83068 100644 --- a/src/core/services/utils/iframe.ts +++ b/src/core/services/utils/iframe.ts @@ -17,6 +17,7 @@ import { WKUserScriptWindow } from 'cordova-plugin-wkuserscript'; import { WKWebViewCookiesWindow } from 'cordova-plugin-wkwebview-cookies'; import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreFile } from '@services/file'; import { CoreFileHelper } from '@services/file-helper'; import { CoreSites } from '@services/sites'; @@ -65,7 +66,7 @@ export class CoreIframeUtilsProvider { checkOnlineFrameInOffline(element: CoreFrameElement, isSubframe?: boolean): boolean { const src = 'src' in element ? element.src : element.data; - if (src && src != 'about:blank' && !CoreUrlUtils.isLocalFileUrl(src) && !CoreApp.isOnline()) { + if (src && src != 'about:blank' && !CoreUrlUtils.isLocalFileUrl(src) && !CoreNetwork.isOnline()) { if (element.classList.contains('core-iframe-offline-disabled')) { // Iframe already hidden, stop. return true; diff --git a/src/core/services/ws.ts b/src/core/services/ws.ts index 7f532887c..9f83fd9e1 100644 --- a/src/core/services/ws.ts +++ b/src/core/services/ws.ts @@ -22,7 +22,7 @@ import { Observable } from 'rxjs'; import { timeout } from 'rxjs/operators'; import { CoreNativeToAngularHttpResponse } from '@classes/native-to-angular-http'; -import { CoreApp } from '@services/app'; +import { CoreNetwork } from '@services/network'; import { CoreFile, CoreFileFormat } from '@services/file'; import { CoreMimetypeUtils } from '@services/utils/mimetype'; import { CoreTextErrorObject, CoreTextUtils } from '@services/utils/text'; @@ -96,7 +96,7 @@ export class CoreWSProvider { call(method: string, data: Record, preSets: CoreWSPreSets): Promise { if (!preSets) { throw new CoreError(Translate.instant('core.unexpectederror')); - } else if (!CoreApp.isOnline()) { + } else if (!CoreNetwork.isOnline()) { throw new CoreNetworkError(); } @@ -254,7 +254,7 @@ export class CoreWSProvider { ): Promise { this.logger.debug('Downloading file', url, path, addExtension); - if (!CoreApp.isOnline()) { + if (!CoreNetwork.isOnline()) { throw new CoreNetworkError(); } @@ -388,7 +388,7 @@ export class CoreWSProvider { * @return Timeout in ms. */ getRequestTimeout(): number { - return CoreApp.isNetworkAccessLimited() ? CoreConstants.WS_TIMEOUT : CoreConstants.WS_TIMEOUT_WIFI; + return CoreNetwork.isNetworkAccessLimited() ? CoreConstants.WS_TIMEOUT : CoreConstants.WS_TIMEOUT_WIFI; } /** @@ -421,7 +421,7 @@ export class CoreWSProvider { if (preSets.siteUrl === undefined) { throw new CoreAjaxError(Translate.instant('core.unexpectederror')); - } else if (!CoreApp.isOnline()) { + } else if (!CoreNetwork.isOnline()) { throw new CoreAjaxError(Translate.instant('core.networkerrormsg')); } @@ -789,7 +789,7 @@ export class CoreWSProvider { syncCall(method: string, data: any, preSets: CoreWSPreSets): T { if (!preSets) { throw new CoreError(Translate.instant('core.unexpectederror')); - } else if (!CoreApp.isOnline()) { + } else if (!CoreNetwork.isOnline()) { throw new CoreNetworkError(); } @@ -873,7 +873,7 @@ export class CoreWSProvider { throw new CoreError('Invalid options passed to upload file.'); } - if (!CoreApp.isOnline()) { + if (!CoreNetwork.isOnline()) { throw new CoreNetworkError(); }