mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-03 00:33:49 +03:00
feat: adding auth window
This commit is contained in:
parent
884ba47b9b
commit
71d79a4a15
7
src/main/events/auth/open-auth-window.ts
Normal file
7
src/main/events/auth/open-auth-window.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import { registerEvent } from "../register-event";
|
||||||
|
import { WindowManager } from "@main/services";
|
||||||
|
|
||||||
|
const openAuthWindow = async (_event: Electron.IpcMainInvokeEvent) =>
|
||||||
|
WindowManager.openAuthWindow();
|
||||||
|
|
||||||
|
registerEvent("openAuthWindow", openAuthWindow);
|
@ -41,6 +41,7 @@ import "./download-sources/add-download-source";
|
|||||||
import "./download-sources/remove-download-source";
|
import "./download-sources/remove-download-source";
|
||||||
import "./download-sources/sync-download-sources";
|
import "./download-sources/sync-download-sources";
|
||||||
import "./auth/signout";
|
import "./auth/signout";
|
||||||
|
import "./auth/open-auth-window";
|
||||||
import "./user/get-user";
|
import "./user/get-user";
|
||||||
import "./profile/get-me";
|
import "./profile/get-me";
|
||||||
import "./profile/update-profile";
|
import "./profile/update-profile";
|
||||||
|
@ -8,7 +8,6 @@ import { DownloadManager, logger, WindowManager } from "@main/services";
|
|||||||
import { dataSource } from "@main/data-source";
|
import { dataSource } from "@main/data-source";
|
||||||
import * as resources from "@locales";
|
import * as resources from "@locales";
|
||||||
import { userPreferencesRepository } from "@main/repository";
|
import { userPreferencesRepository } from "@main/repository";
|
||||||
import { HydraApi } from "./services/hydra-api";
|
|
||||||
|
|
||||||
const { autoUpdater } = updater;
|
const { autoUpdater } = updater;
|
||||||
|
|
||||||
@ -87,11 +86,7 @@ app.on("second-instance", (_event, commandLine) => {
|
|||||||
|
|
||||||
const [, path] = commandLine.pop()?.split("://") ?? [];
|
const [, path] = commandLine.pop()?.split("://") ?? [];
|
||||||
if (path) {
|
if (path) {
|
||||||
if (path.startsWith("auth")) {
|
WindowManager.redirect(path);
|
||||||
HydraApi.handleExternalAuth(path);
|
|
||||||
} else {
|
|
||||||
WindowManager.redirect(path);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -23,8 +23,8 @@ export class HydraApi {
|
|||||||
return this.userAuth.authToken !== "";
|
return this.userAuth.authToken !== "";
|
||||||
}
|
}
|
||||||
|
|
||||||
static async handleExternalAuth(auth: string) {
|
static async handleExternalAuth(uri: string) {
|
||||||
const { payload } = url.parse(auth, true).query;
|
const { payload } = url.parse(uri, true).query;
|
||||||
|
|
||||||
const decodedBase64 = atob(payload as string);
|
const decodedBase64 = atob(payload as string);
|
||||||
const jsonData = JSON.parse(decodedBase64);
|
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 trayIcon from "@resources/tray-icon.png?asset";
|
||||||
import { gameRepository, userPreferencesRepository } from "@main/repository";
|
import { gameRepository, userPreferencesRepository } from "@main/repository";
|
||||||
import { IsNull, Not } from "typeorm";
|
import { IsNull, Not } from "typeorm";
|
||||||
|
import { HydraApi } from "./hydra-api";
|
||||||
|
|
||||||
export class WindowManager {
|
export class WindowManager {
|
||||||
public static mainWindow: Electron.BrowserWindow | null = null;
|
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) {
|
public static redirect(hash: string) {
|
||||||
if (!this.mainWindow) this.createMainWindow();
|
if (!this.mainWindow) this.createMainWindow();
|
||||||
this.loadURL(hash);
|
this.loadURL(hash);
|
||||||
|
@ -143,6 +143,7 @@ contextBridge.exposeInMainWorld("electron", {
|
|||||||
|
|
||||||
/* Auth */
|
/* Auth */
|
||||||
signOut: () => ipcRenderer.invoke("signOut"),
|
signOut: () => ipcRenderer.invoke("signOut"),
|
||||||
|
openAuthWindow: () => ipcRenderer.invoke("openAuthWindow"),
|
||||||
onSignIn: (cb: () => void) => {
|
onSignIn: (cb: () => void) => {
|
||||||
const listener = (_event: Electron.IpcRendererEvent) => cb();
|
const listener = (_event: Electron.IpcRendererEvent) => cb();
|
||||||
ipcRenderer.on("on-signin", listener);
|
ipcRenderer.on("on-signin", listener);
|
||||||
|
@ -113,7 +113,7 @@ export function App() {
|
|||||||
return () => {
|
return () => {
|
||||||
listeners.forEach((unsubscribe) => unsubscribe());
|
listeners.forEach((unsubscribe) => unsubscribe());
|
||||||
};
|
};
|
||||||
}, [fetchUserDetails, updateUserDetails, clearUserDetails]);
|
}, [fetchUserDetails, updateUserDetails, updateLibrary, clearUserDetails]);
|
||||||
|
|
||||||
const handleSearch = useCallback(
|
const handleSearch = useCallback(
|
||||||
(query: string) => {
|
(query: string) => {
|
||||||
|
@ -12,7 +12,7 @@ export function SidebarProfile() {
|
|||||||
|
|
||||||
const handleButtonClick = () => {
|
const handleButtonClick = () => {
|
||||||
if (userDetails === null) {
|
if (userDetails === null) {
|
||||||
window.electron.openExternal("https://auth.hydra.losbroxas.org");
|
window.electron.openAuthWindow();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1
src/renderer/src/declaration.d.ts
vendored
1
src/renderer/src/declaration.d.ts
vendored
@ -115,6 +115,7 @@ declare global {
|
|||||||
|
|
||||||
/* Auth */
|
/* Auth */
|
||||||
signOut: () => Promise<void>;
|
signOut: () => Promise<void>;
|
||||||
|
openAuthWindow: () => Promise<void>;
|
||||||
onSignIn: (cb: () => void) => () => Electron.IpcRenderer;
|
onSignIn: (cb: () => void) => () => Electron.IpcRenderer;
|
||||||
onSignOut: (cb: () => void) => () => Electron.IpcRenderer;
|
onSignOut: (cb: () => void) => () => Electron.IpcRenderer;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user