MOBILE-2478 login: Fix SSO and notifications errors
parent
fe2e519f4e
commit
38e13c421d
|
@ -58,10 +58,12 @@ export class AddonNotificationsProvider {
|
||||||
if (cid && cid[1]) {
|
if (cid && cid[1]) {
|
||||||
notification.courseid = cid[1];
|
notification.courseid = cid[1];
|
||||||
}
|
}
|
||||||
// Try to get the profile picture of the user.
|
if (notification.useridfrom > 0) {
|
||||||
this.userProvider.getProfile(notification.useridfrom, notification.courseid, true).then((user) => {
|
// Try to get the profile picture of the user.
|
||||||
notification.profileimageurlfrom = user.profileimageurl;
|
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 { CoreFileProvider } from '@providers/file';
|
||||||
import { CoreUrlUtilsProvider } from '@providers/utils/url';
|
import { CoreUrlUtilsProvider } from '@providers/utils/url';
|
||||||
import { Observable, Observer } from 'rxjs';
|
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.
|
* 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 window;
|
||||||
protected browserWindow;
|
protected browserWindow;
|
||||||
protected screen;
|
protected screen;
|
||||||
protected isSSO: boolean;
|
protected isSSO: boolean;
|
||||||
protected isLinux: boolean;
|
|
||||||
|
|
||||||
constructor(appProvider: CoreAppProvider, private fileProvider: CoreFileProvider, private urlUtils: CoreUrlUtilsProvider,
|
constructor(appProvider: CoreAppProvider, private fileProvider: CoreFileProvider, private urlUtils: CoreUrlUtilsProvider,
|
||||||
private url: string, target?: string, options: string = '') {
|
private url: string, target?: string, options: string = 'location=yes') {
|
||||||
super(url, target, options);
|
|
||||||
|
|
||||||
if (!appProvider.isDesktop()) {
|
if (!appProvider.isDesktop()) {
|
||||||
// This plugin is only supported in desktop.
|
// This plugin is only supported in desktop.
|
||||||
|
@ -40,7 +39,6 @@ export class InAppBrowserObjectMock extends InAppBrowserObject {
|
||||||
this.browserWindow = require('electron').remote.BrowserWindow;
|
this.browserWindow = require('electron').remote.BrowserWindow;
|
||||||
this.screen = require('electron').screen;
|
this.screen = require('electron').screen;
|
||||||
this.isSSO = !!(url && url.match(/\/launch\.php\?service=.+&passport=/));
|
this.isSSO = !!(url && url.match(/\/launch\.php\?service=.+&passport=/));
|
||||||
this.isLinux = appProvider.isLinux();
|
|
||||||
|
|
||||||
let width = 800,
|
let width = 800,
|
||||||
height = 600,
|
height = 600,
|
||||||
|
@ -71,7 +69,7 @@ export class InAppBrowserObjectMock extends InAppBrowserObject {
|
||||||
this.window = new this.browserWindow(bwOptions);
|
this.window = new this.browserWindow(bwOptions);
|
||||||
this.window.loadURL(url);
|
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.
|
// 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.
|
// 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';
|
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.
|
* @return {Promise<string>} Promise resolved with the launch URL.
|
||||||
*/
|
*/
|
||||||
protected getLaunchUrl(retry: number = 0): Promise<string> {
|
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 => {
|
return new Promise((resolve, reject): void => {
|
||||||
// Execute Javascript to retrieve the launch link.
|
// Execute Javascript to retrieve the launch link.
|
||||||
const jsCode = 'var el = document.querySelector("#launchapp"); el && el.href;';
|
const jsCode = 'var el = document.querySelector("#launchapp"); el && el.href;';
|
||||||
let found = false;
|
let found = false;
|
||||||
|
|
||||||
this.window.webContents.executeJavaScript(jsCode).then((launchUrl) => {
|
this.window.webContents.executeJavaScript(jsCode).then((launchUrl) => {
|
||||||
found = true;
|
found = true;
|
||||||
resolve(launchUrl);
|
resolve(launchUrl);
|
||||||
|
@ -179,7 +182,7 @@ export class InAppBrowserObjectMock extends InAppBrowserObject {
|
||||||
// Helper functions to handle events.
|
// Helper functions to handle events.
|
||||||
const received = (event, url): void => {
|
const received = (event, url): void => {
|
||||||
try {
|
try {
|
||||||
event.url = url || this.window.getURL();
|
event.url = url || (this.window.isDestroyed() ? '' : this.window.getURL());
|
||||||
event.type = name;
|
event.type = name;
|
||||||
observer.next(event);
|
observer.next(event);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
|
@ -203,7 +206,7 @@ export class InAppBrowserObjectMock extends InAppBrowserObject {
|
||||||
case 'loadstart':
|
case 'loadstart':
|
||||||
this.window.webContents.on('did-start-loading', received);
|
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.
|
// Linux doesn't support custom URL Schemes. Check if launch page is loaded.
|
||||||
this.window.webContents.on('did-finish-load', finishLoad);
|
this.window.webContents.on('did-finish-load', finishLoad);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { Injectable } from '@angular/core';
|
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 { CoreAppProvider } from '@providers/app';
|
||||||
import { CoreFileProvider } from '@providers/file';
|
import { CoreFileProvider } from '@providers/file';
|
||||||
import { CoreUrlUtilsProvider } from '@providers/utils/url';
|
import { CoreUrlUtilsProvider } from '@providers/utils/url';
|
||||||
|
@ -36,9 +36,16 @@ export class InAppBrowserMock extends InAppBrowser {
|
||||||
* @param {string} url The URL to load.
|
* @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} [target] The target in which to load the URL, an optional parameter that defaults to _self.
|
||||||
* @param {string} [options] Options for the InAppBrowser.
|
* @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()) {
|
if (!this.appProvider.isDesktop()) {
|
||||||
return super.create(url, target, options);
|
return super.create(url, target, options);
|
||||||
}
|
}
|
||||||
|
|
|
@ -148,6 +148,10 @@ export class LocalNotificationsMock extends LocalNotifications {
|
||||||
* @return {Void}
|
* @return {Void}
|
||||||
*/
|
*/
|
||||||
protected cancelNotification(id: number, omitEvent: boolean, eventName: string): void {
|
protected cancelNotification(id: number, omitEvent: boolean, eventName: string): void {
|
||||||
|
if (!this.scheduled[id]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const notification = this.scheduled[id].notification;
|
const notification = this.scheduled[id].notification;
|
||||||
|
|
||||||
clearTimeout(this.scheduled[id].timeout);
|
clearTimeout(this.scheduled[id].timeout);
|
||||||
|
@ -698,7 +702,7 @@ export class LocalNotificationsMock extends LocalNotifications {
|
||||||
id : notification.id,
|
id : notification.id,
|
||||||
title: notification.title,
|
title: notification.title,
|
||||||
text: notification.text,
|
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) : '{}',
|
data: notification.data ? JSON.stringify(notification.data) : '{}',
|
||||||
triggered: triggered ? 1 : 0
|
triggered: triggered ? 1 : 0
|
||||||
};
|
};
|
||||||
|
|
|
@ -105,10 +105,6 @@ export class CoreUpdateManagerProvider implements CoreInitHandler {
|
||||||
{
|
{
|
||||||
name: 'desktop_local_notifications',
|
name: 'desktop_local_notifications',
|
||||||
fields: [
|
fields: [
|
||||||
{
|
|
||||||
name: 'at',
|
|
||||||
type: 'date'
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: 'data',
|
name: 'data',
|
||||||
type: 'object'
|
type: 'object'
|
||||||
|
|
Loading…
Reference in New Issue