1313*/
1414
1515// Import frontend framework
16- import { Observable , WebSocketClient , QueryRouter , Loader , sessionService , RemoteData } from '/js/src/index.js' ;
16+ import { Observable , WebSocketClient , QueryRouter , Loader , sessionService , RemoteData , showNativeBrowserNotification } from '/js/src/index.js' ;
1717import { Notification as O2Notification } from '/js/src/index.js' ;
1818import Lock from './lock/Lock.js' ;
1919import Environment from './environment/Environment.js' ;
@@ -153,7 +153,7 @@ export default class Model extends Observable {
153153 if ( this . detectors . selected || this . session . role == ROLES . Guest ) {
154154 this . handleLocationChange ( ) ;
155155 }
156- this . requestBrowserNotificationPermissions ( )
156+
157157 this . notify ( ) ;
158158 }
159159
@@ -170,10 +170,14 @@ export default class Model extends Observable {
170170 const { payload : task } = message ;
171171 if ( task ?. taskId ) {
172172 // Notification is for the first task in error from an environment
173- this . showNativeNotification ( {
173+ showNativeBrowserNotification ( {
174174 title : `TASK in ${ task . state ?? 'unknown' } state` ,
175175 body : `Task ${ task . id } in environment ${ task . environmentId } is in ${ task . state ?? 'unknown' } state` ,
176- url : `?page=environment&id=${ task . environmentId } `
176+ icon : '/o2_icon.png' ,
177+ onclick : ( event ) => {
178+ event ?. preventDefault ( ) ;
179+ this . router . go ( `?page=environment&id=${ task . environmentId } ` , '_blank' ) ;
180+ }
177181 } ) ;
178182 }
179183 break ;
@@ -361,36 +365,4 @@ export default class Model extends Observable {
361365 this . notify ( ) ;
362366 }
363367 }
364-
365- /**
366- * Display a browser notification(Notification - Web API)
367- * @param {String } message
368- */
369- showNativeNotification ( message ) {
370- const notification = new Notification ( message . title , { body : message . body , icon : '/o2_icon.png' } ) ;
371- notification . onclick = ( event ) => {
372- event . preventDefault ( ) ;
373- this . router . go ( message . url , '_blank' ) ;
374- }
375- }
376-
377- /**
378- * Request notification permission
379- */
380- requestBrowserNotificationPermissions ( ) {
381- if ( this . checkBrowserNotificationPermissions ( ) ) {
382- Notification . requestPermission ( ) ;
383- }
384- }
385-
386- /**
387- * Defines policy when user can trigger request for enabling notifications
388- * This is used to display/hide enable button
389- * @returns {boolean } True when notifications are not enabled and HTTPS is used
390- */
391- checkBrowserNotificationPermissions ( ) {
392- return ( Notification . permission === 'denied' ||
393- Notification . permission === 'default' ) &&
394- window . location . protocol === "https:" ;
395- }
396368}
0 commit comments