Skip to content

Commit

Permalink
Merge branch 'release/0.1.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
Valandur committed Sep 17, 2015
2 parents c3e9c7f + bbdb0c1 commit 0e42c16
Show file tree
Hide file tree
Showing 6 changed files with 376 additions and 285 deletions.
30 changes: 22 additions & 8 deletions src/app/js/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,27 @@ app.controller('MainController', ['$scope', '$rootScope', '$mdDialog',
$scope.lolClientVersion = "";
$scope.aofClientInfo = {};

$scope.settings = [ { id: 1, name: "Select LoL Client" }, { id: 2, name: "Client info" } ];
$scope.settings = [ { id: 1, name: "Select LoL Client" }, { id: 2, name: "Client info" }, { id: 3, name: "Send current log to aof.gg" } ];

$scope.showAofClientInfo = function(ev) {
$scope.showAofClientInfo = function(event) {
var updateText = "";
if ($scope.aofClientInfo.newVersion) {
updateText = "<br /><br /><strong>New Version avaliable (" + $scope.aofClientInfo.newVersion + ")</strong><br />" + $scope.aofClientInfo.msg;
}


$scope.showDialog("Client info", 'v' + $scope.aofClientInfo.currVersion + updateText, event);
};
$scope.showDialog = function(title, content, event) {
$mdDialog.show(
$mdDialog.alert()
.parent(angular.element(document.querySelector('#popupContainer')))
.clickOutsideToClose(true)
.title('Client info')
.content('v' + $scope.aofClientInfo.currVersion + updateText)
.ariaLabel('Client info')
.title(title)
.content(content)
.ariaLabel(title)
.ok('ok')
.targetEvent(ev)
);
.targetEvent(event)
);
};

$scope.announceClick = function(index) {
Expand All @@ -39,6 +42,13 @@ app.controller('MainController', ['$scope', '$rootScope', '$mdDialog',
if (index == 1) {
$scope.showAofClientInfo();
}
if (index == 2) {
$scope.sendLogs();
}
};

$scope.sendLogs = function() {
ipc.send("sendLogs");
};

$scope.openFile = function() {
Expand Down Expand Up @@ -80,6 +90,10 @@ app.controller('MainController', ['$scope', '$rootScope', '$mdDialog',
});
});

ipc.on("error", function(obj) {
$scope.showDialog(obj.title, obj.content);
});

ipc.send("ready");
}
]);
122 changes: 93 additions & 29 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ let dialog = require("dialog");
let BrowserWindow = require("browser-window");
let _ = require("underscore");
let fs = require("fs");

let aofParser = require(__dirname + "/modules/aof-parser.js");
let replayServer = require(__dirname + "/modules/replay-server.js");
let lolClient = require(__dirname + "/modules/lol-client.js");
let winston = require("winston");

let replay = null;
let mainWindow = null;
Expand All @@ -33,8 +30,40 @@ let staticData = {
};


// Create folder for log files
fs.mkdirSync(app.getPath("userCache") + "/logs/");


// Add loggers
let logFile = app.getPath("userCache") + "/logs/" + (new Date()).getTime() + ".log";
let logger = new winston.Logger({ transports: [] });
logger.add(winston.transports.Console, {
"level": "info"
});
logger.add(winston.transports.File, {
"filename": logFile,
"level": "debug"
});


