Skip to content

Commit

Permalink
error report screen is much better and error reports are automaticall…
Browse files Browse the repository at this point in the history
…y created on unhandled rejections.
  • Loading branch information
mworzala committed Jul 26, 2019
1 parent acad95a commit 0a2b7ad
Show file tree
Hide file tree
Showing 13 changed files with 295 additions and 202 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "proton",
"version": "0.2.28",
"version": "0.2.29",
"description": "A custom minecraft launcher",
"private": false,
"author": "Matt Worzala <bhop.me>",
Expand Down
41 changes: 29 additions & 12 deletions src/main/app/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,8 @@ ipcMain.on('profile:screenshot:delete', async (event, payload) => {

// Mods
ipcMain.on('profile:mod:add', async (event, payload) => {
console.log('adding');
console.log(`Adding mod from data: ${payload.data}`);
const resp = await this.addMod(payload.profile, payload.data);
console.log(resp);
mainWindow.send('profile:mod:add', resp);
// Re render the mods.
this.renderMods(payload.profile);
Expand Down Expand Up @@ -176,28 +175,35 @@ exports.createProfile = async data => {

data.version = {};
const packJson = await fs.readJson(path.join(packTempDir, 'mmc-pack.json'));
packJson.components.forEach(component => {
for (const component of packJson.components) {
switch (component.cachedName.toLowerCase()) {
case 'minecraft':
data.version.version = component.version;
break;
case 'fabricloader':
const ver = component.cachedVersion.split('_');
const ver = component.cachedVersion.split('_yarn-');
console.log(ver);
data.version.flavor = 'fabric';
// data.version.mappings =
data.version.mappings = ver[0];
data.version.loader = ver[1];
versionId = await installer.installFabric(data.version.mappings, data.version.loader);
break;
default:
console.debug(`Ignoring unknown MMCComponent@"${component.cachedName}".`);
break;
}
});
}

// versionId = version folder
// version = { flavor, mappings, loader }
// Get icon
const iconPath = path.join(packTempDir, 'pack.png');
if (await fs.pathExists(iconPath))
icon = await files.loadImage(iconPath);

console.log(packTempDir);
return ;
// Copy game files
await fs.copy(path.join(packTempDir, '.minecraft'), directory);

// Cleanup
await fs.remove(packTempDirOuter);
} else {
await taskmaster.updateTask(tid, 'preparing modpack info', 3/total);
const fileJson = await (await fetch(`https://addons-ecs.forgesvc.net/api/v2/addon/${data.modpack}/file/${data.file}`)).json();
Expand All @@ -213,7 +219,7 @@ exports.createProfile = async data => {
const now = new Date().getTime();
await profileDb.insert({
name, directory,
icon: await files.downloadImage(icon),
icon: typeof icon === 'string' ? await files.downloadImage(icon) : icon.src,
type: data.modpack === undefined ? 'custom' : 'curse',
packData,
created: now, played: 0,
Expand All @@ -234,6 +240,17 @@ exports.createProfile = async data => {
});

await taskmaster.updateTask(tid, 'finishing up', 4/total);

// Index any mods for the profile todo this is waaaaaaaaaaaaaaaay too slow
// const modsDir = path.join(directory, 'mods');
// if (await fs.pathExists(modsDir)) {
// const mods = await fs.readdir(modsDir);
// for (const mod of mods.filter(mod => mod.endsWith('.jar')).map(mod => path.join(modsDir, mod))) {
// console.log('adding ' + mod);
// await this.addMod(name, { path: mod, nocopy: true })
// }
// }

await this.renderProfiles();

console.log(`Finished installing '${name}'!`);
Expand Down Expand Up @@ -405,7 +422,7 @@ exports.addMod = async (profile, data) => {
const fileJson = await (await fetch(`https://addons-ecs.forgesvc.net/api/v2/addon/${data.mod}/file/${data.file}`)).json();
data.path = path.join(target.directory, 'mods', fileJson.fileName);
await files.download(fileJson.downloadUrl, data.path);
} else await fs.copy(data.path, path.join(target.directory, 'mods', path.basename(data.path)));
} else if (!data.nocopy) await fs.copy(data.path, path.join(target.directory, 'mods', path.basename(data.path)));

const modInfo = await loadModInfo(data.path, target.directory);
if (modInfo.error || target.flavor !== modInfo.flavor) {
Expand Down
12 changes: 1 addition & 11 deletions src/main/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,5 @@ ipcMain.on('launcher:restart', () => this.relaunch());
ipcMain.on('sync', async event => {
event.returnValue = {
vibrancy: await config.getValue('app/vibrancy')
}
});

process.on('unhandledRejection', (reason, p) => {
console.log('UNHANDLED REJECTION');
console.log(reason);
console.log(p);
});
process.on('uncaughtException', err => {
console.log('UNHANDLED EXCEPTION');
console.log(err);
};
});
2 changes: 1 addition & 1 deletion src/main/mojang/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
const mojang = require('../mojang/mojang');

const login = async () => {
let clientKey = ipc.sendSync('config:get', 'clientKey');
let clientKey = ipc.sendSync('config:get', 'clientKey').value;

const username = document.getElementById('username').value;
const password = document.getElementById('password').value;
Expand Down
33 changes: 0 additions & 33 deletions src/main/util/hastebin.js

This file was deleted.

63 changes: 28 additions & 35 deletions src/main/util/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

const { app, ipcMain } = require('electron');
const updater = require('../app/updater');
const { app, ipcMain, shell } = require('electron');
const fetch = require('node-fetch');
const fs = require('fs-extra');
const path = require('path');
Expand All @@ -31,7 +30,6 @@ const baseDir = app.getPath('userData');
const reportDir = path.join(baseDir, 'Error Reports');
const mem = Math.floor(require('os').totalmem()/1e6);
let os = { arch: process.arch };
let mainWindow;

exports.MESSAGES = [
'Uh oh, I did a bad thing!',
Expand Down Expand Up @@ -67,68 +65,63 @@ if (process.platform === 'win32') {

fs.mkdirs(reportDir);

ipcMain.on('reporter:submit', (_, data) => this.error(data));

ipcMain.on('reporter:register', event => mainWindow = event.sender);
let mainWindow;
ipcMain.on('sync', event => mainWindow = event.sender);
ipcMain.on('reporter:test', async () => {
const t = undefined;
t.test();
});

ipcMain.on('reporter:haste', async (event, path) => {
ipcMain.on('reporter:haste', async (_, path) => {
// Ensure that the path is actually inside the report directory to avoid somebody having a private file uploaded to hastebin...
if (!pathIsInside(path, reportDir))
return event.sender.send('reporter:haste', { error: 'privacy protection', errorMessage: 'The path to the report is invalid. Please fetch it manually.' });
return mainWindow.send('reporter:haste', { error: 'privacy protection', errorMessage: 'The path to the report is invalid. Please fetch it manually.' });
let contents;
try {
contents = await fs.readFile(path, 'utf8');
} catch (er) {
console.log(er);
console.log('The above has occurred while creating a crash report.');
return event.sender.send('reporter:haste', { error: er.name, errorMessage: er.message });
console.log('An error has occurred while creating an error report.');
return mainWindow.send('reporter:haste', { error: er.name, errorMessage: er.message });
}
const url = await this.haste(contents);
if (url === undefined) {
console.log('Failed to upload report! (503)');
event.sender.send('reporter:haste', { error: 'response code 503', errorMessage: 'It would appear hastebin is currently unavailable.' })
console.log('Failed to upload error report! (503)');
mainWindow.send('reporter:haste', { error: 'response code 503', errorMessage: 'It would appear hastebin is currently unavailable.' })
} else {
console.log(`Uploaded error report @ ${url} (${path}).`);
event.sender.send('reporter:haste', { url });
mainWindow.send('reporter:haste');
await shell.openExternal(url)
}
});

ipcMain.on('reporter:test', async () => {
const t = undefined;

try {
t.test();
} catch (e) {
this.error(e);
}

process.on('unhandledRejection', error => this.error(error.stack));
process.on('uncaughtException', err => {
console.log('UNHANDLED EXCEPTION');
console.log(err);
});

exports.error = async (err, extras) => {
let error = err.stack;
if (error === undefined) {
error = '';
error += `${err.code} (${err.errno})\n`;
error += `${err.path}`;
}

// console.log(err.stack);
exports.error = async (error) => {
const quote = this.MESSAGES[Math.floor(Math.random()*this.MESSAGES.length)];
const usedMem = mem - Math.floor(require('os').freemem()/1e6);
const reportText = `Proton Launcher v${updater.CURRENT}\n` +
const reportText = `Proton Launcher v${__launcher_version}\n` +
`${new Date().toISOString().replace(/T/, ' ').replace(/\..+/, '')}\n` +
`\n` +
`${os.name} ${os.version} ${os.arch}\n` +
`${usedMem}/${mem}mb\n` +
`\n` +
`// ${this.MESSAGES[Math.floor(Math.random()*this.MESSAGES.length)]}\n` +
`// ${quote}\n` +
`\n` +
`${error}\n`;

const fileName = `${new Date().toISOString().replace(/T/, '-').replace(/\..+/, '').replace(':', '-').replace(':', '-')}.txt`;
const filePath = path.join(reportDir, fileName);
// await fs.ensureFile(filePath);
await fs.outputFile(filePath, reportText);
mainWindow.send('reporter:report', filePath);
mainWindow.send('reporter:report', {
quote,
lines: error.split('\n'),
path: filePath
});
};

exports.haste = async (text, alt = false) => {
Expand Down
Loading

0 comments on commit 0a2b7ad

Please sign in to comment.