From 6f614fec629457e9c08add98ae31c61af7c6874c Mon Sep 17 00:00:00 2001 From: khlam <4841220+khlam@users.noreply.github.com> Date: Sat, 19 Oct 2019 11:51:08 -0700 Subject: [PATCH] fix getting cut-off --- main.js | 4 ++-- renderer.js | 24 ++++++++++++++++-------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/main.js b/main.js index d8e4431..a2642b3 100644 --- a/main.js +++ b/main.js @@ -78,7 +78,7 @@ function muteMic() { return new Promise((resolve) => { if (isTalking === false) { console.log("Muted") - mainWindow.webContents.send('ping', 'mic-closed') + mainWindow.webContents.send('micClose', 'mic-closed') mainWindow.setTitle("MUTED") return resolve(true) } @@ -91,7 +91,7 @@ function unmuteMic() { return new Promise((resolve, reject) => { console.log("Talking") isTalking = true - mainWindow.webContents.send('ping', 'mic-open') + mainWindow.webContents.send('micOpen', 'mic-open') mainWindow.setTitle("MIC OPEN") return resolve(true) }) diff --git a/renderer.js b/renderer.js index 8343f36..f2390cc 100644 --- a/renderer.js +++ b/renderer.js @@ -7,8 +7,18 @@ function removeBloat(webview) { `) } +function muteMic(webview){ + console.log("not talking") + webview.sendInputEvent({keyCode: 'Backspace', type: 'keyUp'}); + webview.sendInputEvent({keyCode: 'Backspace', type: 'char'}); + document.getElementById("title-bar-status").style.backgroundColor = "#212226" + document.getElementById("title-bar-controls").style.backgroundColor = "#212226" + document.getElementById("title-bar").style.backgroundColor = "#212226" +} + onload = () => { const webview = document.querySelector('webview') + let muteTimeout = null ipcRenderer.send('asynchronous-message', 'DOMready') @@ -95,8 +105,9 @@ onload = () => { } }) - ipcRenderer.on('ping', (event, msg) => { + ipcRenderer.on('micOpen', (event, msg) => { if (msg === 'mic-open'){ + clearTimeout(muteTimeout) console.log("talking") webview.sendInputEvent({keyCode: 'Backspace', type: 'keyDown'}); webview.sendInputEvent({keyCode: 'Backspace', type: 'char'}); @@ -105,14 +116,11 @@ onload = () => { document.getElementById("title-bar").style.backgroundColor = "green" } - if (msg === 'mic-closed'){ - console.log("not talking") - webview.sendInputEvent({keyCode: 'Backspace', type: 'keyUp'}); - webview.sendInputEvent({keyCode: 'Backspace', type: 'char'}); - document.getElementById("title-bar-status").style.backgroundColor = "#212226" - document.getElementById("title-bar-controls").style.backgroundColor = "#212226" - document.getElementById("title-bar").style.backgroundColor = "#212226" + }) + ipcRenderer.on('micClose', (event, msg) => { + if (msg === 'mic-closed'){ + muteTimeout = setTimeout(() => muteMic(webview), 1000); // 1 second threshold incase of accidental double-click or release so the user doesn't cut-out } })