Skip to content

Commit

Permalink
Merge pull request #34 from grimkor/v0.5.1
Browse files Browse the repository at this point in the history
v0.5.1
  • Loading branch information
grimkor authored Feb 14, 2021
2 parents ca7aae1 + 1d41a95 commit d28ab81
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 19 deletions.
5 changes: 5 additions & 0 deletions electron/backend/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ class Backend {
});
}

stop() {
this.stopLogParser();
ipcMain.removeAllListeners();
}

route(action: string, message: string) {
this.subscriptions.forEach((sub) => sub.event.reply(action, message));
}
Expand Down
4 changes: 4 additions & 0 deletions electron/log_parser/LogParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ class LogParser {
this.tail.watch();
}

stop() {
this.tail.unwatch();
}

setDefaultState() {
this.player = {
...this.player,
Expand Down
6 changes: 6 additions & 0 deletions electron/log_parser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ try {
// @ts-ignore
const Parser = new LogParser(file, process);
Parser.run();
process.addListener("disconnect", () => {
Parser.stop();
});
process.addListener("beforeExit", () => {
Parser.stop();
});
}
} catch (e) {
logger.writeError("LogParser init", e);
Expand Down
10 changes: 7 additions & 3 deletions electron/logger/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from "path";
import {homedir} from "os";
import { homedir } from "os";
import fs from "fs";
import {DatabaseCallback} from "../types";
import { DatabaseCallback } from "../types";

export default class Logger {
outputFile: string;
Expand Down Expand Up @@ -38,7 +38,11 @@ export default class Logger {
this.writeError(name, err?.name, err?.message);
} else {
if (callback) {
callback(result);
try {
callback(result);
} catch (e) {
this.writeError("withErrorHandling", name, e);
}
}
}
};
Expand Down
38 changes: 23 additions & 15 deletions electron/main.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import {app, BrowserWindow, Menu, MenuItemConstructorOptions, shell,} from "electron";
import {
app,
BrowserWindow,
Menu,
MenuItemConstructorOptions,
shell,
} from "electron";
import path from "path";
import url from "url";
import Backend from "./backend";
import electronIsDev from "electron-is-dev";
import Logger from "./logger";
import {getDatabase} from "./database";
import { getDatabase } from "./database";
import {
createCharacterTable,
createConfigTable,
Expand All @@ -14,11 +20,13 @@ import {
createPlayerTable,
} from "./database/defaults";
import upgrade from "./database/upgrade";
import {version} from "../package.json";
import { version } from "../package.json";

const isMac = process.platform === "darwin";
let mainWindow: BrowserWindow | null;

const backend = new Backend();

function createWindow() {
mainWindow = new BrowserWindow({
width: 1024,
Expand Down Expand Up @@ -46,6 +54,7 @@ function createWindow() {
app.on("ready", createWindow);
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
backend.stop();
app.quit();
}
});
Expand All @@ -59,7 +68,7 @@ app.on("activate", () => {
const menu = Menu.buildFromTemplate([
{
label: "File",
submenu: [isMac ? {role: "close"} : {role: "quit"}],
submenu: [isMac ? { role: "close" } : { role: "quit" }],
},
{
label: "About",
Expand Down Expand Up @@ -104,16 +113,16 @@ const menu = Menu.buildFromTemplate([

...((electronIsDev
? [
{
label: "Dev",
submenu: [
{label: "Refresh", role: "reload"},
{
role: "toggleDevTools",
},
],
},
]
{
label: "Dev",
submenu: [
{ label: "Refresh", role: "reload" },
{
role: "toggleDevTools",
},
],
},
]
: []) as MenuItemConstructorOptions[]),
]);
Menu.setApplicationMenu(menu);
Expand Down Expand Up @@ -141,7 +150,6 @@ try {
}
});
});
const backend = new Backend();
backend.run();
});
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"url": "https://github.com/grimkor/fs-stat-tracker"
},
"license": "MIT",
"version": "0.5.0",
"version": "0.5.1",
"private": true,
"dependencies": {
"electron-is-dev": "^1.2.0",
Expand Down

0 comments on commit d28ab81

Please sign in to comment.