MOBILE-3321 core: Decouple Network from App

main
Noel De Martin 2022-05-11 14:06:42 +02:00
parent a0a138f686
commit 73ee4df1ec
88 changed files with 343 additions and 255 deletions

View File

@ -41,7 +41,7 @@ import {
import { AddonCalendarFilter, AddonCalendarHelper } from '../../services/calendar-helper'; import { AddonCalendarFilter, AddonCalendarHelper } from '../../services/calendar-helper';
import { AddonCalendarOffline } from '../../services/calendar-offline'; import { AddonCalendarOffline } from '../../services/calendar-offline';
import { CoreCategoryData, CoreCourses } from '@features/courses/services/courses'; 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 { CoreSwipeSlidesComponent } from '@components/swipe-slides/swipe-slides';
import { import {
CoreSwipeSlidesDynamicItem, CoreSwipeSlidesDynamicItem,
@ -498,7 +498,7 @@ class AddonCalendarMonthSlidesItemsManagerSource extends CoreSwipeSlidesDynamicI
// Don't pass courseId and categoryId, we'll filter them locally. // Don't pass courseId and categoryId, we'll filter them locally.
result = await AddonCalendar.getMonthlyEvents(year, monthNumber); result = await AddonCalendar.getMonthlyEvents(year, monthNumber);
} catch (error) { } catch (error) {
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
// Allow navigating to non-cached months in offline (behave as if using emergency cache). // Allow navigating to non-cached months in offline (behave as if using emergency cache).
result = await AddonCalendarHelper.getOfflineMonthWeeks(year, monthNumber); result = await AddonCalendarHelper.getOfflineMonthWeeks(year, monthNumber);
} else { } else {

View File

@ -14,7 +14,7 @@
import { Component, OnInit, OnDestroy, ViewChild } from '@angular/core'; import { Component, OnInit, OnDestroy, ViewChild } from '@angular/core';
import { IonRefresher } from '@ionic/angular'; import { IonRefresher } from '@ionic/angular';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { CoreEventObserver, CoreEvents } from '@singletons/events';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreDomUtils } from '@services/utils/dom'; import { CoreDomUtils } from '@services/utils/dom';
@ -183,7 +183,7 @@ export class AddonCalendarDayPage implements OnInit, OnDestroy {
this.onlineObserver = Network.onChange().subscribe(() => { this.onlineObserver = Network.onChange().subscribe(() => {
// Execute the callback in the Angular zone, so change detection doesn't stop working. // Execute the callback in the Angular zone, so change detection doesn't stop working.
NgZone.run(() => { 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<void> { async fetchData(sync?: boolean): Promise<void> {
this.syncIcon = CoreConstants.ICON_LOADING; this.syncIcon = CoreConstants.ICON_LOADING;
this.isOnline = CoreApp.isOnline(); this.isOnline = CoreNetwork.isOnline();
if (sync) { if (sync) {
await this.sync(); await this.sync();
@ -674,7 +674,7 @@ class AddonCalendarDaySlidesItemsManagerSource extends CoreSwipeSlidesDynamicIte
); );
} catch (error) { } catch (error) {
// Allow navigating to non-cached days in offline (behave as if using emergency cache). // Allow navigating to non-cached days in offline (behave as if using emergency cache).
if (CoreApp.isOnline()) { if (CoreNetwork.isOnline()) {
throw error; throw error;
} }
} }

View File

@ -23,7 +23,7 @@ import {
import { AddonCalendarEventReminder, AddonCalendarHelper } from '../../services/calendar-helper'; import { AddonCalendarEventReminder, AddonCalendarHelper } from '../../services/calendar-helper';
import { AddonCalendarOffline } from '../../services/calendar-offline'; import { AddonCalendarOffline } from '../../services/calendar-offline';
import { AddonCalendarSync, AddonCalendarSyncEvents, AddonCalendarSyncProvider } from '../../services/calendar-sync'; 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 { CoreEventObserver, CoreEvents } from '@singletons/events';
import { CoreDomUtils } from '@services/utils/dom'; import { CoreDomUtils } from '@services/utils/dom';
import { CoreTextUtils } from '@services/utils/text'; import { CoreTextUtils } from '@services/utils/text';
@ -126,7 +126,7 @@ export class AddonCalendarEventPage implements OnInit, OnDestroy {
this.onlineObserver = Network.onChange().subscribe(() => { this.onlineObserver = Network.onChange().subscribe(() => {
// Execute the callback in the Angular zone, so change detection doesn't stop working. // Execute the callback in the Angular zone, so change detection doesn't stop working.
NgZone.run(() => { 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. * @return Promise resolved when done.
*/ */
async fetchEvent(sync = false, showErrors = false): Promise<void> { async fetchEvent(sync = false, showErrors = false): Promise<void> {
this.isOnline = CoreApp.isOnline(); this.isOnline = CoreNetwork.isOnline();
if (sync) { if (sync) {
const deleted = await this.syncEvents(showErrors); const deleted = await this.syncEvents(showErrors);

View File

@ -14,7 +14,7 @@
import { Component, OnInit, OnDestroy, ViewChild } from '@angular/core'; import { Component, OnInit, OnDestroy, ViewChild } from '@angular/core';
import { IonRefresher } from '@ionic/angular'; import { IonRefresher } from '@ionic/angular';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { CoreEventObserver, CoreEvents } from '@singletons/events';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreDomUtils } from '@services/utils/dom'; import { CoreDomUtils } from '@services/utils/dom';
@ -156,7 +156,7 @@ export class AddonCalendarIndexPage implements OnInit, OnDestroy {
this.onlineObserver = Network.onChange().subscribe(() => { this.onlineObserver = Network.onChange().subscribe(() => {
// Execute the callback in the Angular zone, so change detection doesn't stop working. // Execute the callback in the Angular zone, so change detection doesn't stop working.
NgZone.run(() => { 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<void> { async fetchData(sync?: boolean, showErrors?: boolean): Promise<void> {
this.syncIcon = CoreConstants.ICON_LOADING; this.syncIcon = CoreConstants.ICON_LOADING;
this.isOnline = CoreApp.isOnline(); this.isOnline = CoreNetwork.isOnline();
if (sync) { if (sync) {
// Try to synchronize offline events. // Try to synchronize offline events.

View File

@ -14,7 +14,7 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { CoreSyncBaseProvider, CoreSyncBlockedError } from '@classes/base-sync'; import { CoreSyncBaseProvider, CoreSyncBlockedError } from '@classes/base-sync';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreEvents } from '@singletons/events'; import { CoreEvents } from '@singletons/events';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
@ -134,7 +134,7 @@ export class AddonCalendarSyncProvider extends CoreSyncBaseProvider<AddonCalenda
const eventIds: number[] = await CoreUtils.ignoreErrors(AddonCalendarOffline.getAllEventsIds(siteId), []); const eventIds: number[] = await CoreUtils.ignoreErrors(AddonCalendarOffline.getAllEventsIds(siteId), []);
if (eventIds.length > 0) { if (eventIds.length > 0) {
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
// Cannot sync in offline. // Cannot sync in offline.
throw new CoreNetworkError(); throw new CoreNetworkError();
} }

View File

@ -15,7 +15,7 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreSite, CoreSiteWSPreSets } from '@classes/site'; import { CoreSite, CoreSiteWSPreSets } from '@classes/site';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreTextUtils } from '@services/utils/text'; import { CoreTextUtils } from '@services/utils/text';
import { CoreTimeUtils } from '@services/utils/time'; import { CoreTimeUtils } from '@services/utils/time';
import { CoreUrlUtils } from '@services/utils/url'; import { CoreUrlUtils } from '@services/utils/url';
@ -241,7 +241,7 @@ export class AddonCalendarProvider {
const storeOffline = (): Promise<boolean> => const storeOffline = (): Promise<boolean> =>
AddonCalendarOffline.markDeleted(eventId, name, deleteAll, siteId).then(() => false); AddonCalendarOffline.markDeleted(eventId, name, deleteAll, siteId).then(() => false);
if (forceOffline || !CoreApp.isOnline()) { if (forceOffline || !CoreNetwork.isOnline()) {
// App is offline, store the action. // App is offline, store the action.
return storeOffline(); 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. // 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); CoreConfig.set(AddonCalendarProvider.STARTING_WEEK_DAY, response.daynames[0].dayno);
} }
@ -1707,7 +1707,7 @@ export class AddonCalendarProvider {
return { sent: false, event }; return { sent: false, event };
}; };
if (options.forceOffline || !CoreApp.isOnline()) { if (options.forceOffline || !CoreNetwork.isOnline()) {
// App is offline, store the event. // App is offline, store the event.
return storeOffline(); return storeOffline();
} }

View File

@ -14,7 +14,7 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreTextUtils } from '@services/utils/text'; import { CoreTextUtils } from '@services/utils/text';
import { import {
AddonMessagesOfflineConversationMessagesDBRecord, AddonMessagesOfflineConversationMessagesDBRecord,
@ -283,7 +283,7 @@ export class AddonMessagesOfflineProvider {
conversationid: conversation.id, conversationid: conversation.id,
text: message, text: message,
timecreated: Date.now(), timecreated: Date.now(),
deviceoffline: CoreApp.isOnline() ? 0 : 1, deviceoffline: CoreNetwork.isOnline() ? 0 : 1,
conversation: JSON.stringify({ conversation: JSON.stringify({
name: conversation.name || '', name: conversation.name || '',
subname: conversation.subname || '', subname: conversation.subname || '',
@ -314,7 +314,7 @@ export class AddonMessagesOfflineProvider {
useridfrom: site.getUserId(), useridfrom: site.getUserId(),
smallmessage: message, smallmessage: message,
timecreated: new Date().getTime(), timecreated: new Date().getTime(),
deviceoffline: CoreApp.isOnline() ? 0 : 1, deviceoffline: CoreNetwork.isOnline() ? 0 : 1,
}; };
await site.getDb().insertRecord(MESSAGES_TABLE, entry); await site.getDb().insertRecord(MESSAGES_TABLE, entry);

View File

@ -26,7 +26,7 @@ import { CoreEvents } from '@singletons/events';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { makeSingleton, Translate } from '@singletons'; import { makeSingleton, Translate } from '@singletons';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreConstants } from '@/core/constants'; import { CoreConstants } from '@/core/constants';
import { CoreUser } from '@features/user/services/user'; import { CoreUser } from '@features/user/services/user';
import { CoreError } from '@classes/errors/error'; import { CoreError } from '@classes/errors/error';
@ -193,7 +193,7 @@ export class AddonMessagesSyncProvider extends CoreSyncBaseProvider<AddonMessage
if (!messages.length) { if (!messages.length) {
// Nothing to sync. // Nothing to sync.
return result; return result;
} else if (!CoreApp.isOnline()) { } else if (!CoreNetwork.isOnline()) {
// Cannot sync in offline. Mark messages as device offline. // Cannot sync in offline. Mark messages as device offline.
AddonMessagesOffline.setMessagesDeviceOffline(messages, true); AddonMessagesOffline.setMessagesDeviceOffline(messages, true);
@ -228,7 +228,7 @@ export class AddonMessagesSyncProvider extends CoreSyncBaseProvider<AddonMessage
} catch (error) { } catch (error) {
if (!CoreUtils.isWebServiceError(error)) { if (!CoreUtils.isWebServiceError(error)) {
// Error sending, stop execution. // Error sending, stop execution.
if (CoreApp.isOnline()) { if (CoreNetwork.isOnline()) {
// App is online, unmark deviceoffline if marked. // App is online, unmark deviceoffline if marked.
AddonMessagesOffline.setMessagesDeviceOffline(messages, false); AddonMessagesOffline.setMessagesDeviceOffline(messages, false);
} }

View File

@ -15,7 +15,7 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { CoreLogger } from '@singletons/logger'; import { CoreLogger } from '@singletons/logger';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreUser, CoreUserBasicData } from '@features/user/services/user'; import { CoreUser, CoreUserBasicData } from '@features/user/services/user';
import { import {
AddonMessagesOffline, AddonMessagesOffline,
@ -2424,7 +2424,7 @@ export class AddonMessagesProvider {
siteId = siteId || CoreSites.getCurrentSiteId(); siteId = siteId || CoreSites.getCurrentSiteId();
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
// App is offline, store the message. // App is offline, store the message.
return storeOffline(); return storeOffline();
} }
@ -2555,7 +2555,7 @@ export class AddonMessagesProvider {
}; };
}; };
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
// App is offline, store the message. // App is offline, store the message.
return storeOffline(); return storeOffline();
} }

View File

@ -49,7 +49,7 @@ import { AddonModAssignOffline } from '../../services/assign-offline';
import { CoreUser, CoreUserProfile } from '@features/user/services/user'; import { CoreUser, CoreUserProfile } from '@features/user/services/user';
import { CoreTimeUtils } from '@services/utils/time'; import { CoreTimeUtils } from '@services/utils/time';
import { CoreNavigator } from '@services/navigator'; import { CoreNavigator } from '@services/navigator';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreFileUploaderHelper } from '@features/fileuploader/services/fileuploader-helper'; import { CoreFileUploaderHelper } from '@features/fileuploader/services/fileuploader-helper';
import { CoreLang } from '@services/lang'; import { CoreLang } from '@services/lang';
import { CoreError } from '@classes/errors/error'; import { CoreError } from '@classes/errors/error';
@ -292,7 +292,7 @@ export class AddonModAssignSubmissionComponent implements OnInit, OnDestroy, Can
return; return;
} }
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
CoreDomUtils.showErrorModal('core.networkerrormsg', true); CoreDomUtils.showErrorModal('core.networkerrormsg', true);
return; return;

View File

@ -35,7 +35,7 @@ import {
import { CoreSync } from '@services/sync'; import { CoreSync } from '@services/sync';
import { CoreCourseLogHelper } from '@features/course/services/log-helper'; import { CoreCourseLogHelper } from '@features/course/services/log-helper';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreNetworkError } from '@classes/errors/network-error'; import { CoreNetworkError } from '@classes/errors/network-error';
import { CoreGradesFormattedItem, CoreGradesHelper } from '@features/grades/services/grades-helper'; import { CoreGradesFormattedItem, CoreGradesHelper } from '@features/grades/services/grades-helper';
import { AddonModAssignSubmissionDelegate } from './submission-delegate'; import { AddonModAssignSubmissionDelegate } from './submission-delegate';
@ -215,7 +215,7 @@ export class AddonModAssignSyncProvider extends CoreCourseActivitySyncBaseProvid
return result; return result;
} }
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
// Cannot sync in offline. // Cannot sync in offline.
throw new CoreNetworkError(); throw new CoreNetworkError();
} }

View File

@ -24,7 +24,7 @@ import { CoreGrades } from '@features/grades/services/grades';
import { CoreTimeUtils } from '@services/utils/time'; import { CoreTimeUtils } from '@services/utils/time';
import { CoreCourseLogHelper } from '@features/course/services/log-helper'; import { CoreCourseLogHelper } from '@features/course/services/log-helper';
import { CoreError } from '@classes/errors/error'; import { CoreError } from '@classes/errors/error';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { AddonModAssignOffline } from './assign-offline'; import { AddonModAssignOffline } from './assign-offline';
import { AddonModAssignSubmissionDelegate } from './submission-delegate'; import { AddonModAssignSubmissionDelegate } from './submission-delegate';
@ -1027,7 +1027,7 @@ export class AddonModAssignProvider {
return false; return false;
}; };
if (allowOffline && !CoreApp.isOnline()) { if (allowOffline && !CoreNetwork.isOnline()) {
// App is offline, store the action. // App is offline, store the action.
return storeOffline(); return storeOffline();
} }
@ -1137,7 +1137,7 @@ export class AddonModAssignProvider {
return false; return false;
}; };
if (forceOffline || !CoreApp.isOnline()) { if (forceOffline || !CoreNetwork.isOnline()) {
// App is offline, store the action. // App is offline, store the action.
return storeOffline(); return storeOffline();
} }
@ -1234,7 +1234,7 @@ export class AddonModAssignProvider {
return false; return false;
}; };
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
// App is offline, store the action. // App is offline, store the action.
return storeOffline(); return storeOffline();
} }

View File

@ -25,7 +25,7 @@ import { CoreCourseModuleData } from '@features/course/services/course-helper';
import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate'; import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate';
import { CoreTag, CoreTagItem } from '@features/tag/services/tag'; import { CoreTag, CoreTagItem } from '@features/tag/services/tag';
import { IonRefresher } from '@ionic/angular'; import { IonRefresher } from '@ionic/angular';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreNavigator } from '@services/navigator'; import { CoreNavigator } from '@services/navigator';
import { CoreDomUtils } from '@services/utils/dom'; import { CoreDomUtils } from '@services/utils/dom';
import { CoreTextUtils } from '@services/utils/text'; import { CoreTextUtils } from '@services/utils/text';
@ -190,7 +190,7 @@ export class AddonModBookContentsPage implements OnInit, OnDestroy {
if (!module.contents?.length || (refresh && !contentsAlreadyLoaded)) { if (!module.contents?.length || (refresh && !contentsAlreadyLoaded)) {
// Try to load the contents. // Try to load the contents.
const ignoreCache = refresh && CoreApp.isOnline(); const ignoreCache = refresh && CoreNetwork.isOnline();
try { try {
await CoreCourse.loadModuleContents(module, undefined, undefined, false, ignoreCache); await CoreCourse.loadModuleContents(module, undefined, undefined, false, ignoreCache);

View File

@ -13,7 +13,7 @@
// limitations under the License. // limitations under the License.
import { Component, Input, OnDestroy, OnInit } from '@angular/core'; import { Component, Input, OnDestroy, OnInit } from '@angular/core';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreDomUtils } from '@services/utils/dom'; import { CoreDomUtils } from '@services/utils/dom';
import { ModalController, Network, NgZone } from '@singletons'; import { ModalController, Network, NgZone } from '@singletons';
@ -40,12 +40,12 @@ export class AddonModChatUsersModalComponent implements OnInit, OnDestroy {
protected onlineSubscription: Subscription; protected onlineSubscription: Subscription;
constructor() { constructor() {
this.isOnline = CoreApp.isOnline(); this.isOnline = CoreNetwork.isOnline();
this.currentUserId = CoreSites.getCurrentSiteUserId(); this.currentUserId = CoreSites.getCurrentSiteUserId();
this.onlineSubscription = Network.onChange().subscribe(() => { this.onlineSubscription = Network.onChange().subscribe(() => {
// Execute the callback in the Angular zone, so change detection doesn't stop working. // Execute the callback in the Angular zone, so change detection doesn't stop working.
NgZone.run(() => { NgZone.run(() => {
this.isOnline = CoreApp.isOnline(); this.isOnline = CoreNetwork.isOnline();
}); });
}); });
} }

View File

@ -18,6 +18,7 @@ import { CoreSendMessageFormComponent } from '@components/send-message-form/send
import { CanLeave } from '@guards/can-leave'; import { CanLeave } from '@guards/can-leave';
import { IonContent } from '@ionic/angular'; import { IonContent } from '@ionic/angular';
import { CoreApp } from '@services/app'; import { CoreApp } from '@services/app';
import { CoreNetwork } from '@services/network';
import { CoreNavigator } from '@services/navigator'; import { CoreNavigator } from '@services/navigator';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreDomUtils } from '@services/utils/dom'; import { CoreDomUtils } from '@services/utils/dom';
@ -65,11 +66,11 @@ export class AddonModChatChatPage implements OnInit, OnDestroy, CanLeave {
constructor() { constructor() {
this.currentUserId = CoreSites.getCurrentSiteUserId(); this.currentUserId = CoreSites.getCurrentSiteUserId();
this.isOnline = CoreApp.isOnline(); this.isOnline = CoreNetwork.isOnline();
this.onlineSubscription = Network.onChange().subscribe(() => { this.onlineSubscription = Network.onChange().subscribe(() => {
// Execute the callback in the Angular zone, so change detection doesn't stop working. // Execute the callback in the Angular zone, so change detection doesn't stop working.
NgZone.run(() => { NgZone.run(() => {
this.isOnline = CoreApp.isOnline(); this.isOnline = CoreNetwork.isOnline();
}); });
}); });
} }

View File

@ -17,7 +17,7 @@ import { CoreNetworkError } from '@classes/errors/network-error';
import { CoreCourseActivitySyncBaseProvider } from '@features/course/classes/activity-sync'; import { CoreCourseActivitySyncBaseProvider } from '@features/course/classes/activity-sync';
import { CoreCourse } from '@features/course/services/course'; import { CoreCourse } from '@features/course/services/course';
import { CoreCourseLogHelper } from '@features/course/services/log-helper'; import { CoreCourseLogHelper } from '@features/course/services/log-helper';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
@ -160,7 +160,7 @@ export class AddonModChoiceSyncProvider extends CoreCourseActivitySyncBaseProvid
return result; return result;
} }
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
// Cannot sync in offline. // Cannot sync in offline.
throw new CoreNetworkError(); throw new CoreNetworkError();
} }

View File

@ -18,7 +18,7 @@ import { CoreWSError } from '@classes/errors/wserror';
import { CoreSite, CoreSiteWSPreSets } from '@classes/site'; import { CoreSite, CoreSiteWSPreSets } from '@classes/site';
import { CoreCourseCommonModWSOptions } from '@features/course/services/course'; import { CoreCourseCommonModWSOptions } from '@features/course/services/course';
import { CoreCourseLogHelper } from '@features/course/services/log-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 { CoreFilepool } from '@services/filepool';
import { CoreSites, CoreSitesCommonWSOptions } from '@services/sites'; import { CoreSites, CoreSitesCommonWSOptions } from '@services/sites';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
@ -90,7 +90,7 @@ export class AddonModChoiceProvider {
return false; return false;
}; };
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
// App is offline, store the action. // App is offline, store the action.
return storeOffline(); return storeOffline();
} }
@ -407,7 +407,7 @@ export class AddonModChoiceProvider {
return false; return false;
}; };
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
// App is offline, store the action. // App is offline, store the action.
return storeOffline(); return storeOffline();
} }

View File

@ -21,7 +21,7 @@ import { CoreCourseCommonModWSOptions } from '@features/course/services/course';
import { CoreCourseLogHelper } from '@features/course/services/log-helper'; import { CoreCourseLogHelper } from '@features/course/services/log-helper';
import { CoreFileUploaderStoreFilesResult } from '@features/fileuploader/services/fileuploader'; import { CoreFileUploaderStoreFilesResult } from '@features/fileuploader/services/fileuploader';
import { CoreRatingSync } from '@features/rating/services/rating-sync'; 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 { CoreFileEntry } from '@services/file-helper';
import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites';
import { CoreSync } from '@services/sync'; import { CoreSync } from '@services/sync';
@ -184,7 +184,7 @@ export class AddonModDataSyncProvider extends CoreCourseActivitySyncBaseProvider
return result; return result;
} }
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
// Cannot sync in offline. // Cannot sync in offline.
throw new CoreNetworkError(); throw new CoreNetworkError();
} }

View File

@ -19,7 +19,7 @@ import { CoreCourseCommonModWSOptions } from '@features/course/services/course';
import { CoreCourseLogHelper } from '@features/course/services/log-helper'; import { CoreCourseLogHelper } from '@features/course/services/log-helper';
import { CoreRatingInfo } from '@features/rating/services/rating'; import { CoreRatingInfo } from '@features/rating/services/rating';
import { CoreTagItem } from '@features/tag/services/tag'; import { CoreTagItem } from '@features/tag/services/tag';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreFileEntry } from '@services/file-helper'; import { CoreFileEntry } from '@services/file-helper';
import { CoreFilepool } from '@services/filepool'; import { CoreFilepool } from '@services/filepool';
import { CoreSites, CoreSitesCommonWSOptions, CoreSitesReadingStrategy } from '@services/sites'; import { CoreSites, CoreSitesCommonWSOptions, CoreSitesReadingStrategy } from '@services/sites';
@ -136,7 +136,7 @@ export class AddonModDataProvider {
}; };
// Checks to store offline. // Checks to store offline.
if (!CoreApp.isOnline() || forceOffline) { if (!CoreNetwork.isOnline() || forceOffline) {
const notifications = this.checkFields(fields, contents); const notifications = this.checkFields(fields, contents);
if (notifications.length > 0) { if (notifications.length > 0) {
return { fieldnotifications: notifications }; return { fieldnotifications: notifications };
@ -147,7 +147,7 @@ export class AddonModDataProvider {
await this.deleteEntryOfflineAction(dataId, entryId, AddonModDataAction.ADD, siteId); await this.deleteEntryOfflineAction(dataId, entryId, AddonModDataAction.ADD, siteId);
// App is offline, store the action. // App is offline, store the action.
if (!CoreApp.isOnline() || forceOffline) { if (!CoreNetwork.isOnline() || forceOffline) {
return storeOffline(); return storeOffline();
} }
@ -234,7 +234,7 @@ export class AddonModDataProvider {
return; return;
} }
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
// App is offline, store the action. // App is offline, store the action.
return storeOffline(); return storeOffline();
} }
@ -333,7 +333,7 @@ export class AddonModDataProvider {
return; return;
} }
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
// App is offline, store the action. // App is offline, store the action.
return storeOffline(); return storeOffline();
} }
@ -436,7 +436,7 @@ export class AddonModDataProvider {
}; };
}; };
if (!CoreApp.isOnline() || forceOffline) { if (!CoreNetwork.isOnline() || forceOffline) {
const notifications = this.checkFields(fields, contents); const notifications = this.checkFields(fields, contents);
if (notifications.length > 0) { if (notifications.length > 0) {
return { fieldnotifications: notifications }; return { fieldnotifications: notifications };
@ -446,7 +446,7 @@ export class AddonModDataProvider {
// Remove unnecessary not synced actions. // Remove unnecessary not synced actions.
await this.deleteEntryOfflineAction(dataId, entryId, AddonModDataAction.EDIT, siteId); await this.deleteEntryOfflineAction(dataId, entryId, AddonModDataAction.EDIT, siteId);
if (!CoreApp.isOnline() || forceOffline) { if (!CoreNetwork.isOnline() || forceOffline) {
// App is offline, store the action. // App is offline, store the action.
return storeOffline(); return storeOffline();
} }

View File

@ -19,7 +19,7 @@ import { CoreCourse, CoreCourseCommonModWSOptions } from '@features/course/servi
import { CoreCourseModuleData } from '@features/course/services/course-helper'; import { CoreCourseModuleData } from '@features/course/services/course-helper';
import { CanLeave } from '@guards/can-leave'; import { CanLeave } from '@guards/can-leave';
import { IonContent } from '@ionic/angular'; import { IonContent } from '@ionic/angular';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreNavigator } from '@services/navigator'; import { CoreNavigator } from '@services/navigator';
import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites';
import { CoreDomUtils } from '@services/utils/dom'; import { CoreDomUtils } from '@services/utils/dom';
@ -83,7 +83,7 @@ export class AddonModFeedbackFormPage implements OnInit, OnDestroy, CanLeave {
this.onlineObserver = Network.onChange().subscribe(() => { this.onlineObserver = Network.onChange().subscribe(() => {
// Execute the callback in the Angular zone, so change detection doesn't stop working. // Execute the callback in the Angular zone, so change detection doesn't stop working.
NgZone.run(() => { NgZone.run(() => {
this.offline = !CoreApp.isOnline(); this.offline = !CoreNetwork.isOnline();
}); });
}); });
} }
@ -160,7 +160,7 @@ export class AddonModFeedbackFormPage implements OnInit, OnDestroy, CanLeave {
try { try {
this.module = await CoreCourse.getModule(this.cmId, this.courseId, undefined, true, false, this.currentSite.getId()); 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 = { const options = {
cmId: this.cmId, cmId: this.cmId,
readingStrategy: this.offline ? CoreSitesReadingStrategy.PREFER_CACHE : CoreSitesReadingStrategy.ONLY_NETWORK, readingStrategy: this.offline ? CoreSitesReadingStrategy.PREFER_CACHE : CoreSitesReadingStrategy.ONLY_NETWORK,

View File

@ -18,7 +18,7 @@ import { CoreNetworkError } from '@classes/errors/network-error';
import { CoreCourseActivitySyncBaseProvider } from '@features/course/classes/activity-sync'; import { CoreCourseActivitySyncBaseProvider } from '@features/course/classes/activity-sync';
import { CoreCourse, CoreCourseAnyModuleData } from '@features/course/services/course'; import { CoreCourse, CoreCourseAnyModuleData } from '@features/course/services/course';
import { CoreCourseLogHelper } from '@features/course/services/log-helper'; 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 { CoreSites, CoreSitesReadingStrategy } from '@services/sites';
import { CoreSync } from '@services/sync'; import { CoreSync } from '@services/sync';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
@ -174,7 +174,7 @@ export class AddonModFeedbackSyncProvider extends CoreCourseActivitySyncBaseProv
return result; return result;
} }
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
// Cannot sync in offline. // Cannot sync in offline.
throw new CoreNetworkError(); throw new CoreNetworkError();
} }

View File

@ -17,7 +17,7 @@ import { CoreError } from '@classes/errors/error';
import { CoreSite, CoreSiteWSPreSets } from '@classes/site'; import { CoreSite, CoreSiteWSPreSets } from '@classes/site';
import { CoreCourseCommonModWSOptions } from '@features/course/services/course'; import { CoreCourseCommonModWSOptions } from '@features/course/services/course';
import { CoreCourseLogHelper } from '@features/course/services/log-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 { CoreFilepool } from '@services/filepool';
import { CoreSites, CoreSitesCommonWSOptions, CoreSitesReadingStrategy } from '@services/sites'; import { CoreSites, CoreSitesCommonWSOptions, CoreSitesReadingStrategy } from '@services/sites';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
@ -1187,7 +1187,7 @@ export class AddonModFeedbackProvider {
return response; return response;
}; };
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
// App is offline, store the action. // App is offline, store the action.
return storeOffline(); return storeOffline();
} }

View File

@ -14,7 +14,7 @@
import { Component, Input, OnInit } from '@angular/core'; import { Component, Input, OnInit } from '@angular/core';
import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; 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 { AddonModForum, AddonModForumPost } from '@addons/mod/forum/services/forum';
import { PopoverController } from '@singletons'; import { PopoverController } from '@singletons';
import { CoreDomUtils } from '@services/utils/dom'; import { CoreDomUtils } from '@services/utils/dom';
@ -101,7 +101,7 @@ export class AddonModForumPostOptionsMenuComponent implements OnInit {
*/ */
deletePost(): void { deletePost(): void {
if (!this.offlinePost) { if (!this.offlinePost) {
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
CoreDomUtils.showErrorModal(new CoreNetworkError()); CoreDomUtils.showErrorModal(new CoreNetworkError());
return; return;
@ -117,7 +117,7 @@ export class AddonModForumPostOptionsMenuComponent implements OnInit {
* Edit a post. * Edit a post.
*/ */
editPost(): void { editPost(): void {
if (!this.offlinePost && !CoreApp.isOnline()) { if (!this.offlinePost && !CoreNetwork.isOnline()) {
CoreDomUtils.showErrorModal(new CoreNetworkError()); CoreDomUtils.showErrorModal(new CoreNetworkError());
return; return;

View File

@ -24,7 +24,7 @@ import { CoreRatingSyncProvider } from '@features/rating/services/rating-sync';
import { CoreUser } from '@features/user/services/user'; import { CoreUser } from '@features/user/services/user';
import { CanLeave } from '@guards/can-leave'; import { CanLeave } from '@guards/can-leave';
import { IonContent, IonRefresher } from '@ionic/angular'; import { IonContent, IonRefresher } from '@ionic/angular';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreNavigator } from '@services/navigator'; import { CoreNavigator } from '@services/navigator';
import { CoreScreen } from '@services/screen'; import { CoreScreen } from '@services/screen';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
@ -164,12 +164,12 @@ export class AddonModForumDiscussionPage implements OnInit, AfterViewInit, OnDes
return; return;
} }
this.isOnline = CoreApp.isOnline(); this.isOnline = CoreNetwork.isOnline();
this.externalUrl = CoreSites.getCurrentSite()?.createSiteUrl('/mod/forum/discuss.php', { d: this.discussionId.toString() }); this.externalUrl = CoreSites.getCurrentSite()?.createSiteUrl('/mod/forum/discuss.php', { d: this.discussionId.toString() });
this.onlineObserver = Network.onChange().subscribe(() => { this.onlineObserver = Network.onChange().subscribe(() => {
// Execute the callback in the Angular zone, so change detection doesn't stop working. // Execute the callback in the Angular zone, so change detection doesn't stop working.
NgZone.run(() => { NgZone.run(() => {
this.isOnline = CoreApp.isOnline(); this.isOnline = CoreNetwork.isOnline();
}); });
}); });

View File

@ -16,7 +16,7 @@ import { Injectable } from '@angular/core';
import { FileEntry } from '@ionic-native/file/ngx'; import { FileEntry } from '@ionic-native/file/ngx';
import { CoreFileUploader, CoreFileUploaderStoreFilesResult } from '@features/fileuploader/services/fileuploader'; import { CoreFileUploader, CoreFileUploaderStoreFilesResult } from '@features/fileuploader/services/fileuploader';
import { CoreUser } from '@features/user/services/user'; import { CoreUser } from '@features/user/services/user';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreFile } from '@services/file'; import { CoreFile } from '@services/file';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreTimeUtils } from '@services/utils/time'; import { CoreTimeUtils } from '@services/utils/time';
@ -124,7 +124,7 @@ export class AddonModForumHelperProvider {
await AddonModForumOffline.deleteNewDiscussion(forumId, timeCreated, siteId); await AddonModForumOffline.deleteNewDiscussion(forumId, timeCreated, siteId);
} }
if (saveOffline || !CoreApp.isOnline()) { if (saveOffline || !CoreNetwork.isOnline()) {
await storeOffline(); await storeOffline();
return null; return null;

View File

@ -18,7 +18,7 @@ import { CoreCourseActivitySyncBaseProvider } from '@features/course/classes/act
import { CoreCourseLogHelper } from '@features/course/services/log-helper'; import { CoreCourseLogHelper } from '@features/course/services/log-helper';
import { CoreFileUploader } from '@features/fileuploader/services/fileuploader'; import { CoreFileUploader } from '@features/fileuploader/services/fileuploader';
import { CoreRatingSync } from '@features/rating/services/rating-sync'; import { CoreRatingSync } from '@features/rating/services/rating-sync';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreGroups } from '@services/groups'; import { CoreGroups } from '@services/groups';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreSync } from '@services/sync'; import { CoreSync } from '@services/sync';
@ -230,7 +230,7 @@ export class AddonModForumSyncProvider extends CoreCourseActivitySyncBaseProvide
[] as AddonModForumOfflineDiscussion[], [] as AddonModForumOfflineDiscussion[],
); );
if (discussions.length !== 0 && !CoreApp.isOnline()) { if (discussions.length !== 0 && !CoreNetwork.isOnline()) {
throw new Error('cannot sync in offline'); throw new Error('cannot sync in offline');
} }
@ -369,7 +369,7 @@ export class AddonModForumSyncProvider extends CoreCourseActivitySyncBaseProvide
if (!replies.length) { if (!replies.length) {
// Nothing to sync. // Nothing to sync.
return { warnings: [], updated: false }; return { warnings: [], updated: false };
} else if (!CoreApp.isOnline()) { } else if (!CoreNetwork.isOnline()) {
// Cannot sync in offline. // Cannot sync in offline.
return Promise.reject(null); return Promise.reject(null);
} }
@ -458,7 +458,7 @@ export class AddonModForumSyncProvider extends CoreCourseActivitySyncBaseProvide
[] as AddonModForumOfflineReply[], [] as AddonModForumOfflineReply[],
); );
if (replies.length !== 0 && !CoreApp.isOnline()) { if (replies.length !== 0 && !CoreNetwork.isOnline()) {
throw new Error('Cannot sync in offline'); throw new Error('Cannot sync in offline');
} }

View File

@ -20,7 +20,7 @@ import { CoreCourseLogHelper } from '@features/course/services/log-helper';
import { CoreRatingInfo } from '@features/rating/services/rating'; import { CoreRatingInfo } from '@features/rating/services/rating';
import { CoreTagItem } from '@features/tag/services/tag'; import { CoreTagItem } from '@features/tag/services/tag';
import { CoreUser } from '@features/user/services/user'; import { CoreUser } from '@features/user/services/user';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreFileEntry } from '@services/file-helper'; import { CoreFileEntry } from '@services/file-helper';
import { CoreGroups } from '@services/groups'; import { CoreGroups } from '@services/groups';
import { CoreSitesCommonWSOptions, CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreSitesCommonWSOptions, CoreSites, CoreSitesReadingStrategy } from '@services/sites';
@ -756,7 +756,7 @@ export class AddonModForumProvider {
} catch (error) { } catch (error) {
// Try to get the data from cache stored with the old WS method. // Try to get the data from cache stored with the old WS method.
if ( if (
CoreApp.isOnline() || CoreNetwork.isOnline() ||
method !== 'mod_forum_get_forum_discussions' || method !== 'mod_forum_get_forum_discussions' ||
options.sortOrder !== AddonModForumProvider.SORTORDER_LASTPOST_DESC options.sortOrder !== AddonModForumProvider.SORTORDER_LASTPOST_DESC
) { ) {
@ -1065,7 +1065,7 @@ export class AddonModForumProvider {
return false; return false;
}; };
if (!CoreApp.isOnline() && allowOffline) { if (!CoreNetwork.isOnline() && allowOffline) {
// App is offline, store the action. // App is offline, store the action.
return storeOffline(); return storeOffline();
} }

View File

@ -19,7 +19,7 @@ import { CoreNetworkError } from '@classes/errors/network-error';
import { CoreCourseActivitySyncBaseProvider } from '@features/course/classes/activity-sync'; import { CoreCourseActivitySyncBaseProvider } from '@features/course/classes/activity-sync';
import { CoreCourseLogHelper } from '@features/course/services/log-helper'; import { CoreCourseLogHelper } from '@features/course/services/log-helper';
import { CoreRatingSync } from '@features/rating/services/rating-sync'; import { CoreRatingSync } from '@features/rating/services/rating-sync';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreSync } from '@services/sync'; import { CoreSync } from '@services/sync';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
@ -189,7 +189,7 @@ export class AddonModGlossarySyncProvider extends CoreCourseActivitySyncBaseProv
await CoreUtils.ignoreErrors(this.setSyncTime(syncId, siteId)); await CoreUtils.ignoreErrors(this.setSyncTime(syncId, siteId));
return result; return result;
} else if (!CoreApp.isOnline()) { } else if (!CoreNetwork.isOnline()) {
// Cannot sync in offline. // Cannot sync in offline.
throw new CoreNetworkError(); throw new CoreNetworkError();
} }

View File

@ -20,7 +20,7 @@ import { CoreCourseLogHelper } from '@features/course/services/log-helper';
import { CoreFileUploaderStoreFilesResult } from '@features/fileuploader/services/fileuploader'; import { CoreFileUploaderStoreFilesResult } from '@features/fileuploader/services/fileuploader';
import { CoreRatingInfo } from '@features/rating/services/rating'; import { CoreRatingInfo } from '@features/rating/services/rating';
import { CoreTagItem } from '@features/tag/services/tag'; 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 { CoreSites, CoreSitesCommonWSOptions, CoreSitesReadingStrategy } from '@services/sites';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreWSExternalFile, CoreWSExternalWarning } from '@services/ws'; import { CoreWSExternalFile, CoreWSExternalWarning } from '@services/ws';
@ -898,7 +898,7 @@ export class AddonModGlossaryProvider {
return false; return false;
}; };
if (!CoreApp.isOnline() && otherOptions.allowOffline) { if (!CoreNetwork.isOnline() && otherOptions.allowOffline) {
// App is offline, store the action. // App is offline, store the action.
return storeOffline(); return storeOffline();
} }

View File

@ -24,7 +24,7 @@ import { CoreH5PHelper } from '@features/h5p/classes/helper';
import { CoreH5P } from '@features/h5p/services/h5p'; import { CoreH5P } from '@features/h5p/services/h5p';
import { CoreXAPIOffline } from '@features/xapi/services/offline'; import { CoreXAPIOffline } from '@features/xapi/services/offline';
import { CoreXAPI } from '@features/xapi/services/xapi'; import { CoreXAPI } from '@features/xapi/services/xapi';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreFilepool } from '@services/filepool'; import { CoreFilepool } from '@services/filepool';
import { CoreNavigator } from '@services/navigator'; import { CoreNavigator } from '@services/navigator';
import { CoreSites } from '@services/sites'; 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. // Cannot download the file or already downloaded, play the package directly.
this.play(); 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)) { this.deployedFile?.filesize && CoreFilepool.shouldDownload(this.deployedFile.filesize)) {
// Package is small, download it automatically. Don't block this function for this. // Package is small, download it automatically. Don't block this function for this.
this.downloadAutomatically(); this.downloadAutomatically();
@ -280,7 +280,7 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv
return; return;
} }
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
CoreDomUtils.showErrorModal('core.networkerrormsg', true); CoreDomUtils.showErrorModal('core.networkerrormsg', true);
return; return;

View File

@ -19,7 +19,7 @@ import { CoreCourseActivitySyncBaseProvider } from '@features/course/classes/act
import { CoreCourseLogHelper } from '@features/course/services/log-helper'; import { CoreCourseLogHelper } from '@features/course/services/log-helper';
import { CoreXAPIOffline } from '@features/xapi/services/offline'; import { CoreXAPIOffline } from '@features/xapi/services/offline';
import { CoreXAPI } from '@features/xapi/services/xapi'; import { CoreXAPI } from '@features/xapi/services/xapi';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
@ -103,7 +103,7 @@ export class AddonModH5PActivitySyncProvider extends CoreCourseActivitySyncBaseP
syncActivity(contextId: number, siteId?: string): Promise<AddonModH5PActivitySyncResult> { syncActivity(contextId: number, siteId?: string): Promise<AddonModH5PActivitySyncResult> {
siteId = siteId || CoreSites.getCurrentSiteId(); siteId = siteId || CoreSites.getCurrentSiteId();
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
// Cannot sync in offline. // Cannot sync in offline.
throw new CoreNetworkError(); throw new CoreNetworkError();
} }

View File

@ -21,7 +21,7 @@ import { CoreCourse } from '@features/course/services/course';
import { CoreCourseModuleData } from '@features/course/services/course-helper'; import { CoreCourseModuleData } from '@features/course/services/course-helper';
import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate'; import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate';
import { IonRefresher } from '@ionic/angular'; import { IonRefresher } from '@ionic/angular';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreNavigator } from '@services/navigator'; import { CoreNavigator } from '@services/navigator';
import { CoreDomUtils } from '@services/utils/dom'; import { CoreDomUtils } from '@services/utils/dom';
import { CoreTextUtils } from '@services/utils/text'; import { CoreTextUtils } from '@services/utils/text';
@ -189,7 +189,7 @@ export class AddonModImscpViewPage implements OnInit {
if (!module.contents?.length || (refresh && !contentsAlreadyLoaded)) { if (!module.contents?.length || (refresh && !contentsAlreadyLoaded)) {
// Try to load the contents. // Try to load the contents.
const ignoreCache = refresh && CoreApp.isOnline(); const ignoreCache = refresh && CoreNetwork.isOnline();
try { try {
await CoreCourse.loadModuleContents(module, undefined, undefined, false, ignoreCache); await CoreCourse.loadModuleContents(module, undefined, undefined, false, ignoreCache);

View File

@ -18,7 +18,7 @@ import { CoreSite, CoreSiteWSPreSets } from '@classes/site';
import { CoreCourse, CoreCourseModuleContentFile } from '@features/course/services/course'; import { CoreCourse, CoreCourseModuleContentFile } from '@features/course/services/course';
import { CoreCourseModuleData } from '@features/course/services/course-helper'; import { CoreCourseModuleData } from '@features/course/services/course-helper';
import { CoreCourseLogHelper } from '@features/course/services/log-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 { CoreFilepool } from '@services/filepool';
import { CoreSitesCommonWSOptions, CoreSites } from '@services/sites'; import { CoreSitesCommonWSOptions, CoreSites } from '@services/sites';
import { CoreTextUtils } from '@services/utils/text'; import { CoreTextUtils } from '@services/utils/text';
@ -181,7 +181,7 @@ export class AddonModImscpProvider {
return CoreText.concatenatePaths(dirPath, itemHref); return CoreText.concatenatePaths(dirPath, itemHref);
} catch (error) { } catch (error) {
// Error getting directory, there was an error downloading or we're in browser. Return online URL if connected. // 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 contents = await CoreCourse.getModuleContents(module);
const indexUrl = this.getFileUrlFromContents(contents, itemHref); const indexUrl = this.getFileUrlFromContents(contents, itemHref);

View File

@ -18,7 +18,7 @@ import { IonContent } from '@ionic/angular';
import { CoreError } from '@classes/errors/error'; import { CoreError } from '@classes/errors/error';
import { CanLeave } from '@guards/can-leave'; import { CanLeave } from '@guards/can-leave';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreNavigator } from '@services/navigator'; import { CoreNavigator } from '@services/navigator';
import { CoreSites, CoreSitesCommonWSOptions, CoreSitesReadingStrategy } from '@services/sites'; import { CoreSites, CoreSitesCommonWSOptions, CoreSitesReadingStrategy } from '@services/sites';
import { CoreSync } from '@services/sync'; 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. // If lesson has offline data already, use offline mode.
this.offline = await AddonModLessonOffline.hasOfflineData(this.lesson.id); 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. // Lesson doesn't have offline data, but it allows offline and the device is offline. Use offline mode.
this.offline = true; this.offline = true;
} }
@ -375,7 +375,7 @@ export class AddonModLessonPlayerPage implements OnInit, OnDestroy, CanLeave {
protected async finishRetake(outOfTime?: boolean): Promise<void> { protected async finishRetake(outOfTime?: boolean): Promise<void> {
this.messages = []; this.messages = [];
if (this.offline && CoreApp.isOnline()) { if (this.offline && CoreNetwork.isOnline()) {
// Offline mode but the app is online. Try to sync the data. // Offline mode but the app is online. Try to sync the data.
const result = await CoreUtils.ignoreErrors( const result = await CoreUtils.ignoreErrors(
AddonModLessonSync.syncLesson(this.lesson!.id, true, true), AddonModLessonSync.syncLesson(this.lesson!.id, true, true),

View File

@ -19,7 +19,7 @@ import { CoreNetworkError } from '@classes/errors/network-error';
import { CoreCourseActivitySyncBaseProvider } from '@features/course/classes/activity-sync'; import { CoreCourseActivitySyncBaseProvider } from '@features/course/classes/activity-sync';
import { CoreCourse } from '@features/course/services/course'; import { CoreCourse } from '@features/course/services/course';
import { CoreCourseLogHelper } from '@features/course/services/log-helper'; 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 { CoreSites, CoreSitesReadingStrategy } from '@services/sites';
import { CoreSync } from '@services/sync'; import { CoreSync } from '@services/sync';
import { CoreTimeUtils } from '@services/utils/time'; import { CoreTimeUtils } from '@services/utils/time';
@ -275,7 +275,7 @@ export class AddonModLessonSyncProvider extends CoreCourseActivitySyncBaseProvid
if (!attempts.length) { if (!attempts.length) {
return; return;
} else if (!CoreApp.isOnline()) { } else if (!CoreNetwork.isOnline()) {
// Cannot sync in offline. // Cannot sync in offline.
throw new CoreNetworkError(); throw new CoreNetworkError();
} }
@ -420,7 +420,7 @@ export class AddonModLessonSyncProvider extends CoreCourseActivitySyncBaseProvid
await AddonModLessonOffline.deleteRetake(lessonId, siteId); await AddonModLessonOffline.deleteRetake(lessonId, siteId);
return; return;
} else if (!CoreApp.isOnline()) { } else if (!CoreNetwork.isOnline()) {
// Cannot sync in offline. // Cannot sync in offline.
throw new CoreNetworkError(); throw new CoreNetworkError();
} }

View File

@ -21,7 +21,7 @@ import { CoreCourseLogHelper } from '@features/course/services/log-helper';
import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate'; import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate';
import { CoreQuestion, CoreQuestionQuestionParsed } from '@features/question/services/question'; import { CoreQuestion, CoreQuestionQuestionParsed } from '@features/question/services/question';
import { CoreQuestionDelegate } from '@features/question/services/question-delegate'; 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 { CoreSites, CoreSitesReadingStrategy } from '@services/sites';
import { CoreSync } from '@services/sync'; import { CoreSync } from '@services/sync';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
@ -311,7 +311,7 @@ export class AddonModQuizSyncProvider extends CoreCourseActivitySyncBaseProvider
return this.finishSync(siteId, quiz, courseId, warnings); return this.finishSync(siteId, quiz, courseId, warnings);
} }
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
// Cannot sync in offline. // Cannot sync in offline.
throw new CoreError(Translate.instant('core.cannotconnect')); throw new CoreError(Translate.instant('core.cannotconnect'));
} }

View File

@ -20,6 +20,7 @@ import { CoreCourseContentsPage } from '@features/course/pages/contents/contents
import { CoreCourse } from '@features/course/services/course'; import { CoreCourse } from '@features/course/services/course';
import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate'; import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate';
import { CoreApp } from '@services/app'; import { CoreApp } from '@services/app';
import { CoreNetwork } from '@services/network';
import { CoreFileHelper } from '@services/file-helper'; import { CoreFileHelper } from '@services/file-helper';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreDomUtils } from '@services/utils/dom'; import { CoreDomUtils } from '@services/utils/dom';
@ -79,13 +80,13 @@ export class AddonModResourceIndexComponent extends CoreCourseModuleMainResource
super.ngOnInit(); super.ngOnInit();
this.isIOS = CoreApp.isIOS(); this.isIOS = CoreApp.isIOS();
this.isOnline = CoreApp.isOnline(); this.isOnline = CoreNetwork.isOnline();
// Refresh online status when changes. // Refresh online status when changes.
this.onlineObserver = Network.onChange().subscribe(() => { this.onlineObserver = Network.onChange().subscribe(() => {
// Execute the callback in the Angular zone, so change detection doesn't stop working. // Execute the callback in the Angular zone, so change detection doesn't stop working.
NgZone.run(() => { NgZone.run(() => {
this.isOnline = CoreApp.isOnline(); this.isOnline = CoreNetwork.isOnline();
}); });
}); });

View File

@ -17,7 +17,7 @@ import { Injectable } from '@angular/core';
import { CoreError } from '@classes/errors/error'; import { CoreError } from '@classes/errors/error';
import { CoreCourse, CoreCourseAnyModuleData } from '@features/course/services/course'; import { CoreCourse, CoreCourseAnyModuleData } from '@features/course/services/course';
import { CoreCourseHelper, CoreCourseModuleData } from '@features/course/services/course-helper'; 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 { CoreFile } from '@services/file';
import { CoreFileHelper } from '@services/file-helper'; import { CoreFileHelper } from '@services/file-helper';
import { CoreFilepool } from '@services/filepool'; import { CoreFilepool } from '@services/filepool';
@ -80,7 +80,7 @@ export class AddonModResourceHelperProvider {
return CoreText.concatenatePaths(dirPath, mainFilePath); return CoreText.concatenatePaths(dirPath, mainFilePath);
} catch (e) { } catch (e) {
// Error getting directory, there was an error downloading or we're in browser. Return online URL. // 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. // This URL is going to be injected in an iframe, we need this to make it work.
return CoreSites.getRequiredCurrentSite().checkAndFixPluginfileURL(mainFile.fileurl); return CoreSites.getRequiredCurrentSite().checkAndFixPluginfileURL(mainFile.fileurl);
} }

View File

@ -17,7 +17,7 @@ import { CoreNetworkError } from '@classes/errors/network-error';
import { CoreCourseActivitySyncBaseProvider } from '@features/course/classes/activity-sync'; import { CoreCourseActivitySyncBaseProvider } from '@features/course/classes/activity-sync';
import { CoreCourse } from '@features/course/services/course'; import { CoreCourse } from '@features/course/services/course';
import { CoreCourseLogHelper } from '@features/course/services/log-helper'; import { CoreCourseLogHelper } from '@features/course/services/log-helper';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
@ -168,7 +168,7 @@ export class AddonModSurveySyncProvider extends CoreCourseActivitySyncBaseProvid
} }
if (answersNumber > 0 && data) { if (answersNumber > 0 && data) {
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
// Cannot sync in offline. // Cannot sync in offline.
throw new CoreNetworkError(); throw new CoreNetworkError();
} }

