diff --git a/.github/workflows/build-renderer.yml b/.github/workflows/build-renderer.yml index f4a16498..6aefac43 100644 --- a/.github/workflows/build-renderer.yml +++ b/.github/workflows/build-renderer.yml @@ -4,7 +4,9 @@ concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true -on: push +on: + push: + branches: main jobs: build: @@ -28,11 +30,11 @@ jobs: RENDERER_VITE_EXTERNAL_RESOURCES_URL: ${{ vars.EXTERNAL_RESOURCES_URL }} - name: Deploy to Cloudflare Pages - run: | - npx --yes wrangler@3 pages deploy out/renderer \ - --project-name=hydra-staging \ - --commit-dirty=true \ - --branch=main env: CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + run: | + npx --yes wrangler@3 pages deploy out/renderer \ + --project-name="hydra" \ + --commit-dirty=true \ + --branch="main" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index babfb565..804b03ab 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -57,6 +57,7 @@ jobs: RENDERER_VITE_SENTRY_DSN: ${{ vars.SENTRY_DSN }} RENDERER_VITE_REAL_DEBRID_REFERRAL_ID: ${{ vars.RENDERER_VITE_REAL_DEBRID_REFERRAL_ID }} RENDERER_VITE_TORBOX_REFERRAL_CODE: ${{ vars.RENDERER_VITE_TORBOX_REFERRAL_CODE }} + MAIN_VITE_RENDERER_URL: ${{ vars.MAIN_VITE_RENDERER_URL }} - name: Build Windows if: matrix.os == 'windows-2022' @@ -73,6 +74,7 @@ jobs: RENDERER_VITE_SENTRY_DSN: ${{ vars.SENTRY_DSN }} RENDERER_VITE_REAL_DEBRID_REFERRAL_ID: ${{ vars.RENDERER_VITE_REAL_DEBRID_REFERRAL_ID }} RENDERER_VITE_TORBOX_REFERRAL_CODE: ${{ vars.RENDERER_VITE_TORBOX_REFERRAL_CODE }} + MAIN_VITE_RENDERER_URL: ${{ vars.MAIN_VITE_RENDERER_URL }} - name: Create artifact uses: actions/upload-artifact@v4 diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 4ed800b3..00000000 --- a/Dockerfile +++ /dev/null @@ -1,23 +0,0 @@ -FROM node:22-alpine AS builder - -# Install git (required for git dependencies) -RUN apk add --no-cache git - -WORKDIR /app - -COPY package.json yarn.lock ./ - -# Install dependencies but skip postinstall scripts (electron-builder deps not needed for web build) -RUN yarn install --frozen-lockfile --ignore-scripts - -COPY . . - -RUN yarn electron-vite build - -FROM nginx:alpine - -COPY --from=builder /app/out/renderer /usr/share/nginx/html - -EXPOSE 80 - -CMD ["nginx", "-g", "daemon off;"] diff --git a/src/main/services/window-manager.ts b/src/main/services/window-manager.ts index 70ff130e..c9ea16db 100644 --- a/src/main/services/window-manager.ts +++ b/src/main/services/window-manager.ts @@ -54,20 +54,37 @@ export class WindowManager { show: false, }; - private static loadMainWindowURL(hash = "") { + private static async loadWindowURL(window: BrowserWindow, hash: string = "") { // HMR for renderer base on electron-vite cli. // Load the remote URL for development or the local html file for production. if (is.dev && process.env["ELECTRON_RENDERER_URL"]) { - this.mainWindow?.loadURL( - `${process.env["ELECTRON_RENDERER_URL"]}#/${hash}` - ); - } else { - this.mainWindow?.loadFile( - path.join(__dirname, "../renderer/index.html"), - { + window.loadURL(`${process.env["ELECTRON_RENDERER_URL"]}#/${hash}`); + } else if (process.env["MAIN_VITE_RENDERER_URL"]) { + // Try to load from remote URL in production + try { + await window.loadURL( + `${import.meta.env.MAIN_VITE_RENDERER_URL}#/${hash}` + ); + } catch (error) { + // Fall back to local file if remote URL fails + console.error( + "Failed to load from MAIN_VITE_RENDERER_URL, falling back to local file:", + error + ); + window.loadFile(path.join(__dirname, "../renderer/index.html"), { hash, - } - ); + }); + } + } else { + window.loadFile(path.join(__dirname, "../renderer/index.html"), { + hash, + }); + } + } + + private static async loadMainWindowURL(hash: string = "") { + if (this.mainWindow) { + await this.loadWindowURL(this.mainWindow, hash); } } @@ -268,17 +285,8 @@ export class WindowManager { } private static loadNotificationWindowURL() { - if (is.dev && process.env["ELECTRON_RENDERER_URL"]) { - this.notificationWindow?.loadURL( - `${process.env["ELECTRON_RENDERER_URL"]}#/achievement-notification` - ); - } else { - this.notificationWindow?.loadFile( - path.join(__dirname, "../renderer/index.html"), - { - hash: "achievement-notification", - } - ); + if (this.notificationWindow) { + this.loadWindowURL(this.notificationWindow, "achievement-notification"); } } @@ -450,19 +458,10 @@ export class WindowManager { editorWindow.removeMenu(); - if (is.dev && process.env["ELECTRON_RENDERER_URL"]) { - editorWindow.loadURL( - `${process.env["ELECTRON_RENDERER_URL"]}#/theme-editor?themeId=${themeId}` - ); - } else { - editorWindow.loadFile(path.join(__dirname, "../renderer/index.html"), { - hash: `theme-editor?themeId=${themeId}`, - }); - } + this.loadWindowURL(editorWindow, `theme-editor?themeId=${themeId}`); editorWindow.once("ready-to-show", () => { editorWindow.show(); - this.mainWindow?.webContents.openDevTools(); if (!app.isPackaged || isStaging) { editorWindow.webContents.openDevTools(); } @@ -470,12 +469,11 @@ export class WindowManager { editorWindow.webContents.on("before-input-event", (_event, input) => { if (input.key === "F12") { - this.mainWindow?.webContents.toggleDevTools(); + editorWindow.webContents.toggleDevTools(); } }); editorWindow.on("close", () => { - this.mainWindow?.webContents.closeDevTools(); this.editorWindows.delete(themeId); }); } diff --git a/src/main/vite-env.d.ts b/src/main/vite-env.d.ts index 69ba99fb..c9b006d5 100644 --- a/src/main/vite-env.d.ts +++ b/src/main/vite-env.d.ts @@ -7,6 +7,8 @@ interface ImportMetaEnv { readonly MAIN_VITE_CHECKOUT_URL: string; readonly MAIN_VITE_EXTERNAL_RESOURCES_URL: string; readonly MAIN_VITE_WS_URL: string; + readonly MAIN_VITE_RENDERER_URL: string; + readonly ELECTRON_RENDERER_URL: string; } interface ImportMeta {