MOBILE-3686 courses: Fix permanency of download options setting

main
Pau Ferrer Ocaña 2021-10-14 11:02:03 +02:00
parent 577aa3168f
commit e789d26280
8 changed files with 171 additions and 69 deletions

View File

@ -18,7 +18,7 @@ import { IonContent, IonRefresher } from '@ionic/angular';
import { CoreSites } from '@services/sites'; import { CoreSites } 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';
import { CoreCourses, CoreCourseAnyCourseData } from '@features/courses/services/courses'; import { CoreCourses, CoreCourseAnyCourseData, CoreCoursesProvider } from '@features/courses/services/courses';
import { import {
CoreCourse, CoreCourse,
CoreCourseCompletionActivityStatus, CoreCourseCompletionActivityStatus,
@ -78,14 +78,34 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy {
protected formatOptions?: Record<string, unknown>; protected formatOptions?: Record<string, unknown>;
protected completionObserver?: CoreEventObserver; protected completionObserver?: CoreEventObserver;
protected courseStatusObserver?: CoreEventObserver; protected courseStatusObserver?: CoreEventObserver;
protected siteUpdatedObserver?: CoreEventObserver;
protected downloadEnabledObserver?: CoreEventObserver;
protected syncObserver?: CoreEventObserver; protected syncObserver?: CoreEventObserver;
protected isDestroyed = false; protected isDestroyed = false;
protected modulesHaveCompletion = false; protected modulesHaveCompletion = false;
protected isGuest?: boolean; protected isGuest?: boolean;
protected debouncedUpdateCachedCompletion?: () => void; // Update the cached completion after a certain time. protected debouncedUpdateCachedCompletion?: () => void; // Update the cached completion after a certain time.
constructor() {
// Refresh the enabled flags if site is updated.
this.siteUpdatedObserver = CoreEvents.on(CoreEvents.SITE_UPDATED, () => {
this.downloadCourseEnabled = !CoreCourses.isDownloadCourseDisabledInSite();
this.displayEnableDownload = !CoreSites.getRequiredCurrentSite().isOfflineDisabled() &&
CoreCourseFormatDelegate.displayEnableDownload(this.course);
this.downloadEnabled = this.displayEnableDownload && this.downloadEnabled;
this.initListeners();
}, CoreSites.getCurrentSiteId());
this.downloadEnabledObserver = CoreEvents.on(CoreCoursesProvider.EVENT_DASHBOARD_DOWNLOAD_ENABLED_CHANGED, (data) => {
this.toggleDownload(data.enabled);
});
}
/** /**
* Component being initialized. * @inheritdoc
*/ */
async ngOnInit(): Promise<void> { async ngOnInit(): Promise<void> {
@ -103,10 +123,12 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy {
this.moduleId = CoreNavigator.getRouteNumberParam('moduleId'); this.moduleId = CoreNavigator.getRouteNumberParam('moduleId');
this.isGuest = CoreNavigator.getRouteBooleanParam('isGuest'); this.isGuest = CoreNavigator.getRouteBooleanParam('isGuest');
this.displayEnableDownload = !CoreSites.getCurrentSite()?.isOfflineDisabled() && this.displayEnableDownload = !CoreSites.getRequiredCurrentSite().isOfflineDisabled() &&
CoreCourseFormatDelegate.displayEnableDownload(this.course); CoreCourseFormatDelegate.displayEnableDownload(this.course);
this.downloadCourseEnabled = !CoreCourses.isDownloadCourseDisabledInSite(); this.downloadCourseEnabled = !CoreCourses.isDownloadCourseDisabledInSite();
this.downloadEnabled = this.displayEnableDownload && CoreCourses.getCourseDownloadOptionsEnabled();
this.debouncedUpdateCachedCompletion = CoreUtils.debounce(() => { this.debouncedUpdateCachedCompletion = CoreUtils.debounce(() => {
if (this.modulesHaveCompletion) { if (this.modulesHaveCompletion) {
CoreUtils.ignoreErrors(CoreCourse.getSections(this.course.id, false, true)); CoreUtils.ignoreErrors(CoreCourse.getSections(this.course.id, false, true));
@ -137,7 +159,7 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy {
* @return Promise resolved when done. * @return Promise resolved when done.
*/ */
protected async initListeners(): Promise<void> { protected async initListeners(): Promise<void> {
if (this.downloadCourseEnabled) { if (this.downloadCourseEnabled && !this.courseStatusObserver) {
// Listen for changes in course status. // Listen for changes in course status.
this.courseStatusObserver = CoreEvents.on(CoreEvents.COURSE_STATUS_CHANGED, (data) => { this.courseStatusObserver = CoreEvents.on(CoreEvents.COURSE_STATUS_CHANGED, (data) => {
if (data.courseId == this.course.id || data.courseId == CoreCourseProvider.ALL_COURSES_CLEARED) { if (data.courseId == this.course.id || data.courseId == CoreCourseProvider.ALL_COURSES_CLEARED) {
@ -152,26 +174,30 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy {
return; return;
} }
this.completionObserver = CoreEvents.on( if (!this.completionObserver) {
CoreEvents.COMPLETION_MODULE_VIEWED, this.completionObserver = CoreEvents.on(
(data) => { CoreEvents.COMPLETION_MODULE_VIEWED,
if (data && data.courseId == this.course.id) { (data) => {
this.refreshAfterCompletionChange(true); if (data && data.courseId == this.course.id) {
this.refreshAfterCompletionChange(true);
}
},
);
}
if (!this.syncObserver) {
this.syncObserver = CoreEvents.on(CoreCourseSyncProvider.AUTO_SYNCED, (data) => {
if (!data || data.courseId != this.course.id) {
return;
} }
},
);
this.syncObserver = CoreEvents.on(CoreCourseSyncProvider.AUTO_SYNCED, (data) => { this.refreshAfterCompletionChange(false);
if (!data || data.courseId != this.course.id) {
return;
}
this.refreshAfterCompletionChange(false); if (data.warnings && data.warnings[0]) {
CoreDomUtils.showErrorModal(data.warnings[0]);
if (data.warnings && data.warnings[0]) { }
CoreDomUtils.showErrorModal(data.warnings[0]); });
} }
});
} }
/** /**
@ -472,7 +498,8 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy {
* @param enable Whether enable or disable download enabled toggle. * @param enable Whether enable or disable download enabled toggle.
*/ */
toggleDownload(enable: boolean): void { toggleDownload(enable: boolean): void {
this.downloadEnabled = enable; this.downloadEnabled =
CoreCourses.setCourseDownloadOptionsEnabled(this.displayEnableDownload && enable);
} }
/** /**
@ -517,6 +544,8 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy {
this.completionObserver?.off(); this.completionObserver?.off();
this.courseStatusObserver?.off(); this.courseStatusObserver?.off();
this.syncObserver?.off(); this.syncObserver?.off();
this.siteUpdatedObserver?.off();
this.downloadEnabledObserver?.off();
} }
/** /**

View File

@ -49,6 +49,7 @@ export class CoreCoursesCategoriesPage implements OnInit, OnDestroy {
protected categoryId = 0; protected categoryId = 0;
protected myCoursesObserver: CoreEventObserver; protected myCoursesObserver: CoreEventObserver;
protected siteUpdatedObserver: CoreEventObserver; protected siteUpdatedObserver: CoreEventObserver;
protected downloadEnabledObserver: CoreEventObserver;
protected isDestroyed = false; protected isDestroyed = false;
constructor() { constructor() {
@ -75,6 +76,10 @@ export class CoreCoursesCategoriesPage implements OnInit, OnDestroy {
this.downloadEnabled = (this.downloadCourseEnabled || this.downloadCoursesEnabled) && this.downloadEnabled; this.downloadEnabled = (this.downloadCourseEnabled || this.downloadCoursesEnabled) && this.downloadEnabled;
}, this.currentSiteId); }, this.currentSiteId);
this.downloadEnabledObserver = CoreEvents.on(CoreCoursesProvider.EVENT_DASHBOARD_DOWNLOAD_ENABLED_CHANGED, (data) => {
this.toggleDownload(data.enabled);
});
} }
/** /**
@ -88,6 +93,9 @@ export class CoreCoursesCategoriesPage implements OnInit, OnDestroy {
this.downloadCoursesEnabled = !CoreCourses.isDownloadCoursesDisabledInSite(); this.downloadCoursesEnabled = !CoreCourses.isDownloadCoursesDisabledInSite();
this.myCoursesEnabled = !CoreCourses.isMyCoursesDisabledInSite(); this.myCoursesEnabled = !CoreCourses.isMyCoursesDisabledInSite();
this.downloadEnabled =
(this.downloadCourseEnabled || this.downloadCoursesEnabled) && CoreCourses.getCourseDownloadOptionsEnabled();
this.fetchCategories().finally(() => { this.fetchCategories().finally(() => {
this.categoriesLoaded = true; this.categoriesLoaded = true;
}); });
@ -202,17 +210,21 @@ export class CoreCoursesCategoriesPage implements OnInit, OnDestroy {
/** /**
* Toggle download enabled. * Toggle download enabled.
*
* @param enable If enable or disable.
*/ */
toggleDownload(enabled: boolean): void { toggleDownload(enable: boolean): void {
this.downloadEnabled = enabled; this.downloadEnabled =
CoreCourses.setCourseDownloadOptionsEnabled((this.downloadCourseEnabled || this.downloadCoursesEnabled) && enable);
} }
/** /**
* @inheritdoc * @inheritdoc
*/ */
ngOnDestroy(): void { ngOnDestroy(): void {
this.myCoursesObserver?.off(); this.myCoursesObserver.off();
this.siteUpdatedObserver?.off(); this.siteUpdatedObserver.off();
this.downloadEnabledObserver.off();
this.isDestroyed = true; this.isDestroyed = true;
} }

View File

@ -4,11 +4,11 @@
</ion-button> </ion-button>
<core-context-menu> <core-context-menu>
<core-context-menu-item *ngIf="(downloadCourseEnabled || downloadCoursesEnabled)" [priority]="1000" <core-context-menu-item *ngIf="(downloadCourseEnabled || downloadCoursesEnabled)" [priority]="1000"
[content]="'core.settings.showdownloadoptions' | translate" (action)="switchDownload(!downloadEnabled)" [content]="'core.settings.showdownloadoptions' | translate" (action)="switchDownload(!downloadEnabled)"
iconAction="toggle" [toggle]="downloadEnabled"></core-context-menu-item> iconAction="toggle" [toggle]="downloadEnabled"></core-context-menu-item>
<core-context-menu-item [priority]="500" <core-context-menu-item [priority]="500"
[content]="'addon.storagemanager.managestorage' | translate" [content]="'addon.storagemanager.managestorage' | translate"
(action)="manageCoursesStorage()" iconAction="fas-archive"></core-context-menu-item> (action)="manageCoursesStorage()" iconAction="fas-archive"></core-context-menu-item>
</core-context-menu> </core-context-menu>
</core-navbar-buttons> </core-navbar-buttons>
<ion-content> <ion-content>

View File

@ -44,25 +44,35 @@ export class CoreCoursesDashboardPage implements OnInit, OnDestroy {
blocks: Partial<CoreCourseBlock>[] = []; blocks: Partial<CoreCourseBlock>[] = [];
loaded = false; loaded = false;
protected updateSiteObserver?: CoreEventObserver; protected updateSiteObserver: CoreEventObserver;
protected downloadEnabledObserver: CoreEventObserver;
/**
* Initialize the component.
*/
ngOnInit(): void {
this.searchEnabled = !CoreCourses.isSearchCoursesDisabledInSite();
this.downloadCourseEnabled = !CoreCourses.isDownloadCourseDisabledInSite();
this.downloadCoursesEnabled = !CoreCourses.isDownloadCoursesDisabledInSite();
constructor() {
// Refresh the enabled flags if site is updated. // Refresh the enabled flags if site is updated.
this.updateSiteObserver = CoreEvents.on(CoreEvents.SITE_UPDATED, () => { this.updateSiteObserver = CoreEvents.on(CoreEvents.SITE_UPDATED, () => {
this.searchEnabled = !CoreCourses.isSearchCoursesDisabledInSite(); this.searchEnabled = !CoreCourses.isSearchCoursesDisabledInSite();
this.downloadCourseEnabled = !CoreCourses.isDownloadCourseDisabledInSite(); this.downloadCourseEnabled = !CoreCourses.isDownloadCourseDisabledInSite();
this.downloadCoursesEnabled = !CoreCourses.isDownloadCoursesDisabledInSite(); this.downloadCoursesEnabled = !CoreCourses.isDownloadCoursesDisabledInSite();
this.switchDownload(this.downloadEnabled && this.downloadCourseEnabled && this.downloadCoursesEnabled); this.switchDownload(this.downloadEnabled);
}, CoreSites.getCurrentSiteId()); }, CoreSites.getCurrentSiteId());
this.downloadEnabledObserver = CoreEvents.on(CoreCoursesProvider.EVENT_DASHBOARD_DOWNLOAD_ENABLED_CHANGED, (data) => {
this.switchDownload(data.enabled);
});
}
/**
* @inheritdoc
*/
ngOnInit(): void {
this.searchEnabled = !CoreCourses.isSearchCoursesDisabledInSite();
this.downloadCourseEnabled = !CoreCourses.isDownloadCourseDisabledInSite();
this.downloadCoursesEnabled = !CoreCourses.isDownloadCoursesDisabledInSite();
this.downloadEnabled =
(this.downloadCourseEnabled || this.downloadCoursesEnabled) && CoreCourses.getCourseDownloadOptionsEnabled();
this.loadContent(); this.loadContent();
} }
@ -143,8 +153,8 @@ export class CoreCoursesDashboardPage implements OnInit, OnDestroy {
* @param enable If enable or disable. * @param enable If enable or disable.
*/ */
protected switchDownload(enable: boolean): void { protected switchDownload(enable: boolean): void {
this.downloadEnabled = (this.downloadCourseEnabled || this.downloadCoursesEnabled) && enable; this.downloadEnabled =
CoreEvents.trigger(CoreCoursesProvider.EVENT_DASHBOARD_DOWNLOAD_ENABLED_CHANGED, { enabled: this.downloadEnabled }); CoreCourses.setCourseDownloadOptionsEnabled((this.downloadCourseEnabled || this.downloadCoursesEnabled) && enable);
} }
/** /**
@ -165,7 +175,8 @@ export class CoreCoursesDashboardPage implements OnInit, OnDestroy {
* Component being destroyed. * Component being destroyed.
*/ */
ngOnDestroy(): void { ngOnDestroy(): void {
this.updateSiteObserver?.off(); this.updateSiteObserver.off();
this.downloadEnabledObserver.off();
} }
} }

View File

@ -58,6 +58,7 @@ export class CoreCoursesListPage implements OnInit, OnDestroy {
protected searchText = ''; protected searchText = '';
protected myCoursesObserver: CoreEventObserver; protected myCoursesObserver: CoreEventObserver;
protected siteUpdatedObserver: CoreEventObserver; protected siteUpdatedObserver: CoreEventObserver;
protected downloadEnabledObserver: CoreEventObserver;
protected courseIds = ''; protected courseIds = '';
protected isDestroyed = false; protected isDestroyed = false;
@ -92,6 +93,10 @@ export class CoreCoursesListPage implements OnInit, OnDestroy {
this.fetchCourses(); this.fetchCourses();
} }
}, this.currentSiteId); }, this.currentSiteId);
this.downloadEnabledObserver = CoreEvents.on(CoreCoursesProvider.EVENT_DASHBOARD_DOWNLOAD_ENABLED_CHANGED, (data) => {
this.toggleDownload(data.enabled);
});
} }
/** /**
@ -101,6 +106,9 @@ export class CoreCoursesListPage implements OnInit, OnDestroy {
this.downloadCourseEnabled = !CoreCourses.isDownloadCourseDisabledInSite(); this.downloadCourseEnabled = !CoreCourses.isDownloadCourseDisabledInSite();
this.downloadCoursesEnabled = !CoreCourses.isDownloadCoursesDisabledInSite(); this.downloadCoursesEnabled = !CoreCourses.isDownloadCoursesDisabledInSite();
this.downloadEnabled =
(this.downloadCourseEnabled || this.downloadCoursesEnabled) && CoreCourses.getCourseDownloadOptionsEnabled();
this.mode = CoreNavigator.getRouteParam<CoreCoursesListMode>('mode') || this.mode; this.mode = CoreNavigator.getRouteParam<CoreCoursesListMode>('mode') || this.mode;
this.myCoursesEnabled = !CoreCourses.isMyCoursesDisabledInSite(); this.myCoursesEnabled = !CoreCourses.isMyCoursesDisabledInSite();
@ -269,27 +277,33 @@ export class CoreCoursesListPage implements OnInit, OnDestroy {
/** /**
* Toggle show only my courses. * Toggle show only my courses.
*
* @param enable If enable or disable.
*/ */
toggleEnrolled(enabled: boolean): void { toggleEnrolled(enable: boolean): void {
this.coursesLoaded = false; this.coursesLoaded = false;
this.showOnlyEnrolled = enabled; this.showOnlyEnrolled = enable;
this.fetchCourses(); this.fetchCourses();
} }
/** /**
* Toggle download enabled. * Toggle download enabled.
*
* @param enable If enable or disable.
*/ */
toggleDownload(enabled: boolean): void { toggleDownload(enable: boolean): void {
this.downloadEnabled = enabled; this.downloadEnabled =
CoreCourses.setCourseDownloadOptionsEnabled((this.downloadCourseEnabled || this.downloadCoursesEnabled) && enable);
} }
/** /**
* @inheritdoc * @inheritdoc
*/ */
ngOnDestroy(): void { ngOnDestroy(): void {
this.myCoursesObserver?.off(); this.myCoursesObserver.off();
this.siteUpdatedObserver?.off(); this.siteUpdatedObserver.off();
this.downloadEnabledObserver.off();
this.isDestroyed = true; this.isDestroyed = true;
} }

View File

@ -13,7 +13,6 @@
// limitations under the License. // limitations under the License.
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { CoreLogger } from '@singletons/logger';
import { CoreSites, CoreSitesCommonWSOptions, CoreSitesReadingStrategy } from '@services/sites'; import { CoreSites, CoreSitesCommonWSOptions, CoreSitesReadingStrategy } from '@services/sites';
import { CoreSite, CoreSiteWSPreSets } from '@classes/site'; import { CoreSite, CoreSiteWSPreSets } from '@classes/site';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
@ -63,12 +62,9 @@ export class CoreCoursesProvider {
static readonly STATE_HIDDEN = 'hidden'; static readonly STATE_HIDDEN = 'hidden';
static readonly STATE_FAVOURITE = 'favourite'; static readonly STATE_FAVOURITE = 'favourite';
protected logger: CoreLogger;
protected userCoursesIds: { [id: number]: boolean } = {}; // Use an object to make it faster to search. protected userCoursesIds: { [id: number]: boolean } = {}; // Use an object to make it faster to search.
constructor() { protected downloadOptionsEnabled = false;
this.logger = CoreLogger.getInstance('CoreCoursesProvider');
}
/** /**
* Whether current site supports getting course options. * Whether current site supports getting course options.
@ -1220,6 +1216,32 @@ export class CoreCoursesProvider {
return site.write('core_course_set_favourite_courses', params); return site.write('core_course_set_favourite_courses', params);
} }
/**
* Get download options enabled option.
*
* @return True if enabled, false otherwise.
*/
getCourseDownloadOptionsEnabled(): boolean {
return this.downloadOptionsEnabled;
}
/**
* Set trigger and save the download option.
*
* @param enable True to enable, false to disable.
* @return Current status.
*/
setCourseDownloadOptionsEnabled(enable: boolean): boolean {
if (this.downloadOptionsEnabled == enable) {
return enable;
}
this.downloadOptionsEnabled = enable;
CoreEvents.trigger(CoreCoursesProvider.EVENT_DASHBOARD_DOWNLOAD_ENABLED_CHANGED, { enabled: enable });
return enable;
}
} }
export const CoreCourses = makeSingleton(CoreCoursesProvider); export const CoreCourses = makeSingleton(CoreCoursesProvider);

View File

@ -3,12 +3,12 @@
<ion-icon name="fas-search" slot="icon-only" aria-hidden="true"></ion-icon> <ion-icon name="fas-search" slot="icon-only" aria-hidden="true"></ion-icon>
</ion-button> </ion-button>
<core-context-menu> <core-context-menu>
<core-context-menu-item [priority]="1000" <core-context-menu-item [priority]="1000" *ngIf="displayEnableDownload"
[content]="'core.settings.showdownloadoptions' | translate" (action)="switchDownload(!downloadEnabled)" [content]="'core.settings.showdownloadoptions' | translate" (action)="switchDownload(!downloadEnabled)"
iconAction="toggle" [toggle]="downloadEnabled"></core-context-menu-item> iconAction="toggle" [toggle]="downloadEnabled"></core-context-menu-item>
<core-context-menu-item [priority]="500" <core-context-menu-item [priority]="500"
[content]="'addon.storagemanager.managestorage' | translate" [content]="'addon.storagemanager.managestorage' | translate"
(action)="manageCoursesStorage()" iconAction="fas-archive"></core-context-menu-item> (action)="manageCoursesStorage()" iconAction="fas-archive"></core-context-menu-item>
</core-context-menu> </core-context-menu>
</core-navbar-buttons> </core-navbar-buttons>
<ion-content> <ion-content>

View File

@ -50,22 +50,32 @@ export class CoreSiteHomeIndexPage implements OnInit, OnDestroy {
siteHomeId = 1; siteHomeId = 1;
currentSite!: CoreSite; currentSite!: CoreSite;
searchEnabled = false; searchEnabled = false;
displayEnableDownload = false;
downloadEnabled = false; downloadEnabled = false;
newsForumModule?: NewsForum; newsForumModule?: NewsForum;
protected updateSiteObserver?: CoreEventObserver; protected updateSiteObserver: CoreEventObserver;
protected downloadEnabledObserver: CoreEventObserver;
/**
* Page being initialized.
*/
ngOnInit(): void {
this.searchEnabled = !CoreCourses.isSearchCoursesDisabledInSite();
constructor() {
// Refresh the enabled flags if site is updated. // Refresh the enabled flags if site is updated.
this.updateSiteObserver = CoreEvents.on(CoreEvents.SITE_UPDATED, () => { this.updateSiteObserver = CoreEvents.on(CoreEvents.SITE_UPDATED, () => {
this.searchEnabled = !CoreCourses.isSearchCoursesDisabledInSite(); this.searchEnabled = !CoreCourses.isSearchCoursesDisabledInSite();
this.displayEnableDownload = !CoreSites.getRequiredCurrentSite().isOfflineDisabled();
}, CoreSites.getCurrentSiteId()); }, CoreSites.getCurrentSiteId());
this.downloadEnabledObserver = CoreEvents.on(CoreCoursesProvider.EVENT_DASHBOARD_DOWNLOAD_ENABLED_CHANGED, (data) => {
this.switchDownload(data.enabled);
});
}
/**
* @inheritdoc
*/
ngOnInit(): void {
this.searchEnabled = !CoreCourses.isSearchCoursesDisabledInSite();
this.currentSite = CoreSites.getRequiredCurrentSite(); this.currentSite = CoreSites.getRequiredCurrentSite();
this.siteHomeId = CoreSites.getCurrentSiteHomeId(); this.siteHomeId = CoreSites.getCurrentSiteHomeId();
@ -75,6 +85,9 @@ export class CoreSiteHomeIndexPage implements OnInit, OnDestroy {
CoreCourseHelper.openModule(module, this.siteHomeId, undefined, modParams); CoreCourseHelper.openModule(module, this.siteHomeId, undefined, modParams);
} }
this.displayEnableDownload = !CoreSites.getRequiredCurrentSite().isOfflineDisabled();
this.downloadEnabled = CoreCourses.getCourseDownloadOptionsEnabled();
this.loadContent().finally(() => { this.loadContent().finally(() => {
this.dataLoaded = true; this.dataLoaded = true;
}); });
@ -186,8 +199,8 @@ export class CoreSiteHomeIndexPage implements OnInit, OnDestroy {
* @param enable If enable or disable. * @param enable If enable or disable.
*/ */
protected switchDownload(enable: boolean): void { protected switchDownload(enable: boolean): void {
this.downloadEnabled = enable; this.downloadEnabled =
CoreEvents.trigger(CoreCoursesProvider.EVENT_DASHBOARD_DOWNLOAD_ENABLED_CHANGED, { enabled: this.downloadEnabled }); CoreCourses.setCourseDownloadOptionsEnabled(enable);
} }
/** /**
@ -229,7 +242,8 @@ export class CoreSiteHomeIndexPage implements OnInit, OnDestroy {
* Component being destroyed. * Component being destroyed.
*/ */
ngOnDestroy(): void { ngOnDestroy(): void {
this.updateSiteObserver?.off(); this.updateSiteObserver.off();
this.downloadEnabledObserver.off();
} }
} }