move electron folder

This commit is contained in:
Anton Bracke
2022-02-22 10:41:55 +01:00
parent ac18aab773
commit 41be011d5e
36 changed files with 19 additions and 18 deletions
+54
View File
@@ -0,0 +1,54 @@
import { dialog, shell } from "electron";
import ElectronLog from "electron-log";
import log from "electron-log";
function onError(e: Error) {
try {
log.error(e);
dialog.showErrorBox("WorkAdventure - A JavaScript error occurred", e.stack || "");
} catch (logError) {
console.error(e);
}
}
function onRejection(reason: Error) {
if (reason instanceof Error) {
let _reason = reason;
const errPrototype = Object.getPrototypeOf(reason);
const nameProperty = Object.getOwnPropertyDescriptor(errPrototype, "name");
if (!nameProperty || !nameProperty.writable) {
_reason = new Error(reason.message);
}
_reason.name = `UnhandledRejection ${_reason.name}`;
onError(_reason);
return;
}
const error = new Error(JSON.stringify(reason));
error.name = "UnhandledRejection";
onError(error);
}
function init() {
console.log = log.log.bind(log);
process.on("uncaughtException", onError);
process.on("unhandledRejection", onRejection);
}
export async function openLog() {
const logFilePath = log.transports.file.getFile().path;
await shell.openPath(logFilePath);
}
export function setLogLevel(logLevel: ElectronLog.LogLevel) {
log.transports.console.level = logLevel;
log.transports.file.level = logLevel;
}
export default {
init,
};