Skip to content

Comments

Add a way to use stock electron#67

Merged
iamEvanYT merged 2 commits intomainfrom
evan/stock-electron
May 25, 2025
Merged

Add a way to use stock electron#67
iamEvanYT merged 2 commits intomainfrom
evan/stock-electron

Conversation

@iamEvanYT
Copy link
Member

@iamEvanYT iamEvanYT commented May 25, 2025

Summary by CodeRabbit

  • New Features
    • Added a script to update the Electron version in project files using a single command.
  • Refactor
    • Improved the way Electron components readiness is handled, providing clearer feedback if WidevineCDM is not ready.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 25, 2025

Walkthrough

A new script for updating the Electron version in project files was added, along with a corresponding npm script entry. The Electron component readiness logic was refactored, introducing a utility function to handle the Widevine-specific whenReady check, and updating the main browser logic to use this new function.

Changes

File(s) Change Summary
package.json Added use-stock-electron script; minor formatting update in scripts section.
scripts/use-stock-electron.ts New script to update Electron version in package.json and bun.lock.
src/main/browser/browser.ts Replaced direct Electron components import and readiness check with new utility function.
src/main/modules/electron-components.ts Added waitForElectronComponentsToBeReady function to handle Widevine Electron's components readiness logic.

Sequence Diagram(s)

sequenceDiagram
    participant Browser as browser.ts
    participant ComponentsUtil as electron-components.ts
    participant Electron as electron (dynamic import)

    Browser->>ComponentsUtil: waitForElectronComponentsToBeReady()
    ComponentsUtil->>Electron: dynamic import
    alt Electron has components
        ComponentsUtil->>Electron: components.whenReady()
        Electron-->>ComponentsUtil: resolves/rejects
        ComponentsUtil-->>Browser: true (if resolved) / false (if rejected)
    else Electron has no components
        ComponentsUtil-->>Browser: false
    end
Loading

Possibly related PRs

  • Add Support for Widevine #43: Adds Widevine support through build workflows, signing hooks, and readiness checks, complementing this PR’s Electron version management and readiness refactor.

Poem

🐇
A script to set Electron right,
And check if Widevine’s in sight.
With new utilities in the code,
The browser’s readiness is showed.
Hop, skip, update, and run—
Another CodeRabbit job well done!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6875751 and 2f54c76.

📒 Files selected for processing (1)
  • src/main/browser/browser.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/browser/browser.ts
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: build (windows-latest)
  • GitHub Check: build (ubuntu-latest)
  • GitHub Check: build (macos-latest)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions
Copy link
Contributor

github-actions bot commented May 25, 2025

Build artifacts for all platforms are ready! 🚀

Download the artifacts from:

(execution 15238697980 / attempt 1)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (2)
scripts/use-stock-electron.ts (1)

38-38: Consider making the Electron version configurable.

The hardcoded version "35.3.0" limits flexibility. Consider accepting the version as a command-line argument or environment variable.

-const electronVersion = "35.3.0";
+const electronVersion = process.argv[2] || process.env.ELECTRON_VERSION || "35.3.0";
src/main/modules/electron-components.ts (1)

1-15: Good abstraction for handling Electron variants.

The function provides a clean way to handle differences between stock and Widevine Electron. The dynamic import and property checking approach is solid.

Consider a few minor improvements:

 export async function waitForElectronComponentsToBeReady() {
-  const electron = await import("electron");
+  try {
+    const electron = await import("electron");

-  if ("components" in electron) {
+    if ("components" in electron) {
       const { components } = electron;

       // @ts-ignore: This is defined in Widevine Electron, but not in the stock Electron
       return components
         .whenReady()
         .then(() => true)
         .catch(() => false);
-  }
+    }

-  return Promise.resolve(false);
+    return false;
+  } catch (error) {
+    console.warn("Failed to import electron module:", error);
+    return false;
+  }
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6b80c47 and 6875751.

📒 Files selected for processing (4)
  • package.json (1 hunks)
  • scripts/use-stock-electron.ts (1 hunks)
  • src/main/browser/browser.ts (3 hunks)
  • src/main/modules/electron-components.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/main/browser/browser.ts (1)
src/main/modules/electron-components.ts (1)
  • waitForElectronComponentsToBeReady (1-15)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: build (macos-latest)
  • GitHub Check: build (windows-latest)
  • GitHub Check: build (ubuntu-latest)
🔇 Additional comments (4)
scripts/use-stock-electron.ts (1)

65-67:

Details

✅ Verification successful

Verify the bun.lock array manipulation logic.

The array manipulation operations appear complex and might not work as intended. The splice(1, 0, "") inserts an empty string at index 1, and setting index 3 assumes the array has at least 4 elements.

Please verify this logic with actual bun.lock file structure. The operations might cause array corruption if the assumptions about array length are incorrect.


🏁 Script executed:

#!/bin/bash
# Description: Check the structure of electron entry in bun.lock to verify array manipulation logic

# Search for electron package structure in bun.lock
if [ -f "bun.lock" ]; then
  echo "Current bun.lock electron structure:"
  rg -A 10 '"electron"' bun.lock || echo "No electron entry found"
else
  echo "bun.lock file not found"
fi

Length of output: 4951


bun.lock “electron” entry patch is correct
Verified that the packages["electron"] entry in bun.lock is a 3-element array—[specifier, metadata object, hash]. After

bunLock.packages.electron.splice(1, 0, "")

it becomes 4 elements, so assigning to index 3 is valid and aligns with the pattern used by other packages (specifier, "", metadata, "").

package.json (1)

27-28: LGTM! Script integration looks good.

The new npm script properly integrates the TypeScript script using Bun runtime. The trailing comma addition is also a good formatting improvement.

src/main/browser/browser.ts (2)

3-3: Good refactoring for cleaner imports.

Removing the direct components import and using the utility function improves maintainability and centralizes the Electron variant handling logic.

Also applies to: 13-13


94-97: Improved readiness check logic.

The simplified boolean-based approach is much cleaner than the previous promise chaining. The warning message provides good debugging information.

@iamEvanYT iamEvanYT merged commit dc0f0ad into main May 25, 2025
7 checks passed
@iamEvanYT iamEvanYT deleted the evan/stock-electron branch May 25, 2025 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant