mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-01-23 21:44:55 +03:00
feat: open checkout page
This commit is contained in:
parent
6ef1135ba2
commit
21fecb2c4e
@ -25,6 +25,7 @@ import "./library/verify-executable-path";
|
||||
import "./library/remove-game";
|
||||
import "./library/remove-game-from-library";
|
||||
import "./library/select-game-wine-prefix";
|
||||
import "./misc/open-checkout";
|
||||
import "./misc/open-external";
|
||||
import "./misc/show-open-dialog";
|
||||
import "./torrenting/cancel-game-download";
|
||||
|
22
src/main/events/misc/open-checkout.ts
Normal file
22
src/main/events/misc/open-checkout.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { shell } from "electron";
|
||||
import { registerEvent } from "../register-event";
|
||||
import { userAuthRepository } from "@main/repository";
|
||||
import { HydraApi } from "@main/services";
|
||||
|
||||
const openCheckout = async (_event: Electron.IpcMainInvokeEvent) => {
|
||||
const userAuth = await userAuthRepository.findOne({ where: { id: 1 } });
|
||||
|
||||
if (!userAuth) {
|
||||
return;
|
||||
}
|
||||
|
||||
const paymentToken = await HydraApi.post("/auth/payment", {
|
||||
refreshToken: userAuth.refreshToken,
|
||||
}).then((response) => response.accessToken);
|
||||
|
||||
shell.openExternal(
|
||||
"https://checkout.hydralauncher.gg/?token=" + paymentToken
|
||||
);
|
||||
};
|
||||
|
||||
registerEvent("openCheckout", openCheckout);
|
@ -119,12 +119,6 @@ export const mergeAchievements = async (
|
||||
const mergedLocalAchievements = unlockedAchievements.concat(newAchievements);
|
||||
|
||||
if (game.remoteId) {
|
||||
achievementsLogger.log(
|
||||
"Syncing achievements with cloud",
|
||||
game.title,
|
||||
game.objectID,
|
||||
game.remoteId
|
||||
);
|
||||
await HydraApi.put(
|
||||
"/profile/games/achievements",
|
||||
{
|
||||
@ -142,7 +136,7 @@ export const mergeAchievements = async (
|
||||
);
|
||||
})
|
||||
.catch((err) => {
|
||||
if (err! instanceof SubscriptionRequiredError) {
|
||||
if (!(err instanceof SubscriptionRequiredError)) {
|
||||
achievementsLogger.error(err);
|
||||
}
|
||||
|
||||
|
@ -223,6 +223,7 @@ contextBridge.exposeInMainWorld("electron", {
|
||||
getDefaultDownloadsPath: () => ipcRenderer.invoke("getDefaultDownloadsPath"),
|
||||
isPortableVersion: () => ipcRenderer.invoke("isPortableVersion"),
|
||||
openExternal: (src: string) => ipcRenderer.invoke("openExternal", src),
|
||||
openCheckout: () => ipcRenderer.invoke("openCheckout"),
|
||||
showOpenDialog: (options: Electron.OpenDialogOptions) =>
|
||||
ipcRenderer.invoke("showOpenDialog", options),
|
||||
platform: process.platform,
|
||||
|
1
src/renderer/src/declaration.d.ts
vendored
1
src/renderer/src/declaration.d.ts
vendored
@ -162,6 +162,7 @@ declare global {
|
||||
|
||||
/* Misc */
|
||||
openExternal: (src: string) => Promise<void>;
|
||||
openCheckout: () => Promise<void>;
|
||||
getVersion: () => Promise<string>;
|
||||
ping: () => string;
|
||||
getDefaultDownloadsPath: () => Promise<string>;
|
||||
|
@ -34,7 +34,7 @@ export function GameDetailsContent() {
|
||||
hasNSFWContentBlocked,
|
||||
} = useContext(gameDetailsContext);
|
||||
|
||||
const { userDetails } = useUserDetails();
|
||||
const { userDetails, hasActiveSubscription } = useUserDetails();
|
||||
|
||||
const { setShowCloudSyncModal, getGameBackupPreview } =
|
||||
useContext(cloudSyncContext);
|
||||
@ -103,6 +103,11 @@ export function GameDetailsContent() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!hasActiveSubscription) {
|
||||
window.electron.openCheckout();
|
||||
return;
|
||||
}
|
||||
|
||||
setShowCloudSyncModal(true);
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user