Skip to content

Commit

Permalink
Added sentry.io and more error logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hi-Ray committed Jan 29, 2021
1 parent 66d9228 commit 63ecdae
Show file tree
Hide file tree
Showing 6 changed files with 393 additions and 196 deletions.
50 changes: 38 additions & 12 deletions app/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ function createWindow() {
*/
mainWindow
.loadURL(IS_DEV ? "http://localhost:3000" : `file://${ROOT}/index.html`)
.catch(console.error);
.catch((err) => {
console.error(err);
throw new Error("Error loading main page: " + err.message);
});

/**
* Only show the window when the page has fully loaded.
Expand Down Expand Up @@ -126,10 +129,19 @@ function createWindow() {
ipc.on("PROMPTHELP", async () => {
if (LCUData != "" || LCUData != null || LCUData != {}) {
const { username, password, port, protocol, address } = LCUData;
mainWindow?.webContents.send(
"LCUCONNECT",
await help({ username, password, port, protocol, address })
);
const helpSwagger = help({
username,
password,
port,
protocol,
address,
});

try {
mainWindow?.webContents.send("LCUCONNECT", await helpSwagger);
} catch (e) {
console.error("Failed generating help swagger: " + e.message, e);
}
} else {
console.error("NO CREDENTIALS FOUND");
}
Expand All @@ -147,7 +159,10 @@ function createWindow() {
console.log(`Riotclient is open; corresponding league path: ${leaguePath}`);
const systemYamlPath = path.join(leaguePath, "system.yaml");

modifySystemYaml(systemYamlPath).catch(console.error);
modifySystemYaml(systemYamlPath).catch((err) => {
console.error(err);
throw new Error("Error modifying system yaml: " + err.message);
});
});

/**
Expand All @@ -159,13 +174,21 @@ function createWindow() {
console.log("initial lcu connect");
LCUData = await data;
if (platform() === "linux") {
const { username, password, port, protocol, address } = LCUData;
try {
const { username, password, port, protocol, address } = LCUData;

mainWindow?.webContents.send("credentials_pass", LCUData);
mainWindow?.webContents.send("credentials_pass", LCUData);

help({ username, password, port, protocol, address }).then((res) => {
mainWindow?.webContents.send("LCUCONNECT", res);
});
help({ username, password, port, protocol, address }).then((res) => {
mainWindow?.webContents.send("LCUCONNECT", res);
});
} catch (err) {
console.error(
"Failed to connect to client (might be running in the background i.e not fully closed)",
err
);
throw new Error(err.message);
}

return;
}
Expand All @@ -175,7 +198,10 @@ function createWindow() {
swaggerJson = res;
mainWindow?.webContents.send("LCUCONNECT", res);
})
.catch(console.error);
.catch((err) => {
console.error(err);
throw new Error("Error building /help: " + err.message);
});
return;
}

Expand Down
16 changes: 10 additions & 6 deletions app/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,14 @@ export async function deleteUserSession(
) {
const { username, password, address, port } = LCUData;

/**
* Delete the users session so they have to log back in.
*/
await instance.delete(
`https://${username}:${password}@${address}:${port}/lol-rso-auth/v1/session`
);
try {
/**
* Delete the users session so they have to log back in.
*/
await instance.delete(
`https://${username}:${password}@${address}:${port}/lol-rso-auth/v1/session`
);
} catch (e) {
throw new Error("Unable to delete session: " + e.message);
}
}
20 changes: 9 additions & 11 deletions app/util/RiotConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ export default class RiotConnector extends EventEmitter {
*/
if (!match) {
let product: string = normalizedPath.match(
(platform() !== 'darwin')
platform() !== "darwin"
? '--launch-product=(.*?)[ $"]'
: '--upgrade-product=(.*?)[ $"\n]'
)[1];
let patchline: string = normalizedPath.match(
(platform() !== 'darwin')
platform() !== "darwin"
? '--launch-patchline=(.*?)[ $"]'
: '--upgrade-patchline=(.*?)[ $"\n]'
)[1];
Expand All @@ -108,8 +108,7 @@ export default class RiotConnector extends EventEmitter {
* There is no ProgramData folder on MacOS
*/
let programData = process.env.ProgramData;
if (platform() === 'darwin')
programData = '/Users/Shared';
if (platform() === "darwin") programData = "/Users/Shared";

this.leaguePath = parseDocument(
readFileSync(
Expand All @@ -123,12 +122,8 @@ export default class RiotConnector extends EventEmitter {
).toString()
).get("product_install_full_path");

if (platform() === 'darwin')
this.leaguePath = path.join(
this.leaguePath,
'Contents',
'LoL'
);
if (platform() === "darwin")
this.leaguePath = path.join(this.leaguePath, "Contents", "LoL");
} else {
this.leaguePath = path.dirname(match[1]);
}
Expand Down Expand Up @@ -190,7 +185,10 @@ export default class RiotConnector extends EventEmitter {
* Start the watchers.
*/
start() {
this._riotClientWatch ??= setInterval(this._checkRiotClient.bind(this), 1000);
this._riotClientWatch ??= setInterval(
this._checkRiotClient.bind(this),
1000
);
if (platform() === "linux") {
return;
}
Expand Down
32 changes: 16 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@
"main": "build/app/entry.js",
"dependencies": {
"@sentry/electron": "^2.2.0",
"axios": "^0.21.0",
"electron": "^11.0.4",
"axios": "^0.21.1",
"electron": "^11.2.1",
"mixin-deep": "^2.0.1",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "4.0.1",
"sass": "^1.32.4",
"swagger-ui": "^3.39.0",
"swagger-ui-react": "^3.39.0",
"typescript": "^4.0.3"
"sass": "^1.32.5",
"swagger-ui": "^3.41.1",
"swagger-ui-react": "^3.41.1",
"typescript": "^4.1.3"
},
"scripts": {
"dev": "tsc -p app && concurrently \"cross-env BROWSER=none NODE_ENV=development yarn react:start\" \"wait-on http://localhost:3000/ && electron ./build/app/entry.js\"",
Expand Down Expand Up @@ -68,27 +68,27 @@
]
},
"devDependencies": {
"@rescripts/cli": "^0.0.14",
"@rescripts/cli": "^0.0.15",
"@rescripts/rescript-env": "^0.0.12",
"@types/node": "^14.14.11",
"@types/node": "^14.14.22",
"@types/react": "^17.0.0",
"@types/swagger-ui-dist": "^3.30.0",
"@types/swagger-ui-react": "^3.35.0",
"@typescript-eslint/eslint-plugin": "^4.9.1",
"@typescript-eslint/parser": "^4.9.1",
"@typescript-eslint/eslint-plugin": "^4.14.1",
"@typescript-eslint/parser": "^4.14.1",
"concurrently": "^5.3.0",
"cross-env": "^7.0.3",
"electron-builder": "^22.9.1",
"eslint": "^7.11.0",
"eslint": "^7.18.0",
"eslint-config-airbnb": "18.2.1",
"eslint-config-airbnb-typescript": "^12.0.0",
"eslint-config-prettier": "^7.0.0",
"eslint-config-prettier": "^7.2.0",
"eslint-plugin-import": "2.22.1",
"eslint-plugin-jsx-a11y": "6.4.1",
"eslint-plugin-prettier": "^3.2.0",
"eslint-plugin-react": "7.21.5",
"eslint-plugin-react-hooks": "4.0.0",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-react": "7.22.0",
"eslint-plugin-react-hooks": "4.2.0",
"prettier": "^2.2.1",
"wait-on": "^5.2.0"
"wait-on": "^5.2.1"
}
}
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const App = (): React.ReactElement => {

useEffect(() => {
ipc.on("credentials_pass", (event, creds) => {
console.log(`credentials_pass: ${creds}`);
console.log(`credentials_pass: ${JSON.stringify(creds)}`);
setCredentials(creds);
});

Expand Down
Loading

0 comments on commit 63ecdae

Please sign in to comment.