mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-01-23 13:34:54 +03:00
Merge branch 'rc/v2.0' into feature/refator-process-watcher-and-game-running
# Conflicts: # src/locales/en/translation.json # src/locales/pt/translation.json # src/renderer/src/app.tsx # src/renderer/src/pages/user/user-content.tsx
This commit is contained in:
commit
7b453852b6
@ -1,4 +1,7 @@
|
|||||||
{
|
{
|
||||||
|
"app": {
|
||||||
|
"successfully_signed_in": "Successfully signed in"
|
||||||
|
},
|
||||||
"home": {
|
"home": {
|
||||||
"featured": "Featured",
|
"featured": "Featured",
|
||||||
"trending": "Trending",
|
"trending": "Trending",
|
||||||
@ -243,6 +246,7 @@
|
|||||||
"try_again": "Please, try again",
|
"try_again": "Please, try again",
|
||||||
"sign_out_modal_title": "Are you sure?",
|
"sign_out_modal_title": "Are you sure?",
|
||||||
"cancel": "Cancel",
|
"cancel": "Cancel",
|
||||||
|
"successfully_signed_out": "Successfully signed out",
|
||||||
"sign_out": "Sign out",
|
"sign_out": "Sign out",
|
||||||
"playing_for": "Playing for {{amount}}"
|
"playing_for": "Playing for {{amount}}"
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
{
|
{
|
||||||
|
"app": {
|
||||||
|
"successfully_signed_in": "Logado com sucesso"
|
||||||
|
},
|
||||||
"home": {
|
"home": {
|
||||||
"featured": "Destaque",
|
"featured": "Destaque",
|
||||||
"trending": "Populares",
|
"trending": "Populares",
|
||||||
@ -242,6 +245,7 @@
|
|||||||
"saved_successfully": "Salvo com sucesso",
|
"saved_successfully": "Salvo com sucesso",
|
||||||
"try_again": "Por favor, tente novamente",
|
"try_again": "Por favor, tente novamente",
|
||||||
"cancel": "Cancelar",
|
"cancel": "Cancelar",
|
||||||
|
"successfully_signed_out": "Deslogado com sucesso",
|
||||||
"sign_out": "Sair da conta",
|
"sign_out": "Sair da conta",
|
||||||
"sign_out_modal_title": "Tem certeza?",
|
"sign_out_modal_title": "Tem certeza?",
|
||||||
"playing_for": "Jogando por {{amount}}"
|
"playing_for": "Jogando por {{amount}}"
|
||||||
|
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;
|
||||||
|
|
||||||
@ -74,7 +73,7 @@ app.on("browser-window-created", (_, window) => {
|
|||||||
optimizer.watchWindowShortcuts(window);
|
optimizer.watchWindowShortcuts(window);
|
||||||
});
|
});
|
||||||
|
|
||||||
app.on("second-instance", (_event, commandLine) => {
|
app.on("second-instance", (_event) => {
|
||||||
// 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())
|
||||||
@ -85,20 +84,16 @@ app.on("second-instance", (_event, commandLine) => {
|
|||||||
WindowManager.createMainWindow();
|
WindowManager.createMainWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
app.on("open-url", (_event, url) => {
|
// app.on("open-url", (_event, url) => {
|
||||||
const [, path] = url.split("://");
|
// const [, path] = url.split("://");
|
||||||
WindowManager.redirect(path);
|
// WindowManager.redirect(path);
|
||||||
});
|
// });
|
||||||
|
|
||||||
// Quit when all windows are closed, except on macOS. There, it's common
|
// Quit when all windows are closed, except on macOS. There, it's common
|
||||||
// for applications and their menu bar to stay active until the user quits
|
// for applications and their menu bar to stay active until the user quits
|
||||||
|
@ -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("https://auth.hydra.losbroxas.org/");
|
||||||
|
|
||||||
|
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);
|
||||||
|
@ -142,6 +142,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);
|
||||||
|
@ -111,6 +111,6 @@ export const titleBar = style({
|
|||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
padding: `0 ${SPACING_UNIT * 2}px`,
|
padding: `0 ${SPACING_UNIT * 2}px`,
|
||||||
WebkitAppRegion: "drag",
|
WebkitAppRegion: "drag",
|
||||||
zIndex: "2",
|
zIndex: "4",
|
||||||
borderBottom: `1px solid ${vars.color.border}`,
|
borderBottom: `1px solid ${vars.color.border}`,
|
||||||
} as ComplexStyleRule);
|
} as ComplexStyleRule);
|
||||||
|
@ -7,6 +7,7 @@ import {
|
|||||||
useAppSelector,
|
useAppSelector,
|
||||||
useDownload,
|
useDownload,
|
||||||
useLibrary,
|
useLibrary,
|
||||||
|
useToast,
|
||||||
useUserDetails,
|
useUserDetails,
|
||||||
} from "@renderer/hooks";
|
} from "@renderer/hooks";
|
||||||
|
|
||||||
@ -23,6 +24,7 @@ import {
|
|||||||
setProfileBackground,
|
setProfileBackground,
|
||||||
setGameRunning,
|
setGameRunning,
|
||||||
} from "@renderer/features";
|
} from "@renderer/features";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
export interface AppProps {
|
export interface AppProps {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
@ -32,6 +34,8 @@ export function App() {
|
|||||||
const contentRef = useRef<HTMLDivElement>(null);
|
const contentRef = useRef<HTMLDivElement>(null);
|
||||||
const { updateLibrary, library } = useLibrary();
|
const { updateLibrary, library } = useLibrary();
|
||||||
|
|
||||||
|
const { t } = useTranslation("app");
|
||||||
|
|
||||||
const { clearDownload, setLastPacket } = useDownload();
|
const { clearDownload, setLastPacket } = useDownload();
|
||||||
|
|
||||||
const { fetchUserDetails, updateUserDetails, clearUserDetails } =
|
const { fetchUserDetails, updateUserDetails, clearUserDetails } =
|
||||||
@ -50,6 +54,8 @@ export function App() {
|
|||||||
|
|
||||||
const toast = useAppSelector((state) => state.toast);
|
const toast = useAppSelector((state) => state.toast);
|
||||||
|
|
||||||
|
const { showSuccessToast } = useToast();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
Promise.all([window.electron.getUserPreferences(), updateLibrary()]).then(
|
Promise.all([window.electron.getUserPreferences(), updateLibrary()]).then(
|
||||||
([preferences]) => {
|
([preferences]) => {
|
||||||
@ -96,6 +102,15 @@ export function App() {
|
|||||||
});
|
});
|
||||||
}, [dispatch, fetchUserDetails]);
|
}, [dispatch, fetchUserDetails]);
|
||||||
|
|
||||||
|
const onSignIn = useCallback(() => {
|
||||||
|
fetchUserDetails().then((response) => {
|
||||||
|
if (response) {
|
||||||
|
updateUserDetails(response);
|
||||||
|
showSuccessToast(t("successfully_signed_in"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, [fetchUserDetails, t, showSuccessToast, updateUserDetails]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const unsubscribe = window.electron.onGamesRunning((gamesRunning) => {
|
const unsubscribe = window.electron.onGamesRunning((gamesRunning) => {
|
||||||
if (gamesRunning.length) {
|
if (gamesRunning.length) {
|
||||||
@ -124,23 +139,17 @@ export function App() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const listeners = [
|
const listeners = [
|
||||||
window.electron.onSignIn(() => {
|
window.electron.onSignIn(onSignIn),
|
||||||
fetchUserDetails().then((response) => {
|
|
||||||
if (response) updateUserDetails(response);
|
|
||||||
});
|
|
||||||
}),
|
|
||||||
window.electron.onLibraryBatchComplete(() => {
|
window.electron.onLibraryBatchComplete(() => {
|
||||||
updateLibrary();
|
updateLibrary();
|
||||||
}),
|
}),
|
||||||
window.electron.onSignOut(() => {
|
window.electron.onSignOut(() => clearUserDetails()),
|
||||||
clearUserDetails();
|
|
||||||
}),
|
|
||||||
];
|
];
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
listeners.forEach((unsubscribe) => unsubscribe());
|
listeners.forEach((unsubscribe) => unsubscribe());
|
||||||
};
|
};
|
||||||
}, [fetchUserDetails, updateUserDetails, clearUserDetails, updateLibrary]);
|
}, [onSignIn, updateLibrary, clearUserDetails]);
|
||||||
|
|
||||||
const handleSearch = useCallback(
|
const handleSearch = useCallback(
|
||||||
(query: string) => {
|
(query: string) => {
|
||||||
@ -194,6 +203,13 @@ export function App() {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
<Toast
|
||||||
|
visible={toast.visible}
|
||||||
|
message={toast.message}
|
||||||
|
type={toast.type}
|
||||||
|
onClose={handleToastClose}
|
||||||
|
/>
|
||||||
|
|
||||||
<main>
|
<main>
|
||||||
<Sidebar />
|
<Sidebar />
|
||||||
|
|
||||||
@ -211,13 +227,6 @@ export function App() {
|
|||||||
</main>
|
</main>
|
||||||
|
|
||||||
<BottomPanel />
|
<BottomPanel />
|
||||||
|
|
||||||
<Toast
|
|
||||||
visible={toast.visible}
|
|
||||||
message={toast.message}
|
|
||||||
type={toast.type}
|
|
||||||
onClose={handleToastClose}
|
|
||||||
/>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { keyframes } from "@vanilla-extract/css";
|
import { keyframes } from "@vanilla-extract/css";
|
||||||
import { recipe } from "@vanilla-extract/recipes";
|
import { recipe } from "@vanilla-extract/recipes";
|
||||||
|
|
||||||
import { SPACING_UNIT } from "../../theme.css";
|
import { SPACING_UNIT, vars } from "../../theme.css";
|
||||||
|
|
||||||
export const backdropFadeIn = keyframes({
|
export const backdropFadeIn = keyframes({
|
||||||
"0%": { backdropFilter: "blur(0px)", backgroundColor: "rgba(0, 0, 0, 0.5)" },
|
"0%": { backdropFilter: "blur(0px)", backgroundColor: "rgba(0, 0, 0, 0.5)" },
|
||||||
@ -30,8 +30,8 @@ export const backdrop = recipe({
|
|||||||
display: "flex",
|
display: "flex",
|
||||||
justifyContent: "center",
|
justifyContent: "center",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
zIndex: 1,
|
zIndex: vars.zIndex.backdrop,
|
||||||
top: 0,
|
top: "0",
|
||||||
padding: `${SPACING_UNIT * 3}px`,
|
padding: `${SPACING_UNIT * 3}px`,
|
||||||
backdropFilter: "blur(2px)",
|
backdropFilter: "blur(2px)",
|
||||||
transition: "all ease 0.2s",
|
transition: "all ease 0.2s",
|
||||||
|
@ -12,7 +12,7 @@ export const bottomPanel = style({
|
|||||||
transition: "all ease 0.2s",
|
transition: "all ease 0.2s",
|
||||||
justifyContent: "space-between",
|
justifyContent: "space-between",
|
||||||
position: "relative",
|
position: "relative",
|
||||||
zIndex: "1",
|
zIndex: vars.zIndex.bottomPanel,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const downloadsButton = style({
|
export const downloadsButton = style({
|
||||||
|
@ -17,7 +17,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ export const toast = recipe({
|
|||||||
display: "flex",
|
display: "flex",
|
||||||
flexDirection: "column",
|
flexDirection: "column",
|
||||||
justifyContent: "space-between",
|
justifyContent: "space-between",
|
||||||
zIndex: "0",
|
zIndex: vars.zIndex.toast,
|
||||||
maxWidth: "500px",
|
maxWidth: "500px",
|
||||||
},
|
},
|
||||||
variants: {
|
variants: {
|
||||||
|
1
src/renderer/src/declaration.d.ts
vendored
1
src/renderer/src/declaration.d.ts
vendored
@ -118,6 +118,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;
|
||||||
|
|
||||||
|
@ -6,7 +6,12 @@ import { SPACING_UNIT, vars } from "@renderer/theme.css";
|
|||||||
import { useMemo, useState } from "react";
|
import { useMemo, useState } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import SteamLogo from "@renderer/assets/steam-logo.svg?react";
|
import SteamLogo from "@renderer/assets/steam-logo.svg?react";
|
||||||
import { useAppSelector, useDate, useUserDetails } from "@renderer/hooks";
|
import {
|
||||||
|
useAppSelector,
|
||||||
|
useDate,
|
||||||
|
useToast,
|
||||||
|
useUserDetails,
|
||||||
|
} from "@renderer/hooks";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { buildGameDetailsPath, steamUrlBuilder } from "@renderer/helpers";
|
import { buildGameDetailsPath, steamUrlBuilder } from "@renderer/helpers";
|
||||||
import { PersonIcon, TelescopeIcon } from "@primer/octicons-react";
|
import { PersonIcon, TelescopeIcon } from "@primer/octicons-react";
|
||||||
@ -28,6 +33,7 @@ export function UserContent({
|
|||||||
const { t, i18n } = useTranslation("user_profile");
|
const { t, i18n } = useTranslation("user_profile");
|
||||||
|
|
||||||
const { userDetails, profileBackground, signOut } = useUserDetails();
|
const { userDetails, profileBackground, signOut } = useUserDetails();
|
||||||
|
const { showSuccessToast } = useToast();
|
||||||
|
|
||||||
const [showEditProfileModal, setShowEditProfileModal] = useState(false);
|
const [showEditProfileModal, setShowEditProfileModal] = useState(false);
|
||||||
const [showSignOutModal, setShowSignOutModal] = useState(false);
|
const [showSignOutModal, setShowSignOutModal] = useState(false);
|
||||||
@ -70,7 +76,10 @@ export function UserContent({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleConfirmSignout = async () => {
|
const handleConfirmSignout = async () => {
|
||||||
signOut();
|
await signOut();
|
||||||
|
|
||||||
|
showSuccessToast(t("successfully_signed_out"));
|
||||||
|
|
||||||
navigate("/");
|
navigate("/");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -21,4 +21,10 @@ export const vars = createGlobalTheme(":root", {
|
|||||||
body: "14px",
|
body: "14px",
|
||||||
small: "12px",
|
small: "12px",
|
||||||
},
|
},
|
||||||
|
zIndex: {
|
||||||
|
toast: "2",
|
||||||
|
bottomPanel: "3",
|
||||||
|
titleBar: "4",
|
||||||
|
backdrop: "4",
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user