From e91e5a1a4396b211c8071df76b448c5754867092 Mon Sep 17 00:00:00 2001 From: sparks-alec Date: Thu, 5 Jan 2023 01:29:31 -0500 Subject: [PATCH] add Network Info window --- index.html | 1 + main.js | 39 ++++++++----- networkInterfaces.html | 86 ++++++++++++++++++++++++++++ networkInterfaces.js | 20 +++++++ preload.js | 5 ++ src/img/outline_info_white_18dp.png | Bin 0 -> 210 bytes src/index.css | 5 +- src/search.js | 2 + 8 files changed, 142 insertions(+), 16 deletions(-) create mode 100644 networkInterfaces.html create mode 100644 networkInterfaces.js create mode 100644 src/img/outline_info_white_18dp.png diff --git a/index.html b/index.html index 173089c..3c43cf5 100644 --- a/index.html +++ b/index.html @@ -27,6 +27,7 @@ +
diff --git a/main.js b/main.js index a8f7f6d..57ab437 100644 --- a/main.js +++ b/main.js @@ -1,11 +1,4 @@ -const { - app, - BrowserWindow, - Menu, - ipcMain, - nativeTheme, - dialog, -} = require('electron'); +const { app, BrowserWindow, Menu, ipcMain, nativeTheme, dialog } = require('electron'); const { autoUpdater } = require('electron-updater'); const path = require('path'); @@ -16,6 +9,7 @@ let autoUpdate = false; let manualUpdateCheck = false; let menuObj; let mainWindow; +let networkInfoWindow; const menuTemplate = [ ...(isMac ? [{ role: 'appMenu' }] : []), @@ -95,10 +89,7 @@ const menuTemplate = [ id: 'devicePin', enabled: false, click(menuItem, window, event) { - mainWindow.webContents.send( - 'setActiveDevicePinned', - menuItem.checked - ); + mainWindow.webContents.send('setActiveDevicePinned', menuItem.checked); }, }, { @@ -166,6 +157,18 @@ const windowWin = { }, }; +const networkInfoWin = { + width: 700, + height: 350, + backgroundColor: '#333333', + show: false, + webPreferences: { + contextIsolation: false, + nodeIntegration: true, + preload: path.join(__dirname, 'networkInterfaces.js'), + }, +}; + if (isWin) { app.setAppUserModelId(app.name); } @@ -236,13 +239,19 @@ ipcMain.on('setAutoUpdate', (event, _autoUpdate) => { autoUpdate = _autoUpdate; // update menu item for enabling/disabling auto update - menuTemplate[menuTemplate.length - 1].submenu[2].label = autoUpdate - ? 'Disable Auto Update' - : 'Enable Auto Update'; + menuTemplate[menuTemplate.length - 1].submenu[2].label = autoUpdate ? 'Disable Auto Update' : 'Enable Auto Update'; menuObj = Menu.buildFromTemplate(menuTemplate); Menu.setApplicationMenu(menuObj); }); +ipcMain.on('openNetworkInfoWindow', (event, arg) => { + if (!networkInfoWindow || (networkInfoWindow && networkInfoWindow.isDestroyed())) { + networkInfoWindow = new BrowserWindow(networkInfoWin); + networkInfoWindow.loadFile('networkInterfaces.html'); + } + networkInfoWindow.show(); +}); + // this can be set to true to bypass the download update dialog and skip straight to install prompt autoUpdater.autoDownload = false; diff --git a/networkInterfaces.html b/networkInterfaces.html new file mode 100644 index 0000000..c9f0a6a --- /dev/null +++ b/networkInterfaces.html @@ -0,0 +1,86 @@ + + + Network Information + + + +

Attached Network Interfaces:

+ + + + + + + + + +
IDIP AddressSubnet MaskSearchable Addresses
+ + diff --git a/networkInterfaces.js b/networkInterfaces.js new file mode 100644 index 0000000..9551fc7 --- /dev/null +++ b/networkInterfaces.js @@ -0,0 +1,20 @@ +const SEARCH = require('./src/search.js'); + +window.init = function init() { + const networkInterfaces = SEARCH.getNetworkInterfaces(); + let html = ''; + + for (let i = 0; i < Object.keys(networkInterfaces).length; i++) { + const interfaceID = Object.keys(networkInterfaces)[i]; + const interfaceObj = networkInterfaces[interfaceID]; + console.log(interfaceObj); + + html += `${interfaceID}`; + html += `${interfaceObj[0].address}`; + html += `${interfaceObj[0].netmask}`; + html += `${interfaceObj[0].firstSearchAddress} - ${interfaceObj[0].lastSearchAddress}`; + html += ``; + + document.getElementById('network-interfaces').innerHTML = html; + } +}; diff --git a/preload.js b/preload.js index c29576b..11937c8 100644 --- a/preload.js +++ b/preload.js @@ -106,6 +106,11 @@ window.init = function init() { SAVESLOTS.saveAll(); }; + document.getElementById('network-info-button').onclick = function fooBar(e) { + ipcRenderer.send('openNetworkInfoWindow'); + console.log('FOO'); + }; + document.onkeyup = function keyUp(e) { if (e.key === 'ArrowUp') { VIEW.selectPreviousDevice(); diff --git a/src/img/outline_info_white_18dp.png b/src/img/outline_info_white_18dp.png new file mode 100644 index 0000000000000000000000000000000000000000..b4ad5ddeba79a45e25352cce3a67331ca090486d GIT binary patch literal 210 zcmeAS@N?(olHy`uVBq!ia0vp^LLkh+0wn(&ce?|mW_r3fhG?9hI%%h1ivf>oEQ7m~ zs7p!!dkIsk!DE(P3q{#Y7QV4}zVV<{Vbu;%~vc*zyd=8UGzj zTVIASuV#&n5nFOfQ$u^X^!bJPk6pDjV$v=~a`DIf(8~YC5P0vbuZXw3C(w}$p00i_ I>zopr0CIavp#T5? literal 0 HcmV?d00001 diff --git a/src/index.css b/src/index.css index ab27245..127ed43 100644 --- a/src/index.css +++ b/src/index.css @@ -27,6 +27,9 @@ a { .left { float: left; } +.right { + float: right; +} #main { box-sizing: border-box; @@ -133,7 +136,7 @@ a { /* position: absolute; bottom: 210px; left: 0px;*/ - width: 100%; + width: 262px; height: 30px; padding-right: 10px; /*background: linear-gradient(#2f2f2f 0%, #2c2c2c 100%);*/ diff --git a/src/search.js b/src/search.js index 3d94c0f..57fe5da 100644 --- a/src/search.js +++ b/src/search.js @@ -28,6 +28,8 @@ function getServers() { const last = ip.toLong(subnet.lastAddress) - 1; // console.log(`range ${subnet.firstAddress} - ${subnet.lastAddress}`); address.broadcastAddress = subnet.broadcastAddress; + address.firstSearchAddress = subnet.firstAddress; + address.lastSearchAddress = subnet.lastAddress; if (!validInterfaces[key]) { validInterfaces[key] = [];