xP: beep on highlight

800 Hz seems like it could match a POST beep.
This commit is contained in:
Přemysl Eric Janouch 2022-09-11 03:38:33 +02:00
parent 7e3919e25d
commit 62773acaa0
Signed by: p
GPG Key ID: A0420B94F92B9493

View File

@ -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 ------------------------------------------------------- // ---- Event processing -------------------------------------------------------
let rpc = new RelayRpc(proxy) 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: Find some way of highlighting the tab in a browser.
// TODO: Also highlight on unseen private messages, like xC does. // TODO: Also highlight on unseen private messages, like xC does.
if (!visible && line.isHighlight) if (line.isHighlight) {
beep()
if (!visible)
b.highlighted = true b.highlighted = true
}
}) })
rpc.addEventListener('BufferClear', event => { rpc.addEventListener('BufferClear', event => {
@ -331,15 +360,6 @@ for (let i = 0; i < 24; i++) {
// ---- UI --------------------------------------------------------------------- // ---- 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 = [ let linkRE = [
/https?:\/\//, /https?:\/\//,
/([^\[\](){}<>"'\s]|\([^\[\](){}<>"'\s]*\))+/, /([^\[\](){}<>"'\s]|\([^\[\](){}<>"'\s]*\))+/,
@ -616,11 +636,12 @@ let Input = {
if (b === undefined) if (b === undefined)
return false return false
// TODO: Ding otherwise.
if (b.historyAt > 0) { if (b.historyAt > 0) {
if (b.historyAt == b.history.length) if (b.historyAt == b.history.length)
b.input = textarea.value b.input = textarea.value
textarea.value = b.history[--b.historyAt] textarea.value = b.history[--b.historyAt]
} else {
beep()
} }
return true return true
}, },
@ -630,12 +651,13 @@ let Input = {
if (b === undefined) if (b === undefined)
return false return false
// TODO: Ding otherwise.
if (b.historyAt < b.history.length) { if (b.historyAt < b.history.length) {
if (++b.historyAt == b.history.length) if (++b.historyAt == b.history.length)
textarea.value = b.input textarea.value = b.input
else else
textarea.value = b.history[b.historyAt] textarea.value = b.history[b.historyAt]
} else {
beep()
} }
return true return true
}, },