From 29bdf40ffbf77c1534309925b7356fb9fff2e354 Mon Sep 17 00:00:00 2001 From: Joel Wetzell Date: Mon, 12 Dec 2022 14:54:24 -0600 Subject: [PATCH] pretty src directory --- src/index.css | 8 +-- src/index.js | 2 +- src/plugins.js | 54 +++++++++--------- src/saveSlots.js | 18 ++---- src/search.js | 70 +++++++++++------------- src/view.js | 139 ++++++++++++++++++++++++----------------------- 6 files changed, 138 insertions(+), 153 deletions(-) diff --git a/src/index.css b/src/index.css index 7d9717d..13a5f26 100644 --- a/src/index.css +++ b/src/index.css @@ -118,13 +118,13 @@ a { width: 210px; pointer-events: none; } -#device-inspector{ +#device-inspector { position: absolute; bottom: 0px; width: 100%; } #device-tools { - /* position: absolute; + /* position: absolute; bottom: 210px; left: 0px;*/ width: 100%; @@ -265,7 +265,7 @@ input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; } -input:disabled{ +input:disabled { color: gray; cursor: not-allowed; } @@ -341,6 +341,6 @@ select.button:focus { } /* only allow select on input fields */ -body :not(input):not(select):not(textarea) { +body :not(input):not(select):not(textarea) { user-select: none; } diff --git a/src/index.js b/src/index.js index bfeb854..fcdfc6d 100644 --- a/src/index.js +++ b/src/index.js @@ -1 +1 @@ -window.init(); \ No newline at end of file +window.init(); diff --git a/src/plugins.js b/src/plugins.js index 24e2305..39b4318 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -10,20 +10,20 @@ const allPlugins = {}; module.exports.all = allPlugins; module.exports.init = function init(callback) { - let pluginDirectoryPath = path.normalize(path.join(__dirname, `../plugins`)); console.log(`Loading plugin files... ${pluginDirectoryPath}`); fs.readdir(pluginDirectoryPath, (err, files) => { - - files.forEach((plugin)=>{ + files.forEach((plugin) => { if (plugin[0] !== '.') { - console.log(`${plugin} started`); // eslint-disable-next-line import/no-dynamic-require - allPlugins[plugin] = require(path.join(pluginDirectoryPath, `/${plugin}/main.js`)); + allPlugins[plugin] = require(path.join( + pluginDirectoryPath, + `/${plugin}/main.js` + )); const p = allPlugins[plugin]; @@ -35,50 +35,46 @@ module.exports.init = function init(callback) { }; p.template = _.template( - fs.readFileSync(path.join(pluginDirectoryPath, `/${plugin}/template.ejs`), + fs.readFileSync( + path.join(pluginDirectoryPath, `/${plugin}/template.ejs`), 'utf8' ) ); p.info = _.template( - fs.readFileSync(path.join(pluginDirectoryPath, `/${plugin}/info.html`), + fs.readFileSync( + path.join(pluginDirectoryPath, `/${plugin}/info.html`), 'utf8' ) ); - //if (p.heartbeatTimeout === undefined || p.heartbeatTimeout < 50) { - if(p.config.heartbeatTimeout){ - p.heartbeatTimeout = p.config.heartbeatInterval * 1.5; - }else{ - p.heartbeatTimeout = 10000; - } + if (p.config.heartbeatTimeout) { + p.heartbeatTimeout = p.config.heartbeatInterval * 1.5; + } else { + p.heartbeatTimeout = 10000; + } //} - if(p.config.heartbeatInterval){ - p.heartbeatInterval = Math.max(50, p.config.heartbeatInterval); - }else{ - p.heartbeatInterval = 5000; - } - - // p.fields = {}; - // if(p.config.fields){ - // p.config.fields.forEach(field => { - // p.fields[field.key] = field.value; - // }); - // } - - + if (p.config.heartbeatInterval) { + p.heartbeatInterval = Math.max(50, p.config.heartbeatInterval); + } else { + p.heartbeatInterval = 5000; + } + // p.fields = {}; + // if(p.config.fields){ + // p.config.fields.forEach(field => { + // p.fields[field.key] = field.value; + // }); + // } // if (p.heartbeatInterval === undefined || p.heartbeatInterval < 50) { // p.heartbeatInterval = 5000; // } - } }); callback(); - }); }; diff --git a/src/saveSlots.js b/src/saveSlots.js index eed9462..2dc4aad 100644 --- a/src/saveSlots.js +++ b/src/saveSlots.js @@ -19,7 +19,7 @@ function loadSlot(slotIndex) { VIEW.toggleSlotButtons(slotIndex); activeSlot = slotIndex; - Object.keys(DEVICE.all).forEach((d)=>{ + Object.keys(DEVICE.all).forEach((d) => { DEVICE.changePinIndex(DEVICE.all[d], false); }); VIEW.resetPinned(); @@ -33,7 +33,6 @@ function loadSlot(slotIndex) { if (device.id === savedDevice.id) { VIEW.pinDevice(device); VIEW.switchDevice(device.id); - } else if ( device.addresses[0] === savedDevice.addresses[0] && device.type === savedDevice.type && @@ -43,12 +42,10 @@ function loadSlot(slotIndex) { VIEW.switchDevice(device.id); } }); - }); -}; +} module.exports.loadSlot = loadSlot; - module.exports.loadDevices = function loadDevices() { console.log(`Loading ${savedDevices.length} saved devices...`); @@ -60,12 +57,11 @@ module.exports.loadDevices = function loadDevices() { port: savedDevices[i].port, addresses: savedDevices[i].addresses, id: savedDevices[i].id, - fields: savedDevices[i].fields + fields: savedDevices[i].fields, }); } }; - module.exports.saveAll = function saveAll() { console.log('Saving...'); const currentPins = VIEW.getPinnedDevices(); @@ -75,7 +71,7 @@ module.exports.saveAll = function saveAll() { savedSlots[activeSlot][i] = { addresses: currentPins[i].addresses, type: currentPins[i].type, - id: currentPins[i].id + id: currentPins[i].id, }; } localStorage.setItem('savedSlots', JSON.stringify(savedSlots)); @@ -94,15 +90,13 @@ module.exports.saveAll = function saveAll() { defaultName: device.defaultName, port: device.port, id: device.id, - fields: device.fields + fields: device.fields, }; i++; }); localStorage.setItem('savedDevices', JSON.stringify(savedDevices)); - }; - module.exports.deleteFromSlots = function deleteFromSlots(device) { for (let i = 1; i <= 3; i++) { console.log(savedSlots); @@ -114,12 +108,10 @@ module.exports.deleteFromSlots = function deleteFromSlots(device) { } }; - module.exports.reloadActiveSlot = function reloadActiveSlot() { loadSlot(activeSlot); }; - module.exports.resetSlots = function resetSlots() { localStorage.clear(); }; diff --git a/src/search.js b/src/search.js index 8f23d84..30549c7 100644 --- a/src/search.js +++ b/src/search.js @@ -15,13 +15,17 @@ let allServers = false; function getServers() { const interfaces = os.networkInterfaces(); const result = []; - + Object.keys(interfaces).forEach((key) => { const addresses = interfaces[key]; for (let i = addresses.length; i--; ) { const address = addresses[i]; - if (address.family === 'IPv4' && !address.internal && address.address.substring(0, 3)!="169") { + if ( + address.family === 'IPv4' && + !address.internal && + address.address.substring(0, 3) != '169' + ) { const subnet = ip.subnet(address.address, address.netmask); let current = ip.toLong(subnet.firstAddress); const last = ip.toLong(subnet.lastAddress) - 1; @@ -31,7 +35,6 @@ function getServers() { } }); return result; - } const searchSockets = []; @@ -43,9 +46,9 @@ function searchAll() { ipcRenderer.send('disableSearchAll', ''); document.getElementById('search-button').style.opacity = 0.2; - // Removed this block to fix #21 + // Removed this block to fix #21 // "After adding devices via search, searching again leaves all devices stuck in reload state" - // + // // Object.keys(DEVICE.all).forEach((i) => { // DEVICE.infoUpdate(DEVICE.all[i], 'status', 'refresh'); // }); @@ -63,26 +66,21 @@ function searchAll() { Object.keys(PLUGINS.all).forEach((p) => { const plugin = PLUGINS.all[p]; - + try { const t = plugin.config.searchOptions.type; - if(t === 'TCPport'){ + if (t === 'TCPport') { if (TCPFlag) { searchTCP(p, plugin.config); } - - }else if(t === 'Bonjour'){ + } else if (t === 'Bonjour') { searchBonjour(p, plugin.config); - - }else if(t === 'UDPsocket'){ + } else if (t === 'UDPsocket') { searchUDP(p, plugin.config); - - }else if(t === 'multicast'){ + } else if (t === 'multicast') { searchMulticast(p, plugin.config); - } - } catch (err) { console.error(`Unable to search for plugin ${p}`); } @@ -102,14 +100,11 @@ function searchAll() { ipcRenderer.send('enableSearchAll', ''); }, 10000); -}; +} module.exports.searchAll = searchAll; - - function searchBonjour(pluginType, plugin) { bonjour.find({ type: plugin.searchOptions.bonjourName }, (e) => { - const validAddresses = []; e.addresses.forEach((address) => { if (address.indexOf(':') === -1) { @@ -124,20 +119,22 @@ function searchBonjour(pluginType, plugin) { addresses: validAddresses, }); }); - -}; - +} function searchTCP(pluginType, plugin) { for (let i = 0; i < allServers.length; i++) { TCPtest(allServers[i], pluginType, plugin); } -}; +} function TCPtest(ipAddr, pluginType, plugin) { - const client = net.createConnection(plugin.searchOptions.testPort, ipAddr, () => { - client.write(plugin.searchOptions.searchBuffer); - }); + const client = net.createConnection( + plugin.searchOptions.testPort, + ipAddr, + () => { + client.write(plugin.searchOptions.searchBuffer); + } + ); client.on('data', (data) => { if (plugin.searchOptions.validateResponse(data)) { DEVICE.registerDevice({ @@ -152,14 +149,12 @@ function TCPtest(ipAddr, pluginType, plugin) { client.on('error', (err) => { // no device here }); -}; - +} function searchUDP(pluginType, plugin) { const i = searchSockets.push(dgram.createSocket('udp4')) - 1; searchSockets[i].bind(plugin.searchOptions.listenPort, () => { - // searchSockets[i].send( // plugin.searchOptions.searchBuffer, // plugin.searchOptions.devicePort, @@ -205,16 +200,15 @@ function searchUDP(pluginType, plugin) { searchSockets[i].on('listening', () => { searchSockets[i].setBroadcast(true); searchSockets[i].send( - plugin.searchOptions.searchBuffer, - plugin.searchOptions.devicePort, - '255.255.255.255', - (err) => { - // console.log(err) - } - ); + plugin.searchOptions.searchBuffer, + plugin.searchOptions.devicePort, + '255.255.255.255', + (err) => { + // console.log(err) + } + ); }); -}; - +} function searchMulticast(pluginType, plugin) { const socket = dgram.createSocket('udp4'); diff --git a/src/view.js b/src/view.js index bd7c55e..4edcbfc 100644 --- a/src/view.js +++ b/src/view.js @@ -12,9 +12,7 @@ module.exports.init = function init() { populatePluginLists(); }; - function drawDeviceFrame(id) { - const $deviceDrawArea = document.getElementById(`device-${id}-draw-area`); const $devicePinned = document.getElementById(`device-${id}-pinned`); @@ -30,7 +28,8 @@ function drawDeviceFrame(id) { // scrollbar styles are inline to prevent the styles flickering in str += '