MOBILE-2376 core: Decrease exceptions in console on start
parent
e1cb1ad7ec
commit
ce62a16460
|
@ -129,7 +129,7 @@ export class AddonMessagesMainMenuHandler implements CoreMainMenuHandler, CoreCr
|
||||||
*/
|
*/
|
||||||
execute(siteId?: string): Promise<any> {
|
execute(siteId?: string): Promise<any> {
|
||||||
if (this.sitesProvider.isCurrentSite(siteId)) {
|
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()) {
|
if (this.appProvider.isDesktop() && this.localNotificationsProvider.isAvailable()) {
|
||||||
|
|
|
@ -58,11 +58,12 @@ export class AddonMessagesSyncProvider extends CoreSyncBaseProvider {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all messages pending to be sent in the site.
|
* 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 {string} [siteId] Site ID to sync. If not defined, sync all sites.
|
||||||
* @param {Promise<any>} Promise resolved if sync is successful, rejected if sync fails.
|
* @param {boolean} [onlyDeviceOffline=false] True to only sync discussions that failed because device was offline.
|
||||||
|
* @param {Promise<any>} Promise resolved if sync is successful, rejected if sync fails.
|
||||||
*/
|
*/
|
||||||
protected syncAllDiscussionsFunc(onlyDeviceOffline: boolean = false, siteId?: string): Promise<any> {
|
protected syncAllDiscussionsFunc(siteId?: string, onlyDeviceOffline: boolean = false): Promise<any> {
|
||||||
const promise = onlyDeviceOffline ?
|
const promise = onlyDeviceOffline ?
|
||||||
this.messagesOffline.getAllDeviceOfflineMessages(siteId) :
|
this.messagesOffline.getAllDeviceOfflineMessages(siteId) :
|
||||||
this.messagesOffline.getAllMessages(siteId);
|
this.messagesOffline.getAllMessages(siteId);
|
||||||
|
|
|
@ -264,6 +264,11 @@ export class AddonPushNotificationsProvider {
|
||||||
return previous + parseInt(counter, 10);
|
return previous + parseInt(counter, 10);
|
||||||
}, 0);
|
}, 0);
|
||||||
|
|
||||||
|
if (!this.appProvider.isDesktop() && !this.appProvider.isMobile()) {
|
||||||
|
// Browser doesn't have an app badge, stop.
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
// Set the app badge.
|
// Set the app badge.
|
||||||
return this.badge.set(total).then(() => {
|
return this.badge.set(total).then(() => {
|
||||||
return total;
|
return total;
|
||||||
|
|
|
@ -133,24 +133,26 @@ export class AddonRemoteThemesProvider {
|
||||||
* Get remote styles of a certain site.
|
* Get remote styles of a certain site.
|
||||||
*
|
*
|
||||||
* @param {string} [siteId] Site ID. If not defined, current 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}> {
|
get(siteId?: string): Promise<{fileUrl: string, styles: string}> {
|
||||||
siteId = siteId || this.sitesProvider.getCurrentSiteId();
|
siteId = siteId || this.sitesProvider.getCurrentSiteId();
|
||||||
|
|
||||||
let fileUrl;
|
|
||||||
|
|
||||||
return this.sitesProvider.getSite(siteId).then((site) => {
|
return this.sitesProvider.getSite(siteId).then((site) => {
|
||||||
const infos = site.getInfo();
|
const infos = site.getInfo();
|
||||||
|
let promise,
|
||||||
|
fileUrl;
|
||||||
|
|
||||||
if (infos && infos.mobilecssurl) {
|
if (infos && infos.mobilecssurl) {
|
||||||
fileUrl = infos.mobilecssurl;
|
fileUrl = infos.mobilecssurl;
|
||||||
|
|
||||||
if (this.fileProvider.isAvailable()) {
|
if (this.fileProvider.isAvailable()) {
|
||||||
// The file system is available. Download the file and remove old CSS files if needed.
|
// 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 {
|
} else {
|
||||||
// Return the online URL.
|
// Return the online URL.
|
||||||
return fileUrl;
|
promise = Promise.resolve(fileUrl);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (infos && infos.mobilecssurl === '') {
|
if (infos && infos.mobilecssurl === '') {
|
||||||
|
@ -158,20 +160,22 @@ export class AddonRemoteThemesProvider {
|
||||||
this.filepoolProvider.removeFilesByComponent(siteId, AddonRemoteThemesProvider.COMPONENT, 1);
|
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 promise.then((url) => {
|
||||||
return this.http.get(url).toPromise();
|
this.logger.debug('Loading styles from: ', url);
|
||||||
}).then((response): any => {
|
|
||||||
const text = response && response.text();
|
// Get the CSS content using HTTP because we will treat the styles before saving them in the file.
|
||||||
if (typeof text == 'string') {
|
return this.http.get(url).toPromise();
|
||||||
return {fileUrl: fileUrl, styles: this.get35Styles(text)};
|
}).then((response): any => {
|
||||||
} else {
|
const text = response && response.text();
|
||||||
return Promise.reject(null);
|
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);
|
this.disableElement(this.stylesEls[siteId].element, disabled);
|
||||||
|
|
||||||
return this.get(siteId).then((data) => {
|
return this.get(siteId).then((data) => {
|
||||||
|
if (typeof data == 'undefined') {
|
||||||
|
// Nothing to load.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const hash = <string> Md5.hashAsciiStr(data.styles);
|
const hash = <string> Md5.hashAsciiStr(data.styles);
|
||||||
|
|
||||||
// Update the styles only if they have changed.
|
// Update the styles only if they have changed.
|
||||||
|
@ -271,6 +280,8 @@ export class AddonRemoteThemesProvider {
|
||||||
preloadCurrentSite(): Promise<any> {
|
preloadCurrentSite(): Promise<any> {
|
||||||
return this.sitesProvider.getStoredCurrentSiteId().then((siteId) => {
|
return this.sitesProvider.getStoredCurrentSiteId().then((siteId) => {
|
||||||
return this.addSite(siteId);
|
return this.addSite(siteId);
|
||||||
|
}, () => {
|
||||||
|
// No current site stored.
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -184,9 +184,9 @@ export class CoreCronDelegate {
|
||||||
return this.setHandlerLastExecutionTime(name, Date.now()).then(() => {
|
return this.setHandlerLastExecutionTime(name, Date.now()).then(() => {
|
||||||
this.scheduleNextExecution(name);
|
this.scheduleNextExecution(name);
|
||||||
});
|
});
|
||||||
}, () => {
|
}, (error) => {
|
||||||
// Handler call failed. Retry soon.
|
// 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);
|
this.scheduleNextExecution(name, CoreCronDelegate.MIN_INTERVAL);
|
||||||
|
|
||||||
return Promise.reject(null);
|
return Promise.reject(null);
|
||||||
|
@ -440,7 +440,9 @@ export class CoreCronDelegate {
|
||||||
|
|
||||||
this.handlers[name].timeout = setTimeout(() => {
|
this.handlers[name].timeout = setTimeout(() => {
|
||||||
delete this.handlers[name].timeout;
|
delete this.handlers[name].timeout;
|
||||||
this.checkAndExecuteHandler(name);
|
this.checkAndExecuteHandler(name).catch(() => {
|
||||||
|
// Ignore errors.
|
||||||
|
});
|
||||||
}, nextExecution);
|
}, nextExecution);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -918,7 +918,9 @@ export class CoreFileProvider {
|
||||||
* @return {Promise<any>} Promise resolved when done.
|
* @return {Promise<any>} Promise resolved when done.
|
||||||
*/
|
*/
|
||||||
clearTmpFolder(): Promise<any> {
|
clearTmpFolder(): Promise<any> {
|
||||||
return this.removeDir(CoreFileProvider.TMPFOLDER);
|
return this.removeDir(CoreFileProvider.TMPFOLDER).catch(() => {
|
||||||
|
// Ignore errors because the folder might not exist.
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -975,6 +975,8 @@ export class CoreSitesProvider {
|
||||||
this.logger.debug(`Restore session in site ${siteId}`);
|
this.logger.debug(`Restore session in site ${siteId}`);
|
||||||
|
|
||||||
return this.loadSite(siteId);
|
return this.loadSite(siteId);
|
||||||
|
}).catch(() => {
|
||||||
|
// No current session.
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue