1
0
mirror of https://github.com/dkmstr/openuds-gui.git synced 2025-03-12 08:58:21 +03:00

Detected session termination and fixed Launchers to detect "close button" pressed

This commit is contained in:
Adolfo Gómez García 2021-05-11 18:01:17 +02:00
parent bf45826e89
commit 8eaa2b7f33
2 changed files with 114 additions and 102 deletions

View File

@ -16,6 +16,27 @@ export class Plugin {
}
launchURL(url: string): void {
// Internal helper for notify errors
const notifyError = (error?: any) => {
let msg: string = django.gettext(
'Error communicating with your service. Please, retry again.'
);
if (typeof error === 'string') {
msg = error;
} else if (error.status === 403) {
// Session timeout
msg = django.gettext('Your session has expired. Please, login again');
}
window.setTimeout(() => {
this.showAlert(django.gettext('Error'), msg, 5000);
if (error.status === 403) {
window.setTimeout(() => {
this.api.logout();
}, 5000);
}
});
};
// If uds url...
if (url.substring(0, 7) === 'udsa://') {
const params = url.split('//')[1].split('/');
@ -27,70 +48,64 @@ export class Plugin {
0,
// Now UDS tries to check status
new Observable<boolean>((observer) => {
const notifyError = () => {
window.setTimeout(() => {
this.showAlert(
django.gettext('Error'),
django.gettext(
'Error communicating with your service. Please, retry again.'
),
5000
);
});
};
let readyTime = 0;
const checker = () => {
this.api.status(params[0], params[1]).subscribe(
(data) => {
if (data.status === 'ready') {
if (!readyTime) {
readyTime = Date.now(); // Milisecodns
alert.componentInstance.data.title = django.gettext(
'Service ready'
);
alert.componentInstance.data.body = django.gettext(
'Launching UDS Client, almost done.'
);
} else {
// If Component took too long...
if (Date.now() - readyTime > this.delay * 5) {
// Wait 5 times the default delay
alert.componentInstance.data.title =
django.gettext('Service ready') +
' - ' +
django.gettext('UDS Client not launching');
alert.componentInstance.data.body =
'<span style="color: red; ">' +
django.gettext(
'It seems that you don\'t have UDS Client installed. Please, install it from here: '
) +
'</span>' +
'<a href="' + this.api.config.urls.clientDownload + '">' +
django.gettext('UDS Client Download') +
'</a>';
if (alert.componentInstance) {
// Not closed dialog...
this.api.status(params[0], params[1]).subscribe(
(data) => {
if (data.status === 'ready') {
if (!readyTime) {
readyTime = Date.now(); // Milisecodns
alert.componentInstance.data.title = django.gettext(
'Service ready'
);
alert.componentInstance.data.body = django.gettext(
'Launching UDS Client, almost done.'
);
} else {
// If Component took too long...
if (Date.now() - readyTime > this.delay * 5) {
// Wait 5 times the default delay
alert.componentInstance.data.title =
django.gettext('Service ready') +
' - ' +
django.gettext('UDS Client not launching');
alert.componentInstance.data.body =
'<span style="color: red; ">' +
django.gettext(
'It seems that you don\'t have UDS Client installed. Please, install it from here: '
) +
'</span>' +
'<a href="' +
this.api.config.urls.clientDownload +
'">' +
django.gettext('UDS Client Download') +
'</a>';
}
}
window.setTimeout(checker, this.delay); // Recheck after delay seconds
} else if (data.status === 'accessed') {
alert.componentInstance.data.body = django.gettext(
'Machine ready, waiting for UDS Client'
);
observer.next(true);
observer.complete();
} else if (data.status === 'running') {
window.setTimeout(checker, this.delay); // Recheck after delay seconds
} else {
observer.next(true);
observer.complete();
notifyError();
}
window.setTimeout(checker, this.delay); // Recheck after delay seconds
} else if (data.status === 'accessed') {
alert.componentInstance.data.body = django.gettext(
'Machine ready, waiting for UDS Client'
);
},
(error) => {
observer.next(true);
observer.complete();
} else if (data.status === 'running') {
window.setTimeout(checker, this.delay); // Recheck after delay seconds
} else {
observer.next(true);
observer.complete();
notifyError();
notifyError(error);
}
},
(error) => {
observer.next(true);
observer.complete();
notifyError();
}
);
);
}
};
window.setTimeout(checker);
})
@ -126,58 +141,49 @@ export class Plugin {
0,
// Now UDS tries to check status before closing dialog...
new Observable<boolean>((observer) => {
const notifyError = (error: string = null) => {
window.setTimeout(() => {
this.showAlert(
django.gettext('Error'),
error ||
django.gettext(
'Error communicating with your service. Please, retry again.'
),
5000
);
});
};
const checker = () => {
this.api.transportUrl(url).subscribe(
(data) => {
if (data.url) {
observer.next(true);
observer.complete(); // Notify window to close...
if (data.url.indexOf('o_s_w=') !== -1) {
window.location.href = data.url;
} else {
// If the url contains "o_n_w", will open the url on a new window ALWAYS
let name = 'global';
if (data.url.indexOf('o_n_w=') !== -1) {
// Extract window name from o_n_w parameter if present
const onw = /.*o_n_w=([a-zA-Z0-9._-]*)/.exec(data.url);
if (onw) {
name = onw[1];
if (alert.componentInstance) {
// Not closed dialog...
this.api.transportUrl(url).subscribe(
(data) => {
if (data.url) {
observer.next(true);
observer.complete(); // Notify window to close...
if (data.url.indexOf('o_s_w=') !== -1) {
window.location.href = data.url;
} else {
// If the url contains "o_n_w", will open the url on a new window ALWAYS
let name = 'global';
if (data.url.indexOf('o_n_w=') !== -1) {
// Extract window name from o_n_w parameter if present
const onw = /.*o_n_w=([a-zA-Z0-9._-]*)/.exec(data.url);
if (onw) {
name = onw[1];
}
}
if (Plugin.transportsWindow[name]) {
Plugin.transportsWindow[name].close();
}
Plugin.transportsWindow[name] = window.open(
data.url,
'uds_trans_' + name
);
}
if (Plugin.transportsWindow[name]) {
Plugin.transportsWindow[name].close();
}
Plugin.transportsWindow[name] = window.open(
data.url,
'uds_trans_' + name
);
} else if (!data.running) {
observer.next(true);
observer.complete();
notifyError(data.error);
} else {
window.setTimeout(checker, this.delay); // Recheck after 5 seconds
}
} else if (!data.running) {
},
(error) => {
observer.next(true);
observer.complete();
notifyError(data.error);
} else {
window.setTimeout(checker, this.delay); // Recheck after 5 seconds
notifyError(error);
}
},
(error) => {
observer.next(true);
observer.complete();
notifyError();
}
);
);
}
};
window.setTimeout(checker);
})

View File

@ -33,6 +33,12 @@ export interface UDSApiServiceType {
/* transport url */
transportUrl(url: string): Observable<JSONTransportURLService>;
/* Go to admin dashboard */
gotoAdmin(): void;
/* Executes logout */
logout(): void;
/**
* Gets services information
*/