diff options
author | Přemysl Eric Janouch <p@janouch.name> | 2022-09-11 03:38:33 +0200 |
---|---|---|
committer | Přemysl Eric Janouch <p@janouch.name> | 2022-09-11 03:42:08 +0200 |
commit | 62773acaa099d7633a6d83d44b790f4f53fb274e (patch) | |
tree | 649b17fe30ea772d92c27e590025c20da0ae0c73 | |
parent | 7e3919e25d83c58edc2a18980c3833be67d8aa87 (diff) | |
download | xK-62773acaa099d7633a6d83d44b790f4f53fb274e.tar.gz xK-62773acaa099d7633a6d83d44b790f4f53fb274e.tar.xz xK-62773acaa099d7633a6d83d44b790f4f53fb274e.zip |
xP: beep on highlight
800 Hz seems like it could match a POST beep.
-rw-r--r-- | xP/public/xP.js | 48 |
1 files 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 }, |