mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-21 18:13:55 +00:00
feat: refactor open auth
This commit is contained in:
@@ -1,7 +1,22 @@
|
||||
import i18next from "i18next";
|
||||
import { registerEvent } from "../register-event";
|
||||
import { WindowManager } from "@main/services";
|
||||
import { HydraApi, WindowManager } from "@main/services";
|
||||
import { AuthPage } from "@shared";
|
||||
|
||||
const openAuthWindow = async (_event: Electron.IpcMainInvokeEvent) =>
|
||||
WindowManager.openAuthWindow();
|
||||
const openAuthWindow = async (
|
||||
_event: Electron.IpcMainInvokeEvent,
|
||||
page: AuthPage
|
||||
) => {
|
||||
const searchParams = new URLSearchParams({
|
||||
lng: i18next.language,
|
||||
});
|
||||
|
||||
if ([AuthPage.UpdateEmail, AuthPage.UpdatePassword].includes(page)) {
|
||||
const { accessToken } = await HydraApi.refreshToken();
|
||||
searchParams.set("token", accessToken);
|
||||
}
|
||||
|
||||
return WindowManager.openAuthWindow(page, searchParams);
|
||||
};
|
||||
|
||||
registerEvent("openAuthWindow", openAuthWindow);
|
||||
|
||||
@@ -30,7 +30,6 @@ import "./library/remove-game-from-library";
|
||||
import "./library/select-game-wine-prefix";
|
||||
import "./library/reset-game-achievements";
|
||||
import "./misc/open-checkout";
|
||||
import "./misc/open-manage-account";
|
||||
import "./misc/open-external";
|
||||
import "./misc/show-open-dialog";
|
||||
import "./misc/get-features";
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
import { shell } from "electron";
|
||||
import { registerEvent } from "../register-event";
|
||||
import { HydraApi, logger } from "@main/services";
|
||||
import { ManageAccountPage } from "@types";
|
||||
|
||||
const openManageAccount = async (
|
||||
_event: Electron.IpcMainInvokeEvent,
|
||||
page: ManageAccountPage
|
||||
) => {
|
||||
try {
|
||||
const { accessToken } = await HydraApi.refreshToken();
|
||||
|
||||
const params = new URLSearchParams({
|
||||
token: accessToken,
|
||||
});
|
||||
|
||||
shell.openExternal(
|
||||
`${import.meta.env.MAIN_VITE_AUTH_URL}/${page}?${params.toString()}`
|
||||
);
|
||||
} catch (err) {
|
||||
logger.error("Failed to open manage account", err);
|
||||
}
|
||||
};
|
||||
|
||||
registerEvent("openManageAccount", openManageAccount);
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
shell,
|
||||
} from "electron";
|
||||
import { is } from "@electron-toolkit/utils";
|
||||
import i18next, { t } from "i18next";
|
||||
import { t } from "i18next";
|
||||
import path from "node:path";
|
||||
import icon from "@resources/icon.png?asset";
|
||||
import trayIcon from "@resources/tray-icon.png?asset";
|
||||
@@ -17,6 +17,7 @@ import { gameRepository, userPreferencesRepository } from "@main/repository";
|
||||
import { IsNull, Not } from "typeorm";
|
||||
import { HydraApi } from "./hydra-api";
|
||||
import UserAgent from "user-agents";
|
||||
import { AuthPage } from "@shared";
|
||||
|
||||
export class WindowManager {
|
||||
public static mainWindow: Electron.BrowserWindow | null = null;
|
||||
@@ -142,7 +143,7 @@ export class WindowManager {
|
||||
});
|
||||
}
|
||||
|
||||
public static openAuthWindow() {
|
||||
public static openAuthWindow(page: AuthPage, searchParams: URLSearchParams) {
|
||||
if (this.mainWindow) {
|
||||
const authWindow = new BrowserWindow({
|
||||
width: 600,
|
||||
@@ -164,12 +165,8 @@ export class WindowManager {
|
||||
|
||||
if (!app.isPackaged) authWindow.webContents.openDevTools();
|
||||
|
||||
const searchParams = new URLSearchParams({
|
||||
lng: i18next.language,
|
||||
});
|
||||
|
||||
authWindow.loadURL(
|
||||
`${import.meta.env.MAIN_VITE_AUTH_URL}/?${searchParams.toString()}`
|
||||
`${import.meta.env.MAIN_VITE_AUTH_URL}/${page}?${searchParams.toString()}`
|
||||
);
|
||||
|
||||
authWindow.once("ready-to-show", () => {
|
||||
|
||||
Reference in New Issue
Block a user