View File

@ -17,7 +17,7 @@ import { CoreError } from '@classes/errors/error';
import { CoreSite, CoreSiteWSPreSets } from '@classes/site'; import { CoreSite, CoreSiteWSPreSets } from '@classes/site';
import { CoreCourseCommonModWSOptions } from '@features/course/services/course'; import { CoreCourseCommonModWSOptions } from '@features/course/services/course';
import { CoreCourseLogHelper } from '@features/course/services/log-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 { CoreFilepool } from '@services/filepool';
import { CoreSites, CoreSitesCommonWSOptions } from '@services/sites'; import { CoreSites, CoreSitesCommonWSOptions } from '@services/sites';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
@ -257,7 +257,7 @@ export class AddonModSurveyProvider {
siteId = siteId || CoreSites.getCurrentSiteId(); siteId = siteId || CoreSites.getCurrentSiteId();
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
// App is offline, store the message. // App is offline, store the message.
return storeOffline(); return storeOffline();
} }

View File

@ -21,7 +21,7 @@ import { CoreCourse } from '@features/course/services/course';
import { CoreTag, CoreTagItem } from '@features/tag/services/tag'; import { CoreTag, CoreTagItem } from '@features/tag/services/tag';
import { CoreUser } from '@features/user/services/user'; import { CoreUser } from '@features/user/services/user';
import { IonContent } from '@ionic/angular'; import { IonContent } from '@ionic/angular';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreGroup, CoreGroups } from '@services/groups'; import { CoreGroup, CoreGroups } from '@services/groups';
import { CoreNavigator } from '@services/navigator'; import { CoreNavigator } from '@services/navigator';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
@ -116,13 +116,13 @@ export class AddonModWikiIndexComponent extends CoreCourseModuleMainActivityComp
) { ) {
super('AddonModLessonIndexComponent', content, courseContentsPage); super('AddonModLessonIndexComponent', content, courseContentsPage);
this.isOnline = CoreApp.isOnline(); this.isOnline = CoreNetwork.isOnline();
// Refresh online status when changes. // Refresh online status when changes.
this.onlineSubscription = Network.onChange().subscribe(() => { this.onlineSubscription = Network.onChange().subscribe(() => {
// Execute the callback in the Angular zone, so change detection doesn't stop working. // Execute the callback in the Angular zone, so change detection doesn't stop working.
NgZone.run(() => { NgZone.run(() => {
this.isOnline = CoreApp.isOnline(); this.isOnline = CoreNetwork.isOnline();
}); });
}); });
} }

View File

@ -16,7 +16,7 @@ import { Injectable } from '@angular/core';
import { CoreSyncBaseProvider, CoreSyncBlockedError } from '@classes/base-sync'; import { CoreSyncBaseProvider, CoreSyncBlockedError } from '@classes/base-sync';
import { CoreNetworkError } from '@classes/errors/network-error'; import { CoreNetworkError } from '@classes/errors/network-error';
import { CoreCourseLogHelper } from '@features/course/services/log-helper'; import { CoreCourseLogHelper } from '@features/course/services/log-helper';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreGroups } from '@services/groups'; import { CoreGroups } from '@services/groups';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreSync } from '@services/sync'; import { CoreSync } from '@services/sync';
@ -224,7 +224,7 @@ export class AddonModWikiSyncProvider extends CoreSyncBaseProvider<AddonModWikiS
return result; return result;
} }
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
// Cannot sync in offline. // Cannot sync in offline.
throw new CoreNetworkError(); throw new CoreNetworkError();
} }

View File

@ -18,7 +18,7 @@ import { CoreSite, CoreSiteWSPreSets } from '@classes/site';
import { CoreCourseCommonModWSOptions } from '@features/course/services/course'; import { CoreCourseCommonModWSOptions } from '@features/course/services/course';
import { CoreCourseLogHelper } from '@features/course/services/log-helper'; import { CoreCourseLogHelper } from '@features/course/services/log-helper';
import { CoreTagItem } from '@features/tag/services/tag'; import { CoreTagItem } from '@features/tag/services/tag';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreNavigator } from '@services/navigator'; import { CoreNavigator } from '@services/navigator';
import { CoreSites, CoreSitesCommonWSOptions, CoreSitesReadingStrategy } from '@services/sites'; import { CoreSites, CoreSitesCommonWSOptions, CoreSitesReadingStrategy } from '@services/sites';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
@ -706,7 +706,7 @@ export class AddonModWikiProvider {
return -1; return -1;
}; };
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
// App is offline, store the action. // App is offline, store the action.
return storeOffline(); return storeOffline();
} }

View File

@ -17,7 +17,7 @@ import { CoreSyncBaseProvider, CoreSyncBlockedError } from '@classes/base-sync';
import { CoreNetworkError } from '@classes/errors/network-error'; import { CoreNetworkError } from '@classes/errors/network-error';
import { CoreCourseLogHelper } from '@features/course/services/log-helper'; import { CoreCourseLogHelper } from '@features/course/services/log-helper';
import { CoreFileUploaderStoreFilesResult } from '@features/fileuploader/services/fileuploader'; import { CoreFileUploaderStoreFilesResult } from '@features/fileuploader/services/fileuploader';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreFileEntry } from '@services/file-helper'; import { CoreFileEntry } from '@services/file-helper';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreSync } from '@services/sync'; import { CoreSync } from '@services/sync';
@ -195,7 +195,7 @@ export class AddonModWorkshopSyncProvider extends CoreSyncBaseProvider<AddonModW
return result; return result;
} }
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
// Cannot sync in offline. // Cannot sync in offline.
throw new CoreNetworkError(); throw new CoreNetworkError();
} }

View File

