From 21fecb2c4e00f0da7b6dc471754af2c7aa65b86c Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Mon, 21 Oct 2024 15:30:38 -0300 Subject: [PATCH] feat: open checkout page --- src/main/events/index.ts | 1 + src/main/events/misc/open-checkout.ts | 22 +++++++++++++++++++ .../achievements/merge-achievements.ts | 8 +------ src/preload/index.ts | 1 + src/renderer/src/declaration.d.ts | 1 + .../game-details/game-details-content.tsx | 7 +++++- 6 files changed, 32 insertions(+), 8 deletions(-) create mode 100644 src/main/events/misc/open-checkout.ts diff --git a/src/main/events/index.ts b/src/main/events/index.ts index 87fbdbe0..eea8e3ed 100644 --- a/src/main/events/index.ts +++ b/src/main/events/index.ts @@ -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"; diff --git a/src/main/events/misc/open-checkout.ts b/src/main/events/misc/open-checkout.ts new file mode 100644 index 00000000..e1e35674 --- /dev/null +++ b/src/main/events/misc/open-checkout.ts @@ -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); diff --git a/src/main/services/achievements/merge-achievements.ts b/src/main/services/achievements/merge-achievements.ts index 84302e73..b1ae0273 100644 --- a/src/main/services/achievements/merge-achievements.ts +++ b/src/main/services/achievements/merge-achievements.ts @@ -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); } diff --git a/src/preload/index.ts b/src/preload/index.ts index d75045ac..6090e636 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -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, diff --git a/src/renderer/src/declaration.d.ts b/src/renderer/src/declaration.d.ts index 68e22d67..24e541e7 100644 --- a/src/renderer/src/declaration.d.ts +++ b/src/renderer/src/declaration.d.ts @@ -162,6 +162,7 @@ declare global { /* Misc */ openExternal: (src: string) => Promise; + openCheckout: () => Promise; getVersion: () => Promise; ping: () => string; getDefaultDownloadsPath: () => Promise; diff --git a/src/renderer/src/pages/game-details/game-details-content.tsx b/src/renderer/src/pages/game-details/game-details-content.tsx index a112e9d1..442446b2 100644 --- a/src/renderer/src/pages/game-details/game-details-content.tsx +++ b/src/renderer/src/pages/game-details/game-details-content.tsx @@ -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); };