diff --git a/src/main/events/torrenting/start-game-download.ts b/src/main/events/torrenting/start-game-download.ts index 17099450..ce16e97b 100644 --- a/src/main/events/torrenting/start-game-download.ts +++ b/src/main/events/torrenting/start-game-download.ts @@ -1,5 +1,4 @@ import { registerEvent } from "../register-event"; -import parseTorrent from "parse-torrent"; import type { StartGameDownloadPayload } from "@types"; import { DownloadManager, HydraApi, logger } from "@main/services"; @@ -9,7 +8,6 @@ import { createGame } from "@main/services/library-sync"; import { steamUrlBuilder } from "@shared"; import { dataSource } from "@main/data-source"; import { DownloadQueue, Game } from "@main/entity"; -import { HydraAnalytics } from "@main/services/hydra-analytics"; const startGameDownload = async ( _event: Electron.IpcMainInvokeEvent, @@ -91,17 +89,6 @@ const startGameDownload = async ( logger.error("Failed to create game download", err); }); - if (uri.startsWith("magnet:")) { - try { - const { infoHash } = await parseTorrent(payload.uri); - if (infoHash) { - HydraAnalytics.postDownload(infoHash).catch(() => {}); - } - } catch (err) { - logger.error("Failed to parse torrent", err); - } - } - await DownloadManager.cancelDownload(updatedGame!.id); await DownloadManager.startDownload(updatedGame!); diff --git a/src/main/services/hydra-analytics.ts b/src/main/services/hydra-analytics.ts deleted file mode 100644 index f4a6b24c..00000000 --- a/src/main/services/hydra-analytics.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { userSubscriptionRepository } from "@main/repository"; -import axios from "axios"; -import { appVersion } from "@main/constants"; - -export class HydraAnalytics { - private static instance = axios.create({ - baseURL: import.meta.env.MAIN_VITE_ANALYTICS_API_URL, - headers: { "User-Agent": `Hydra Launcher v${appVersion}` }, - }); - - private static async hasActiveSubscription() { - const userSubscription = await userSubscriptionRepository.findOne({ - where: { id: 1 }, - }); - - return ( - userSubscription?.expiresAt && userSubscription.expiresAt > new Date() - ); - } - - static async postDownload(hash: string) { - const hasSubscription = await this.hasActiveSubscription(); - - return this.instance - .post("/track", { - event: "download", - attributes: { - hash, - hasSubscription, - }, - }) - .then((response) => response.data); - } -} diff --git a/src/main/services/hydra-api.ts b/src/main/services/hydra-api.ts index b2125ac4..f642f43b 100644 --- a/src/main/services/hydra-api.ts +++ b/src/main/services/hydra-api.ts @@ -12,6 +12,7 @@ import { UserNotLoggedInError, SubscriptionRequiredError } from "@shared"; import { omit } from "lodash-es"; import { appVersion } from "@main/constants"; import { getUserData } from "./user/get-user-data"; +import { isFuture, isToday } from "date-fns"; interface HydraApiOptions { needsAuth?: boolean; @@ -45,10 +46,8 @@ export class HydraApi { } private static hasActiveSubscription() { - return ( - this.userAuth.subscription?.expiresAt && - this.userAuth.subscription.expiresAt > new Date() - ); + const expiresAt = this.userAuth.subscription?.expiresAt; + return expiresAt && (isFuture(expiresAt) || isToday(expiresAt)); } static async handleExternalAuth(uri: string) { diff --git a/src/renderer/src/hooks/use-user-details.ts b/src/renderer/src/hooks/use-user-details.ts index ab4408cc..feca478c 100644 --- a/src/renderer/src/hooks/use-user-details.ts +++ b/src/renderer/src/hooks/use-user-details.ts @@ -14,6 +14,7 @@ import type { UserDetails, } from "@types"; import { UserFriendModalTab } from "@renderer/pages/shared-modals/user-friend-modal"; +import { isFuture, isToday } from "date-fns"; export function useUserDetails() { const dispatch = useAppDispatch(); @@ -128,10 +129,8 @@ export function useUserDetails() { const unblockUser = (userId: string) => window.electron.unblockUser(userId); const hasActiveSubscription = useMemo(() => { - return ( - userDetails?.subscription?.expiresAt && - new Date(userDetails.subscription.expiresAt) > new Date() - ); + const expiresAt = userDetails?.subscription?.expiresAt; + return expiresAt && (isFuture(expiresAt) || isToday(expiresAt)); }, [userDetails]); return { diff --git a/src/renderer/src/pages/game-details/cloud-sync-files-modal/cloud-sync-files-modal.tsx b/src/renderer/src/pages/game-details/cloud-sync-files-modal/cloud-sync-files-modal.tsx index c70f69b7..6fd277e7 100644 --- a/src/renderer/src/pages/game-details/cloud-sync-files-modal/cloud-sync-files-modal.tsx +++ b/src/renderer/src/pages/game-details/cloud-sync-files-modal/cloud-sync-files-modal.tsx @@ -75,7 +75,7 @@ export function CloudSyncFilesModal({ showSuccessToast(t("custom_backup_location_set")); getGameBackupPreview(); } - }, [objectId, setValue, shop, showSuccessToast, getGameBackupPreview]); + }, [objectId, setValue, shop, showSuccessToast, getGameBackupPreview, t]); const handleFileMappingMethodClick = useCallback( (mappingOption: FileMappingMethod) => {