From 12903c70882789374a1b52962a478f20b33b563d Mon Sep 17 00:00:00 2001 From: khlam <4841220+khlam@users.noreply.github.com> Date: Mon, 14 Oct 2019 17:35:25 -0700 Subject: [PATCH] Dev mode --- main.js | 26 +++++++++++++++++++------- package.json | 2 +- renderer.js | 17 +++++++++++++---- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/main.js b/main.js index cfdbe28..f13e1bd 100644 --- a/main.js +++ b/main.js @@ -7,6 +7,8 @@ const ioHook = require('iohook') // be closed automatically when the JavaScript object is garbage collected. let mainWindow +let devMode = false + function createWindow () { // Create the browser window. mainWindow = new BrowserWindow({ @@ -19,9 +21,15 @@ function createWindow () { webviewTag: true } }) + if (process.argv.length === 3) { + if (process.argv[2] === 'dev'){ + devMode = true + } + } - - mainWindow.setMenu(null) + if (devMode === false){ + mainWindow.setMenu(null) + } // and load the index.html of the app. mainWindow.loadFile('index.html') @@ -103,7 +111,8 @@ function unmuteMic() { app.on('ready', event => { ioHook.start(); - muteMic() + + console.log(`Dev Mode: ${devMode}`) }) ioHook.on('mousedown', event => { @@ -119,14 +128,17 @@ ioHook.on('mouseup', event => { } }) -ipcMain.on('asynchronous-message', (event, arg) => { - if (arg === 'connected') { +ipcMain.on('asynchronous-message', (event, msg) => { + if (msg === 'connected') { isConnected = true } - if (arg === 'disconnected') { + if (msg === 'disconnected') { isConnected = false isTalking = false } - console.log(arg) + + if (msg === 'DOMready') { + mainWindow.webContents.send('devMode', devMode) + } }) diff --git a/package.json b/package.json index 3130d71..c79f531 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Discord Sandboxed with Push-to-Talk", "main": "main.js", "scripts": { - "start": "electron .", + "start": "electron . dev", "postinstall": "electron-builder install-app-deps", "package-win": "electron-builder --win --publish never" }, diff --git a/renderer.js b/renderer.js index 0d624b7..beb76f4 100644 --- a/renderer.js +++ b/renderer.js @@ -2,7 +2,9 @@ const { ipcRenderer } = require('electron') onload = () => { const webview = document.querySelector('webview') - //webview.openDevTools() + + ipcRenderer.send('asynchronous-message', 'DOMready') + webview.addEventListener('console-message', (e) => { if (e.message === "Constructed RTCPeerConnection") { console.log("Connected to server") @@ -15,16 +17,23 @@ onload = () => { } }) - ipcRenderer.on('ping', (event, message) => { - if (message === 'mic-open'){ + ipcRenderer.on('ping', (event, msg) => { + if (msg === 'mic-open'){ console.log("talking") webview.sendInputEvent({keyCode: 'Backspace', type: 'keyDown'}); webview.sendInputEvent({keyCode: 'Backspace', type: 'char'}); } - if (message === 'mic-closed'){ + if (msg === 'mic-closed'){ console.log("not talking") webview.sendInputEvent({keyCode: 'Backspace', type: 'keyUp'}); webview.sendInputEvent({keyCode: 'Backspace', type: 'char'}); } }) + + ipcRenderer.on('devMode', (event, msg) => { + console.log(`Dev Mode: ${msg}`) + if (msg === true) { + webview.openDevTools() + } + }) } \ No newline at end of file