Merge pull request #4263 from dpalou/MOBILE-4670

MOBILE-4670 h5p: Auto hide offline error if back online
main
Pau Ferrer Ocaña 2024-12-12 11:02:21 +01:00 committed by GitHub
commit 22736e33fd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 4 deletions

View File

@ -107,6 +107,7 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv
protected messageListenerFunction: (event: MessageEvent) => Promise<void>; protected messageListenerFunction: (event: MessageEvent) => Promise<void>;
protected checkCompletionAfterLog = false; // It's called later, when the user plays the package. protected checkCompletionAfterLog = false; // It's called later, when the user plays the package.
protected onlineObserver: Subscription; protected onlineObserver: Subscription;
protected offlineErrorAlert: HTMLIonAlertElement | null = null;
constructor( constructor(
protected content?: IonContent, protected content?: IonContent,
@ -133,15 +134,23 @@ export class AddonModH5PActivityIndexComponent extends CoreCourseModuleMainActiv
/** /**
* React to a network status change. * React to a network status change.
*/ */
protected networkChanged(): void { protected async networkChanged(): Promise<void> {
const wasOnline = this.isOnline; const wasOnline = this.isOnline;
this.isOnline = CoreNetwork.isOnline(); this.isOnline = CoreNetwork.isOnline();
if (this.isOnline && this.offlineErrorAlert) {
// Back online, dismiss the offline error alert.
this.offlineErrorAlert.dismiss();
this.offlineErrorAlert = null;
}
if (this.playing && !this.fileUrl && !this.isOnline && wasOnline && this.trackComponent) { if (this.playing && !this.fileUrl && !this.isOnline && wasOnline && this.trackComponent) {
// User lost connection while playing an online package with tracking. Show an error. // User lost connection while playing an online package with tracking. Show an error.
CoreDomUtils.showErrorModal(new CoreError(Translate.instant('core.course.changesofflinemaybelost'), { this.offlineErrorAlert = await CoreDomUtils.showErrorModal(
title: Translate.instant('core.youreoffline'), new CoreError(Translate.instant('core.course.changesofflinemaybelost'), {
})); title: Translate.instant('core.youreoffline'),
}),
);
return; return;
} }