Add closePushNotification

This commit is contained in:
Ivanq 2019-04-17 19:56:19 +03:00
parent b55d2b53df
commit e618c0e9ef
2 changed files with 42 additions and 1 deletions

View file

@ -33,6 +33,7 @@ class Wrapper
@address = null @address = null
@opener_tested = false @opener_tested = false
@announcer_line = null @announcer_line = null
@push_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
@ -192,6 +193,8 @@ class Wrapper
@actionRequestFullscreen() @actionRequestFullscreen()
else if cmd == "wrapperPushNotification" else if cmd == "wrapperPushNotification"
@actionPushNotification(message) @actionPushNotification(message)
else if cmd == "wrapperClosePushNotification"
@actionClosePushNotification(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
@ -256,11 +259,22 @@ class Wrapper
if permission == "granted" if permission == "granted"
@displayPushNotification message @displayPushNotification message
actionClosePushNotification: (message) ->
$.when(@event_site_info).done =>
# Check that this site may send notifications
if "PushNotifications" not in @site_info.settings.permissions
res = {"error": "No PushNotifications permission"}
@sendInner {"cmd": "response", "to": message.id, "result": res}
return
id = message.params[0]
@push_notifications[id].close()
displayPushNotification: (message) -> displayPushNotification: (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
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) =>
@ -269,6 +283,7 @@ class Wrapper
@sendInner {"cmd": "pushNotificationClick", "params": {"id": id}} @sendInner {"cmd": "pushNotificationClick", "params": {"id": id}}
notification.onclose = () => notification.onclose = () =>
@sendInner {"cmd": "pushNotificationClose", "params": {"id": id}} @sendInner {"cmd": "pushNotificationClose", "params": {"id": id}}
delete @push_notifications[id]
actionPermissionAdd: (message) -> actionPermissionAdd: (message) ->
permission = message.params permission = message.params

View file

@ -961,6 +961,7 @@ $.extend( $.easing,
this.address = null; this.address = null;
this.opener_tested = false; this.opener_tested = false;
this.announcer_line = null; this.announcer_line = null;
this.push_notifications = {};
this.allowed_event_constructors = [window.MouseEvent, window.KeyboardEvent, window.PointerEvent]; this.allowed_event_constructors = [window.MouseEvent, window.KeyboardEvent, window.PointerEvent];
window.onload = this.onPageLoad; window.onload = this.onPageLoad;
window.onhashchange = (function(_this) { window.onhashchange = (function(_this) {
@ -1165,6 +1166,8 @@ $.extend( $.easing,
return this.actionRequestFullscreen(); return this.actionRequestFullscreen();
} else if (cmd === "wrapperPushNotification") { } else if (cmd === "wrapperPushNotification") {
return this.actionPushNotification(message); return this.actionPushNotification(message);
} else if (cmd === "wrapperClosePushNotification") {
return this.actionClosePushNotification(message);
} else { } else {
if (message.id < 1000000) { if (message.id < 1000000) {
if (message.cmd === "fileWrite" && !this.modified_panel_updater_timer && (typeof site_info !== "undefined" && site_info !== null ? (ref = site_info.settings) != null ? ref.own : void 0 : void 0)) { if (message.cmd === "fileWrite" && !this.modified_panel_updater_timer && (typeof site_info !== "undefined" && site_info !== null ? (ref = site_info.settings) != null ? ref.own : void 0 : void 0)) {
@ -1270,12 +1273,34 @@ $.extend( $.easing,
})(this)); })(this));
}; };
Wrapper.prototype.actionClosePushNotification = function(message) {
return $.when(this.event_site_info).done((function(_this) {
return function() {
var id, res;
if (indexOf.call(_this.site_info.settings.permissions, "PushNotifications") < 0) {
res = {
"error": "No PushNotifications permission"
};
_this.sendInner({
"cmd": "response",
"to": message.id,
"result": res
});
return;
}
id = message.params[0];
return _this.push_notifications[id].close();
};
})(this));
};
Wrapper.prototype.displayPushNotification = function(message) { Wrapper.prototype.displayPushNotification = function(message) {
var id, notification, options, title; var id, notification, options, title;
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);
this.push_notifications[id] = notification;
notification.onshow = (function(_this) { notification.onshow = (function(_this) {
return function() { return function() {
return _this.sendInner({ return _this.sendInner({
@ -1300,12 +1325,13 @@ $.extend( $.easing,
})(this); })(this);
return notification.onclose = (function(_this) { return notification.onclose = (function(_this) {
return function() { return function() {
return _this.sendInner({ _this.sendInner({
"cmd": "pushNotificationClose", "cmd": "pushNotificationClose",
"params": { "params": {
"id": id "id": id
} }
}); });
return delete _this.push_notifications[id];
}; };
})(this); })(this);
}; };