Support Notification API
This commit is contained in:
parent
d7d75a1fe8
commit
b55d2b53df
3 changed files with 120 additions and 11 deletions
|
@ -868,6 +868,8 @@ class UiWebsocket(object):
|
||||||
self.response(to, _["Modify your client's configuration and access all site"] + " <span style='color: red'>" + _["(Dangerous!)"] + "</span>")
|
self.response(to, _["Modify your client's configuration and access all site"] + " <span style='color: red'>" + _["(Dangerous!)"] + "</span>")
|
||||||
elif permission == "NOSANDBOX":
|
elif permission == "NOSANDBOX":
|
||||||
self.response(to, _["Modify your client's configuration and access all site"] + " <span style='color: red'>" + _["(Dangerous!)"] + "</span>")
|
self.response(to, _["Modify your client's configuration and access all site"] + " <span style='color: red'>" + _["(Dangerous!)"] + "</span>")
|
||||||
|
elif permission == "PushNotification":
|
||||||
|
self.response(to, _["Send notifications"])
|
||||||
else:
|
else:
|
||||||
self.response(to, "")
|
self.response(to, "")
|
||||||
|
|
||||||
|
|
|
@ -190,6 +190,8 @@ class Wrapper
|
||||||
@actionPermissionAdd(message)
|
@actionPermissionAdd(message)
|
||||||
else if cmd == "wrapperRequestFullscreen"
|
else if cmd == "wrapperRequestFullscreen"
|
||||||
@actionRequestFullscreen()
|
@actionRequestFullscreen()
|
||||||
|
else if cmd == "wrapperPushNotification"
|
||||||
|
@actionPushNotification(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
|
||||||
|
@ -236,6 +238,38 @@ 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) ->
|
||||||
|
$.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
|
||||||
|
# Check that the wrapper may send notifications
|
||||||
|
if Notification.permission == "granted"
|
||||||
|
@displayPushNotification message
|
||||||
|
else if Notification.permission == "denied"
|
||||||
|
res = {"error": "Push notifications are disabled by the user"}
|
||||||
|
@sendInner {"cmd": "response", "to": message.id, "result": res}
|
||||||
|
else
|
||||||
|
Notification.requestPermission().then (permission) =>
|
||||||
|
if permission == "granted"
|
||||||
|
@displayPushNotification message
|
||||||
|
|
||||||
|
displayPushNotification: (message) ->
|
||||||
|
title = message.params[0]
|
||||||
|
id = message.params[1]
|
||||||
|
options = message.params[2]
|
||||||
|
notification = new Notification(title, options)
|
||||||
|
notification.onshow = () =>
|
||||||
|
@sendInner {"cmd": "response", "to": message.id, "result": "ok"}
|
||||||
|
notification.onclick = (e) =>
|
||||||
|
if not options.focus_tab
|
||||||
|
e.preventDefault()
|
||||||
|
@sendInner {"cmd": "pushNotificationClick", "params": {"id": id}}
|
||||||
|
notification.onclose = () =>
|
||||||
|
@sendInner {"cmd": "pushNotificationClose", "params": {"id": id}}
|
||||||
|
|
||||||
actionPermissionAdd: (message) ->
|
actionPermissionAdd: (message) ->
|
||||||
permission = message.params
|
permission = message.params
|
||||||
$.when(@event_site_info).done =>
|
$.when(@event_site_info).done =>
|
||||||
|
|
|
@ -34,7 +34,6 @@
|
||||||
|
|
||||||
}).call(this);
|
}).call(this);
|
||||||
|
|
||||||
|
|
||||||
/* ---- src/Ui/media/lib/Translate.coffee ---- */
|
/* ---- src/Ui/media/lib/Translate.coffee ---- */
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,7 +44,6 @@
|
||||||
|
|
||||||
}).call(this);
|
}).call(this);
|
||||||
|
|
||||||
|
|
||||||
/* ---- src/Ui/media/lib/ZeroWebsocket.coffee ---- */
|
/* ---- src/Ui/media/lib/ZeroWebsocket.coffee ---- */
|
||||||
|
|
||||||
|
|
||||||
|
@ -201,7 +199,6 @@
|
||||||
|
|
||||||
}).call(this);
|
}).call(this);
|
||||||
|
|
||||||
|
|
||||||
/* ---- src/Ui/media/lib/jquery.cssanim.js ---- */
|
/* ---- src/Ui/media/lib/jquery.cssanim.js ---- */
|
||||||
|
|
||||||
|
|
||||||
|
@ -307,7 +304,6 @@ if (window.getComputedStyle(document.body).transform) {
|
||||||
|
|
||||||
}).call(this);
|
}).call(this);
|
||||||
|
|
||||||
|
|
||||||
/* ---- src/Ui/media/lib/jquery.easing.js ---- */
|
/* ---- src/Ui/media/lib/jquery.easing.js ---- */
|
||||||
|
|
||||||
|
|
||||||
|
@ -535,7 +531,6 @@ $.extend( $.easing,
|
||||||
|
|
||||||
}).call(this);
|
}).call(this);
|
||||||
|
|
||||||
|
|
||||||
/* ---- src/Ui/media/Infopanel.coffee ---- */
|
/* ---- src/Ui/media/Infopanel.coffee ---- */
|
||||||
|
|
||||||
|
|
||||||
|
@ -626,7 +621,6 @@ $.extend( $.easing,
|
||||||
|
|
||||||
}).call(this);
|
}).call(this);
|
||||||
|
|
||||||
|
|
||||||
/* ---- src/Ui/media/Loading.coffee ---- */
|
/* ---- src/Ui/media/Loading.coffee ---- */
|
||||||
|
|
||||||
|
|
||||||
|
@ -773,7 +767,6 @@ $.extend( $.easing,
|
||||||
|
|
||||||
}).call(this);
|
}).call(this);
|
||||||
|
|
||||||
|
|
||||||
/* ---- src/Ui/media/Notifications.coffee ---- */
|
/* ---- src/Ui/media/Notifications.coffee ---- */
|
||||||
|
|
||||||
|
|
||||||
|
@ -908,7 +901,6 @@ $.extend( $.easing,
|
||||||
|
|
||||||
}).call(this);
|
}).call(this);
|
||||||
|
|
||||||
|
|
||||||
/* ---- src/Ui/media/Wrapper.coffee ---- */
|
/* ---- src/Ui/media/Wrapper.coffee ---- */
|
||||||
|
|
||||||
|
|
||||||
|
@ -1171,6 +1163,8 @@ $.extend( $.easing,
|
||||||
return this.actionPermissionAdd(message);
|
return this.actionPermissionAdd(message);
|
||||||
} else if (cmd === "wrapperRequestFullscreen") {
|
} else if (cmd === "wrapperRequestFullscreen") {
|
||||||
return this.actionRequestFullscreen();
|
return this.actionRequestFullscreen();
|
||||||
|
} else if (cmd === "wrapperPushNotification") {
|
||||||
|
return this.actionPushNotification(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)) {
|
||||||
|
@ -1239,6 +1233,83 @@ $.extend( $.easing,
|
||||||
return request_fullscreen.call(elem);
|
return request_fullscreen.call(elem);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Wrapper.prototype.actionPushNotification = function(message) {
|
||||||
|
return $.when(this.event_site_info).done((function(_this) {
|
||||||
|
return function() {
|
||||||
|
var 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;
|
||||||
|
}
|
||||||
|
if (Notification.permission === "granted") {
|
||||||
|
return _this.displayPushNotification(message);
|
||||||
|
} else if (Notification.permission === "denied") {
|
||||||
|
res = {
|
||||||
|
"error": "Push notifications are disabled by the user"
|
||||||
|
};
|
||||||
|
return _this.sendInner({
|
||||||
|
"cmd": "response",
|
||||||
|
"to": message.id,
|
||||||
|
"result": res
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return Notification.requestPermission().then(function(permission) {
|
||||||
|
if (permission === "granted") {
|
||||||
|
return _this.displayPushNotification(message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})(this));
|
||||||
|
};
|
||||||
|
|
||||||
|
Wrapper.prototype.displayPushNotification = function(message) {
|
||||||
|
var id, notification, options, title;
|
||||||
|
title = message.params[0];
|
||||||
|
id = message.params[1];
|
||||||
|
options = message.params[2];
|
||||||
|
notification = new Notification(title, options);
|
||||||
|
notification.onshow = (function(_this) {
|
||||||
|
return function() {
|
||||||
|
return _this.sendInner({
|
||||||
|
"cmd": "response",
|
||||||
|
"to": message.id,
|
||||||
|
"result": "ok"
|
||||||
|
});
|
||||||
|
};
|
||||||
|
})(this);
|
||||||
|
notification.onclick = (function(_this) {
|
||||||
|
return function(e) {
|
||||||
|
if (!options.focus_tab) {
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
return _this.sendInner({
|
||||||
|
"cmd": "pushNotificationClick",
|
||||||
|
"params": {
|
||||||
|
"id": id
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
})(this);
|
||||||
|
return notification.onclose = (function(_this) {
|
||||||
|
return function() {
|
||||||
|
return _this.sendInner({
|
||||||
|
"cmd": "pushNotificationClose",
|
||||||
|
"params": {
|
||||||
|
"id": id
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
})(this);
|
||||||
|
};
|
||||||
|
|
||||||
Wrapper.prototype.actionPermissionAdd = function(message) {
|
Wrapper.prototype.actionPermissionAdd = function(message) {
|
||||||
var permission;
|
var permission;
|
||||||
permission = message.params;
|
permission = message.params;
|
||||||
|
@ -1328,9 +1399,11 @@ $.extend( $.easing,
|
||||||
Wrapper.prototype.displayPrompt = function(message, type, caption, placeholder, cb) {
|
Wrapper.prototype.displayPrompt = function(message, type, caption, placeholder, cb) {
|
||||||
var body, button, input;
|
var body, button, input;
|
||||||
body = $("<span class='message'></span>").html(message);
|
body = $("<span class='message'></span>").html(message);
|
||||||
if (placeholder == null) {
|
if (placeholder != null) {
|
||||||
|
placeholder;
|
||||||
|
} else {
|
||||||
placeholder = "";
|
placeholder = "";
|
||||||
}
|
};
|
||||||
input = $("<input/>", {
|
input = $("<input/>", {
|
||||||
type: type,
|
type: type,
|
||||||
"class": "input button-" + type,
|
"class": "input button-" + type,
|
||||||
|
@ -1946,4 +2019,4 @@ $.extend( $.easing,
|
||||||
|
|
||||||
window.zeroframe = new WrapperZeroFrame(window.wrapper);
|
window.zeroframe = new WrapperZeroFrame(window.wrapper);
|
||||||
|
|
||||||
}).call(this);
|
}).call(this);
|
Loading…
Reference in a new issue