feat: correcting date in process-watcher

This commit is contained in:
Chubby Granny Chaser 2024-05-29 17:20:47 +01:00
commit 85516c1744
No known key found for this signature in database
47 changed files with 334 additions and 489 deletions

View file

@ -186,7 +186,8 @@ export class DownloadManager {
}
if (WindowManager.mainWindow && game) {
WindowManager.mainWindow.setProgressBar(progress === 1 ? -1 : progress);
if (!isNaN(progress))
WindowManager.mainWindow.setProgressBar(progress === 1 ? -1 : progress);
const payload = {
numPeers: Number(status.connections),
@ -237,11 +238,12 @@ export class DownloadManager {
if (this.gid) {
await this.aria2.call("forcePause", this.gid);
this.gid = null;
this.game = null;
this.realDebridTorrentId = null;
WindowManager.mainWindow?.setProgressBar(-1);
}
this.game = null;
this.realDebridTorrentId = null;
WindowManager.mainWindow?.setProgressBar(-1);
}
static async resumeDownload(game: Game) {
@ -251,6 +253,7 @@ export class DownloadManager {
this.gid = gid;
this.game = game;
this.realDebridTorrentId = null;
} else {
return this.startDownload(game);
}
@ -269,7 +272,6 @@ export class DownloadManager {
);
} else {
this.gid = await this.aria2.call("addUri", [game.repack.magnet], options);
this.downloads.set(game.id, this.gid);
}

View file

@ -1,11 +1,26 @@
import winston from "winston";
import { logsPath } from "@main/constants";
import log from "electron-log";
import path from "path";
export const logger = winston.createLogger({
level: "info",
format: winston.format.json(),
transports: [
new winston.transports.File({ filename: "error.log", level: "error" }),
new winston.transports.File({ filename: "info.log", level: "info" }),
new winston.transports.File({ filename: "combined.log" }),
],
log.transports.file.resolvePathFn = (
_: log.PathVariables,
message?: log.LogMessage | undefined
) => {
if (message?.level === "error") {
return path.join(logsPath, "error.txt");
}
if (message?.level === "info") {
return path.join(logsPath, "info.txt");
}
return path.join(logsPath, "logs.txt");
};
log.errorHandler.startCatching({
showDialog: false,
});
log.initialize();
export const logger = log.scope("main");

View file

@ -46,7 +46,7 @@ export const watchProcesses = async () => {
await gameRepository.update(game.id, {
playTimeInMilliseconds: game.playTimeInMilliseconds + delta,
lastTimePlayed: new Date().toUTCString(),
lastTimePlayed: new Date(),
});
}

View file

@ -17,8 +17,6 @@ import { IsNull, Not } from "typeorm";
export class WindowManager {
public static mainWindow: Electron.BrowserWindow | null = null;
public static splashWindow: Electron.BrowserWindow | null = null;
public static isReadyToShowMainWindow = false;
private static loadURL(hash = "") {
// HMR for renderer base on electron-vite cli.
@ -37,44 +35,8 @@ export class WindowManager {
}
}
private static loadSplashURL() {
// HMR for renderer base on electron-vite cli.
// Load the remote URL for development or the local html file for production.
if (is.dev && process.env["ELECTRON_RENDERER_URL"]) {
this.splashWindow?.loadURL(
`${process.env["ELECTRON_RENDERER_URL"]}#/splash`
);
} else {
this.splashWindow?.loadFile(
path.join(__dirname, "../renderer/index.html"),
{
hash: "splash",
}
);
}
}
public static createSplashScreen() {
if (this.splashWindow) return;
this.splashWindow = new BrowserWindow({
width: 380,
height: 380,
frame: false,
resizable: false,
backgroundColor: "#1c1c1c",
webPreferences: {
preload: path.join(__dirname, "../preload/index.mjs"),
sandbox: false,
},
});
this.loadSplashURL();
this.splashWindow.removeMenu();
}
public static createMainWindow() {
if (this.mainWindow || !this.isReadyToShowMainWindow) return;
if (this.mainWindow) return;
this.mainWindow = new BrowserWindow({
width: 1200,
@ -94,6 +56,7 @@ export class WindowManager {
preload: path.join(__dirname, "../preload/index.mjs"),
sandbox: false,
},
show: false,
});
this.loadURL();
@ -101,6 +64,7 @@ export class WindowManager {
this.mainWindow.on("ready-to-show", () => {
if (!app.isPackaged) WindowManager.mainWindow?.webContents.openDevTools();
WindowManager.mainWindow?.show();
});
this.mainWindow.on("close", async () => {
@ -115,12 +79,6 @@ export class WindowManager {
});
}
public static prepareMainWindowAndCloseSplash() {
this.isReadyToShowMainWindow = true;
this.splashWindow?.close();
this.createMainWindow();
}
public static redirect(hash: string) {
if (!this.mainWindow) this.createMainWindow();
this.loadURL(hash);