Rename Push notifications to Web notifications
This commit is contained in:
parent
e618c0e9ef
commit
9ddb984004
1 changed files with 20 additions and 20 deletions
|
@ -33,7 +33,7 @@ class Wrapper
|
||||||
@address = null
|
@address = null
|
||||||
@opener_tested = false
|
@opener_tested = false
|
||||||
@announcer_line = null
|
@announcer_line = null
|
||||||
@push_notifications = {}
|
@web_notifications = {}
|
||||||
|
|
||||||
@allowed_event_constructors = [window.MouseEvent, window.KeyboardEvent, window.PointerEvent] # Allowed event constructors
|
@allowed_event_constructors = [window.MouseEvent, window.KeyboardEvent, window.PointerEvent] # Allowed event constructors
|
||||||
|
|
||||||
|
@ -191,10 +191,10 @@ class Wrapper
|
||||||
@actionPermissionAdd(message)
|
@actionPermissionAdd(message)
|
||||||
else if cmd == "wrapperRequestFullscreen"
|
else if cmd == "wrapperRequestFullscreen"
|
||||||
@actionRequestFullscreen()
|
@actionRequestFullscreen()
|
||||||
else if cmd == "wrapperPushNotification"
|
else if cmd == "wrapperWebNotification"
|
||||||
@actionPushNotification(message)
|
@actionWebNotification(message)
|
||||||
else if cmd == "wrapperClosePushNotification"
|
else if cmd == "wrapperCloseWebNotification"
|
||||||
@actionClosePushNotification(message)
|
@actionCloseWebNotification(message)
|
||||||
else # Send to websocket
|
else # Send to websocket
|
||||||
if message.id < 1000000
|
if message.id < 1000000
|
||||||
if message.cmd == "fileWrite" and not @modified_panel_updater_timer and site_info?.settings?.own
|
if message.cmd == "fileWrite" and not @modified_panel_updater_timer and site_info?.settings?.own
|
||||||
|
@ -241,49 +241,49 @@ class Wrapper
|
||||||
request_fullscreen = elem.requestFullScreen || elem.webkitRequestFullscreen || elem.mozRequestFullScreen || elem.msRequestFullScreen
|
request_fullscreen = elem.requestFullScreen || elem.webkitRequestFullscreen || elem.mozRequestFullScreen || elem.msRequestFullScreen
|
||||||
request_fullscreen.call(elem)
|
request_fullscreen.call(elem)
|
||||||
|
|
||||||
actionPushNotification: (message) ->
|
actionWebNotification: (message) ->
|
||||||
$.when(@event_site_info).done =>
|
$.when(@event_site_info).done =>
|
||||||
# Check that this site may send notifications
|
# Check that this site may send notifications
|
||||||
if "PushNotifications" not in @site_info.settings.permissions
|
if "WebNotifications" not in @site_info.settings.permissions
|
||||||
res = {"error": "No PushNotifications permission"}
|
res = {"error": "No WebNotifications permission"}
|
||||||
@sendInner {"cmd": "response", "to": message.id, "result": res}
|
@sendInner {"cmd": "response", "to": message.id, "result": res}
|
||||||
return
|
return
|
||||||
# Check that the wrapper may send notifications
|
# Check that the wrapper may send notifications
|
||||||
if Notification.permission == "granted"
|
if Notification.permission == "granted"
|
||||||
@displayPushNotification message
|
@displayWebNotification message
|
||||||
else if Notification.permission == "denied"
|
else if Notification.permission == "denied"
|
||||||
res = {"error": "Push notifications are disabled by the user"}
|
res = {"error": "Web notifications are disabled by the user"}
|
||||||
@sendInner {"cmd": "response", "to": message.id, "result": res}
|
@sendInner {"cmd": "response", "to": message.id, "result": res}
|
||||||
else
|
else
|
||||||
Notification.requestPermission().then (permission) =>
|
Notification.requestPermission().then (permission) =>
|
||||||
if permission == "granted"
|
if permission == "granted"
|
||||||
@displayPushNotification message
|
@displayWebNotification message
|
||||||
|
|
||||||
actionClosePushNotification: (message) ->
|
actionCloseWebNotification: (message) ->
|
||||||
$.when(@event_site_info).done =>
|
$.when(@event_site_info).done =>
|
||||||
# Check that this site may send notifications
|
# Check that this site may send notifications
|
||||||
if "PushNotifications" not in @site_info.settings.permissions
|
if "WebNotifications" not in @site_info.settings.permissions
|
||||||
res = {"error": "No PushNotifications permission"}
|
res = {"error": "No WebNotifications permission"}
|
||||||
@sendInner {"cmd": "response", "to": message.id, "result": res}
|
@sendInner {"cmd": "response", "to": message.id, "result": res}
|
||||||
return
|
return
|
||||||
id = message.params[0]
|
id = message.params[0]
|
||||||
@push_notifications[id].close()
|
@web_notifications[id].close()
|
||||||
|
|
||||||
displayPushNotification: (message) ->
|
displayWebNotification: (message) ->
|
||||||
title = message.params[0]
|
title = message.params[0]
|
||||||
id = message.params[1]
|
id = message.params[1]
|
||||||
options = message.params[2]
|
options = message.params[2]
|
||||||
notification = new Notification(title, options)
|
notification = new Notification(title, options)
|
||||||
@push_notifications[id] = notification
|
@web_notifications[id] = notification
|
||||||
notification.onshow = () =>
|
notification.onshow = () =>
|
||||||
@sendInner {"cmd": "response", "to": message.id, "result": "ok"}
|
@sendInner {"cmd": "response", "to": message.id, "result": "ok"}
|
||||||
notification.onclick = (e) =>
|
notification.onclick = (e) =>
|
||||||
if not options.focus_tab
|
if not options.focus_tab
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
@sendInner {"cmd": "pushNotificationClick", "params": {"id": id}}
|
@sendInner {"cmd": "webNotificationClick", "params": {"id": id}}
|
||||||
notification.onclose = () =>
|
notification.onclose = () =>
|
||||||
@sendInner {"cmd": "pushNotificationClose", "params": {"id": id}}
|
@sendInner {"cmd": "webNotificationClose", "params": {"id": id}}
|
||||||
delete @push_notifications[id]
|
delete @web_notifications[id]
|
||||||
|
|
||||||
actionPermissionAdd: (message) ->
|
actionPermissionAdd: (message) ->
|
||||||
permission = message.params
|
permission = message.params
|
||||||
|
|
Loading…
Reference in a new issue