From 7f600a0cbfc55e39c17e31404ce7244cbcc2542b Mon Sep 17 00:00:00 2001 From: Chubby Granny Chaser Date: Mon, 2 Dec 2024 17:10:13 +0000 Subject: [PATCH 1/4] feat: adding csp update --- .env.example | 1 - .github/workflows/build.yml | 10 ------- src/main/events/index.ts | 3 +- src/preload/index.ts | 3 +- src/renderer/index.html | 6 +++- src/renderer/src/app.tsx | 29 +++++++++++++------ src/renderer/src/components/modal/modal.tsx | 1 + .../src/components/sidebar/sidebar.tsx | 26 ++++------------- src/renderer/src/declaration.d.ts | 3 +- src/renderer/src/vite-env.d.ts | 8 ----- 10 files changed, 37 insertions(+), 53 deletions(-) diff --git a/.env.example b/.env.example index 991a06ff..b12e9517 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,3 @@ MAIN_VITE_API_URL=API_URL MAIN_VITE_AUTH_URL=AUTH_URL MAIN_VITE_STEAMGRIDDB_API_KEY=YOUR_API_KEY -RENDERER_VITE_INTERCOM_APP_ID=YOUR_APP_ID diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 89392011..0f650fc5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,16 +22,6 @@ jobs: with: node-version: 20.18.0 - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v2 - with: - aws-access-key-id: ${{ secrets.R2_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.R2_SECRET_ACCESS_KEY }} - aws-region: ${{ env.AWS_REGION }} - - - name: Push build to R2 - run: aws s3 sync ./docs s3://${{ vars.BUILDS_BUCKET_NAME }} - - name: Install dependencies run: yarn diff --git a/src/main/events/index.ts b/src/main/events/index.ts index eff62531..932b80e4 100644 --- a/src/main/events/index.ts +++ b/src/main/events/index.ts @@ -1,4 +1,4 @@ -import { appVersion, defaultDownloadsPath, isStaging } from "@main/constants"; +import { appVersion, defaultDownloadsPath } from "@main/constants"; import { ipcMain } from "electron"; import "./catalogue/get-catalogue"; @@ -72,6 +72,5 @@ import "./misc/show-item-in-folder"; ipcMain.handle("ping", () => "pong"); ipcMain.handle("getVersion", () => appVersion); -ipcMain.handle("isStaging", () => isStaging); ipcMain.handle("isPortableVersion", () => isPortableVersion()); ipcMain.handle("getDefaultDownloadsPath", () => defaultDownloadsPath); diff --git a/src/preload/index.ts b/src/preload/index.ts index 0166ba2a..17f4b3e9 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -15,6 +15,7 @@ import type { import type { CatalogueCategory } from "@shared"; import type { AxiosProgressEvent } from "axios"; import { GameAchievement } from "@main/entity"; +import { isStaging } from "@main/constants"; contextBridge.exposeInMainWorld("electron", { /* Torrenting */ @@ -198,7 +199,7 @@ contextBridge.exposeInMainWorld("electron", { ping: () => ipcRenderer.invoke("ping"), getVersion: () => ipcRenderer.invoke("getVersion"), getDefaultDownloadsPath: () => ipcRenderer.invoke("getDefaultDownloadsPath"), - isStaging: () => ipcRenderer.invoke("isStaging"), + isStaging, isPortableVersion: () => ipcRenderer.invoke("isPortableVersion"), openExternal: (src: string) => ipcRenderer.invoke("openExternal", src), openCheckout: () => ipcRenderer.invoke("openCheckout"), diff --git a/src/renderer/index.html b/src/renderer/index.html index bfc3a206..c3ce2e83 100644 --- a/src/renderer/index.html +++ b/src/renderer/index.html @@ -6,8 +6,12 @@ Hydra +
diff --git a/src/renderer/src/app.tsx b/src/renderer/src/app.tsx index 5a479879..e40d2d27 100644 --- a/src/renderer/src/app.tsx +++ b/src/renderer/src/app.tsx @@ -2,8 +2,6 @@ import { useCallback, useContext, useEffect, useRef } from "react"; import { Sidebar, BottomPanel, Header, Toast } from "@renderer/components"; -import Intercom from "@intercom/messenger-js-sdk"; - import { useAppDispatch, useAppSelector, @@ -36,10 +34,6 @@ export interface AppProps { children: React.ReactNode; } -Intercom({ - app_id: import.meta.env.RENDERER_VITE_INTERCOM_APP_ID, -}); - export function App() { const contentRef = useRef(null); const { updateLibrary, library } = useLibrary(); @@ -68,6 +62,25 @@ export function App() { clearUserDetails, } = useUserDetails(); + useEffect(() => { + if (userDetails) { + const $existingScript = document.getElementById("user-details"); + + const content = `window.userDetails = ${JSON.stringify(userDetails)};`; + + if ($existingScript) { + $existingScript.textContent = content; + } else { + const $script = document.createElement("script"); + $script.id = "user-details"; + $script.type = "text/javascript"; + $script.textContent = content; + + document.head.appendChild($script); + } + } + }, [userDetails]); + const dispatch = useAppDispatch(); const navigate = useNavigate(); @@ -215,9 +228,7 @@ export function App() { useEffect(() => { new MutationObserver(() => { - const modal = document.body.querySelector( - "[role=dialog]:not([data-intercom-frame='true'])" - ); + const modal = document.body.querySelector("[data-hydra-dialog]"); dispatch(toggleDraggingDisabled(Boolean(modal))); }).observe(document.body, { diff --git a/src/renderer/src/components/modal/modal.tsx b/src/renderer/src/components/modal/modal.tsx index eb2894de..af15feb5 100644 --- a/src/renderer/src/components/modal/modal.tsx +++ b/src/renderer/src/components/modal/modal.tsx @@ -107,6 +107,7 @@ export function Modal({ aria-labelledby={title} aria-describedby={description} ref={modalContentRef} + data-hydra-dialog >
diff --git a/src/renderer/src/components/sidebar/sidebar.tsx b/src/renderer/src/components/sidebar/sidebar.tsx index 787cf66a..f487681c 100644 --- a/src/renderer/src/components/sidebar/sidebar.tsx +++ b/src/renderer/src/components/sidebar/sidebar.tsx @@ -22,8 +22,6 @@ import { SidebarProfile } from "./sidebar-profile"; import { sortBy } from "lodash-es"; import { CommentDiscussionIcon } from "@primer/octicons-react"; -import { show, update } from "@intercom/messenger-js-sdk"; - const SIDEBAR_MIN_WIDTH = 200; const SIDEBAR_INITIAL_WIDTH = 250; const SIDEBAR_MAX_WIDTH = 450; @@ -50,23 +48,7 @@ export function Sidebar() { return sortBy(library, (game) => game.title); }, [library]); - const { userDetails, hasActiveSubscription } = useUserDetails(); - - useEffect(() => { - if (userDetails) { - window.electron.isStaging().then((isStaging) => { - update({ - user_id: userDetails.id + (isStaging ? "-staging" : ""), - name: userDetails.displayName, - Username: userDetails.username, - email: userDetails.email ?? undefined, - Email: userDetails.email, - "Subscription expiration date": userDetails?.subscription?.expiresAt, - "Payment status": userDetails?.subscription?.status, - }); - }); - } - }, [userDetails, hasActiveSubscription]); + const { hasActiveSubscription } = useUserDetails(); const { lastPacket, progress } = useDownload(); @@ -269,7 +251,11 @@ export function Sidebar() {
{hasActiveSubscription && ( -