@ -18,7 +18,7 @@ import { CoreSite, CoreSiteWSPreSets } from '@classes/site';
import { CoreCourseCommonModWSOptions } from '@features/course/services/course'; import { CoreCourseCommonModWSOptions } from '@features/course/services/course';
import { CoreCourseLogHelper } from '@features/course/services/log-helper'; import { CoreCourseLogHelper } from '@features/course/services/log-helper';
import { CoreGradesMenuItem } from '@features/grades/services/grades-helper'; import { CoreGradesMenuItem } from '@features/grades/services/grades-helper';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreSites, CoreSitesCommonWSOptions, CoreSitesReadingStrategy } from '@services/sites'; import { CoreSites, CoreSitesCommonWSOptions, CoreSitesReadingStrategy } from '@services/sites';
import { CoreTextFormat, defaultTextFormat } from '@services/utils/text'; import { CoreTextFormat, defaultTextFormat } from '@services/utils/text';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
@ -729,7 +729,7 @@ export class AddonModWorkshopProvider {
// If we are editing an offline submission, discard previous first. // If we are editing an offline submission, discard previous first.
await AddonModWorkshopOffline.deleteSubmissionAction(workshopId, AddonModWorkshopAction.ADD, siteId); await AddonModWorkshopOffline.deleteSubmissionAction(workshopId, AddonModWorkshopAction.ADD, siteId);
if (!CoreApp.isOnline() && allowOffline) { if (!CoreNetwork.isOnline() && allowOffline) {
// App is offline, store the action. // App is offline, store the action.
return storeOffline(); return storeOffline();
} }
@ -825,7 +825,7 @@ export class AddonModWorkshopProvider {
// If we are editing an offline discussion, discard previous first. // If we are editing an offline discussion, discard previous first.
await AddonModWorkshopOffline.deleteSubmissionAction(workshopId, AddonModWorkshopAction.UPDATE, siteId); await AddonModWorkshopOffline.deleteSubmissionAction(workshopId, AddonModWorkshopAction.UPDATE, siteId);
if (!CoreApp.isOnline() && allowOffline) { if (!CoreNetwork.isOnline() && allowOffline) {
// App is offline, store the action. // App is offline, store the action.
return storeOffline(); return storeOffline();
} }
@ -904,7 +904,7 @@ export class AddonModWorkshopProvider {
// If we are editing an offline discussion, discard previous first. // If we are editing an offline discussion, discard previous first.
await AddonModWorkshopOffline.deleteSubmissionAction(workshopId, AddonModWorkshopAction.DELETE, siteId); await AddonModWorkshopOffline.deleteSubmissionAction(workshopId, AddonModWorkshopAction.DELETE, siteId);
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
// App is offline, store the action. // App is offline, store the action.
return storeOffline(); return storeOffline();
} }
@ -1173,7 +1173,7 @@ export class AddonModWorkshopProvider {
// If we are editing an offline discussion, discard previous first. // If we are editing an offline discussion, discard previous first.
await AddonModWorkshopOffline.deleteAssessment(workshopId, assessmentId, siteId); await AddonModWorkshopOffline.deleteAssessment(workshopId, assessmentId, siteId);
if (!CoreApp.isOnline() && allowOffline) { if (!CoreNetwork.isOnline() && allowOffline) {
// App is offline, store the action. // App is offline, store the action.
return storeOffline(); return storeOffline();
} }
@ -1251,7 +1251,7 @@ export class AddonModWorkshopProvider {
// If we are editing an offline discussion, discard previous first. // If we are editing an offline discussion, discard previous first.
await AddonModWorkshopOffline.deleteEvaluateSubmission(workshopId, submissionId, siteId); await AddonModWorkshopOffline.deleteEvaluateSubmission(workshopId, submissionId, siteId);
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
// App is offline, store the action. // App is offline, store the action.
return storeOffline(); return storeOffline();
} }
@ -1342,7 +1342,7 @@ export class AddonModWorkshopProvider {
// If we are editing an offline discussion, discard previous first. // If we are editing an offline discussion, discard previous first.
await AddonModWorkshopOffline.deleteEvaluateAssessment(workshopId, assessmentId, siteId); await AddonModWorkshopOffline.deleteEvaluateAssessment(workshopId, assessmentId, siteId);
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
// App is offline, store the action. // App is offline, store the action.
return storeOffline(); return storeOffline();
} }

View File

@ -16,7 +16,7 @@ import { Injectable } from '@angular/core';
import { CoreSyncBaseProvider } from '@classes/base-sync'; import { CoreSyncBaseProvider } from '@classes/base-sync';
import { CoreNetworkError } from '@classes/errors/network-error'; import { CoreNetworkError } from '@classes/errors/network-error';
import { CoreCourses } from '@features/courses/services/courses'; import { CoreCourses } from '@features/courses/services/courses';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { Translate, makeSingleton } from '@singletons'; import { Translate, makeSingleton } from '@singletons';
@ -148,7 +148,7 @@ export class AddonNotesSyncProvider extends CoreSyncBaseProvider<AddonNotesSyncR
return result; return result;
} }
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
// Cannot sync in offline. // Cannot sync in offline.
throw new CoreNetworkError(); throw new CoreNetworkError();
} }

View File

@ -17,7 +17,7 @@ import { CoreWSError } from '@classes/errors/wserror';
import { CoreSite, CoreSiteWSPreSets } from '@classes/site'; import { CoreSite, CoreSiteWSPreSets } from '@classes/site';
import { CorePushNotifications } from '@features/pushnotifications/services/pushnotifications'; import { CorePushNotifications } from '@features/pushnotifications/services/pushnotifications';
import { CoreUser } from '@features/user/services/user'; import { CoreUser } from '@features/user/services/user';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreWSExternalWarning } from '@services/ws'; import { CoreWSExternalWarning } from '@services/ws';
@ -58,7 +58,7 @@ export class AddonNotesProvider {
return false; return false;
}; };
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
// App is offline, store the note. // App is offline, store the note.
return storeOffline(); return storeOffline();
} }
@ -161,7 +161,7 @@ export class AddonNotesProvider {
return false; return false;
}; };
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
// App is offline, store the note. // App is offline, store the note.
return storeOffline(); return storeOffline();
} }

View File

