mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-03 00:33:49 +03:00
feat: add event and check if user is logged in
This commit is contained in:
parent
6b03705d54
commit
17cfc7bb02
@ -22,6 +22,7 @@ import "./library/open-game-installer-path";
|
|||||||
import "./library/update-executable-path";
|
import "./library/update-executable-path";
|
||||||
import "./library/remove-game";
|
import "./library/remove-game";
|
||||||
import "./library/remove-game-from-library";
|
import "./library/remove-game-from-library";
|
||||||
|
import "./misc/is-user-logged-in";
|
||||||
import "./misc/open-external";
|
import "./misc/open-external";
|
||||||
import "./misc/show-open-dialog";
|
import "./misc/show-open-dialog";
|
||||||
import "./torrenting/cancel-game-download";
|
import "./torrenting/cancel-game-download";
|
||||||
|
8
src/main/events/misc/is-user-logged-in.ts
Normal file
8
src/main/events/misc/is-user-logged-in.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import { registerEvent } from "../register-event";
|
||||||
|
import { HydraApi } from "@main/services/hydra-api";
|
||||||
|
|
||||||
|
const isUserLoggedIn = async (_event: Electron.IpcMainInvokeEvent) => {
|
||||||
|
return HydraApi.isLoggedIn();
|
||||||
|
};
|
||||||
|
|
||||||
|
registerEvent("isUserLoggedIn", isUserLoggedIn);
|
@ -14,6 +14,10 @@ export class HydraApi {
|
|||||||
expirationTimestamp: 0,
|
expirationTimestamp: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static isLoggedIn() {
|
||||||
|
return this.userAuth.authToken !== "";
|
||||||
|
}
|
||||||
|
|
||||||
static async handleExternalAuth(auth: string) {
|
static async handleExternalAuth(auth: string) {
|
||||||
const { payload } = url.parse(auth, true).query;
|
const { payload } = url.parse(auth, true).query;
|
||||||
|
|
||||||
|
@ -106,6 +106,7 @@ contextBridge.exposeInMainWorld("electron", {
|
|||||||
getVersion: () => ipcRenderer.invoke("getVersion"),
|
getVersion: () => ipcRenderer.invoke("getVersion"),
|
||||||
getDefaultDownloadsPath: () => ipcRenderer.invoke("getDefaultDownloadsPath"),
|
getDefaultDownloadsPath: () => ipcRenderer.invoke("getDefaultDownloadsPath"),
|
||||||
openExternal: (src: string) => ipcRenderer.invoke("openExternal", src),
|
openExternal: (src: string) => ipcRenderer.invoke("openExternal", src),
|
||||||
|
isUserLoggedIn: () => ipcRenderer.invoke("isUserLoggedIn"),
|
||||||
showOpenDialog: (options: Electron.OpenDialogOptions) =>
|
showOpenDialog: (options: Electron.OpenDialogOptions) =>
|
||||||
ipcRenderer.invoke("showOpenDialog", options),
|
ipcRenderer.invoke("showOpenDialog", options),
|
||||||
platform: process.platform,
|
platform: process.platform,
|
||||||
|
@ -86,10 +86,13 @@ export function App() {
|
|||||||
dispatch(setProfileBackground(profileBackground));
|
dispatch(setProfileBackground(profileBackground));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: Check if user is logged in before calling this */
|
window.electron.isUserLoggedIn().then((isLoggedIn) => {
|
||||||
|
if (isLoggedIn) {
|
||||||
fetchUserDetails().then((response) => {
|
fetchUserDetails().then((response) => {
|
||||||
if (response) setUserDetails(response);
|
if (response) setUserDetails(response);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
}, [dispatch, fetchUserDetails]);
|
}, [dispatch, fetchUserDetails]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
1
src/renderer/src/declaration.d.ts
vendored
1
src/renderer/src/declaration.d.ts
vendored
@ -96,6 +96,7 @@ declare global {
|
|||||||
|
|
||||||
/* Misc */
|
/* Misc */
|
||||||
openExternal: (src: string) => Promise<void>;
|
openExternal: (src: string) => Promise<void>;
|
||||||
|
isUserLoggedIn: () => Promise<boolean>;
|
||||||
getVersion: () => Promise<string>;
|
getVersion: () => Promise<string>;
|
||||||
ping: () => string;
|
ping: () => string;
|
||||||
getDefaultDownloadsPath: () => Promise<string>;
|
getDefaultDownloadsPath: () => Promise<string>;
|
||||||
|
Loading…
Reference in New Issue
Block a user