diff --git a/README.md b/README.md index a4bf8fa..1dcefdd 100644 --- a/README.md +++ b/README.md @@ -13,29 +13,15 @@ Note that since this client is running the Discord web client, the following fea - Discord's "High Quality Audio" or whatever -## Configuration -> ~/.config/discord-sandbox/settings.json -> delay: Push to Talk Release Delay (ms) -> pttDevice: Push to Talk Device ("mouse" or "keyboard") -> key: Push to Talk Key +## Toggle Mute +Push-to-Talk is configured using the SIGUSR2. Send a SIGUSR2 to the electron process to trigger a click on the mute button. +You can send this signal in the terminal with pkill +`pkill -SIGUSR2 --oldest electron` -### Example Configuration -> { -> "delay": "1000" -> "pttDevice": "mouse" -> "key": "4" -> } +> Note: Make sure to use --oldest. Otherwise, the electron GPU processes will get angry and quit passive-agressively: +> [130264:0223/232600.871793:FATAL:gpu\_data\_manager\_impl\_private.cc(448)] GPU process isn't usable. Goodbye. +> /home/michael/builds/discord-sandboxed/node\_modules/electron/dist/electron exited with signal SIGTRAP -## Push to Talk -1. To enable push-to-talk, open Discord-Sandbox, set your push-to-talk key to `Backspace`, and lower the `Push to Talk Release Delay` slider all the way to 0 as shown. -

- -

- -2. Click on the gear icon in the top left corner. Check the box to enable system-wide push to talk. Set your push to talk key by clicking in the black box and pressing the desired key (Default PTT key is mouse button 4). Configuration settings are stored in `/Documents/DiscordSandbox/config.json`. -

- -

## Telemetry Mitigations @@ -45,7 +31,7 @@ As detailed from [Luna Mendes' discord-unofficial-docs]("https://luna.gitlab.io/ Discord likely does other sneaky things to spy on us. If you have any ideas on improving this project's security/privacy please let me know by opening an issue! -Clicking on the Logs icon to the right of the settings button in the client will open the Log window, which will detail when a communication by the client is blocked. +Clicking on the Logs icon in the client will open the Log window, which will detail when a communication by the client is blocked.