@ -16,7 +16,7 @@ import { Component, OnDestroy, OnInit } from '@angular/core';
import { IonRefresher } from '@ionic/angular'; import { IonRefresher } from '@ionic/angular';
import { Md5 } from 'ts-md5/dist/md5'; import { Md5 } from 'ts-md5/dist/md5';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreDomUtils } from '@services/utils/dom'; import { CoreDomUtils } from '@services/utils/dom';
import { CoreTextUtils } from '@services/utils/text'; import { CoreTextUtils } from '@services/utils/text';
@ -154,7 +154,7 @@ export class AddonPrivateFilesIndexPage implements OnInit, OnDestroy {
* Upload a new file. * Upload a new file.
*/ */
async uploadFile(): Promise<void> { async uploadFile(): Promise<void> {
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
CoreDomUtils.showErrorModal('core.fileuploader.errormustbeonlinetoupload', true); CoreDomUtils.showErrorModal('core.fileuploader.errormustbeonlinetoupload', true);
return; return;

View File

@ -32,6 +32,7 @@ import { CoreConstants } from '@/core/constants';
import { CoreSitePlugins } from '@features/siteplugins/services/siteplugins'; import { CoreSitePlugins } from '@features/siteplugins/services/siteplugins';
import { CoreDomUtils } from '@services/utils/dom'; import { CoreDomUtils } from '@services/utils/dom';
import { CoreDom } from '@singletons/dom'; import { CoreDom } from '@singletons/dom';
import { CoreNetwork } from '@services/network';
const MOODLE_VERSION_PREFIX = 'version-'; const MOODLE_VERSION_PREFIX = 'version-';
const MOODLEAPP_VERSION_PREFIX = 'moodleapp-'; const MOODLEAPP_VERSION_PREFIX = 'moodleapp-';
@ -310,7 +311,7 @@ export class AppComponent implements OnInit, AfterViewInit {
Network.onChange().subscribe(() => { Network.onChange().subscribe(() => {
// Execute the callback in the Angular zone, so change detection doesn't stop working. // Execute the callback in the Angular zone, so change detection doesn't stop working.
NgZone.run(() => { NgZone.run(() => {
const isOnline = CoreApp.isOnline(); const isOnline = CoreNetwork.isOnline();
const hadOfflineMessage = document.body.classList.contains('core-offline'); const hadOfflineMessage = document.body.classList.contains('core-offline');
document.body.classList.toggle('core-offline', !isOnline); 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); document.body.classList.toggle('core-offline', !isOnline);
// Set StatusBar properties. // Set StatusBar properties.

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreSync } from '@services/sync'; import { CoreSync } from '@services/sync';
import { CoreTextUtils } from '@services/utils/text'; import { CoreTextUtils } from '@services/utils/text';
@ -272,7 +272,7 @@ export class CoreSyncBaseProvider<T = void> {
* @return Resolved with siteIds selected. Rejected if offline. * @return Resolved with siteIds selected. Rejected if offline.
*/ */
async syncOnSites(syncFunctionLog: string, syncFunction: (siteId: string) => void, siteId?: string): Promise<void> { async syncOnSites(syncFunctionLog: string, syncFunction: (siteId: string) => void, siteId?: string): Promise<void> {
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
const message = `Cannot sync '${syncFunctionLog}' because device is offline.`; const message = `Cannot sync '${syncFunctionLog}' because device is offline.`;
this.logger.debug(message); this.logger.debug(message);

View File

@ -16,6 +16,7 @@ import { InAppBrowserObject, InAppBrowserOptions } from '@ionic-native/in-app-br
import { Md5 } from 'ts-md5/dist/md5'; import { Md5 } from 'ts-md5/dist/md5';
import { CoreApp } from '@services/app'; import { CoreApp } from '@services/app';
import { CoreNetwork } from '@services/network';
import { CoreDB } from '@services/db'; import { CoreDB } from '@services/db';
import { CoreEvents } from '@singletons/events'; import { CoreEvents } from '@singletons/events';
import { CoreFile } from '@services/file'; import { CoreFile } from '@services/file';
@ -537,7 +538,7 @@ export class CoreSite {
const initialToken = this.token || ''; const initialToken = this.token || '';
data = data || {}; data = data || {};
if (!CoreApp.isOnline() && this.offlineDisabled) { if (!CoreNetwork.isOnline() && this.offlineDisabled) {
throw new CoreError(Translate.instant('core.errorofflinedisabled')); throw new CoreError(Translate.instant('core.errorofflinedisabled'));
} }
@ -995,7 +996,7 @@ export class CoreSite {
const now = Date.now(); const now = Date.now();
let expirationTime: number | undefined; let expirationTime: number | undefined;
preSets.omitExpires = preSets.omitExpires || preSets.forceOffline || !CoreApp.isOnline(); preSets.omitExpires = preSets.omitExpires || preSets.forceOffline || !CoreNetwork.isOnline();
if (!preSets.omitExpires) { if (!preSets.omitExpires) {
expirationTime = entry.expirationTime + this.getExpirationDelay(preSets.updateFrequency); expirationTime = entry.expirationTime + this.getExpirationDelay(preSets.updateFrequency);
@ -1987,7 +1988,7 @@ export class CoreSite {
updateFrequency = updateFrequency || CoreSite.FREQUENCY_USUALLY; updateFrequency = updateFrequency || CoreSite.FREQUENCY_USUALLY;
let expirationDelay = this.UPDATE_FREQUENCIES[updateFrequency] || this.UPDATE_FREQUENCIES[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. // Not WiFi, increase the expiration delay a 50% to decrease the data usage in this case.
expirationDelay *= 1.5; expirationDelay *= 1.5;
} }
@ -2011,7 +2012,7 @@ export class CoreSite {
} else if (this.tokenPluginFileWorksPromise) { } else if (this.tokenPluginFileWorksPromise) {
// Check ongoing, use the same promise. // Check ongoing, use the same promise.
return this.tokenPluginFileWorksPromise; 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. // Not online, cannot check it. Assume it's working, but don't save the result.
return Promise.resolve(true); return Promise.resolve(true);
} }

View File

@ -19,7 +19,7 @@ import { CoreFileUploader, CoreFileUploaderTypeList } from '@features/fileupload
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreTextUtils } from '@services/utils/text'; import { CoreTextUtils } from '@services/utils/text';
import { Translate } from '@singletons'; import { Translate } from '@singletons';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreDomUtils } from '@services/utils/dom'; import { CoreDomUtils } from '@services/utils/dom';
import { CoreFileUploaderHelper } from '@features/fileuploader/services/fileuploader-helper'; import { CoreFileUploaderHelper } from '@features/fileuploader/services/fileuploader-helper';
import { CoreFileEntry } from '@services/file-helper'; import { CoreFileEntry } from '@services/file-helper';
@ -132,7 +132,7 @@ export class CoreAttachmentsComponent implements OnInit {
async add(): Promise<void> { async add(): Promise<void> {
const allowOffline = !!this.allowOffline && this.allowOffline !== 'false'; const allowOffline = !!this.allowOffline && this.allowOffline !== 'false';
if (!allowOffline && !CoreApp.isOnline()) { if (!allowOffline && !CoreNetwork.isOnline()) {
CoreDomUtils.showErrorModal('core.fileuploader.errormustbeonlinetoupload', true); CoreDomUtils.showErrorModal('core.fileuploader.errormustbeonlinetoupload', true);
return; return;

View File

@ -14,6 +14,7 @@
import { Component, Input, Output, OnInit, OnDestroy, EventEmitter } from '@angular/core'; import { Component, Input, Output, OnInit, OnDestroy, EventEmitter } from '@angular/core';
import { CoreApp } from '@services/app'; import { CoreApp } from '@services/app';
import { CoreNetwork } from '@services/network';
import { CoreFilepool } from '@services/filepool'; import { CoreFilepool } from '@services/filepool';
import { CoreFileHelper } from '@services/file-helper'; import { CoreFileHelper } from '@services/file-helper';
import { CorePluginFileDelegate } from '@services/plugin-file-delegate'; import { CorePluginFileDelegate } from '@services/plugin-file-delegate';
@ -197,7 +198,7 @@ export class CoreFileComponent implements OnInit, OnDestroy {
return; return;
} }
if (!CoreApp.isOnline() && (!openAfterDownload || (openAfterDownload && if (!CoreNetwork.isOnline() && (!openAfterDownload || (openAfterDownload &&
!CoreFileHelper.isStateDownloaded(this.state)))) { !CoreFileHelper.isStateDownloaded(this.state)))) {
CoreDomUtils.showErrorModal('core.networkerrormsg', true); CoreDomUtils.showErrorModal('core.networkerrormsg', true);

View File

@ -14,12 +14,12 @@
import { Component, Input, OnInit, OnChanges, OnDestroy, SimpleChange } from '@angular/core'; import { Component, Input, OnInit, OnChanges, OnDestroy, SimpleChange } from '@angular/core';
import { CoreApp } from '@services/app';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { CoreEventObserver, CoreEvents } from '@singletons/events';
import { CoreUserProvider, CoreUserBasicData } from '@features/user/services/user'; import { CoreUserProvider, CoreUserBasicData } from '@features/user/services/user';
import { CoreNavigator } from '@services/navigator'; import { CoreNavigator } from '@services/navigator';
import { CoreNetwork } from '@services/network';
/** /**
* Component to display a "user avatar". * Component to display a "user avatar".
@ -119,7 +119,7 @@ export class CoreUserAvatarComponent implements OnInit, OnChanges, OnDestroy {
return this.user.lastaccess * 1000 >= time; return this.user.lastaccess * 1000 >= time;
} else { } else {
// You have to have Internet access first. // You have to have Internet access first.
return !!this.user.isonline && CoreApp.isOnline(); return !!this.user.isonline && CoreNetwork.isOnline();
} }
} }

View File

@ -34,6 +34,7 @@ import { CoreError } from '@classes/errors/error';
import { CoreSite } from '@classes/site'; import { CoreSite } from '@classes/site';
import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { CoreEventObserver, CoreEvents } from '@singletons/events';
import { CoreConstants } from '../constants'; import { CoreConstants } from '../constants';
import { CoreNetwork } from '@services/network';
/** /**
* Directive to handle external content. * Directive to handle external content.
@ -427,7 +428,7 @@ export class CoreExternalContentDirective implements AfterViewInit, OnChanges, O
clickableEl.addEventListener(eventName, () => { clickableEl.addEventListener(eventName, () => {
// User played media or opened a downloadable link. // User played media or opened a downloadable link.
// Download the file if in wifi and it hasn't been downloaded already (for big files). // 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. // 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); CoreFilepool.getUrlByUrl(site.getId(), url, this.component, this.componentId, 0, false);
} }

View File

@ -40,6 +40,7 @@ import { CoreCommentsOffline } from '@features/comments/services/comments-offlin
import { CoreCommentsDBRecord } from '@features/comments/services/database/comments'; import { CoreCommentsDBRecord } from '@features/comments/services/database/comments';
import { CoreTimeUtils } from '@services/utils/time'; import { CoreTimeUtils } from '@services/utils/time';
import { CoreApp } from '@services/app'; import { CoreApp } from '@services/app';
import { CoreNetwork } from '@services/network';
import moment from 'moment'; import moment from 'moment';
import { Subscription } from 'rxjs'; import { Subscription } from 'rxjs';
@ -108,11 +109,11 @@ export class CoreCommentsViewerPage implements OnInit, OnDestroy {
} }
}, CoreSites.getCurrentSiteId()); }, CoreSites.getCurrentSiteId());
this.isOnline = CoreApp.isOnline(); this.isOnline = CoreNetwork.isOnline();
this.onlineObserver = Network.onChange().subscribe(() => { this.onlineObserver = Network.onChange().subscribe(() => {
// Execute the callback in the Angular zone, so change detection doesn't stop working. // Execute the callback in the Angular zone, so change detection doesn't stop working.
NgZone.run(() => { NgZone.run(() => {
this.isOnline = CoreApp.isOnline(); this.isOnline = CoreNetwork.isOnline();
}); });
}); });
} }

View File

@ -19,7 +19,7 @@ import { CoreEvents } from '@singletons/events';
import { makeSingleton, Translate } from '@singletons'; import { makeSingleton, Translate } from '@singletons';
import { CoreCommentsOffline } from './comments-offline'; import { CoreCommentsOffline } from './comments-offline';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreNetworkError } from '@classes/errors/network-error'; import { CoreNetworkError } from '@classes/errors/network-error';
import { CoreCommentsDBRecord, CoreCommentsDeletedDBRecord } from './database/comments'; import { CoreCommentsDBRecord, CoreCommentsDeletedDBRecord } from './database/comments';
@ -204,7 +204,7 @@ export class CoreCommentsSyncProvider extends CoreSyncBaseProvider<CoreCommentsS
return result; return result;
} }
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
// Cannot sync in offline. // Cannot sync in offline.
throw new CoreNetworkError(); throw new CoreNetworkError();
} }

View File

@ -15,7 +15,7 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { CoreError } from '@classes/errors/error'; import { CoreError } from '@classes/errors/error';
import { CoreSite, CoreSiteWSPreSets } from '@classes/site'; import { CoreSite, CoreSiteWSPreSets } from '@classes/site';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreWSExternalWarning } from '@services/ws'; import { CoreWSExternalWarning } from '@services/ws';
@ -95,7 +95,7 @@ export class CoreCommentsProvider {
return false; return false;
}; };
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
// App is offline, store the comment. // App is offline, store the comment.
return storeOffline(); return storeOffline();
} }
@ -243,7 +243,7 @@ export class CoreCommentsProvider {
return false; return false;
}; };
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
// App is offline, store the comment. // App is offline, store the comment.
return storeOffline(); return storeOffline();
} }

View File

@ -15,7 +15,7 @@
import { CoreConstants } from '@/core/constants'; import { CoreConstants } from '@/core/constants';
import { CoreNetworkError } from '@classes/errors/network-error'; import { CoreNetworkError } from '@classes/errors/network-error';
import { CoreFilterHelper } from '@features/filter/services/filter-helper'; import { CoreFilterHelper } from '@features/filter/services/filter-helper';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreFilepool } from '@services/filepool'; import { CoreFilepool } from '@services/filepool';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreCourse, CoreCourseAnyModuleData } from '../services/course'; import { CoreCourse, CoreCourseAnyModuleData } from '../services/course';
@ -84,7 +84,7 @@ export class CoreCourseActivityPrefetchHandlerBase extends CoreCourseModulePrefe
): Promise<void> { ): Promise<void> {
siteId = siteId || CoreSites.getCurrentSiteId(); siteId = siteId || CoreSites.getCurrentSiteId();
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
// Cannot prefetch in offline. // Cannot prefetch in offline.
throw new CoreNetworkError(); throw new CoreNetworkError();
} }

View File

@ -16,7 +16,7 @@ import { CoreConstants } from '@/core/constants';
import { OnInit, OnDestroy, Input, Output, EventEmitter, Component, Optional, Inject } from '@angular/core'; import { OnInit, OnDestroy, Input, Output, EventEmitter, Component, Optional, Inject } from '@angular/core';
import { CoreAnyError } from '@classes/errors/error'; import { CoreAnyError } from '@classes/errors/error';
import { IonRefresher } from '@ionic/angular'; import { IonRefresher } from '@ionic/angular';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreDomUtils } from '@services/utils/dom'; import { CoreDomUtils } from '@services/utils/dom';
@ -354,7 +354,7 @@ export class CoreCourseModuleMainResourceComponent implements OnInit, OnDestroy,
if (!this.module.contents?.length || (refresh && !contentsAlreadyLoaded)) { if (!this.module.contents?.length || (refresh && !contentsAlreadyLoaded)) {
// Try to load the contents. // Try to load the contents.
const ignoreCache = refresh && CoreApp.isOnline(); const ignoreCache = refresh && CoreNetwork.isOnline();
try { try {
await CoreCourse.loadModuleContents(this.module, undefined, undefined, false, ignoreCache); await CoreCourse.loadModuleContents(this.module, undefined, undefined, false, ignoreCache);

View File

@ -14,7 +14,7 @@
import { CoreNetworkError } from '@classes/errors/network-error'; import { CoreNetworkError } from '@classes/errors/network-error';
import { CoreFilterHelper } from '@features/filter/services/filter-helper'; import { CoreFilterHelper } from '@features/filter/services/filter-helper';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreFilepool } from '@services/filepool'; import { CoreFilepool } from '@services/filepool';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreWSFile } from '@services/ws'; import { CoreWSFile } from '@services/ws';
@ -57,7 +57,7 @@ export class CoreCourseResourcePrefetchHandlerBase extends CoreCourseModulePrefe
* @return Promise resolved when all content is downloaded. * @return Promise resolved when all content is downloaded.
*/ */
async downloadOrPrefetch(module: CoreCourseModuleData, courseId: number, prefetch?: boolean, dirPath?: string): Promise<void> { async downloadOrPrefetch(module: CoreCourseModuleData, courseId: number, prefetch?: boolean, dirPath?: string): Promise<void> {
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
// Cannot download in offline. // Cannot download in offline.
throw new CoreNetworkError(); throw new CoreNetworkError();
} }

View File

@ -23,7 +23,7 @@ import { CoreCourseModuleDelegate } from '@features/course/services/module-deleg
import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate'; import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate';
import { CoreCourses, CoreEnrolledCourseData } from '@features/courses/services/courses'; import { CoreCourses, CoreEnrolledCourseData } from '@features/courses/services/courses';
import { CoreGradesFormattedRow, CoreGradesFormattedTableRow, CoreGradesHelper } from '@features/grades/services/grades-helper'; 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 { CoreFilepool } from '@services/filepool';
import { CoreNavigator } from '@services/navigator'; import { CoreNavigator } from '@services/navigator';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
@ -79,13 +79,13 @@ export class CoreCourseModuleSummaryComponent implements OnInit, OnDestroy {
constructor() { constructor() {
this.siteId = CoreSites.getCurrentSiteId(); this.siteId = CoreSites.getCurrentSiteId();
this.isOnline = CoreApp.isOnline(); this.isOnline = CoreNetwork.isOnline();
// Refresh online status when changes. // Refresh online status when changes.
this.onlineSubscription = Network.onChange().subscribe(() => { this.onlineSubscription = Network.onChange().subscribe(() => {
// Execute the callback in the Angular zone, so change detection doesn't stop working. // Execute the callback in the Angular zone, so change detection doesn't stop working.
NgZone.run(() => { NgZone.run(() => {
this.isOnline = CoreApp.isOnline(); this.isOnline = CoreNetwork.isOnline();
}); });
}); });
} }

View File

@ -58,7 +58,7 @@ import {
} from './module-prefetch-delegate'; } from './module-prefetch-delegate';
import { CoreFileSizeSum } from '@services/plugin-file-delegate'; import { CoreFileSizeSum } from '@services/plugin-file-delegate';
import { CoreFileHelper } from '@services/file-helper'; import { CoreFileHelper } from '@services/file-helper';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreSite } from '@classes/site'; import { CoreSite } from '@classes/site';
import { CoreFile } from '@services/file'; import { CoreFile } from '@services/file';
import { CoreUrlUtils } from '@services/utils/url'; import { CoreUrlUtils } from '@services/utils/url';
@ -798,7 +798,7 @@ export class CoreCourseHelperProvider {
files?: CoreCourseModuleContentFile[], files?: CoreCourseModuleContentFile[],
options: CoreUtilsOpenFileOptions = {}, options: CoreUtilsOpenFileOptions = {},
): Promise<void> { ): Promise<void> {
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
// Not online, get the offline file. It will fail if not found. // Not online, get the offline file. It will fail if not found.
let path: string | undefined; let path: string | undefined;
try { try {
@ -950,7 +950,7 @@ export class CoreCourseHelperProvider {
): Promise<string> { ): Promise<string> {
siteId = siteId || CoreSites.getCurrentSiteId(); siteId = siteId || CoreSites.getCurrentSiteId();
const isOnline = CoreApp.isOnline(); const isOnline = CoreNetwork.isOnline();
const mainFile = files[0]; const mainFile = files[0];
const timemodified = mainFile.timemodified || 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. // 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); this.downloadModule(module, courseId, component, componentId, files, siteId);
} }

View File

@ -15,7 +15,7 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Params } from '@angular/router'; import { Params } from '@angular/router';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreEvents } from '@singletons/events'; import { CoreEvents } from '@singletons/events';
import { CoreLogger } from '@singletons/logger'; import { CoreLogger } from '@singletons/logger';
import { CoreSitesCommonWSOptions, CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreSitesCommonWSOptions, CoreSites, CoreSitesReadingStrategy } from '@services/sites';
@ -554,7 +554,7 @@ export class CoreCourseProvider {
return sections; return sections;
} catch { } catch {
// The module might still be cached by a request with different parameters. // The module might still be cached by a request with different parameters.
if (!ignoreCache && !CoreApp.isOnline()) { if (!ignoreCache && !CoreNetwork.isOnline()) {
if (includeStealth) { if (includeStealth) {
// Older versions didn't include the includestealthmodules option. // Older versions didn't include the includestealthmodules option.
return doRequest(site, courseId, moduleId, modName, false, true); return doRequest(site, courseId, moduleId, modName, false, true);
@ -1168,7 +1168,7 @@ export class CoreCourseProvider {
CoreCourseOffline.markCompletedManually(cmId, completed, courseId, undefined, siteId); CoreCourseOffline.markCompletedManually(cmId, completed, courseId, undefined, siteId);
// The offline function requires a courseId and it could be missing because it's a calculated field. // 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. // App is offline, store the action.
return storeOffline(); return storeOffline();
} }

View File

@ -14,7 +14,7 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreTextUtils } from '@services/utils/text'; import { CoreTextUtils } from '@services/utils/text';
import { CoreTimeUtils } from '@services/utils/time'; import { CoreTimeUtils } from '@services/utils/time';
@ -134,7 +134,7 @@ export class CoreCourseLogHelperProvider {
async log(ws: string, data: Record<string, unknown>, component: string, componentId: number, siteId?: string): Promise<void> { async log(ws: string, data: Record<string, unknown>, component: string, componentId: number, siteId?: string): Promise<void> {
const site = await CoreSites.getSite(siteId); const site = await CoreSites.getSite(siteId);
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
// App is offline, store the action. // App is offline, store the action.
return this.storeOffline(ws, data, component, componentId, site.getId()); return this.storeOffline(ws, data, component, componentId, site.getId());
} }

View File

@ -17,7 +17,7 @@ import { Injectable } from '@angular/core';
import { CoreSyncBaseProvider } from '@classes/base-sync'; import { CoreSyncBaseProvider } from '@classes/base-sync';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreTextUtils } from '@services/utils/text'; import { CoreTextUtils } from '@services/utils/text';
import { CoreCourseOffline } from './course-offline'; import { CoreCourseOffline } from './course-offline';
@ -167,7 +167,7 @@ export class CoreCourseSyncProvider extends CoreSyncBaseProvider<CoreCourseSyncR
return result; return result;
} }
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
// Cannot sync in offline. // Cannot sync in offline.
throw new CoreNetworkError(); throw new CoreNetworkError();
} }

View File

@ -20,6 +20,7 @@ import { FileEntry, IFile } from '@ionic-native/file/ngx';
import { MediaFile } from '@ionic-native/media-capture/ngx'; import { MediaFile } from '@ionic-native/media-capture/ngx';
import { CoreApp } from '@services/app'; import { CoreApp } from '@services/app';
import { CoreNetwork } from '@services/network';
import { CoreFile, CoreFileProvider, CoreFileProgressEvent } from '@services/file'; import { CoreFile, CoreFileProvider, CoreFileProgressEvent } from '@services/file';
import { CoreDomUtils } from '@services/utils/dom'; import { CoreDomUtils } from '@services/utils/dom';
import { CoreMimetypeUtils } from '@services/utils/mimetype'; import { CoreMimetypeUtils } from '@services/utils/mimetype';
@ -122,7 +123,7 @@ export class CoreFileUploaderHelperProvider {
return; return;
} }
if (!allowOffline && !CoreApp.isOnline()) { if (!allowOffline && !CoreNetwork.isOnline()) {
throw new CoreError(Translate.instant('core.fileuploader.errormustbeonlinetoupload')); throw new CoreError(Translate.instant('core.fileuploader.errormustbeonlinetoupload'));
} }
@ -132,7 +133,7 @@ export class CoreFileUploaderHelperProvider {
if (size < 0) { if (size < 0) {
return CoreDomUtils.showConfirm(Translate.instant('core.fileuploader.confirmuploadunknownsize')); return CoreDomUtils.showConfirm(Translate.instant('core.fileuploader.confirmuploadunknownsize'));
} else if (size >= wifiThreshold || (CoreApp.isNetworkAccessLimited() && size >= limitedThreshold)) { } else if (size >= wifiThreshold || (CoreNetwork.isNetworkAccessLimited() && size >= limitedThreshold)) {
const readableSize = CoreTextUtils.bytesToSize(size, 2); const readableSize = CoreTextUtils.bytesToSize(size, 2);
return CoreDomUtils.showConfirm( return CoreDomUtils.showConfirm(
@ -365,7 +366,7 @@ export class CoreFileUploaderHelperProvider {
return false; return false;
} }
if (!allowOffline && !CoreApp.isOnline()) { if (!allowOffline && !CoreNetwork.isOnline()) {
// Not allowed, show error. // Not allowed, show error.
CoreDomUtils.showErrorModal('core.fileuploader.errormustbeonlinetoupload', true); CoreDomUtils.showErrorModal('core.fileuploader.errormustbeonlinetoupload', true);
@ -796,7 +797,7 @@ export class CoreFileUploaderHelperProvider {
return this.uploadFile(path, maxSize, checkSize, options, siteId); return this.uploadFile(path, maxSize, checkSize, options, siteId);
}; };
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
return errorUploading(Translate.instant('core.fileuploader.errormustbeonlinetoupload')); return errorUploading(Translate.instant('core.fileuploader.errormustbeonlinetoupload'));
} }

View File

@ -14,7 +14,7 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreFilterDelegate } from './filter-delegate'; import { CoreFilterDelegate } from './filter-delegate';
import { import {
@ -299,7 +299,7 @@ export class CoreFilterHelperProvider {
const cachedData = this.moduleContextsCache[siteId][courseId][contextLevel]; 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. // We can use cache, return the filters if found.
return cachedData.contexts[contextLevel] && cachedData.contexts[contextLevel][instanceId]; return cachedData.contexts[contextLevel] && cachedData.contexts[contextLevel][instanceId];
} }

View File

@ -14,7 +14,7 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreSite } from '@classes/site'; import { CoreSite } from '@classes/site';
import { CoreWSExternalWarning } from '@services/ws'; import { CoreWSExternalWarning } from '@services/ws';
@ -338,7 +338,7 @@ export class CoreFilterProvider {
// Check if we have the contexts in the memory cache. // Check if we have the contexts in the memory cache.
const siteContexts = this.contextsCache[site.getId()]; const siteContexts = this.contextsCache[site.getId()];
const isOnline = CoreApp.isOnline(); const isOnline = CoreNetwork.isOnline();
const result: CoreFilterClassifiedFilters = {}; const result: CoreFilterClassifiedFilters = {};
let allFound = true; let allFound = true;

View File

@ -14,7 +14,7 @@
import { Component, Input, ElementRef, OnInit, OnDestroy, OnChanges, SimpleChange } from '@angular/core'; 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 { CoreFilepool } from '@services/filepool';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreDomUtils } from '@services/utils/dom'; import { CoreDomUtils } from '@services/utils/dom';
@ -111,7 +111,7 @@ export class CoreH5PPlayerComponent implements OnInit, OnChanges, OnDestroy {
* @return Promise resolved when done. * @return Promise resolved when done.
*/ */
async download(): Promise<void> { async download(): Promise<void> {
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
CoreDomUtils.showErrorModal('core.networkerrormsg', true); CoreDomUtils.showErrorModal('core.networkerrormsg', true);
return; return;
@ -144,7 +144,7 @@ export class CoreH5PPlayerComponent implements OnInit, OnChanges, OnDestroy {
*/ */
protected async attemptDownloadInBg(): Promise<void> { protected async attemptDownloadInBg(): Promise<void> {
if (!this.urlParams || !this.src || !this.siteCanDownload || !CoreH5P.canGetTrustedH5PFileInSite() || if (!this.urlParams || !this.src || !this.siteCanDownload || !CoreH5P.canGetTrustedH5PFileInSite() ||
!CoreApp.isOnline()) { !CoreNetwork.isOnline()) {
return; return;
} }

View File

@ -18,6 +18,7 @@ import { Subscription } from 'rxjs';
import { debounceTime } from 'rxjs/operators'; import { debounceTime } from 'rxjs/operators';
import { CoreApp } from '@services/app'; import { CoreApp } from '@services/app';
import { CoreNetwork } from '@services/network';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreDomUtils } from '@services/utils/dom'; import { CoreDomUtils } from '@services/utils/dom';
import { CoreLoginHelper } from '@features/login/services/login-helper'; import { CoreLoginHelper } from '@features/login/services/login-helper';
@ -244,7 +245,7 @@ export class CoreLoginCredentialsPage implements OnInit, OnDestroy {
return; return;
} }
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
CoreDomUtils.showErrorModal('core.networkerrormsg', true); CoreDomUtils.showErrorModal('core.networkerrormsg', true);
return; return;

View File

@ -16,6 +16,7 @@ import { Component, OnInit, OnDestroy, ViewChild, ElementRef } from '@angular/co
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { CoreApp } from '@services/app'; import { CoreApp } from '@services/app';
import { CoreNetwork } from '@services/network';
import { CoreSites, CoreSitesReadingStrategy } from '@services/sites'; import { CoreSites, CoreSitesReadingStrategy } from '@services/sites';
import { CoreDomUtils } from '@services/utils/dom'; import { CoreDomUtils } from '@services/utils/dom';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
@ -201,7 +202,7 @@ export class CoreLoginReconnectPage implements OnInit, OnDestroy {
return; return;
} }
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
CoreDomUtils.showErrorModal('core.networkerrormsg', true); CoreDomUtils.showErrorModal('core.networkerrormsg', true);
return; return;

View File

@ -16,6 +16,7 @@ import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
import { FormBuilder, FormGroup, ValidatorFn, AbstractControl, ValidationErrors } from '@angular/forms'; import { FormBuilder, FormGroup, ValidatorFn, AbstractControl, ValidationErrors } from '@angular/forms';
import { CoreApp } from '@services/app'; import { CoreApp } from '@services/app';
import { CoreNetwork } from '@services/network';
import { CoreConfig } from '@services/config'; import { CoreConfig } from '@services/config';
import { CoreSites, CoreSiteCheckResponse, CoreLoginSiteInfo, CoreSitesDemoSiteData } from '@services/sites'; import { CoreSites, CoreSiteCheckResponse, CoreLoginSiteInfo, CoreSitesDemoSiteData } from '@services/sites';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
@ -242,7 +243,7 @@ export class CoreLoginSitePage implements OnInit {
return; return;
} }
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
CoreDomUtils.showErrorModal('core.networkerrormsg', true); CoreDomUtils.showErrorModal('core.networkerrormsg', true);
return; return;

View File

@ -16,7 +16,7 @@ import { ContextLevel } from '@/core/constants';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { CoreSyncBaseProvider } from '@classes/base-sync'; import { CoreSyncBaseProvider } from '@classes/base-sync';
import { CoreNetworkError } from '@classes/errors/network-error'; import { CoreNetworkError } from '@classes/errors/network-error';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreTextUtils } from '@services/utils/text'; import { CoreTextUtils } from '@services/utils/text';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
@ -202,7 +202,7 @@ export class CoreRatingSyncProvider extends CoreSyncBaseProvider<CoreRatingSyncI
// Nothing to sync. // Nothing to sync.
return result; return result;
} }
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
// Cannot sync in offline. // Cannot sync in offline.
throw new CoreNetworkError(); throw new CoreNetworkError();
} }

View File

@ -16,7 +16,7 @@ import { ContextLevel } from '@/core/constants';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { CoreSiteWSPreSets, CoreSite } from '@classes/site'; import { CoreSiteWSPreSets, CoreSite } from '@classes/site';
import { CoreUser } from '@features/user/services/user'; import { CoreUser } from '@features/user/services/user';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreWSExternalWarning } from '@services/ws'; import { CoreWSExternalWarning } from '@services/ws';
@ -114,7 +114,7 @@ export class CoreRatingProvider {
}, siteId); }, siteId);
}; };
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
// App is offline, store the action. // App is offline, store the action.
return storeOffline(); return storeOffline();
} }

View File

@ -27,6 +27,7 @@ import { CoreConfig } from '@services/config';
import { CoreDomUtils } from '@services/utils/dom'; import { CoreDomUtils } from '@services/utils/dom';
import { CoreNavigator } from '@services/navigator'; import { CoreNavigator } from '@services/navigator';
import { CorePlatform } from '@services/platform'; import { CorePlatform } from '@services/platform';
import { CoreNetwork } from '@services/network';
/** /**
* Device Info to be shown and copied to clipboard. * Device Info to be shown and copied to clipboard.
@ -92,8 +93,8 @@ export class CoreSettingsDeviceInfoPage implements OnDestroy {
versionCode: CoreConstants.CONFIG.versioncode, versionCode: CoreConstants.CONFIG.versioncode,
compilationTime: CoreConstants.BUILD.compilationTime || 0, compilationTime: CoreConstants.BUILD.compilationTime || 0,
lastCommit: CoreConstants.BUILD.lastCommitHash || '', lastCommit: CoreConstants.BUILD.lastCommitHash || '',
networkStatus: appProvider.isOnline() ? 'online' : 'offline', networkStatus: CoreNetwork.isOnline() ? 'online' : 'offline',
wifiConnection: appProvider.isWifi() ? 'yes' : 'no', wifiConnection: CoreNetwork.isWifi() ? 'yes' : 'no',
localNotifAvailable: CoreLocalNotifications.isAvailable() ? 'yes' : 'no', localNotifAvailable: CoreLocalNotifications.isAvailable() ? 'yes' : 'no',
pushId: CorePushNotifications.getPushId(), pushId: CorePushNotifications.getPushId(),
deviceType: '', deviceType: '',
@ -179,7 +180,7 @@ export class CoreSettingsDeviceInfoPage implements OnDestroy {
this.onlineObserver = Network.onChange().subscribe(() => { this.onlineObserver = Network.onChange().subscribe(() => {
// Execute the callback in the Angular zone, so change detection doesn't stop working. // Execute the callback in the Angular zone, so change detection doesn't stop working.
NgZone.run(() => { NgZone.run(() => {
this.deviceInfo.networkStatus = appProvider.isOnline() ? 'online' : 'offline'; this.deviceInfo.networkStatus = CoreNetwork.isOnline() ? 'online' : 'offline';
}); });
}); });

View File

@ -14,6 +14,7 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { CoreApp } from '@services/app'; import { CoreApp } from '@services/app';
import { CoreNetwork } from '@services/network';
import { CoreCronDelegate } from '@services/cron'; import { CoreCronDelegate } from '@services/cron';
import { CoreEvents } from '@singletons/events'; import { CoreEvents } from '@singletons/events';
import { CoreFilepool } from '@services/filepool'; import { CoreFilepool } from '@services/filepool';
@ -262,10 +263,10 @@ export class CoreSettingsHelperProvider {
if (site.isLoggedOut()) { if (site.isLoggedOut()) {
// Cannot sync logged out sites. // Cannot sync logged out sites.
throw new CoreError(Translate.instant('core.settings.cannotsyncloggedout')); throw new CoreError(Translate.instant('core.settings.cannotsyncloggedout'));
} else if (hasSyncHandlers && !CoreApp.isOnline()) { } else if (hasSyncHandlers && !CoreNetwork.isOnline()) {
// We need connection to execute sync. // We need connection to execute sync.
throw new CoreError(Translate.instant('core.settings.cannotsyncoffline')); 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')); throw new CoreError(Translate.instant('core.settings.cannotsyncwithoutwifi'));
} }

View File

@ -14,7 +14,7 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreFilepool } from '@services/filepool'; import { CoreFilepool } from '@services/filepool';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
@ -401,7 +401,7 @@ export class CoreUserProvider {
const preference = await CoreUtils.ignoreErrors(CoreUserOffline.getPreference(name, siteId)); const preference = await CoreUtils.ignoreErrors(CoreUserOffline.getPreference(name, siteId));
if (preference && !CoreApp.isOnline()) { if (preference && !CoreNetwork.isOnline()) {
// Offline, return stored value. // Offline, return stored value.
return preference.value; return preference.value;
} }
@ -760,7 +760,7 @@ export class CoreUserProvider {
async setUserPreference(name: string, value: string, siteId?: string): Promise<void> { async setUserPreference(name: string, value: string, siteId?: string): Promise<void> {
siteId = siteId || CoreSites.getCurrentSiteId(); siteId = siteId || CoreSites.getCurrentSiteId();
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
// Offline, just update the preference. // Offline, just update the preference.
return CoreUserOffline.setPreference(name, value); return CoreUserOffline.setPreference(name, value);
} }

View File

@ -14,7 +14,7 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { CoreApp } from '@services/app'; import { CoreNetwork } from '@services/network';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreSite } from '@classes/site'; import { CoreSite } from '@classes/site';
@ -94,7 +94,7 @@ export class CoreXAPIProvider {
return false; return false;
}; };
if (!CoreApp.isOnline() || options.offline) { if (!CoreNetwork.isOnline() || options.offline) {
// App is offline, store the action. // App is offline, store the action.
return storeOffline(); return storeOffline();
} }

View File

@ -18,7 +18,7 @@ import { CoreDB } from '@services/db';
import { CoreEvents } from '@singletons/events'; import { CoreEvents } from '@singletons/events';
import { SQLiteDB, SQLiteDBTableSchema } from '@classes/sqlitedb'; 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 { CoreLogger } from '@singletons/logger';
import { CoreColors } from '@singletons/colors'; import { CoreColors } from '@singletons/colors';
import { DBNAME, SCHEMA_VERSIONS_TABLE_NAME, SCHEMA_VERSIONS_TABLE_SCHEMA, SchemaVersionsDBEntry } from '@services/database/app'; 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 { CorePromisedValue } from '@classes/promised-value';
import { Subscription } from 'rxjs'; import { Subscription } from 'rxjs';
import { CorePlatform } from '@services/platform'; import { CorePlatform } from '@services/platform';
import { CoreNetwork } from '@services/network';
/** /**
* Factory to provide some global functionalities, like access to the global app database. * Factory to provide some global functionalities, like access to the global app database.
@ -53,7 +54,6 @@ export class CoreAppProvider {
protected isKeyboardShown = false; protected isKeyboardShown = false;
protected keyboardOpening = false; protected keyboardOpening = false;
protected keyboardClosing = false; protected keyboardClosing = false;
protected forceOffline = false;
protected redirect?: CoreRedirectData; protected redirect?: CoreRedirectData;
protected schemaVersionsTable = asyncInstance<CoreDatabaseTable<SchemaVersionsDBEntry, 'name'>>(); protected schemaVersionsTable = asyncInstance<CoreDatabaseTable<SchemaVersionsDBEntry, 'name'>>();
@ -329,54 +329,30 @@ export class CoreAppProvider {
* Returns whether we are online. * Returns whether we are online.
* *
* @return Whether the app is online. * @return Whether the app is online.
* @deprecated since 4.1.0. Use CoreNetwork instead.
*/ */
isOnline(): boolean { isOnline(): boolean {
if (this.forceOffline) { return CoreNetwork.isOnline();
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;
} }
/** /**
* Check if device uses a limited connection. * Check if device uses a limited connection.
* *
* @return Whether the device uses a limited connection. * @return Whether the device uses a limited connection.
* @deprecated since 4.1.0. Use CoreNetwork instead.
*/ */
isNetworkAccessLimited(): boolean { isNetworkAccessLimited(): boolean {
if (!this.isMobile()) { return CoreNetwork.isNetworkAccessLimited();
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. * Check if device uses a wifi connection.
* *
* @return Whether the device uses a wifi connection. * @return Whether the device uses a wifi connection.
* @deprecated since 4.1.0. Use CoreNetwork instead.
*/ */
isWifi(): boolean { 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. * Set value of forceOffline flag. If true, the app will think the device is offline.
* *
* @param value Value to set. * @param value Value to set.
* @deprecated since 4.1.0. Use CoreNetwork instead.
*/ */
setForceOffline(value: boolean): void { setForceOffline(value: boolean): void {
this.forceOffline = !!value; CoreNetwork.setForceOffline(value);
} }
/** /**

View File

@ -15,6 +15,7 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { CoreApp } from '@services/app'; import { CoreApp } from '@services/app';
import { CoreNetwork } from '@services/network';
import { CoreConfig } from '@services/config'; import { CoreConfig } from '@services/config';
import { CoreUtils } from '@services/utils/utils'; import { CoreUtils } from '@services/utils/utils';
import { CoreConstants } from '@/core/constants'; import { CoreConstants } from '@/core/constants';
@ -89,7 +90,7 @@ export class CoreCronDelegateService {
const usesNetwork = this.handlerUsesNetwork(name); const usesNetwork = this.handlerUsesNetwork(name);
const isSync = !force && this.isHandlerSync(name); const isSync = !force && this.isHandlerSync(name);
if (usesNetwork && !CoreApp.isOnline()) { if (usesNetwork && !CoreNetwork.isOnline()) {
// Offline, stop executing. // Offline, stop executing.
const message = `Cannot execute handler because device is offline: ${name}`; const message = `Cannot execute handler because device is offline: ${name}`;
this.logger.debug(message); this.logger.debug(message);
@ -102,7 +103,7 @@ export class CoreCronDelegateService {
// Check network connection. // Check network connection.
const syncOnlyOnWifi = await CoreConfig.get(CoreConstants.SETTINGS_SYNC_ONLY_ON_WIFI, false); 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. // Cannot execute in this network connection, retry soon.
const message = `Cannot execute handler because device is using limited connection: ${name}`; const message = `Cannot execute handler because device is using limited connection: ${name}`;
this.logger.debug(message); this.logger.debug(message);

View File

@ -16,6 +16,7 @@ import { Injectable } from '@angular/core';
import { FileEntry } from '@ionic-native/file/ngx'; import { FileEntry } from '@ionic-native/file/ngx';
import { CoreApp } from '@services/app'; import { CoreApp } from '@services/app';
import { CoreNetwork } from '@services/network';
import { CoreFile } from '@services/file'; import { CoreFile } from '@services/file';
import { CoreFilepool } from '@services/filepool'; import { CoreFilepool } from '@services/filepool';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
@ -167,8 +168,8 @@ export class CoreFileHelperProvider {
} }
// The file system is available. // The file system is available.
const isWifi = CoreApp.isWifi(); const isWifi = CoreNetwork.isWifi();
const isOnline = CoreApp.isOnline(); const isOnline = CoreNetwork.isOnline();
if (state == CoreConstants.DOWNLOADED) { if (state == CoreConstants.DOWNLOADED) {
// File is downloaded, get the local file URL. // File is downloaded, get the local file URL.

View File

@ -16,6 +16,7 @@ import { Injectable } from '@angular/core';
import { Md5 } from 'ts-md5/dist/md5'; import { Md5 } from 'ts-md5/dist/md5';
import { CoreApp } from '@services/app'; import { CoreApp } from '@services/app';
import { CoreNetwork } from '@services/network';
import { CoreEventPackageStatusChanged, CoreEvents } from '@singletons/events'; import { CoreEventPackageStatusChanged, CoreEvents } from '@singletons/events';
import { CoreFile } from '@services/file'; import { CoreFile } from '@services/file';
import { CorePluginFileDelegate } from '@services/plugin-file-delegate'; import { CorePluginFileDelegate } from '@services/plugin-file-delegate';
@ -506,7 +507,7 @@ export class CoreFilepoolProvider {
if (this.sizeCache[fileUrl] !== undefined) { if (this.sizeCache[fileUrl] !== undefined) {
size = this.sizeCache[fileUrl]; size = this.sizeCache[fileUrl];
} else { } else {
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
// Cannot check size in offline, stop. // Cannot check size in offline, stop.
throw new CoreError(Translate.instant('core.cannotconnect')); throw new CoreError(Translate.instant('core.cannotconnect'));
} }
@ -515,7 +516,7 @@ export class CoreFilepoolProvider {
} }
// Calculate the size of the file. // Calculate the size of the file.
const isWifi = CoreApp.isWifi(); const isWifi = CoreNetwork.isWifi();
const sizeUnknown = size <= 0; const sizeUnknown = size <= 0;
if (!sizeUnknown) { if (!sizeUnknown) {
@ -550,7 +551,7 @@ export class CoreFilepoolProvider {
* is not accessible. Also, this will have no effect if the queue is already running. * is not accessible. Also, this will have no effect if the queue is already running.
*/ */
protected checkQueueProcessing(): void { protected checkQueueProcessing(): void {
if (!CoreFile.isAvailable() || !CoreApp.isOnline()) { if (!CoreFile.isAvailable() || !CoreNetwork.isOnline()) {
this.queueState = CoreFilepoolProvider.QUEUE_PAUSED; this.queueState = CoreFilepoolProvider.QUEUE_PAUSED;
return; return;
@ -1053,7 +1054,7 @@ export class CoreFilepoolProvider {
if (!fileObject || if (!fileObject ||
this.isFileOutdated(fileObject, options.revision, options.timemodified) && this.isFileOutdated(fileObject, options.revision, options.timemodified) &&
CoreApp.isOnline() && CoreNetwork.isOnline() &&
!ignoreStale !ignoreStale
) { ) {
throw new CoreError('Needs to be downloaded'); throw new CoreError('Needs to be downloaded');
@ -1597,7 +1598,7 @@ export class CoreFilepoolProvider {
throw new CoreError('File not downloaded.'); 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'); throw new CoreError('File is outdated');
} }
} catch (error) { } catch (error) {
@ -2497,7 +2498,7 @@ export class CoreFilepoolProvider {
if (this.queueState !== CoreFilepoolProvider.QUEUE_RUNNING) { if (this.queueState !== CoreFilepoolProvider.QUEUE_RUNNING) {
// Silently ignore, the queue is on pause. // Silently ignore, the queue is on pause.
throw CoreFilepoolProvider.ERR_QUEUE_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; throw CoreFilepoolProvider.ERR_FS_OR_NETWORK_UNAVAILABLE;
} }
@ -2817,7 +2818,7 @@ export class CoreFilepoolProvider {
*/ */
shouldDownload(size: number): boolean { shouldDownload(size: number): boolean {
return size <= CoreFilepoolProvider.DOWNLOAD_THRESHOLD || return size <= CoreFilepoolProvider.DOWNLOAD_THRESHOLD ||
(CoreApp.isWifi() && size <= CoreFilepoolProvider.WIFI_DOWNLOAD_THRESHOLD); (CoreNetwork.isWifi() && size <= CoreFilepoolProvider.WIFI_DOWNLOAD_THRESHOLD);
} }
/** /**

View File

@ -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);

View File

@ -60,6 +60,7 @@ import { CoreDatabaseConfiguration, CoreDatabaseTable } from '@classes/database/
import { CoreDatabaseCachingStrategy, CoreDatabaseTableProxy } from '@classes/database/database-table-proxy'; import { CoreDatabaseCachingStrategy, CoreDatabaseTableProxy } from '@classes/database/database-table-proxy';
import { asyncInstance, AsyncInstance } from '../utils/async-instance'; import { asyncInstance, AsyncInstance } from '../utils/async-instance';
import { CoreConfig } from './config'; import { CoreConfig } from './config';
import { CoreNetwork } from '@services/network';
export const CORE_SITE_SCHEMAS = new InjectionToken<CoreSiteSchema[]>('CORE_SITE_SCHEMAS'); export const CORE_SITE_SCHEMAS = new InjectionToken<CoreSiteSchema[]>('CORE_SITE_SCHEMAS');
export const CORE_SITE_CURRENT_SITE_ID_CONFIG = 'current_site_id'; export const CORE_SITE_CURRENT_SITE_ID_CONFIG = 'current_site_id';
@ -216,7 +217,7 @@ export class CoreSitesProvider {
if (!CoreUrlUtils.isHttpURL(siteUrl)) { if (!CoreUrlUtils.isHttpURL(siteUrl)) {
throw new CoreError(Translate.instant('core.login.invalidsite')); throw new CoreError(Translate.instant('core.login.invalidsite'));
} else if (!CoreApp.isOnline()) { } else if (!CoreNetwork.isOnline()) {
throw new CoreNetworkError(); throw new CoreNetworkError();
} }
@ -429,7 +430,7 @@ export class CoreSitesProvider {
service?: string, service?: string,
retry?: boolean, retry?: boolean,
): Promise<CoreSiteUserTokenResponse> { ): Promise<CoreSiteUserTokenResponse> {
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
throw new CoreNetworkError(); throw new CoreNetworkError();
} }

View File

@ -54,6 +54,7 @@ import { filter } from 'rxjs/operators';
import { Subscription } from 'rxjs'; import { Subscription } from 'rxjs';
import { CoreComponentsRegistry } from '@singletons/components-registry'; import { CoreComponentsRegistry } from '@singletons/components-registry';
import { CoreDom } from '@singletons/dom'; import { CoreDom } from '@singletons/dom';
import { CoreNetwork } from '@services/network';
/* /*
* "Utils" service with helper functions for UI, DOM elements and HTML code. * "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; limitedThreshold = limitedThreshold === undefined ? CoreConstants.DOWNLOAD_THRESHOLD : limitedThreshold;
let wifiPrefix = ''; let wifiPrefix = '';
if (CoreApp.isNetworkAccessLimited()) { if (CoreNetwork.isNetworkAccessLimited()) {
wifiPrefix = Translate.instant('core.course.confirmlimiteddownload'); wifiPrefix = Translate.instant('core.course.confirmlimiteddownload');
} }
@ -194,7 +195,7 @@ export class CoreDomUtilsProvider {
), ),
); );
} else if (alwaysConfirm || size.size >= wifiThreshold || } 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'); message = message || (size.size === 0 ? 'core.course.confirmdownloadzerosize' : 'core.course.confirmdownload');
return this.showConfirm( return this.showConfirm(

View File

@ -17,6 +17,7 @@ import { WKUserScriptWindow } from 'cordova-plugin-wkuserscript';
import { WKWebViewCookiesWindow } from 'cordova-plugin-wkwebview-cookies'; import { WKWebViewCookiesWindow } from 'cordova-plugin-wkwebview-cookies';
import { CoreApp } from '@services/app'; import { CoreApp } from '@services/app';
import { CoreNetwork } from '@services/network';
import { CoreFile } from '@services/file'; import { CoreFile } from '@services/file';
import { CoreFileHelper } from '@services/file-helper'; import { CoreFileHelper } from '@services/file-helper';
import { CoreSites } from '@services/sites'; import { CoreSites } from '@services/sites';
@ -65,7 +66,7 @@ export class CoreIframeUtilsProvider {
checkOnlineFrameInOffline(element: CoreFrameElement, isSubframe?: boolean): boolean { checkOnlineFrameInOffline(element: CoreFrameElement, isSubframe?: boolean): boolean {
const src = 'src' in element ? element.src : element.data; 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')) { if (element.classList.contains('core-iframe-offline-disabled')) {
// Iframe already hidden, stop. // Iframe already hidden, stop.
return true; return true;

View File

@ -22,7 +22,7 @@ import { Observable } from 'rxjs';
import { timeout } from 'rxjs/operators'; import { timeout } from 'rxjs/operators';
import { CoreNativeToAngularHttpResponse } from '@classes/native-to-angular-http'; 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 { CoreFile, CoreFileFormat } from '@services/file';
import { CoreMimetypeUtils } from '@services/utils/mimetype'; import { CoreMimetypeUtils } from '@services/utils/mimetype';
import { CoreTextErrorObject, CoreTextUtils } from '@services/utils/text'; import { CoreTextErrorObject, CoreTextUtils } from '@services/utils/text';
@ -96,7 +96,7 @@ export class CoreWSProvider {
call<T = unknown>(method: string, data: Record<string, unknown>, preSets: CoreWSPreSets): Promise<T> { call<T = unknown>(method: string, data: Record<string, unknown>, preSets: CoreWSPreSets): Promise<T> {
if (!preSets) { if (!preSets) {
throw new CoreError(Translate.instant('core.unexpectederror')); throw new CoreError(Translate.instant('core.unexpectederror'));
} else if (!CoreApp.isOnline()) { } else if (!CoreNetwork.isOnline()) {
throw new CoreNetworkError(); throw new CoreNetworkError();
} }
@ -254,7 +254,7 @@ export class CoreWSProvider {
): Promise<CoreWSDownloadedFileEntry> { ): Promise<CoreWSDownloadedFileEntry> {
this.logger.debug('Downloading file', url, path, addExtension); this.logger.debug('Downloading file', url, path, addExtension);
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
throw new CoreNetworkError(); throw new CoreNetworkError();
} }
@ -388,7 +388,7 @@ export class CoreWSProvider {
* @return Timeout in ms. * @return Timeout in ms.
*/ */
getRequestTimeout(): number { 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) { if (preSets.siteUrl === undefined) {
throw new CoreAjaxError(Translate.instant('core.unexpectederror')); throw new CoreAjaxError(Translate.instant('core.unexpectederror'));
} else if (!CoreApp.isOnline()) { } else if (!CoreNetwork.isOnline()) {
throw new CoreAjaxError(Translate.instant('core.networkerrormsg')); throw new CoreAjaxError(Translate.instant('core.networkerrormsg'));
} }
@ -789,7 +789,7 @@ export class CoreWSProvider {
syncCall<T = unknown>(method: string, data: any, preSets: CoreWSPreSets): T { syncCall<T = unknown>(method: string, data: any, preSets: CoreWSPreSets): T {
if (!preSets) { if (!preSets) {
throw new CoreError(Translate.instant('core.unexpectederror')); throw new CoreError(Translate.instant('core.unexpectederror'));
} else if (!CoreApp.isOnline()) { } else if (!CoreNetwork.isOnline()) {
throw new CoreNetworkError(); throw new CoreNetworkError();
} }
@ -873,7 +873,7 @@ export class CoreWSProvider {
throw new CoreError('Invalid options passed to upload file.'); throw new CoreError('Invalid options passed to upload file.');
} }
if (!CoreApp.isOnline()) { if (!CoreNetwork.isOnline()) {
throw new CoreNetworkError(); throw new CoreNetworkError();
} }