From fe0eb1ea62c73bc3bf2ae5db38458c617ec0afc1 Mon Sep 17 00:00:00 2001 From: Xzandro Date: Mon, 13 Mar 2017 10:02:37 +0100 Subject: [PATCH] Changed plugin load behavour Handled exception for client side socket errors Added location information in the Information section --- app/main.js | 34 +++++++++++++++++++++++----------- app/pages/Information.js | 17 +++++++++++++++-- app/proxy/SWProxy.js | 6 +++++- package.json | 5 +++-- 4 files changed, 46 insertions(+), 16 deletions(-) diff --git a/app/main.js b/app/main.js index 245d8f07..f76d0b5a 100644 --- a/app/main.js +++ b/app/main.js @@ -17,13 +17,14 @@ let defaultConfig = { Plugins: {} } } +global.plugins = []; storage.getAll(function(error, data) { if (error) throw error; let merged = _.merge(defaultConfig, data); global.config = merged.Config; - global.plugins = loadPlugins(); + initPlugins(); }); app.on('ready', () => { @@ -82,6 +83,13 @@ ipcMain.on('updateConfig', (event, arg) => { }); }) +ipcMain.on('getFolderLocations', (event, arg) => { + event.returnValue = { + settings: app.getPath('userData'), + plugins: path.join(path.dirname(app.getPath('exe')), 'plugins') + }; +}) + function createWindow () { win = new BrowserWindow({ minWidth: 800, @@ -97,24 +105,28 @@ function createWindow () { })) } -function loadPlugins() { - // Initialize Plugins - let plugins = []; +function initPlugins() { const pluginDir = path.join(path.dirname(app.getPath('exe')), 'plugins'); // Check plugin folder existence - try { - fs.readdirSync(pluginDir); - } catch (err) { - if (err.code === 'ENOENT') { + fs.readdir(pluginDir, (error, files) => { + if (error && error.code === 'ENOENT') { + console.log(error) // Create the folder by copying default plugins ncp(path.join(__dirname, 'plugins'), pluginDir, err => { - console.error(err); + global.plugins = loadPlugins(); }); } else { - throw(err); + global.plugins = loadPlugins(); } - } + }); +} + +function loadPlugins() { + // Initialize Plugins + let plugins = []; + + const pluginDir = path.join(path.dirname(app.getPath('exe')), 'plugins'); // Load each plugin module in the folder fs.readdirSync(pluginDir).forEach(function (file) { diff --git a/app/pages/Information.js b/app/pages/Information.js index ba57da66..165b045d 100644 --- a/app/pages/Information.js +++ b/app/pages/Information.js @@ -1,11 +1,24 @@ +const { ipcRenderer } = require('electron'); + import React from 'react'; -import { Header } from 'semantic-ui-react'; +import { Divider, Header, Input, Segment } from 'semantic-ui-react'; class Information extends React.Component { render () { + const folderLocations = ipcRenderer.sendSync('getFolderLocations'); return ( -

Information

+
+

Information

+
+ Locations +
+ + + +
) } } diff --git a/app/proxy/SWProxy.js b/app/proxy/SWProxy.js index 997a886c..909de705 100644 --- a/app/proxy/SWProxy.js +++ b/app/proxy/SWProxy.js @@ -86,10 +86,14 @@ class SWProxy extends EventEmitter { srvSocket.pipe(socket); socket.pipe(srvSocket); }); - + srvSocket.on('error', (error) => { console.log('Caught server socket error.'); }); + + socket.on('error', (error) => { + console.log('Caught client socket error.'); + }); }); this.log({ type: 'info', source: 'proxy', message: `Now listening on port ${port}` }); diff --git a/package.json b/package.json index fd8d6dc6..8482919a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "sw-exporter", "productName": "Summoners War Exporter", - "version": "0.0.3", + "version": "0.0.4", "description": "This tool will parse intercepted data from Summoners War and extract information on the monsters and runes of the user.", "main": "./app/main.js", "scripts": { @@ -14,8 +14,9 @@ }, "build": { "productName": "Summoners War Exporter", + "appId": "com.electron.sw-exporter", "win": { - "target": "dir" + "target": ["dir"] } }, "keywords": [],