mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-22 18:33:56 +00:00
feat: adding auth window
This commit is contained in:
@@ -23,8 +23,8 @@ export class HydraApi {
|
||||
return this.userAuth.authToken !== "";
|
||||
}
|
||||
|
||||
static async handleExternalAuth(auth: string) {
|
||||
const { payload } = url.parse(auth, true).query;
|
||||
static async handleExternalAuth(uri: string) {
|
||||
const { payload } = url.parse(uri, true).query;
|
||||
|
||||
const decodedBase64 = atob(payload as string);
|
||||
const jsonData = JSON.parse(decodedBase64);
|
||||
|
||||
@@ -15,6 +15,7 @@ import icon from "@resources/icon.png?asset";
|
||||
import trayIcon from "@resources/tray-icon.png?asset";
|
||||
import { gameRepository, userPreferencesRepository } from "@main/repository";
|
||||
import { IsNull, Not } from "typeorm";
|
||||
import { HydraApi } from "./hydra-api";
|
||||
|
||||
export class WindowManager {
|
||||
public static mainWindow: Electron.BrowserWindow | null = null;
|
||||
@@ -80,6 +81,41 @@ export class WindowManager {
|
||||
});
|
||||
}
|
||||
|
||||
public static openAuthWindow() {
|
||||
if (this.mainWindow) {
|
||||
const authWindow = new BrowserWindow({
|
||||
width: 600,
|
||||
height: 640,
|
||||
backgroundColor: "#1c1c1c",
|
||||
parent: this.mainWindow,
|
||||
modal: true,
|
||||
show: false,
|
||||
maximizable: false,
|
||||
resizable: false,
|
||||
minimizable: false,
|
||||
webPreferences: {
|
||||
sandbox: false,
|
||||
},
|
||||
});
|
||||
|
||||
authWindow.removeMenu();
|
||||
|
||||
authWindow.loadURL("http://localhost:3000");
|
||||
|
||||
authWindow.once("ready-to-show", () => {
|
||||
authWindow.show();
|
||||
});
|
||||
|
||||
authWindow.webContents.on("will-navigate", (_event, url) => {
|
||||
if (url.startsWith("hydralauncher://auth")) {
|
||||
authWindow.close();
|
||||
|
||||
HydraApi.handleExternalAuth(url);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static redirect(hash: string) {
|
||||
if (!this.mainWindow) this.createMainWindow();
|
||||
this.loadURL(hash);
|
||||
|
||||
Reference in New Issue
Block a user