This function sends "javascript" message to the client, that executes its content. In this particular code, a notification message is shown
(self, title, content, icon="")
| 542 | self._send_spontaneous_websocket_message(_MSG_JS + code) |
| 543 | |
| 544 | def notification_message(self, title, content, icon=""): |
| 545 | """This function sends "javascript" message to the client, that executes its content. |
| 546 | In this particular code, a notification message is shown |
| 547 | """ |
| 548 | code = """ |
| 549 | var options = { |
| 550 | body: "%(content)s", |
| 551 | icon: "%(icon)s" |
| 552 | } |
| 553 | if (!("Notification" in window)) { |
| 554 | alert("%(content)s"); |
| 555 | }else if (Notification.permission === "granted") { |
| 556 | var notification = new Notification("%(title)s", options); |
| 557 | }else if (Notification.permission !== 'denied') { |
| 558 | Notification.requestPermission(function (permission) { |
| 559 | if (permission === "granted") { |
| 560 | var notification = new Notification("%(title)s", options); |
| 561 | } |
| 562 | }); |
| 563 | } |
| 564 | """ % {'title': title, 'content': content, 'icon': icon} |
| 565 | self.execute_javascript(code) |
| 566 | |
| 567 | def do_POST(self): |
| 568 | self._instance() |
no test coverage detected