mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-02-01 19:15:07 +01:00
Merge branch 'main' into feature/delete-all-dowload-sources
This commit is contained in:
@@ -14,4 +14,5 @@ export const levelKeys = {
|
|||||||
userPreferences: "userPreferences",
|
userPreferences: "userPreferences",
|
||||||
language: "language",
|
language: "language",
|
||||||
sqliteMigrationDone: "sqliteMigrationDone",
|
sqliteMigrationDone: "sqliteMigrationDone",
|
||||||
|
screenState: "screenState",
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,7 +2,13 @@ import { Downloader, DownloadError } from "@shared";
|
|||||||
import { WindowManager } from "../window-manager";
|
import { WindowManager } from "../window-manager";
|
||||||
import { publishDownloadCompleteNotification } from "../notifications";
|
import { publishDownloadCompleteNotification } from "../notifications";
|
||||||
import type { Download, DownloadProgress, UserPreferences } from "@types";
|
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 { PythonRPC } from "../python-rpc";
|
||||||
import {
|
import {
|
||||||
LibtorrentPayload,
|
LibtorrentPayload,
|
||||||
|
|||||||
@@ -18,10 +18,7 @@ export class DatanodesApi {
|
|||||||
const pathSegments = parsedUrl.pathname.split("/").filter(Boolean);
|
const pathSegments = parsedUrl.pathname.split("/").filter(Boolean);
|
||||||
const fileCode = pathSegments[0];
|
const fileCode = pathSegments[0];
|
||||||
|
|
||||||
await this.jar.setCookie(
|
await this.jar.setCookie("lang=english;", "https://datanodes.to");
|
||||||
"lang=english;",
|
|
||||||
"https://datanodes.to"
|
|
||||||
);
|
|
||||||
|
|
||||||
const payload = new URLSearchParams({
|
const payload = new URLSearchParams({
|
||||||
op: "download2",
|
op: "download2",
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import { HydraApi } from "./hydra-api";
|
|||||||
import UserAgent from "user-agents";
|
import UserAgent from "user-agents";
|
||||||
import { db, gamesSublevel, levelKeys } from "@main/level";
|
import { db, gamesSublevel, levelKeys } from "@main/level";
|
||||||
import { slice, sortBy } from "lodash-es";
|
import { slice, sortBy } from "lodash-es";
|
||||||
import type { UserPreferences } from "@types";
|
import type { ScreenState, UserPreferences } from "@types";
|
||||||
import { AuthPage } from "@shared";
|
import { AuthPage } from "@shared";
|
||||||
import { isStaging } from "@main/constants";
|
import { isStaging } from "@main/constants";
|
||||||
|
|
||||||
@@ -26,27 +26,8 @@ export class WindowManager {
|
|||||||
|
|
||||||
private static readonly editorWindows: Map<string, BrowserWindow> = new Map();
|
private static readonly editorWindows: Map<string, BrowserWindow> = new Map();
|
||||||
|
|
||||||
private static loadMainWindowURL(hash = "") {
|
private static initialConfigInitializationMainWindow: Electron.BrowserWindowConstructorOptions =
|
||||||
// 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({
|
|
||||||
width: 1200,
|
width: 1200,
|
||||||
height: 720,
|
height: 720,
|
||||||
minWidth: 1024,
|
minWidth: 1024,
|
||||||
@@ -65,7 +46,65 @@ export class WindowManager {
|
|||||||
sandbox: false,
|
sandbox: false,
|
||||||
},
|
},
|
||||||
show: 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: ScreenState) {
|
||||||
|
await db.put(levelKeys.screenState, configScreenWhenClosed, {
|
||||||
|
valueEncoding: "json",
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async loadScreenConfig() {
|
||||||
|
const data = await db.get<string, ScreenState | undefined>(
|
||||||
|
levelKeys.screenState,
|
||||||
|
{
|
||||||
|
valueEncoding: "json",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return data ?? { isMaximized: false, height: 720, width: 1200 };
|
||||||
|
}
|
||||||
|
|
||||||
|
private static updateInitialConfig(
|
||||||
|
newConfig: Partial<Electron.BrowserWindowConstructorOptions>
|
||||||
|
) {
|
||||||
|
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(
|
this.mainWindow.webContents.session.webRequest.onBeforeSendHeaders(
|
||||||
(details, callback) => {
|
(details, callback) => {
|
||||||
@@ -143,9 +182,26 @@ 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 ?? 720,
|
||||||
|
width: this.initialConfigInitializationMainWindow.width ?? 1200,
|
||||||
|
isMaximized: true,
|
||||||
|
}
|
||||||
|
: { ...lastBounds, isMaximized };
|
||||||
|
|
||||||
|
await this.saveScreenConfig(screenConfig);
|
||||||
|
}
|
||||||
|
|
||||||
if (userPreferences?.preferQuitInsteadOfHiding) {
|
if (userPreferences?.preferQuitInsteadOfHiding) {
|
||||||
app.quit();
|
app.quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
WindowManager.mainWindow?.setProgressBar(-1);
|
WindowManager.mainWindow?.setProgressBar(-1);
|
||||||
WindowManager.mainWindow = null;
|
WindowManager.mainWindow = null;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -82,3 +82,11 @@ export interface UserPreferences {
|
|||||||
repackUpdatesNotificationsEnabled?: boolean;
|
repackUpdatesNotificationsEnabled?: boolean;
|
||||||
achievementNotificationsEnabled?: boolean;
|
achievementNotificationsEnabled?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ScreenState {
|
||||||
|
x?: number;
|
||||||
|
y?: number;
|
||||||
|
height: number;
|
||||||
|
width: number;
|
||||||
|
isMaximized: boolean;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user