mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
feat: correcting date in process-watcher
This commit is contained in:
commit
85516c1744
47 changed files with 334 additions and 489 deletions
|
|
@ -26,6 +26,8 @@ export const databasePath = path.join(
|
|||
"hydra.db"
|
||||
);
|
||||
|
||||
export const logsPath = path.join(app.getPath("appData"), "hydra", "logs");
|
||||
|
||||
export const seedsPath = app.isPackaged
|
||||
? path.join(process.resourcesPath, "seeds")
|
||||
: path.join(__dirname, "..", "..", "seeds");
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ export class Game {
|
|||
@Column("int", { default: 0 })
|
||||
bytesDownloaded: number;
|
||||
|
||||
@Column("text", { nullable: true })
|
||||
@Column("datetime", { nullable: true })
|
||||
lastTimePlayed: Date | null;
|
||||
|
||||
@Column("float", { default: 0 })
|
||||
|
|
|
|||
|
|
@ -1,41 +1,27 @@
|
|||
import { AppUpdaterEvents } from "@types";
|
||||
import { registerEvent } from "../register-event";
|
||||
import updater, { ProgressInfo, UpdateInfo } from "electron-updater";
|
||||
import updater, { UpdateInfo } from "electron-updater";
|
||||
import { WindowManager } from "@main/services";
|
||||
import { app } from "electron";
|
||||
|
||||
const { autoUpdater } = updater;
|
||||
|
||||
const sendEvent = (event: AppUpdaterEvents) => {
|
||||
WindowManager.splashWindow?.webContents.send("autoUpdaterEvent", event);
|
||||
WindowManager.mainWindow?.webContents.send("autoUpdaterEvent", event);
|
||||
};
|
||||
|
||||
const mockValuesForDebug = async () => {
|
||||
sendEvent({ type: "update-downloaded" });
|
||||
sendEvent({ type: "update-available", info: { version: "1.3.0" } });
|
||||
// sendEvent({ type: "update-downloaded" });
|
||||
};
|
||||
|
||||
const checkForUpdates = async (_event: Electron.IpcMainInvokeEvent) => {
|
||||
autoUpdater
|
||||
.addListener("error", () => {
|
||||
sendEvent({ type: "error" });
|
||||
})
|
||||
.addListener("checking-for-update", () => {
|
||||
sendEvent({ type: "checking-for-updates" });
|
||||
})
|
||||
.addListener("update-not-available", () => {
|
||||
sendEvent({ type: "update-not-available" });
|
||||
})
|
||||
.addListener("update-available", (info: UpdateInfo) => {
|
||||
sendEvent({ type: "update-available", info });
|
||||
})
|
||||
.addListener("update-downloaded", () => {
|
||||
sendEvent({ type: "update-downloaded" });
|
||||
})
|
||||
.addListener("download-progress", (info: ProgressInfo) => {
|
||||
sendEvent({ type: "download-progress", info });
|
||||
})
|
||||
.addListener("update-cancelled", () => {
|
||||
sendEvent({ type: "update-cancelled" });
|
||||
});
|
||||
|
||||
if (app.isPackaged) {
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
import { WindowManager } from "@main/services";
|
||||
import { registerEvent } from "../register-event";
|
||||
import updater from "electron-updater";
|
||||
|
||||
const { autoUpdater } = updater;
|
||||
|
||||
const continueToMainWindow = async (_event: Electron.IpcMainInvokeEvent) => {
|
||||
autoUpdater.removeAllListeners();
|
||||
WindowManager.prepareMainWindowAndCloseSplash();
|
||||
};
|
||||
|
||||
registerEvent("continueToMainWindow", continueToMainWindow);
|
||||
|
|
@ -1,16 +1,13 @@
|
|||
import { app } from "electron";
|
||||
import { registerEvent } from "../register-event";
|
||||
import updater from "electron-updater";
|
||||
import { WindowManager } from "@main/services";
|
||||
|
||||
const { autoUpdater } = updater;
|
||||
|
||||
const restartAndInstallUpdate = async (_event: Electron.IpcMainInvokeEvent) => {
|
||||
autoUpdater.removeAllListeners();
|
||||
if (app.isPackaged) {
|
||||
autoUpdater.quitAndInstall(true, true);
|
||||
} else {
|
||||
autoUpdater.removeAllListeners();
|
||||
WindowManager.prepareMainWindowAndCloseSplash();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ import "./user-preferences/update-user-preferences";
|
|||
import "./user-preferences/auto-launch";
|
||||
import "./autoupdater/check-for-updates";
|
||||
import "./autoupdater/restart-and-install-update";
|
||||
import "./autoupdater/continue-to-main-window";
|
||||
import "./user-preferences/authenticate-real-debrid";
|
||||
|
||||
ipcMain.handle("ping", () => "pong");
|
||||
|
|
|
|||
|
|
@ -50,8 +50,6 @@ const startGameDownload = async (
|
|||
isDeleted: false,
|
||||
}
|
||||
);
|
||||
|
||||
return DownloadManager.startDownload(game);
|
||||
} else {
|
||||
const steamGame = stateManager
|
||||
.getValue("steamGames")
|
||||
|
|
@ -81,16 +79,16 @@ const startGameDownload = async (
|
|||
|
||||
return result;
|
||||
});
|
||||
|
||||
const createdGame = await gameRepository.findOne({
|
||||
where: {
|
||||
objectID,
|
||||
},
|
||||
relations: { repack: true },
|
||||
});
|
||||
|
||||
return DownloadManager.startDownload(createdGame!);
|
||||
}
|
||||
|
||||
const updatedGame = await gameRepository.findOne({
|
||||
where: {
|
||||
objectID,
|
||||
},
|
||||
relations: { repack: true },
|
||||
});
|
||||
|
||||
await DownloadManager.startDownload(updatedGame!);
|
||||
};
|
||||
|
||||
registerEvent("startGameDownload", startGameDownload);
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ app.whenReady().then(() => {
|
|||
where: { id: 1 },
|
||||
});
|
||||
|
||||
WindowManager.createSplashScreen();
|
||||
WindowManager.createMainWindow();
|
||||
WindowManager.createSystemTray(userPreferences?.language || "en");
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -0,0 +1,49 @@
|
|||
import { Game } from "@main/entity";
|
||||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class AlterLastTimePlayedToDatime1716776027208
|
||||
implements MigrationInterface
|
||||
{
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
// 2024-05-27 02:08:17
|
||||
// Mon, 27 May 2024 02:08:17 GMT
|
||||
const updateLastTimePlayedValues = `
|
||||
UPDATE game SET lastTimePlayed = (SELECT
|
||||
SUBSTR(lastTimePlayed, 13, 4) || '-' || -- Year
|
||||
CASE SUBSTR(lastTimePlayed, 9, 3)
|
||||
WHEN 'Jan' THEN '01'
|
||||
WHEN 'Feb' THEN '02'
|
||||
WHEN 'Mar' THEN '03'
|
||||
WHEN 'Apr' THEN '04'
|
||||
WHEN 'May' THEN '05'
|
||||
WHEN 'Jun' THEN '06'
|
||||
WHEN 'Jul' THEN '07'
|
||||
WHEN 'Aug' THEN '08'
|
||||
WHEN 'Sep' THEN '09'
|
||||
WHEN 'Oct' THEN '10'
|
||||
WHEN 'Nov' THEN '11'
|
||||
WHEN 'Dec' THEN '12'
|
||||
END || '-' || -- Month
|
||||
SUBSTR(lastTimePlayed, 6, 2) || ' ' || -- Day
|
||||
SUBSTR(lastTimePlayed, 18, 8) -- hh:mm:ss;
|
||||
FROM game)
|
||||
WHERE lastTimePlayed IS NOT NULL;
|
||||
`;
|
||||
|
||||
await queryRunner.query(updateLastTimePlayedValues);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
const queryBuilder = queryRunner.manager.createQueryBuilder(Game, "game");
|
||||
|
||||
const result = await queryBuilder.getMany();
|
||||
|
||||
for (const game of result) {
|
||||
if (!game.lastTimePlayed) continue;
|
||||
await queryRunner.query(
|
||||
`UPDATE game set lastTimePlayed = ? WHERE id = ?;`,
|
||||
[game.lastTimePlayed.toUTCString(), game.id]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +1,7 @@
|
|||
import { FixRepackUploadDate1715900413313 } from "./1715900413313-fix_repack_uploadDate";
|
||||
import { AlterLastTimePlayedToDatime1716776027208 } from "./1716776027208-alter_lastTimePlayed_to_datime";
|
||||
|
||||
export default [FixRepackUploadDate1715900413313];
|
||||
export default [
|
||||
FixRepackUploadDate1715900413313,
|
||||
AlterLastTimePlayedToDatime1716776027208,
|
||||
];
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ export const watchProcesses = async () => {
|
|||
|
||||
await gameRepository.update(game.id, {
|
||||
playTimeInMilliseconds: game.playTimeInMilliseconds + delta,
|
||||
lastTimePlayed: new Date().toUTCString(),
|
||||
lastTimePlayed: new Date(),
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue