diff --git a/main.js b/main.js index a2642b3..3243654 100644 --- a/main.js +++ b/main.js @@ -69,38 +69,25 @@ app.on('activate', function () { // code. You can also put them in separate files and require them here. 'use strict'; - -let isTalking = false +let selfMute = false let isConnected = false function muteMic() { - if (isConnected === true) { - return new Promise((resolve) => { - if (isTalking === false) { - console.log("Muted") - mainWindow.webContents.send('micClose', 'mic-closed') - mainWindow.setTitle("MUTED") - return resolve(true) - } - }) - } + console.log("Muted") + mainWindow.webContents.send('micClose', 'mic-closed') + mainWindow.setTitle("MUTED") } function unmuteMic() { - if (isConnected === true) { - return new Promise((resolve, reject) => { - console.log("Talking") - isTalking = true - mainWindow.webContents.send('micOpen', 'mic-open') - mainWindow.setTitle("MIC OPEN") - return resolve(true) - }) + if (isConnected === true && selfMute === false) { + console.log("Talking") + mainWindow.webContents.send('micOpen', 'mic-open') + mainWindow.setTitle("MIC OPEN") } } app.on('ready', event => { ioHook.start(); - console.log(`Dev Mode: ${devMode}`) }) @@ -112,7 +99,6 @@ ioHook.on('mousedown', event => { ioHook.on('mouseup', event => { if (event.button == '4') { - isTalking = false muteMic() } }) @@ -120,26 +106,24 @@ ioHook.on('mouseup', event => { ipcMain.on('asynchronous-message', (event, msg) => { if (msg === 'connected') { isConnected = true - isTalking = false muteMic() } if (msg === 'disconnected') { isConnected = false - isTalking = false } if (msg === 'self-muted') { console.log("self-muted") - isConnected = false + selfMute = true } if (msg === 'self-unmuted') { console.log("self-unmuted") - isConnected = true + selfMute = false } if (msg === 'DOMready') { - mainWindow.webContents.send('devMode', devMode) + mainWindow.webContents.send('devMode', devMode) } }) diff --git a/renderer.js b/renderer.js index 6003939..b550396 100644 --- a/renderer.js +++ b/renderer.js @@ -1,10 +1,8 @@ const { remote, ipcRenderer } = require('electron') function removeBloat(webview) { - webview.executeJavaScript(` - document.getElementsByClassName("anchor-3Z-8Bb anchorUnderlineOnHover-2ESHQB")[0].remove(); - document.getElementsByClassName("contents-18-Yxp button-3AYNKb button-2vd_v_")[0].remove(); - `) + webview.executeJavaScript(`document.getElementsByClassName("anchor-3Z-8Bb anchorUnderlineOnHover-2ESHQB")[0].remove();`) // Remove top-right help button + webview.executeJavaScript(`document.getElementsByClassName("contents-18-Yxp button-3AYNKb button-2vd_v_")[0].remove();`) // Remove gift from chat } function muteMic(webview){ @@ -71,31 +69,27 @@ onload = () => { `) } + // To be finished if (e.message === "DOM changed") { removeBloat(webview) } // Execute JS into the webview after login - // Removes download button and help button if (e.message === "discord-load-complete") { - webview.executeJavaScript(` - document.getElementsByClassName("listItem-2P_4kh")[document.getElementsByClassName("listItem-2P_4kh").length - 1].remove(); - - `) + webview.executeJavaScript(`document.getElementsByClassName("listItem-2P_4kh")[document.getElementsByClassName("listItem-2P_4kh").length - 1].remove();`) // Remove download button removeBloat(webview) } }) ipcRenderer.on('micOpen', (event, msg) => { if (msg === 'mic-open'){ - clearTimeout(muteTimeout) + clearTimeout(muteTimeout) // Cancel mic-off incase of accidental double-tap console.log("talking") webview.sendInputEvent({keyCode: 'Backspace', type: 'keyDown'}); webview.sendInputEvent({keyCode: 'Backspace', type: 'char'}); document.getElementById("title-bar-status").style.backgroundColor = "green" document.getElementById("title-bar-controls").style.backgroundColor = "green" document.getElementById("title-bar").style.backgroundColor = "green" - } })