This commit is contained in:
khlam 2019-10-18 21:30:26 -07:00
parent 2c61c4be93
commit a0265c922a
3 changed files with 81 additions and 27 deletions

View File

@ -26,20 +26,20 @@ webview {
-webkit-app-region: drag; -webkit-app-region: drag;
margin: 0; margin: 0;
display: flex; display: flex;
background-color: #23272A; background-color: #212226;
width: 100%; width: 100%;
height: 3%; height: 3%;
} }
.menu-button-container { .menu-button-container {
background-color: #23272A; background-color: #212226;
display: flex; display: flex;
align-items: center; align-items: center;
flex-grow: 1; flex-grow: 1;
} }
.status { .status {
background-color: #23272A; background-color: #212226;
color: #FFFFFF; color: #FFFFFF;
display: flex; display: flex;
justify-content: center; justify-content: center;
@ -48,7 +48,7 @@ webview {
} }
.window-controls-container { .window-controls-container {
background-color: #23272A; background-color: #212226;
display: flex; display: flex;
justify-content: flex-end; justify-content: flex-end;
align-items: center; align-items: center;

32
main.js
View File

@ -73,26 +73,14 @@ app.on('activate', function () {
let isTalking = false let isTalking = false
let isConnected = false let isConnected = false
function muteDelay() {
return new Promise((resolve) => {
setTimeout(function(){
return resolve(true)
}, 1300); // big fat push to talk delay .com
})
}
function muteMic() { function muteMic() {
if (isConnected === true) { if (isConnected === true) {
return new Promise((resolve) => { return new Promise((resolve) => {
if (isTalking === false) { if (isTalking === false) {
muteDelay().then(val => { console.log("Muted")
if (isTalking === false) { mainWindow.webContents.send('ping', 'mic-closed')
console.log("Muted") mainWindow.setTitle("MUTED")
mainWindow.webContents.send('ping', 'mic-closed') return resolve(true)
mainWindow.setTitle("MUTED")
return resolve(true)
}
})
} }
}) })
} }
@ -132,6 +120,8 @@ ioHook.on('mouseup', event => {
ipcMain.on('asynchronous-message', (event, msg) => { ipcMain.on('asynchronous-message', (event, msg) => {
if (msg === 'connected') { if (msg === 'connected') {
isConnected = true isConnected = true
isTalking = false
muteMic()
} }
if (msg === 'disconnected') { if (msg === 'disconnected') {
@ -139,6 +129,16 @@ ipcMain.on('asynchronous-message', (event, msg) => {
isTalking = false isTalking = false
} }
if (msg === 'self-muted') {
console.log("self-muted")
isConnected = false
}
if (msg === 'self-unmuted') {
console.log("self-unmuted")
isConnected = true
}
if (msg === 'DOMready') { if (msg === 'DOMready') {
mainWindow.webContents.send('devMode', devMode) mainWindow.webContents.send('devMode', devMode)
} }

View File

@ -1,5 +1,12 @@
const { remote, ipcRenderer } = require('electron') 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();
`)
}
onload = () => { onload = () => {
const webview = document.querySelector('webview') const webview = document.querySelector('webview')
@ -16,7 +23,7 @@ onload = () => {
}else { }else {
console.log("waiting for load") console.log("waiting for load")
} }
}, 1500); }, 500);
`) `)
}); });
@ -32,12 +39,59 @@ onload = () => {
ipcRenderer.send('asynchronous-message', 'disconnected') ipcRenderer.send('asynchronous-message', 'disconnected')
} }
// Execute JS into the webview after login to remove the download button at the bottom of the server list. if (e.message === "muted") {
console.log("Self Muted in Discord")
ipcRenderer.send('asynchronous-message', 'self-muted')
}
if (e.message === "unmuted") {
console.log("Self Muted in Discord")
ipcRenderer.send('asynchronous-message', 'self-unmuted')
}
if (e.message === "signalingState => stable, negotiation needed: false") {
console.log("Mute/Unmute")
removeBloat(webview)
webview.executeJavaScript(`
if (document.querySelectorAll('[aria-label="Mute"]').length === 0){
console.log("muted")
}else {
console.log("unmuted")
}
`)
}
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") { if (e.message === "discord-load-complete") {
webview.executeJavaScript(` webview.executeJavaScript(`
let a = document.getElementsByClassName("listItem-2P_4kh"); document.getElementsByClassName("listItem-2P_4kh")[document.getElementsByClassName("listItem-2P_4kh").length - 1].remove();
a[a.length-1].innerHTML = "";
const targetNode = document.getElementsByClassName("scroller-2FKFPG firefoxFixScrollFlex-cnI2ix systemPad-3UxEGl scroller-2TZvBN")[0]
const config = { attributes: true, childList: true, subtree: true };
const callback = function(mutationsList, observer) {
for(let mutation of mutationsList) {
if (mutation.type === 'childList') {
console.log('DOM changed');
}
else if (mutation.type === 'attributes') {
console.log('DOM changed');
}
}
};
const observer = new MutationObserver(callback);
observer.observe(targetNode, config);
`) `)
removeBloat(webview)
} }
}) })
@ -55,9 +109,9 @@ onload = () => {
console.log("not talking") console.log("not talking")
webview.sendInputEvent({keyCode: 'Backspace', type: 'keyUp'}); webview.sendInputEvent({keyCode: 'Backspace', type: 'keyUp'});
webview.sendInputEvent({keyCode: 'Backspace', type: 'char'}); webview.sendInputEvent({keyCode: 'Backspace', type: 'char'});
document.getElementById("title-bar-status").style.backgroundColor = "#23272A" document.getElementById("title-bar-status").style.backgroundColor = "#212226"
document.getElementById("title-bar-controls").style.backgroundColor = "#23272A" document.getElementById("title-bar-controls").style.backgroundColor = "#212226"
document.getElementById("title-bar").style.backgroundColor = "#23272A" document.getElementById("title-bar").style.backgroundColor = "#212226"
} }
}) })