Skip to content

feat: added bandwidth limit#94

Merged
Nat3z merged 2 commits intomainfrom
feat/download-bandwidth-throttle
Mar 5, 2026
Merged

feat: added bandwidth limit#94
Nat3z merged 2 commits intomainfrom
feat/download-bandwidth-throttle

Conversation

@Nat3z
Copy link
Owner

@Nat3z Nat3z commented Mar 5, 2026

Summary by CodeRabbit

Release Notes

  • New Features

    • Added bandwidth limit configuration option in General settings, allowing users to control download speeds from 0 to 100 MB/s (unlimited by default)
  • Chores

    • Updated application version to 3.0.3
    • Updated updater version to 1.4.0

@vercel
Copy link

vercel bot commented Mar 5, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
open-game-installer-web Ready Ready Preview, Comment Mar 5, 2026 7:05am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 5, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: aa6039dd-f4eb-47b4-bf54-f85df0e88ca7

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Version updates applied to application and updater packages. Bandwidth throttling functionality introduced via GlobalTokenBucket and ThrottleStream in the download handler, with corresponding UI configuration option for bandwidth limit setting.

Changes

Cohort / File(s) Summary
Version Bumps
application/package.json, updater/package.json
Version increments: application from 3.0.1 to 3.0.3; updater from 1.3.5 to 1.4.0.
Bandwidth Throttling Implementation
application/src/electron/handlers/handler.ddl.ts
Introduces GlobalTokenBucket and ThrottleStream infrastructure for bandwidth-limited downloads. Adds BANDWIDTH_LIMIT_BYTES_PER_SEC state management, conditional stream throttling at chunk/part/direct-download levels, and abort cleanup for throttle streams.
Bandwidth Configuration UI
application/src/frontend/views/ClientOptionsView.svelte
Adds new bandwidthLimit option to General settings category with numeric input (0–100 MB/s, default 0 for unlimited).

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant UI as ClientOptionsView
    participant Storage as Configuration Storage
    participant Handler as handler.ddl
    participant TB as GlobalTokenBucket
    participant TS as ThrottleStream
    participant File as File Output

    User->>UI: Sets bandwidth limit (MB/s)
    UI->>Storage: Saves bandwidth limit
    
    Handler->>Storage: Reads bandwidth limit on init
    Handler->>TB: Updates token bucket with limit
    Handler->>Handler: Log configured bandwidth
    
    activate Handler
    Note over Handler: Download initiates
    Handler->>TB: Check token availability
    
    alt Bandwidth limit > 0
        TB-->>TS: Create throttle stream(s)
        Handler->>TS: Pipe download response through throttle
        TS->>File: Throttled data chunks
    else Bandwidth limit = 0
        Handler->>File: Direct pipe (no throttling)
    end
    
    Handler->>Handler: On abort: destroy throttle streams
    deactivate Handler
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Hop! Hop! The bandwidth now has bounds,
With throttle streams and token sounds,
Three-oh-three and one-four-oh,
Smooth downloads at controlled flow! 🚀

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title 'feat: added bandwidth limit' accurately describes the main change across all modified files, which introduces bandwidth throttling support for downloads.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/download-bandwidth-throttle

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@Nat3z
Copy link
Owner Author

Nat3z commented Mar 5, 2026

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 5, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Typecheck Passed - All type checks successful!

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: 1

🧹 Nitpick comments (1)
application/src/electron/handlers/handler.ddl.ts (1)

692-700: Extract duplicated throttle piping into one helper.

The same conditional throttle/piping and abort cleanup logic is repeated across multiple paths. Centralizing it will reduce drift and future bugs.

Refactor sketch
+  private pipeWithOptionalThrottle(
+    source: Readable,
+    destination: fs.WriteStream
+  ): ThrottleStream | undefined {
+    if (BANDWIDTH_LIMIT_BYTES_PER_SEC > 0) {
+      const throttle = new ThrottleStream();
+      source.pipe(throttle);
+      throttle.pipe(destination);
+      return throttle;
+    }
+    source.pipe(destination);
+    return undefined;
+  }
-        let _partThrottle: ThrottleStream | undefined;
-        if (BANDWIDTH_LIMIT_BYTES_PER_SEC > 0) {
-          _partThrottle = new ThrottleStream();
-          part.response.data.pipe(_partThrottle);
-          _partThrottle.pipe(part.fileStream);
-        } else {
-          part.response.data.pipe(part.fileStream);
-        }
+        const _partThrottle = this.pipeWithOptionalThrottle(
+          part.response.data,
+          part.fileStream
+        );

Also applies to: 708-709, 854-862, 874-875, 1289-1297, 1309-1310, 1678-1686, 1695-1696

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@application/src/electron/handlers/handler.ddl.ts` around lines 692 - 700,
Duplicate throttle/piping and abort cleanup logic around ThrottleStream usage
(e.g., the block creating _chunkThrottle, piping chunk.response.data ->
_chunkThrottle -> chunk.fileStream or directly to chunk.fileStream, and setting
stream = chunk.fileStream) appears in multiple places; extract this into a
single helper (e.g., createThrottledPipe or pipeWithOptionalThrottle) that
accepts the readable (chunk.response.data), the writable (chunk.fileStream), and
BANDWIDTH_LIMIT_BYTES_PER_SEC, returns the final stream and the ThrottleStream
(if any) and ensures consistent abort/cleanup handling; replace all instances
(including the example using _chunkThrottle and stream) to call the helper and
wire its returned values into existing abort logic so piping and cleanup are
centralized.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@application/src/frontend/views/ClientOptionsView.svelte`:
- Around line 93-96: The UI uses "MB/s" but the backend uses binary MiB
(1024*1024) units—update the UI to use consistent binary units: change the
setting's displayName and description in ClientOptionsView.svelte (the object
with keys displayName, description, defaultValue) to reference "MiB/s" (or
explicitly "MiB/s (1024*1024 bytes/s)") and adjust the explanatory text
accordingly (e.g., "Maximum download speed for direct downloads in MiB/s. Set to
0 for unlimited.") so the label matches the backend conversion.

---

Nitpick comments:
In `@application/src/electron/handlers/handler.ddl.ts`:
- Around line 692-700: Duplicate throttle/piping and abort cleanup logic around
ThrottleStream usage (e.g., the block creating _chunkThrottle, piping
chunk.response.data -> _chunkThrottle -> chunk.fileStream or directly to
chunk.fileStream, and setting stream = chunk.fileStream) appears in multiple
places; extract this into a single helper (e.g., createThrottledPipe or
pipeWithOptionalThrottle) that accepts the readable (chunk.response.data), the
writable (chunk.fileStream), and BANDWIDTH_LIMIT_BYTES_PER_SEC, returns the
final stream and the ThrottleStream (if any) and ensures consistent
abort/cleanup handling; replace all instances (including the example using
_chunkThrottle and stream) to call the helper and wire its returned values into
existing abort logic so piping and cleanup are centralized.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 88a797ba-a4b9-4bf5-b551-3627fb39d72e

📥 Commits

Reviewing files that changed from the base of the PR and between 685190c and cac4770.

📒 Files selected for processing (4)
  • application/package.json
  • application/src/electron/handlers/handler.ddl.ts
  • application/src/frontend/views/ClientOptionsView.svelte
  • updater/package.json

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@Nat3z Nat3z merged commit e40dde9 into main Mar 5, 2026
5 of 6 checks passed
@Nat3z Nat3z deleted the feat/download-bandwidth-throttle branch March 5, 2026 07:05
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Typecheck Passed - All type checks successful!

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