diff --git a/main.js b/main.js index 1891ad0..562f8f7 100644 --- a/main.js +++ b/main.js @@ -4,38 +4,18 @@ const {clipboard} = require('electron') const path = require('path') const URL = require('url').URL -const { initConfig, saveConfig } = require('./src/config') - -let ioHook = null - -try { - ioHook = require('iohook') -} catch(e) { - console.log(e) - ioHook = false -} - 'use strict'; let mainWindow let logWindow -let settingsWindow let devMode = false let selfMute = false let isConnected = false let webViewSession = null -let isTalking = false -let muteTimeout = null let configObj let micPermissionGranted = false -let isChangingPTTKey = false - -let pttEnable = 'mousedown' // init to mousedown/up -let pttDisable = 'mouseup' -let pttWatch = 'button' - // Set Dev mode if (process.argv.length === 3) { if (process.argv[2] === 'dev'){ @@ -43,21 +23,6 @@ if (process.argv.length === 3) { } } -function unmuteMic() { - if ( selfMute === false){ - isTalking = true - console.log("Talking") - mainWindow.webContents.send('micOpen', 'mic-open') - mainWindow.setTitle("MIC OPEN") - } -} - -function muteMic() { - console.log("Not Talking") - mainWindow.webContents.send('micClose', 'mic-closed') - mainWindow.setTitle("MIC CLOSED") -} - function createMainWindow () { // Create the browser window. mainWindow = new BrowserWindow({ @@ -115,28 +80,6 @@ function createLogWindow() { }) } -function createSettingsWindow() { - settingsWindow = new BrowserWindow({ - width: 700, - height: 400, - show: true, - resizable: false, - alwaysOnTop:true, - webPreferences: { - preload: path.join(__dirname, 'src/settingsLoad.js'), - nodeIntegration: false, - enableRemoteModule: false, - }, - frame: false - }) - - settingsWindow.loadFile('./views/settings.html') - settingsWindow.setTitle("Settings") - settingsWindow.on('closed', function () { - isChangingPTTKey = false - settingsWindow = null - }) -} function maximizeMinimizeState(windowName){ if (windowName.isMaximized()) { @@ -146,66 +89,13 @@ function maximizeMinimizeState(windowName){ } } -function restartioHook() { - if (ioHook) { - console.log("restarting io Hook") - return new Promise((resolve, reject) => { - return new Promise((resolve, reject) => { - ioHook.removeAllListeners('mousedown', () => {}) - ioHook.removeAllListeners('mouseup', () => {}) - ioHook.removeAllListeners('keydown', () => {}) - ioHook.removeAllListeners('keyup', () => {}) - ioHook.unload() - console.log("ioHook stopped") - return resolve(true) - }).then (v => { - return new Promise((resolve, reject) => { - ioHook.load() - console.log("ioHook started") - return resolve(true) - }).then(v => { - ioHook.start() - return resolve(true) - }) - }) - }) - } -} - -function setPTTKey() { - if (ioHook && configObj.pttDevice && configObj.pttDevice) { - console.log("Set PTT Key") - if (configObj.pttDevice === 'mouse'){ - pttEnable = 'mousedown' - pttDisable = 'mouseup' - pttWatch = 'button' - }else if (configObj.pttDevice === 'keyboard'){ - pttEnable = 'keydown' - pttDisable = 'keyup' - pttWatch = 'keycode' - }else { - console.log("ERROR: configObj did not set PTT device to mouse or keyboard.") - } - - ioHook.on(pttEnable, event => { - if (event[pttWatch] == configObj.key && (micPermissionGranted === true) && (isConnected === true) && (isChangingPTTKey === false)) { - clearTimeout(muteTimeout) - unmuteMic() - } - }) - - ioHook.on(pttDisable, event => { - if (event[pttWatch] == configObj.key) { - if (isTalking === true) { - isTalking = false - muteTimeout = setTimeout(() => muteMic(), configObj.delay) - } - } - }) - - }else { - console.log("Not listening for keypresses. ioHook library error or PTT keys not set.") - } +function listenForKeySignal() { + console.log('listening for key signals...'); + // Listen for process signal + // SIGUSR2 - Toggle muted + process.on('SIGUSR2', () => { + mainWindow.webContents.send('micToggle', 'mic-toggled'); + }); } app.on('ready', createMainWindow) @@ -332,13 +222,6 @@ ipcMain.on('asynchronous-message', (event, _data) => { mainWindow.webContents.send('devMode', devMode) } - if (msg === 'confirmMicClose') { - if (isTalking === true) { - console.log("Mic state desync. Opening Mic.") - unmuteMic() - } - } - if (msg === 'blockUpdate') { if (logWindow){ logWindow.webContents.send('blockUpdate', _data.data) @@ -352,9 +235,6 @@ ipcMain.on('asynchronous-message', (event, _data) => { if (_data.data.wName === 1) { logWindow.minimize() } - if (_data.data.wName === 2) { - settingsWindow.minimize() - } } if (msg === 'maximizeApplication') { @@ -364,9 +244,6 @@ ipcMain.on('asynchronous-message', (event, _data) => { if (_data.data.wName === 1) { maximizeMinimizeState(logWindow) } - if (_data.data.wName === 2) { - maximizeMinimizeState(settingsWindow) - } } if (msg === 'closeApplication') { @@ -376,9 +253,6 @@ ipcMain.on('asynchronous-message', (event, _data) => { if (_data.data.wName === 1) { logWindow.close() } - if (_data.data.wName === 2) { - settingsWindow.close() - } } if (msg === 'openLog') { @@ -390,114 +264,11 @@ ipcMain.on('asynchronous-message', (event, _data) => { logWindow.center() } } - - if (msg === 'openSettings') { - if (settingsWindow) { - if (settingsWindow.isMinimized()) settingsWindow.restore() - settingsWindow.focus() - }else { - createSettingsWindow() - settingsWindow.center() - } - } - - if (msg === 'SettingsDOMReady') { - if (settingsWindow) { - console.log("SettingsDOMReady. Sending Settings DOM obj") - settingsWindow.webContents.send('settingsObj', configObj) - } - } - - if (msg === 'setPTTKey') { - if (settingsWindow) { - if (ioHook) { - isChangingPTTKey = true - console.log("waiting for user to rebind") - if (settingsWindow && isChangingPTTKey) { - - restartioHook().then(v => { - - mainWindow.blur() - - ioHook.once('keydown', event => { - if (settingsWindow && isChangingPTTKey) { - console.log("rebind success") - configObj.pttDevice = 'keyboard' - configObj.key = event.keycode - isChangingPTTKey = false - saveConfig(configObj) - settingsWindow.webContents.send('settingsObj', configObj) - setPTTKey() - } - }) - - // Ignore using left click (mouse1) - ioHook.once('mousedown', event => { - if (settingsWindow && isChangingPTTKey && event.button !== 1) { - console.log("rebind success") - configObj.pttDevice = 'mouse' - configObj.key = event.button - isChangingPTTKey = false - saveConfig(configObj) - settingsWindow.webContents.send('settingsObj', configObj) - setPTTKey() - } - }) - }) - } - } - } - } - - if (msg === 'cancelSetPTTKey') { - console.log("cancel set new PTT") - isChangingPTTKey = false - saveConfig(configObj) - settingsWindow.webContents.send('settingsObj', configObj) - } - - if (msg === 'setPTTDelay') { - console.log(`New PTT Delay: ${_data.data} ms`) - configObj.delay = _data.data - saveConfig(configObj) - settingsWindow.webContents.send('settingsObj', configObj) - } - - if (msg === 'disablePTT') { - if (_data.data === false) { - console.log(`PTT Disabled`) - configObj.delay = null - configObj.key = null - configObj.pttDevice = null - saveConfig(configObj) - settingsWindow.webContents.send('settingsObj', configObj) - } - if (_data.data === true) { - console.log(`PTT Enabled`) - configObj.delay = 1000 - configObj.key = "none" - configObj.pttDevice = "none" - saveConfig(configObj) - settingsWindow.webContents.send('settingsObj', configObj) - } - - } - }) app.on('ready', event => { console.log(`Dev Mode: ${devMode}`) - initConfig() - .then(value => { - configObj = value - return configObj - }) - .then(configObj => { - console.log(configObj) - restartioHook().then(() => { - setPTTKey() - }) - }) + listenForKeySignal(); }) diff --git a/src/config.js b/src/config.js deleted file mode 100644 index f42b128..0000000 --- a/src/config.js +++ /dev/null @@ -1,51 +0,0 @@ -const {app} = require('electron') -const fs = require('graceful-fs') -const path = require('path') - -function _saveToConfig (configObj) { - return new Promise(function (resolve, reject) { - const configFile = path.join(app.getPath('home'), '.config', 'discord-sandboxed', 'config.json'); - console.log('\tUpdating config.json', configObj) - fs.writeFile(configFile, JSON.stringify(configObj, null, 2), (err) => { - if (err) throw err; - return resolve(configObj) - }) - }) -} - -module.exports = { - initConfig: function () { - return new Promise((resolve, reject) => { - const configDir = path.join(app.getPath('home'), '.config', 'discord-sandboxed'); - const configFile = path.join(app.getPath('home'), '.config', 'discord-sandboxed', 'config.json'); - console.log('init config at ', configFile); - - let configObj // Init configObj - - // If config dir does not exist create it - if (!fs.existsSync(configDir)){ - fs.mkdirSync(configDir) - } - - // If config.json does not exist, create it with blank values - if (!fs.existsSync(configFile)) { - console.log(`\tCreated Default Config at [${configFile}]`) - configObj = { - 'pttDevice': 'mouse', - 'key': '4', - 'delay': '1000', - } - return resolve(_saveToConfig(configObj)) - } - try { - configObj = JSON.parse(fs.readFileSync(configFile, 'utf8')) - return resolve(configObj) - } catch (err) { - return reject(err) - } - }) - }, - saveConfig: function(configObj) { - return _saveToConfig(configObj) - } -} diff --git a/src/mainLoad.js b/src/mainLoad.js index 1b813de..b8fda56 100644 --- a/src/mainLoad.js +++ b/src/mainLoad.js @@ -1,20 +1,16 @@ const { ipcRenderer } = require('electron') - + // Pass commands sent from main.js to mainRender.js ipcRenderer.on('devMode', (event, msg) => { console.log(`PRELOAD: Dev Mode: ${msg}`) window.postMessage({ type: "devMode", text: `${msg}` }, "*") }) -ipcRenderer.on('micOpen', (event, msg) => { - window.postMessage({ type: "micOpen"}, "*") +ipcRenderer.on('micToggle', (event, msg) => { + console.log('got toggle mic'); + window.postMessage({ type: "micToggle"}, "*") }) -ipcRenderer.on('micClose', (event, msg) => { - window.postMessage({ type: "micClose"}, "*") -}) - - ipcRenderer.on('URLCopied', (event, msg) => { window.postMessage({ type: "URLCopied"}, "*") }) @@ -80,12 +76,7 @@ window.addEventListener( if (event.data.type === 'openLog'){ ipcRenderer.send('asynchronous-message', {msg: 'openLog'}) } - - - if (event.data.type === 'openSettings'){ - ipcRenderer.send('asynchronous-message', {msg: 'openSettings'}) - } } }, false -) \ No newline at end of file +) diff --git a/src/settingsLoad.js b/src/settingsLoad.js deleted file mode 100644 index 50960ac..0000000 --- a/src/settingsLoad.js +++ /dev/null @@ -1,50 +0,0 @@ -const { ipcRenderer } = require('electron') - -// Pass commands sent from main.js to settingsRender -ipcRenderer.on('settingsObj', (event, msg) => { - window.postMessage({ type: "settingsObj", payload: msg }, "*") -}) - -ipcRenderer.on('unfocused', (event, msg) => { - window.postMessage({ type: "unfocused"}, "*") -}) - -ipcRenderer.on('focused', (event, msg) => { - window.postMessage({ type: "focused"}, "*") -}) - -// Pass commands sent from settings window (processed by settingsRender.js) to main.js -window.addEventListener( - "message", - event => { - if (event.origin === "file://" && event.source === window) { - - if (event.data.type === 'SettingsDOMReady'){ - ipcRenderer.send('asynchronous-message', {msg: 'SettingsDOMReady'}) - } - if (event.data.type === 'setPTTKey'){ - ipcRenderer.send('asynchronous-message', {msg: 'setPTTKey'}) - } - if (event.data.type === 'cancelSetPTTKey'){ - ipcRenderer.send('asynchronous-message', {msg: 'cancelSetPTTKey'}) - } - if (event.data.type === 'setPTTDelay'){ - ipcRenderer.send('asynchronous-message', {msg: 'setPTTDelay', data: event.data.delay}) - } - if (event.data.type === 'disablePTT'){ - ipcRenderer.send('asynchronous-message', {msg: 'disablePTT', data: event.data.pttEnable}) - } - - if (event.data.type === 'minimizeApplication'){ - ipcRenderer.send('asynchronous-message', {msg: 'minimizeApplication', data: event.data.payload}) - } - if (event.data.type === 'maximizeApplication'){ - ipcRenderer.send('asynchronous-message', {msg: 'maximizeApplication', data: event.data.payload}) - } - if (event.data.type === 'closeApplication'){ - ipcRenderer.send('asynchronous-message', {msg: 'closeApplication', data: event.data.payload}) - } - } - }, - false -) diff --git a/views/css/settingsStyle.css b/views/css/settingsStyle.css deleted file mode 100644 index 6aa3f7b..0000000 --- a/views/css/settingsStyle.css +++ /dev/null @@ -1,37 +0,0 @@ -html, body{ - color: #ffffff; - font-family: "Hack Nerd Font", Courier, monospace; - background-color: #2f3136; - margin: 0px; - padding: 0px; -} - - -td:last-child { - padding-left: 16px; -} - -.settingsContainer { - color: #ffffff; - margin: 16px; -} - -.niceButton { - color: #ffffff; - background-color: #000000; - padding: 8px; - border-radius: 8px; - cursor: pointer; -} - -input { - font-family: "Hack Nerd Font", Courier, monospace; - display: inline-block; - color: #dcddde; - background-color: #36393f; - border: 1px solid #1d1e22; - border-radius: 4px; - padding: 8px; - outline: none; -} - diff --git a/views/index.html b/views/index.html index a50b333..63d6b35 100644 --- a/views/index.html +++ b/views/index.html @@ -15,54 +15,6 @@