MOBILE-2478 login: Fix SSO and notifications errors
parent
fe2e519f4e
commit
38e13c421d
|
@ -58,10 +58,12 @@ export class AddonNotificationsProvider {
|
|||
if (cid && cid[1]) {
|
||||
notification.courseid = cid[1];
|
||||
}
|
||||
// Try to get the profile picture of the user.
|
||||
this.userProvider.getProfile(notification.useridfrom, notification.courseid, true).then((user) => {
|
||||
notification.profileimageurlfrom = user.profileimageurl;
|
||||
});
|
||||
if (notification.useridfrom > 0) {
|
||||
// Try to get the profile picture of the user.
|
||||
this.userProvider.getProfile(notification.useridfrom, notification.courseid, true).then((user) => {
|
||||
notification.profileimageurlfrom = user.profileimageurl;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -16,21 +16,20 @@ import { CoreAppProvider } from '@providers/app';
|
|||
import { CoreFileProvider } from '@providers/file';
|
||||
import { CoreUrlUtilsProvider } from '@providers/utils/url';
|
||||
import { Observable, Observer } from 'rxjs';
|
||||
import { InAppBrowserObject, InAppBrowserEvent } from '@ionic-native/in-app-browser';
|
||||
import { InAppBrowserEvent } from '@ionic-native/in-app-browser';
|
||||
|
||||
/**
|
||||
* Emulates the Cordova InAppBrowserObject in desktop apps.
|
||||
* We aren't extending InAppBrowserObject because its constructor also opens a window, so we'd end up with 2 windows.
|
||||
*/
|
||||
export class InAppBrowserObjectMock extends InAppBrowserObject {
|
||||
export class InAppBrowserObjectMock {
|
||||
protected window;
|
||||
protected browserWindow;
|
||||
protected screen;
|
||||
protected isSSO: boolean;
|
||||
protected isLinux: boolean;
|
||||
|
||||
constructor(appProvider: CoreAppProvider, private fileProvider: CoreFileProvider, private urlUtils: CoreUrlUtilsProvider,
|
||||
private url: string, target?: string, options: string = '') {
|
||||
super(url, target, options);
|
||||
private url: string, target?: string, options: string = 'location=yes') {
|
||||
|
||||
if (!appProvider.isDesktop()) {
|
||||
// This plugin is only supported in desktop.
|
||||
|
@ -40,7 +39,6 @@ export class InAppBrowserObjectMock extends InAppBrowserObject {
|
|||
this.browserWindow = require('electron').remote.BrowserWindow;
|
||||
this.screen = require('electron').screen;
|
||||
this.isSSO = !!(url && url.match(/\/launch\.php\?service=.+&passport=/));
|
||||
this.isLinux = appProvider.isLinux();
|
||||
|
||||
let width = 800,
|
||||
height = 600,
|
||||
|
@ -71,7 +69,7 @@ export class InAppBrowserObjectMock extends InAppBrowserObject {
|
|||
this.window = new this.browserWindow(bwOptions);
|
||||
this.window.loadURL(url);
|
||||
|
||||
if (this.isLinux && this.isSSO) {
|
||||
if (this.isSSO) {
|
||||
// SSO in Linux. Simulate it's an iOS device so we can retrieve the launch URL.
|
||||
// This is needed because custom URL scheme is not supported in Linux.
|
||||
const userAgent = 'Mozilla/5.0 (iPad) AppleWebKit/603.3.8 (KHTML, like Gecko) Mobile/14G60';
|
||||
|
@ -113,11 +111,16 @@ export class InAppBrowserObjectMock extends InAppBrowserObject {
|
|||
* @return {Promise<string>} Promise resolved with the launch URL.
|
||||
*/
|
||||
protected getLaunchUrl(retry: number = 0): Promise<string> {
|
||||
|
||||
if (this.window.isDestroyed()) {
|
||||
// Window is destroyed, stop.
|
||||
return Promise.reject(null);
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject): void => {
|
||||
// Execute Javascript to retrieve the launch link.
|
||||
const jsCode = 'var el = document.querySelector("#launchapp"); el && el.href;';
|
||||
let found = false;
|
||||
|
||||
this.window.webContents.executeJavaScript(jsCode).then((launchUrl) => {
|
||||
found = true;
|
||||
resolve(launchUrl);
|
||||
|
@ -179,7 +182,7 @@ export class InAppBrowserObjectMock extends InAppBrowserObject {
|
|||
// Helper functions to handle events.
|
||||
const received = (event, url): void => {
|
||||
try {
|
||||
event.url = url || this.window.getURL();
|
||||
event.url = url || (this.window.isDestroyed() ? '' : this.window.getURL());
|
||||
event.type = name;
|
||||
observer.next(event);
|
||||
} catch (ex) {
|
||||
|
@ -203,7 +206,7 @@ export class InAppBrowserObjectMock extends InAppBrowserObject {
|
|||
case 'loadstart':
|
||||
this.window.webContents.on('did-start-loading', received);
|
||||
|
||||
if (this.isLinux && this.isSSO) {
|
||||
if (this.isSSO) {
|
||||
// Linux doesn't support custom URL Schemes. Check if launch page is loaded.
|
||||
this.window.webContents.on('did-finish-load', finishLoad);
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
// limitations under the License.
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { InAppBrowser, InAppBrowserObject } from '@ionic-native/in-app-browser';
|
||||
import { InAppBrowser } from '@ionic-native/in-app-browser';
|
||||
import { CoreAppProvider } from '@providers/app';
|
||||
import { CoreFileProvider } from '@providers/file';
|
||||
import { CoreUrlUtilsProvider } from '@providers/utils/url';
|
||||
|
@ -36,9 +36,16 @@ export class InAppBrowserMock extends InAppBrowser {
|
|||
* @param {string} url The URL to load.
|
||||
* @param {string} [target] The target in which to load the URL, an optional parameter that defaults to _self.
|
||||
* @param {string} [options] Options for the InAppBrowser.
|
||||
* @return {InAppBrowserObject} The new instance.
|
||||
* @return {any} The new instance.
|
||||
*/
|
||||
create(url: string, target?: string, options: string = ''): InAppBrowserObject {
|
||||
create(url: string, target?: string, options: string = 'location=yes'): any {
|
||||
if (options && typeof options !== 'string') {
|
||||
// Convert to string.
|
||||
options = Object.keys(options).map((key) => {
|
||||
return key + '=' + options[key];
|
||||
}).join(',');
|
||||
}
|
||||
|
||||
if (!this.appProvider.isDesktop()) {
|
||||
return super.create(url, target, options);
|
||||
}
|
||||
|
|
|
@ -148,6 +148,10 @@ export class LocalNotificationsMock extends LocalNotifications {
|
|||
* @return {Void}
|
||||
*/
|
||||
protected cancelNotification(id: number, omitEvent: boolean, eventName: string): void {
|
||||
if (!this.scheduled[id]) {
|
||||
return;
|
||||
}
|
||||
|
||||
const notification = this.scheduled[id].notification;
|
||||
|
||||
clearTimeout(this.scheduled[id].timeout);
|
||||
|
@ -698,7 +702,7 @@ export class LocalNotificationsMock extends LocalNotifications {
|
|||
id : notification.id,
|
||||
title: notification.title,
|
||||
text: notification.text,
|
||||
at: notification.at ? notification.at.getTime() : 0,
|
||||
at: notification.at ? (typeof notification.at == 'object' ? notification.at.getTime() : notification.at) : 0,
|
||||
data: notification.data ? JSON.stringify(notification.data) : '{}',
|
||||
triggered: triggered ? 1 : 0
|
||||
};
|
||||
|
|
|
@ -105,10 +105,6 @@ export class CoreUpdateManagerProvider implements CoreInitHandler {
|
|||
{
|
||||
name: 'desktop_local_notifications',
|
||||
fields: [
|
||||
{
|
||||
name: 'at',
|
||||
type: 'date'
|
||||
},
|
||||
{
|
||||
name: 'data',
|
||||
type: 'object'
|
||||
|
|
Loading…
Reference in New Issue