mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-03 08:43:48 +03:00
feat: refactor deeplnik handler
This commit is contained in:
parent
1bf2c8faf9
commit
16c4460011
@ -1,6 +1,5 @@
|
|||||||
import { defaultDownloadsPath } from "@main/constants";
|
import { defaultDownloadsPath } from "@main/constants";
|
||||||
import { app, ipcMain } from "electron";
|
import { app, ipcMain } from "electron";
|
||||||
import { HydraApi } from "@main/services/hydra-api";
|
|
||||||
|
|
||||||
import "./catalogue/get-catalogue";
|
import "./catalogue/get-catalogue";
|
||||||
import "./catalogue/get-game-shop-details";
|
import "./catalogue/get-game-shop-details";
|
||||||
@ -46,5 +45,4 @@ import "./profile/get-me";
|
|||||||
|
|
||||||
ipcMain.handle("ping", () => "pong");
|
ipcMain.handle("ping", () => "pong");
|
||||||
ipcMain.handle("getVersion", () => app.getVersion());
|
ipcMain.handle("getVersion", () => app.getVersion());
|
||||||
ipcMain.handle("isUserLoggedIn", () => HydraApi.isLoggedIn());
|
|
||||||
ipcMain.handle("getDefaultDownloadsPath", () => defaultDownloadsPath);
|
ipcMain.handle("getDefaultDownloadsPath", () => defaultDownloadsPath);
|
||||||
|
@ -72,7 +72,7 @@ app.on("browser-window-created", (_, window) => {
|
|||||||
optimizer.watchWindowShortcuts(window);
|
optimizer.watchWindowShortcuts(window);
|
||||||
});
|
});
|
||||||
|
|
||||||
app.on("second-instance", async (_event, commandLine) => {
|
app.on("second-instance", (_event, commandLine) => {
|
||||||
// Someone tried to run a second instance, we should focus our window.
|
// Someone tried to run a second instance, we should focus our window.
|
||||||
if (WindowManager.mainWindow) {
|
if (WindowManager.mainWindow) {
|
||||||
if (WindowManager.mainWindow.isMinimized())
|
if (WindowManager.mainWindow.isMinimized())
|
||||||
@ -86,8 +86,7 @@ app.on("second-instance", async (_event, commandLine) => {
|
|||||||
const [, path] = commandLine.pop()?.split("://") ?? [];
|
const [, path] = commandLine.pop()?.split("://") ?? [];
|
||||||
if (path) {
|
if (path) {
|
||||||
if (path.startsWith("auth")) {
|
if (path.startsWith("auth")) {
|
||||||
//hydralauncher://auth?payload=responsedaapiembase64
|
HydraApi.handleExternalAuth(path);
|
||||||
await HydraApi.handleExternalAuth(path.split("=")[1]);
|
|
||||||
} else {
|
} else {
|
||||||
WindowManager.redirect(path);
|
WindowManager.redirect(path);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { userAuthRepository } from "@main/repository";
|
import { userAuthRepository } from "@main/repository";
|
||||||
import axios, { AxiosError, AxiosInstance } from "axios";
|
import axios, { AxiosError, AxiosInstance } from "axios";
|
||||||
import { WindowManager } from "./window-manager";
|
import { WindowManager } from "./window-manager";
|
||||||
|
import url from "url";
|
||||||
|
|
||||||
export class HydraApi {
|
export class HydraApi {
|
||||||
private static instance: AxiosInstance;
|
private static instance: AxiosInstance;
|
||||||
@ -18,7 +19,9 @@ export class HydraApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static async handleExternalAuth(auth: string) {
|
static async handleExternalAuth(auth: string) {
|
||||||
const decodedBase64 = atob(auth);
|
const { payload } = url.parse(auth, true).query;
|
||||||
|
|
||||||
|
const decodedBase64 = atob(payload as string);
|
||||||
const jsonData = JSON.parse(decodedBase64);
|
const jsonData = JSON.parse(decodedBase64);
|
||||||
|
|
||||||
const { accessToken, expiresIn, refreshToken } = jsonData;
|
const { accessToken, expiresIn, refreshToken } = jsonData;
|
||||||
|
@ -104,7 +104,6 @@ contextBridge.exposeInMainWorld("electron", {
|
|||||||
/* Misc */
|
/* Misc */
|
||||||
ping: () => ipcRenderer.invoke("ping"),
|
ping: () => ipcRenderer.invoke("ping"),
|
||||||
getVersion: () => ipcRenderer.invoke("getVersion"),
|
getVersion: () => ipcRenderer.invoke("getVersion"),
|
||||||
isUserLoggedIn: () => ipcRenderer.invoke("isUserLoggedIn"),
|
|
||||||
getDefaultDownloadsPath: () => ipcRenderer.invoke("getDefaultDownloadsPath"),
|
getDefaultDownloadsPath: () => ipcRenderer.invoke("getDefaultDownloadsPath"),
|
||||||
openExternal: (src: string) => ipcRenderer.invoke("openExternal", src),
|
openExternal: (src: string) => ipcRenderer.invoke("openExternal", src),
|
||||||
showOpenDialog: (options: Electron.OpenDialogOptions) =>
|
showOpenDialog: (options: Electron.OpenDialogOptions) =>
|
||||||
|
1
src/renderer/src/declaration.d.ts
vendored
1
src/renderer/src/declaration.d.ts
vendored
@ -97,7 +97,6 @@ declare global {
|
|||||||
/* Misc */
|
/* Misc */
|
||||||
openExternal: (src: string) => Promise<void>;
|
openExternal: (src: string) => Promise<void>;
|
||||||
getVersion: () => Promise<string>;
|
getVersion: () => Promise<string>;
|
||||||
isUserLoggedIn: () => Promise<boolean>;
|
|
||||||
ping: () => string;
|
ping: () => string;
|
||||||
getDefaultDownloadsPath: () => Promise<string>;
|
getDefaultDownloadsPath: () => Promise<string>;
|
||||||
showOpenDialog: (
|
showOpenDialog: (
|
||||||
|
Loading…
Reference in New Issue
Block a user