diff --git a/src/addon/messages/providers/mainmenu-handler.ts b/src/addon/messages/providers/mainmenu-handler.ts index f934224be..2fde797bf 100644 --- a/src/addon/messages/providers/mainmenu-handler.ts +++ b/src/addon/messages/providers/mainmenu-handler.ts @@ -129,7 +129,7 @@ export class AddonMessagesMainMenuHandler implements CoreMainMenuHandler, CoreCr */ execute(siteId?: string): Promise { if (this.sitesProvider.isCurrentSite(siteId)) { - this.eventsProvider.trigger(AddonMessagesProvider.READ_CRON_EVENT, undefined, siteId); + this.eventsProvider.trigger(AddonMessagesProvider.READ_CRON_EVENT, {}, siteId); } if (this.appProvider.isDesktop() && this.localNotificationsProvider.isAvailable()) { diff --git a/src/addon/messages/providers/sync.ts b/src/addon/messages/providers/sync.ts index 0cc5a6c5b..0a9b77ac7 100644 --- a/src/addon/messages/providers/sync.ts +++ b/src/addon/messages/providers/sync.ts @@ -58,11 +58,12 @@ export class AddonMessagesSyncProvider extends CoreSyncBaseProvider { /** * Get all messages pending to be sent in the site. - * @param {boolean} [onlyDeviceOffline=false] True to only sync discussions that failed because device was offline, - * @param {string} [siteId] Site ID to sync. If not defined, sync all sites. - * @param {Promise} Promise resolved if sync is successful, rejected if sync fails. + * + * @param {string} [siteId] Site ID to sync. If not defined, sync all sites. + * @param {boolean} [onlyDeviceOffline=false] True to only sync discussions that failed because device was offline. + * @param {Promise} Promise resolved if sync is successful, rejected if sync fails. */ - protected syncAllDiscussionsFunc(onlyDeviceOffline: boolean = false, siteId?: string): Promise { + protected syncAllDiscussionsFunc(siteId?: string, onlyDeviceOffline: boolean = false): Promise { const promise = onlyDeviceOffline ? this.messagesOffline.getAllDeviceOfflineMessages(siteId) : this.messagesOffline.getAllMessages(siteId); diff --git a/src/addon/pushnotifications/providers/pushnotifications.ts b/src/addon/pushnotifications/providers/pushnotifications.ts index 98e1e266e..74bb4ec75 100644 --- a/src/addon/pushnotifications/providers/pushnotifications.ts +++ b/src/addon/pushnotifications/providers/pushnotifications.ts @@ -264,6 +264,11 @@ export class AddonPushNotificationsProvider { return previous + parseInt(counter, 10); }, 0); + if (!this.appProvider.isDesktop() && !this.appProvider.isMobile()) { + // Browser doesn't have an app badge, stop. + return total; + } + // Set the app badge. return this.badge.set(total).then(() => { return total; diff --git a/src/addon/remotethemes/providers/remotethemes.ts b/src/addon/remotethemes/providers/remotethemes.ts index 067bca557..ceebbf659 100644 --- a/src/addon/remotethemes/providers/remotethemes.ts +++ b/src/addon/remotethemes/providers/remotethemes.ts @@ -133,24 +133,26 @@ export class AddonRemoteThemesProvider { * Get remote styles of a certain site. * * @param {string} [siteId] Site ID. If not defined, current site. - * @return {Promise<{fileUrl: string, styles: string}>} Promise resolved with the styles and the URL of the CSS file. + * @return {Promise<{fileUrl: string, styles: string}>} Promise resolved with the styles and the URL of the CSS file, + * resolved with undefined if no styles to load. */ get(siteId?: string): Promise<{fileUrl: string, styles: string}> { siteId = siteId || this.sitesProvider.getCurrentSiteId(); - let fileUrl; - return this.sitesProvider.getSite(siteId).then((site) => { const infos = site.getInfo(); + let promise, + fileUrl; + if (infos && infos.mobilecssurl) { fileUrl = infos.mobilecssurl; if (this.fileProvider.isAvailable()) { // The file system is available. Download the file and remove old CSS files if needed. - return this.downloadFileAndRemoveOld(siteId, fileUrl); + promise = this.downloadFileAndRemoveOld(siteId, fileUrl); } else { // Return the online URL. - return fileUrl; + promise = Promise.resolve(fileUrl); } } else { if (infos && infos.mobilecssurl === '') { @@ -158,20 +160,22 @@ export class AddonRemoteThemesProvider { this.filepoolProvider.removeFilesByComponent(siteId, AddonRemoteThemesProvider.COMPONENT, 1); } - return Promise.reject(null); + return; } - }).then((url) => { - this.logger.debug('Loading styles from: ', url); - // Get the CSS content using HTTP because we will treat the styles before saving them in the file. - return this.http.get(url).toPromise(); - }).then((response): any => { - const text = response && response.text(); - if (typeof text == 'string') { - return {fileUrl: fileUrl, styles: this.get35Styles(text)}; - } else { - return Promise.reject(null); - } + return promise.then((url) => { + this.logger.debug('Loading styles from: ', url); + + // Get the CSS content using HTTP because we will treat the styles before saving them in the file. + return this.http.get(url).toPromise(); + }).then((response): any => { + const text = response && response.text(); + if (typeof text == 'string') { + return {fileUrl: fileUrl, styles: this.get35Styles(text)}; + } else { + return Promise.reject(null); + } + }); }); } @@ -208,6 +212,11 @@ export class AddonRemoteThemesProvider { this.disableElement(this.stylesEls[siteId].element, disabled); return this.get(siteId).then((data) => { + if (typeof data == 'undefined') { + // Nothing to load. + return; + } + const hash = Md5.hashAsciiStr(data.styles); // Update the styles only if they have changed. @@ -271,6 +280,8 @@ export class AddonRemoteThemesProvider { preloadCurrentSite(): Promise { return this.sitesProvider.getStoredCurrentSiteId().then((siteId) => { return this.addSite(siteId); + }, () => { + // No current site stored. }); } diff --git a/src/providers/cron.ts b/src/providers/cron.ts index 4aa968ded..d891d44b2 100644 --- a/src/providers/cron.ts +++ b/src/providers/cron.ts @@ -184,9 +184,9 @@ export class CoreCronDelegate { return this.setHandlerLastExecutionTime(name, Date.now()).then(() => { this.scheduleNextExecution(name); }); - }, () => { + }, (error) => { // Handler call failed. Retry soon. - this.logger.debug(`Execution of handler '${name}' failed.`); + this.logger.error(`Execution of handler '${name}' failed.`, error); this.scheduleNextExecution(name, CoreCronDelegate.MIN_INTERVAL); return Promise.reject(null); @@ -440,7 +440,9 @@ export class CoreCronDelegate { this.handlers[name].timeout = setTimeout(() => { delete this.handlers[name].timeout; - this.checkAndExecuteHandler(name); + this.checkAndExecuteHandler(name).catch(() => { + // Ignore errors. + }); }, nextExecution); }); } diff --git a/src/providers/file.ts b/src/providers/file.ts index 836685ab6..9677ab62f 100644 --- a/src/providers/file.ts +++ b/src/providers/file.ts @@ -918,7 +918,9 @@ export class CoreFileProvider { * @return {Promise} Promise resolved when done. */ clearTmpFolder(): Promise { - return this.removeDir(CoreFileProvider.TMPFOLDER); + return this.removeDir(CoreFileProvider.TMPFOLDER).catch(() => { + // Ignore errors because the folder might not exist. + }); } /** diff --git a/src/providers/sites.ts b/src/providers/sites.ts index 8b9694b15..2c087c955 100644 --- a/src/providers/sites.ts +++ b/src/providers/sites.ts @@ -975,6 +975,8 @@ export class CoreSitesProvider { this.logger.debug(`Restore session in site ${siteId}`); return this.loadSite(siteId); + }).catch(() => { + // No current session. }); }