From 03a3d734f17b60adf656fe2ed3015f5248761931 Mon Sep 17 00:00:00 2001 From: Kelvin Date: Mon, 10 Mar 2025 23:46:18 -0300 Subject: [PATCH] resolved conflicts --- src/main/level/sublevels/keys.ts | 1 + .../services/download/download-manager.ts | 8 +- src/main/services/hosters/datanodes.ts | 5 +- src/main/services/window-manager.ts | 104 ++++++++++++++---- src/types/level.types.ts | 8 ++ 5 files changed, 99 insertions(+), 27 deletions(-) diff --git a/src/main/level/sublevels/keys.ts b/src/main/level/sublevels/keys.ts index 3f0a09ea..6559e460 100644 --- a/src/main/level/sublevels/keys.ts +++ b/src/main/level/sublevels/keys.ts @@ -14,4 +14,5 @@ export const levelKeys = { userPreferences: "userPreferences", language: "language", sqliteMigrationDone: "sqliteMigrationDone", + screenState: "screenState", }; diff --git a/src/main/services/download/download-manager.ts b/src/main/services/download/download-manager.ts index bdf926f3..860cf5cf 100644 --- a/src/main/services/download/download-manager.ts +++ b/src/main/services/download/download-manager.ts @@ -2,7 +2,13 @@ import { Downloader, DownloadError } from "@shared"; import { WindowManager } from "../window-manager"; import { publishDownloadCompleteNotification } from "../notifications"; import type { Download, DownloadProgress, UserPreferences } from "@types"; -import { GofileApi, QiwiApi, DatanodesApi, MediafireApi, PixelDrainApi } from "../hosters"; +import { + GofileApi, + QiwiApi, + DatanodesApi, + MediafireApi, + PixelDrainApi, +} from "../hosters"; import { PythonRPC } from "../python-rpc"; import { LibtorrentPayload, diff --git a/src/main/services/hosters/datanodes.ts b/src/main/services/hosters/datanodes.ts index 90402485..29708322 100644 --- a/src/main/services/hosters/datanodes.ts +++ b/src/main/services/hosters/datanodes.ts @@ -18,10 +18,7 @@ export class DatanodesApi { const pathSegments = parsedUrl.pathname.split("/").filter(Boolean); const fileCode = pathSegments[0]; - await this.jar.setCookie( - "lang=english;", - "https://datanodes.to" - ); + await this.jar.setCookie("lang=english;", "https://datanodes.to"); const payload = new URLSearchParams({ op: "download2", diff --git a/src/main/services/window-manager.ts b/src/main/services/window-manager.ts index dde51b5f..104d0aad 100644 --- a/src/main/services/window-manager.ts +++ b/src/main/services/window-manager.ts @@ -17,7 +17,7 @@ import { HydraApi } from "./hydra-api"; import UserAgent from "user-agents"; import { db, gamesSublevel, levelKeys } from "@main/level"; import { slice, sortBy } from "lodash-es"; -import type { UserPreferences } from "@types"; +import type { ScreenState, UserPreferences } from "@types"; import { AuthPage } from "@shared"; import { isStaging } from "@main/constants"; @@ -26,27 +26,8 @@ export class WindowManager { private static readonly editorWindows: Map = new Map(); - private static loadMainWindowURL(hash = "") { - // 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.mainWindow?.loadURL( - `${process.env["ELECTRON_RENDERER_URL"]}#/${hash}` - ); - } else { - this.mainWindow?.loadFile( - path.join(__dirname, "../renderer/index.html"), - { - hash, - } - ); - } - } - - public static createMainWindow() { - if (this.mainWindow) return; - - this.mainWindow = new BrowserWindow({ + private static initialConfigInitializationMainWindow: Electron.BrowserWindowConstructorOptions = + { width: 1200, height: 720, minWidth: 1024, @@ -65,7 +46,70 @@ export class WindowManager { sandbox: false, }, show: false, + }; + + private static loadMainWindowURL(hash = "") { + // 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.mainWindow?.loadURL( + `${process.env["ELECTRON_RENDERER_URL"]}#/${hash}` + ); + } else { + this.mainWindow?.loadFile( + path.join(__dirname, "../renderer/index.html"), + { + hash, + } + ); + } + } + + private static async saveScreenConfig({ + ...configScreenWhenClosed + }: { + x: number | undefined; + y: number | undefined; + width: number; + height: number; + isMaximized: boolean; + }) { + await db.put(levelKeys.screenState, configScreenWhenClosed, { + valueEncoding: "json", }); + } + + private static async loadScreenConfig() { + const data = await db.get(levelKeys.screenState, { + valueEncoding: "json", + }); + return data ?? {}; + } + + private static updateInitialConfig( + newConfig: Partial + ) { + this.initialConfigInitializationMainWindow = { + ...this.initialConfigInitializationMainWindow, + ...newConfig, + }; + } + + public static async createMainWindow() { + if (this.mainWindow) return; + + const { isMaximized = false, ...configWithoutMaximized } = + await this.loadScreenConfig(); + + this.updateInitialConfig(configWithoutMaximized); + + this.mainWindow = new BrowserWindow( + this.initialConfigInitializationMainWindow + ); + + if (isMaximized) { + this.mainWindow.maximize(); + } this.mainWindow.webContents.session.webRequest.onBeforeSendHeaders( (details, callback) => { @@ -143,6 +187,22 @@ export class WindowManager { } ); + if (this.mainWindow) { + const lastBounds = this.mainWindow.getBounds(); + const isMaximized = this.mainWindow.isMaximized() ?? false; + const screenConfig = isMaximized + ? { + x: undefined, + y: undefined, + height: this.initialConfigInitializationMainWindow.height!, + width: this.initialConfigInitializationMainWindow.width!, + isMaximized: true, + } + : { ...lastBounds, isMaximized }; + + await this.saveScreenConfig(screenConfig); + } + if (userPreferences?.preferQuitInsteadOfHiding) { app.quit(); } diff --git a/src/types/level.types.ts b/src/types/level.types.ts index ff710367..ae8e5a26 100644 --- a/src/types/level.types.ts +++ b/src/types/level.types.ts @@ -82,3 +82,11 @@ export interface UserPreferences { repackUpdatesNotificationsEnabled?: boolean; achievementNotificationsEnabled?: boolean; } + +export interface ScreenState { + x?: number; + y?: number; + height: number; + width: number; + isMaximized: boolean; +}