feat: open checkout page

This commit is contained in:
Zamitto 2024-10-21 15:30:38 -03:00
parent 6ef1135ba2
commit 21fecb2c4e
6 changed files with 32 additions and 8 deletions

View File

@ -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";

View 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);

View File

@ -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);
}

View File

@ -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,

View File

@ -162,6 +162,7 @@ declare global {
/* Misc */
openExternal: (src: string) => Promise<void>;
openCheckout: () => Promise<void>;
getVersion: () => Promise<string>;
ping: () => string;
getDefaultDownloadsPath: () => Promise<string>;

View File

@ -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);
};