Skip to content

Add mock web build for Cloudflare Pages previews#21

Closed
0suu wants to merge 1 commit into
mainfrom
codex/add-cloudflare-pages-build-scripts-1fmpe7
Closed

Add mock web build for Cloudflare Pages previews#21
0suu wants to merge 1 commit into
mainfrom
codex/add-cloudflare-pages-build-scripts-1fmpe7

Conversation

@0suu

@0suu 0suu commented Dec 27, 2025

Copy link
Copy Markdown
Owner

Summary

  • add a dedicated web build script that outputs the renderer to dist for Cloudflare Pages with SPA routing fallback
  • introduce a mock-only runtime path so VITE_APP_MODE=mock uses local data and stub storage/bridges instead of SwitchBot API calls, now covering every device type once
  • document Pages preview settings and keep renderer startup wiring compatible with Electron and static hosting

Testing

  • npm run build:web

Codex Task

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Dec 27, 2025

Copy link
Copy Markdown

Deploying switchbotcontroller with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5b633ea
Status: ✅  Deploy successful!
Preview URL: https://ad09a12e.switchbotcontroller.pages.dev
Branch Preview URL: https://codex-add-cloudflare-pages-b-rtwv.switchbotcontroller.pages.dev

View logs

@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello @0suu, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the project's deployability and testability by introducing a dedicated web build for Cloudflare Pages. It establishes a robust mock mode that allows the application's renderer to function entirely with local, simulated data, effectively decoupling it from the SwitchBot API and Electron-specific functionalities. This enables developers to preview and test the application's UI and logic in a web browser environment without requiring actual API credentials or an Electron setup, streamlining the development and review process for the frontend.

Highlights

  • Cloudflare Pages Web Build: Introduced a dedicated web build script (npm run build:web) to deploy the renderer as a static site on Cloudflare Pages, complete with SPA routing fallback.
  • Comprehensive Mock Mode: Implemented a mock-only runtime (VITE_APP_MODE=mock) that simulates all SwitchBot API interactions using local dummy data, covering every device type, to enable testing without real API calls.
  • Mock Storage and Bridge: Created mock implementations for electronStore (using localStorage) and switchBotBridge to provide a consistent environment for the web build, mirroring the Electron app's IPC communication.
  • Conditional API Logic: Updated API client and Redux slices to conditionally bypass real API credential checks and use mock data when isMockMode is active, ensuring seamless operation in preview environments.
  • Documentation: Added clear instructions to the README.md for setting up Cloudflare Pages previews, including build commands and environment variables.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Dec 27, 2025

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
❌ Deployment failed
View logs
switchbotcintroller 5b633ea Dec 27 2025, 10:38 PM

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a mock web build for Cloudflare Pages previews, which is a great addition for testing and previews. The implementation is well-structured, introducing a bridge abstraction to switch between the real API and a mock implementation. The changes across the codebase, from the API client to Redux slices and build configuration, are consistent and correctly implement the mock mode. I've found a couple of minor issues in the mock bridge implementation that should be addressed to improve its correctness and type safety. Overall, this is a solid contribution.

Comment on lines +130 to +150
async sendCommand(deviceId: string, command: string, parameter?: any) {
const status = mockStatuses[deviceId];
if (status) {
if (command === "turnOn") {
status.power = "on";
status.moving = false;
} else if (command === "turnOff") {
status.power = "off";
status.moving = false;
} else if (command === "setPosition") {
const parsed = typeof parameter === "string" ? Number(String(parameter).split(",").pop()) : Number(parameter);
if (!Number.isNaN(parsed)) {
status.slidePosition = Math.max(0, Math.min(100, Math.round(parsed)));
}
status.moving = false;
} else if (command === "press") {
status.lastAction = "pressed";
}
}
return { success: true, data: successResponse({}) };
},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The sendCommand mock has a couple of issues:

  1. The function signature doesn't match the SwitchBotBridgeLike interface, as it's missing the commandType parameter.
  2. It incorrectly returns a success response even when the deviceId is not found. It should return a failure response in that case.

Here's a suggested fix that addresses both points.

  async sendCommand(deviceId: string, command: string, parameter?: any, commandType?: "command" | "customize") {
    const status = mockStatuses[deviceId];
    if (!status) {
      return { success: false, error: "Device not found" };
    }

    if (command === "turnOn") {
      status.power = "on";
      status.moving = false;
    } else if (command === "turnOff") {
      status.power = "off";
      status.moving = false;
    } else if (command === "setPosition") {
      const parsed = typeof parameter === "string" ? Number(String(parameter).split(",").pop()) : Number(parameter);
      if (!Number.isNaN(parsed)) {
        status.slidePosition = Math.max(0, Math.min(100, Math.round(parsed)));
      }
      status.moving = false;
    } else if (command === "press") {
      status.lastAction = "pressed";
    }
    return { success: true, data: successResponse({}) };
  },

if (typeof window === "undefined") return;
if (!window.switchBotBridge) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
window.switchBotBridge = mockSwitchBotBridge as any;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using as any for type assertion should be avoided as it bypasses TypeScript's type checking and hides potential type errors. The eslint-disable-next-line comment also indicates this is a known issue. With the proposed fix to mockSwitchBotBridge.sendCommand, the mock object's type will be compatible with the SwitchBotBridgeAPI interface, so as any is no longer necessary. Please remove it and the corresponding eslint-disable comment.

Suggested change
window.switchBotBridge = mockSwitchBotBridge as any;
window.switchBotBridge = mockSwitchBotBridge;

@0suu 0suu closed this Feb 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant