From 5cbb3ea2c9b923def5ddca9cf5eae3e3faa65a58 Mon Sep 17 00:00:00 2001 From: cpsdqs Date: Sun, 10 Sep 2017 02:36:14 +0200 Subject: [PATCH] Make G (growl) send a Notification --- jssrc/term_screen.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/jssrc/term_screen.js b/jssrc/term_screen.js index b5b5a28..08bc68e 100644 --- a/jssrc/term_screen.js +++ b/jssrc/term_screen.js @@ -909,6 +909,18 @@ class TermScreen { }) } + showNotification (text) { + // TODO: request permission earlier + // the requestPermission should be user-triggered; asking upfront seems + // a little awkward + if (Notification && Notification.permission === 'granted') { + let notification = new Notification('ESPTerm', { + body: text + }); + notification.addEventListener('click', () => window.focus()); + } + } + load (str) { const content = str.substr(1); @@ -922,6 +934,8 @@ class TermScreen { case 'B': this.beep(); break; + case 'G': + this.showNotification(content); default: console.warn(`Bad data message type; ignoring.\n${JSON.stringify(content)}`) }