mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
refactor to levelDB
This commit is contained in:
parent
0e7a0d1afa
commit
08935ceabd
4 changed files with 18 additions and 25 deletions
|
@ -13,4 +13,5 @@ export const levelKeys = {
|
||||||
userPreferences: "userPreferences",
|
userPreferences: "userPreferences",
|
||||||
language: "language",
|
language: "language",
|
||||||
sqliteMigrationDone: "sqliteMigrationDone",
|
sqliteMigrationDone: "sqliteMigrationDone",
|
||||||
|
screenState: "screenState",
|
||||||
};
|
};
|
||||||
|
|
|
@ -17,19 +17,13 @@ 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";
|
||||||
import { writeFile, readFile } from "fs/promises";
|
|
||||||
|
|
||||||
export class WindowManager {
|
export class WindowManager {
|
||||||
public static mainWindow: Electron.BrowserWindow | null = null;
|
public static mainWindow: Electron.BrowserWindow | null = null;
|
||||||
|
|
||||||
private static configPath = path.join(
|
|
||||||
app.getPath("userData"),
|
|
||||||
"HydraScreenState.json"
|
|
||||||
);
|
|
||||||
|
|
||||||
private static initialConfigInitializationMainWindow: Electron.BrowserWindowConstructorOptions =
|
private static initialConfigInitializationMainWindow: Electron.BrowserWindowConstructorOptions =
|
||||||
{
|
{
|
||||||
width: 1200,
|
width: 1200,
|
||||||
|
@ -61,25 +55,16 @@ export class WindowManager {
|
||||||
height: number;
|
height: number;
|
||||||
isMaximized: boolean;
|
isMaximized: boolean;
|
||||||
}) {
|
}) {
|
||||||
try {
|
await db.put(levelKeys.screenState, configScreenWhenClosed, {
|
||||||
await writeFile(
|
valueEncoding: "json",
|
||||||
this.configPath,
|
});
|
||||||
JSON.stringify(configScreenWhenClosed, null, 0),
|
|
||||||
"utf-8"
|
|
||||||
);
|
|
||||||
} catch (error) {
|
|
||||||
console.error("failed to save screenConfig", error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async loadScreenConfig() {
|
private static async loadScreenConfig() {
|
||||||
try {
|
const data = await db.get<string, ScreenState>(levelKeys.screenState, {
|
||||||
const screenConfigData = await readFile(this.configPath, "utf-8");
|
valueEncoding: "json",
|
||||||
return JSON.parse(screenConfigData);
|
});
|
||||||
} catch (error) {
|
return data ?? {};
|
||||||
console.error("failed to load screenConfig:", error);
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
private static updateInitialConfig(
|
private static updateInitialConfig(
|
||||||
newConfig: Partial<Electron.BrowserWindowConstructorOptions>
|
newConfig: Partial<Electron.BrowserWindowConstructorOptions>
|
||||||
|
@ -110,7 +95,7 @@ export class WindowManager {
|
||||||
public static async createMainWindow() {
|
public static async createMainWindow() {
|
||||||
if (this.mainWindow) return;
|
if (this.mainWindow) return;
|
||||||
|
|
||||||
const { isMaximized, ...configWithoutMaximized } =
|
const { isMaximized = false, ...configWithoutMaximized } =
|
||||||
await this.loadScreenConfig();
|
await this.loadScreenConfig();
|
||||||
|
|
||||||
this.updateInitialConfig(configWithoutMaximized);
|
this.updateInitialConfig(configWithoutMaximized);
|
||||||
|
|
|
@ -196,7 +196,6 @@ export function HeroPanelActions() {
|
||||||
{game.favorite ? <HeartFillIcon /> : <HeartIcon />}
|
{game.favorite ? <HeartFillIcon /> : <HeartIcon />}
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
onClick={() => setShowGameOptionsModal(true)}
|
onClick={() => setShowGameOptionsModal(true)}
|
||||||
theme="outline"
|
theme="outline"
|
||||||
|
|
|
@ -81,3 +81,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;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue