From 62773acaa099d7633a6d83d44b790f4f53fb274e Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch
Date: Sun, 11 Sep 2022 03:38:33 +0200 Subject: xP: beep on highlight 800 Hz seems like it could match a POST beep. --- xP/public/xP.js | 48 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/xP/public/xP.js b/xP/public/xP.js index b62d6c2..7fa6bf3 100644 --- a/xP/public/xP.js +++ b/xP/public/xP.js @@ -127,6 +127,32 @@ class RelayRpc extends EventTarget { } } +// ---- Utilities -------------------------------------------------------------- + +// On macOS, the Alt/Option key transforms characters, which basically breaks +// all event.altKey shortcuts, so require combining them with Control as well +// on that system. +function hasShortcutModifiers(event) { + // This method of detection only works with Blink browsers, as of writing. + return event.altKey && !event.metaKey && + (navigator.userAgentData?.platform === 'macOS') === event.ctrlKey +} + +const audioContext = new AudioContext() + +function beep() { + let gain = audioContext.createGain() + gain.gain.value = 0.5 + gain.connect(audioContext.destination) + + let oscillator = audioContext.createOscillator() + oscillator.type = "triangle" + oscillator.frequency.value = 800 + oscillator.connect(gain) + oscillator.start(audioContext.currentTime) + oscillator.stop(audioContext.currentTime + 0.1) +} + // ---- Event processing ------------------------------------------------------- let rpc = new RelayRpc(proxy) @@ -300,8 +326,11 @@ rpc.addEventListener('BufferLine', event => { // TODO: Find some way of highlighting the tab in a browser. // TODO: Also highlight on unseen private messages, like xC does. - if (!visible && line.isHighlight) - b.highlighted = true + if (line.isHighlight) { + beep() + if (!visible) + b.highlighted = true + } }) rpc.addEventListener('BufferClear', event => { @@ -331,15 +360,6 @@ for (let i = 0; i < 24; i++) { // ---- UI --------------------------------------------------------------------- -// On macOS, the Alt/Option key transforms characters, which basically breaks -// all event.altKey shortcuts, so require combining them with Control as well -// on that system. -function hasShortcutModifiers(event) { - // This method of detection only works with Blink browsers, as of writing. - return event.altKey && !event.metaKey && - (navigator.userAgentData?.platform === 'macOS') === event.ctrlKey -} - let linkRE = [ /https?:\/\//, /([^\[\](){}<>"'\s]|\([^\[\](){}<>"'\s]*\))+/, @@ -616,11 +636,12 @@ let Input = { if (b === undefined) return false - // TODO: Ding otherwise. if (b.historyAt > 0) { if (b.historyAt == b.history.length) b.input = textarea.value textarea.value = b.history[--b.historyAt] + } else { + beep() } return true }, @@ -630,12 +651,13 @@ let Input = { if (b === undefined) return false - // TODO: Ding otherwise. if (b.historyAt < b.history.length) { if (++b.historyAt == b.history.length) textarea.value = b.input else textarea.value = b.history[b.historyAt] + } else { + beep() } return true }, -- cgit v1.2.3-70-g09d2