// Add global error handlers
process.on("uncaughtException", function (error) {
logger.error("App Uncaught exception: " + error);
}
process.on("error", function (error) {
logger.error("App Error: " + error);
}


// Log operating system
console.log("We are running on " + process.platform);
logger.info("We are running on " + process.platform);
logger.info("Application data path: " + app.getPath("userCache"));


// Load our modules
let aofParser = require(__dirname + "/modules/aof-parser.js")(logger);
let replayServer = require(__dirname + "/modules/replay-server.js")(logger);
let lolClient = require(__dirname + "/modules/lol-client.js")(logger);


// Quit when all windows are closed.
Expand All @@ -44,9 +73,10 @@ app.on("window-all-closed", function() {
}
});


// User settings
function loadUserSettings(callback) {
console.log("Loading user settings");
logger.info("Loading user settings");
fs.readFile(app.getPath("userCache") + "/settings", function(err, data) {
if (!err) {
settings = JSON.parse(data);
Expand All @@ -56,21 +86,21 @@ function loadUserSettings(callback) {
});
}
function saveUserSettings() {
console.log("Saving user settings");
logger.info("Saving user settings");
settings.lolClientPath = lolClient.leaguePath();
fs.writeFileSync(app.getPath("userCache") + "/settings", JSON.stringify(settings, null, 2));
}


// Check for updates
function checkForUpdates(callback) {
console.log("Checking for application updates");
logger.info("Checking for application updates");
let version = { currVersion: JSON.parse(fs.readFileSync(__dirname + "/package.json")).version, newVersion: null, msg: null };
let timeout = setTimeout(function() {
req.abort();
console.log("Could not check for updates, request timed out");
logger.warn("Could not check for updates, request timed out");
callback();
}, 10000);
}, 5000);
let req = request({ url: "http://api.aof.gg/version", json: true }, function(err, response, body) {
clearTimeout(timeout);
if (!err && response && response.statusCode == 200) {
Expand All @@ -81,7 +111,7 @@ function checkForUpdates(callback) {
}
mainWindow.webContents.send("aofUpdate", version);
} else {
console.log("Error while retrieving version: " + err + " " + JSON.stringify(response));
logger.warn("Error while retrieving version: " + err + " " + JSON.stringify(response));
}

callback();
Expand All @@ -91,27 +121,22 @@ function checkForUpdates(callback) {

// Get static data from api
function getStaticData(callback) {
console.log("Loading static data");
logger.info("Loading static data");
fs.readFile(app.getPath("userCache") + "/static", function(err, data) {
if (!err) {
console.log("Reading static data from local cache");
logger.info("Reading static data from local cache");
staticData = JSON.parse(data);
staticData.extended = true;
}

console.log("Retrieving static data from server");
let timeout = setTimeout(function() {
req.abort();
console.log("Could not retreive static data, request timed out");
callback();
}, 10000)
let req = request({ url: "http://api.aof.gg/static", json: true }, function(err, response, body) {
logger.info("Retrieving static data from server");
request({ url: "http://api.aof.gg/static", json: true ,timeout: 10000}, function(err, response, body) {
if (!err && response && response.statusCode == 200 && !body.err && body.data) {
staticData = body.data;
staticData.extended = true;
fs.writeFileSync(app.getPath("userCache") + "/static", JSON.stringify(staticData));
} else {
console.log("Error while retrieving static data: " + err + " " + JSON.stringify(response));
logger.warn("Error while retrieving static data: " + err + " " + JSON.stringify(response));
}

callback();
Expand Down Expand Up @@ -200,7 +225,7 @@ ipc.on("openReplay", function(event, args) {
if (files && files.length == 1) {
aofParser.parse(files[0], function(err, replayMetadata, replayData) {
if (err) {
console.log(err);
logger.warn("Could not parse replay file " + files[0] + ": " + err);
} else {
replay = extendReplayMetadata(replayMetadata);
event.sender.send("parsedReplayFile", replay);
Expand All @@ -215,15 +240,54 @@ ipc.on("openReplay", function(event, args) {
ipc.on("play", function(event, args) {
replayServer.resetReplay();

let run = lolClient.launch(replayServer.host(), replayServer.port(), staticData.regions[replay.regionId].ShortName, replay.gameId, replay.key, function() {
mainWindow.minimize();

lolClient.launch(replayServer.host(), replayServer.port(), staticData.regions[replay.regionId].ShortName,
replay.gameId, replay.key, function(success) {
mainWindow.restore();

if (!success)
event.sender.send("error", {
title: "LoL Client error",
content: "Could not start the League of Legends client<br>Please send us your current log file so we can reproduce what happened. (You can send the report in the top right)."});
});
});


ipc.on("sendLogs", function(event, args) {
console.log("sending report");
let report = {
date: new Date(),
platform: process.platform,
arch: process.arch,
aofClient: JSON.parse(fs.readFileSync(__dirname + "/package.json")).version,
leagueClient: {
path: lolClient.leaguePath(),
version: lolClient.version()
},
logs: fs.readFileSync(logFile, 'utf8')
};

console.log(JSON.stringify(report));

request({
url: "http://api.aof.gg/client/reports",
method: "POST",
json: true,
headers: {
"content-type": "application/json"
},
body: report
}, function(err,httpResponse,body){
if (httpResponse.statusCode != 200) {
event.sender.send("error", {
title: "Error sending report",
content: "Could not send error report.<br>Please report your issue to support@aof.gg and provide the following file: " + logFile });
} else {

}

});

if (run) {
mainWindow.minimize();
} else {
console.log("Could not run league client");
}
});


Expand Down
Loading

0 comments on commit 0e42c16

Please sign in to comment.