Skip to content

Commit

Permalink
Changed plugin load behavour
Browse files Browse the repository at this point in the history
Handled exception for client side socket errors
Added location information in the Information section
  • Loading branch information
Xzandro committed Mar 13, 2017
1 parent 844c785 commit fe0eb1e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 16 deletions.
34 changes: 23 additions & 11 deletions app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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,
Expand All @@ -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) {
Expand Down
17 changes: 15 additions & 2 deletions app/pages/Information.js
Original file line number Diff line number Diff line change
@@ -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 (
<h1>Information</h1>
<div>
<h1>Information</h1>
<Header as='h4' attached='top'>
Locations
</Header>
<Segment attached>
<Input label='Settings' defaultValue={folderLocations.settings} fluid readOnly />
<Divider hidden />
<Input label='Plugins' defaultValue={folderLocations.plugins} fluid readOnly />
</Segment>
</div>
)
}
}
Expand Down
6 changes: 5 additions & 1 deletion app/proxy/SWProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}` });
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -14,8 +14,9 @@
},
"build": {
"productName": "Summoners War Exporter",
"appId": "com.electron.sw-exporter",
"win": {
"target": "dir"
"target": ["dir"]
}
},
"keywords": [],
Expand Down

0 comments on commit fe0eb1e

Please sign in to comment.