Skip to content

Conversation

@yujonglee
Copy link
Contributor

@yujonglee yujonglee commented Dec 2, 2025

Summary

Adds a new tauri-plugin-network plugin that monitors network availability using an actor-based approach. The plugin:

  • Creates a NetworkActor that periodically checks network connectivity by fetching https://www.google.com/generate_204 every 2 seconds
  • Emits NetworkStatusEvent when network status changes (online ↔ offline)
  • Links to the root supervisor when parent_supervisor is provided in InitOptions
  • Uses ractor::time::send_after for scheduling periodic checks with minimal CPU/battery overhead

Review & Testing Checklist for Human

  • Verify supervisor linking behavior: The actor is spawned independently and then linked to the parent supervisor via actor_ref.get_cell().link(parent_cell). This is different from spawning as a child of a DynamicSupervisor. Confirm this provides the expected supervision/restart behavior.
  • Check timing edge case: Request timeout is 5s but check interval is 2s. If network is slow, could this cause overlapping requests? Consider if this needs adjustment.
  • Test event emission: Run the app and verify NetworkStatusEvent is properly emitted when toggling network connectivity (e.g., disable WiFi)
  • Initial state: Actor starts assuming is_online: true. First event only emits after first check if status differs. Verify this is acceptable behavior.

Recommended test plan:

  1. Run ONBOARDING=0 pnpm -F desktop tauri dev
  2. Add a listener for NetworkStatusEvent in the frontend (or check logs)
  3. Toggle network connectivity and verify events are emitted on status change

Notes

  • No commands are exposed - only events. If you need to query current status, a command would need to be added.
  • TypeScript bindings not generated yet - would need pnpm -F @hypr/plugin-network codegen after adding package.json/tsconfig.json

Requested by: @yujonglee (yujonglee.dev@gmail.com)
Link to Devin run: https://app.devin.ai/sessions/6cdf968dba9e41d3bde5687ff85c5c0b

- Add NetworkActor that periodically checks network availability by fetching https://www.google.com/generate_204
- Actor is supervised by root supervisor when parent_supervisor is provided
- Emits NetworkStatusEvent when network status changes
- Default check interval is 2 seconds with minimal CPU/battery overhead

Co-Authored-By: yujonglee <yujonglee.dev@gmail.com>
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI' or '@devin'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@netlify
Copy link

netlify bot commented Dec 2, 2025

Deploy Preview for hyprnote ready!

Name Link
🔨 Latest commit 5f2bbcc
🔍 Latest deploy log https://app.netlify.com/projects/hyprnote/deploys/692ed7ade6566e00084f2ff1
😎 Deploy Preview https://deploy-preview-2069--hyprnote.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 2, 2025

📝 Walkthrough

Walkthrough

A new tauri-plugin-network plugin is introduced to monitor network connectivity. It integrates into the desktop app's plugin system, spawns a network actor that periodically checks reachability via HTTP requests, and emits status change events through Tauri's event system.

Changes

Cohort / File(s) Summary
Plugin Workspace Declaration
Cargo.toml
Added public path-based reference to tauri-plugin-network plugin
Desktop App Integration
apps/desktop/src-tauri/Cargo.toml, apps/desktop/src-tauri/src/lib.rs
Added network plugin as workspace dependency; wired plugin initialization with parent supervisor context in the plugin chain
Network Plugin Scaffold
plugins/network/Cargo.toml, plugins/network/build.rs
Added plugin manifest with workspace dependencies (ractor, reqwest, tauri, specta); added build script for plugin configuration
Network Plugin Implementation
plugins/network/src/actor.rs, plugins/network/src/event.rs, plugins/network/src/lib.rs
Implemented NetworkActor for periodic connectivity checks via HTTP HEAD requests; defined NetworkStatusEvent for status emission; added plugin initialization with optional parent supervisor linking and Specta type generation

Sequence Diagram(s)

sequenceDiagram
    actor TauriApp as Tauri App
    participant NetPlugin as Network Plugin
    participant NetActor as NetworkActor
    participant HTTP as HTTP Client
    participant EventBus as Event Bus

    TauriApp->>NetPlugin: init(InitOptions)
    NetPlugin->>NetActor: spawn & link to supervisor
    activate NetActor
    NetActor->>NetActor: pre_start: initialize<br/>is_online = true
    NetActor->>NetActor: schedule_check<br/>(CHECK_INTERVAL)
    deactivate NetActor

    loop Every CHECK_INTERVAL
        NetActor->>NetActor: receive Check msg
        activate NetActor
        NetActor->>HTTP: HEAD request to CHECK_URL
        alt Success (200/204)
            HTTP-->>NetActor: success
            NetActor->>NetActor: is_online = true
        else Failure
            HTTP-->>NetActor: error
            NetActor->>NetActor: is_online = false
        end
        alt Status Changed
            rect rgb(200, 220, 240)
                Note over NetActor,EventBus: Status change detected
                NetActor->>EventBus: emit NetworkStatusEvent
                EventBus->>TauriApp: broadcast event
            end
        end
        NetActor->>NetActor: schedule_check<br/>(next interval)
        deactivate NetActor
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • plugins/network/src/actor.rs: Requires careful review of the actor lifecycle (pre_start, handle), periodic scheduling logic, HTTP client configuration, error handling, and state mutation patterns within the ractor framework.
  • plugins/network/src/lib.rs: Verify plugin initialization, supervisor linking semantics, Specta integration, and async spawn error handling.
  • Integration points: Ensure parent_supervisor context flows correctly from app initialization through plugin wiring.

Possibly related PRs

  • add root supervisor in desktop app #1881: Adds root supervisor wiring to plugin initialization—the network plugin's parent_supervisor parameter depends on this supervisor context being threaded into the app startup.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding a new tauri-plugin-network for network availability monitoring, which is the core focus of the entire changeset.
Description check ✅ Passed The description comprehensively explains the plugin's functionality, implementation details, testing considerations, and includes a recommended test plan directly related to the changeset.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch devin/1764677494-add-network-plugin

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

@netlify
Copy link

netlify bot commented Dec 2, 2025

Deploy Preview for hyprnote-storybook ready!

Name Link
🔨 Latest commit 5f2bbcc
🔍 Latest deploy log https://app.netlify.com/projects/hyprnote-storybook/deploys/692ed7ad72fc5b00083a0e4c
😎 Deploy Preview https://deploy-preview-2069--hyprnote-storybook.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

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 (6)
plugins/network/Cargo.toml (2)

4-4: Update placeholder author metadata.

The author is set to "You" which appears to be placeholder text. Consider updating to the actual author name or matching the pattern used by other plugins in the workspace.


8-8: Add a meaningful description.

The description field is empty. Consider adding a brief description like "Network availability monitoring plugin for Tauri" to improve discoverability and documentation.

plugins/network/src/actor.rs (4)

7-9: Consider reusing existing is_online() from crates/network.

There's already an is_online() function in crates/network/src/lib.rs that uses ICMP ping to check connectivity. This introduces a second, different approach (HTTP HEAD request). If the HTTP approach is intentional (e.g., ICMP is often blocked in corporate networks), consider documenting this decision. Otherwise, consider reusing the existing implementation for consistency.


47-50: Initial state assumes online without verification.

Setting is_online: true before the first connectivity check could briefly show incorrect state to the frontend. Consider either:

  1. Performing an initial check before setting state, or
  2. Starting with is_online: false (safer default) and emitting an event once confirmed online
         Ok(NetworkState {
             app: args.app,
-            is_online: true,
+            is_online: false,
         })

93-95: Redundant status check for 204.

HTTP 204 No Content is already a success status code (2xx range), so response.status().is_success() will return true for 204. The explicit check is redundant.

     match client.head(CHECK_URL).send().await {
-        Ok(response) => response.status().is_success() || response.status().as_u16() == 204,
+        Ok(response) => response.status().is_success(),
         Err(_) => false,
     }

83-91: Consider reusing the HTTP client.

A new reqwest::Client is created on every check. While the overhead is minimal given the 2+ second interval, you could store the client in NetworkState for better efficiency, as reqwest::Client is designed to be reused and internally manages connection pooling.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8320877 and 5f2bbcc.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (8)
  • Cargo.toml (1 hunks)
  • apps/desktop/src-tauri/Cargo.toml (1 hunks)
  • apps/desktop/src-tauri/src/lib.rs (1 hunks)
  • plugins/network/Cargo.toml (1 hunks)
  • plugins/network/build.rs (1 hunks)
  • plugins/network/src/actor.rs (1 hunks)
  • plugins/network/src/event.rs (1 hunks)
  • plugins/network/src/lib.rs (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
plugins/*/src/lib.rs

📄 CodeRabbit inference engine (plugins/AGENTS.md)

After updating commands in plugins/<NAME>/src/lib.rs, run codegen, update plugins/<NAME>/permissions/default.toml, and apps/desktop/src-tauri/capabilities/default.json

Files:

  • plugins/network/src/lib.rs
🧠 Learnings (1)
📚 Learning: 2025-11-27T11:40:22.782Z
Learnt from: CR
Repo: fastrepl/hyprnote PR: 0
File: plugins/AGENTS.md:0-0
Timestamp: 2025-11-27T11:40:22.782Z
Learning: Applies to plugins/*/src/lib.rs : After updating commands in `plugins/<NAME>/src/lib.rs`, run `codegen`, update `plugins/<NAME>/permissions/default.toml`, and `apps/desktop/src-tauri/capabilities/default.json`

Applied to files:

  • apps/desktop/src-tauri/src/lib.rs
  • Cargo.toml
  • plugins/network/build.rs
  • plugins/network/Cargo.toml
  • apps/desktop/src-tauri/Cargo.toml
🧬 Code graph analysis (4)
apps/desktop/src-tauri/src/lib.rs (1)
plugins/network/src/lib.rs (1)
  • init (24-58)
plugins/network/src/event.rs (1)
packages/store/src/schema-external.ts (1)
  • Event (150-150)
plugins/network/src/lib.rs (2)
apps/desktop/src-tauri/src/lib.rs (3)
  • make_specta_builder (198-206)
  • make_specta_builder (214-214)
  • export_types (213-223)
plugins/network/src/actor.rs (1)
  • name (29-31)
plugins/network/src/actor.rs (1)
crates/network/src/lib.rs (1)
  • is_online (1-16)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
  • GitHub Check: Redirect rules - hyprnote-storybook
  • GitHub Check: Header rules - hyprnote-storybook
  • GitHub Check: Pages changed - hyprnote-storybook
  • GitHub Check: Redirect rules - hyprnote
  • GitHub Check: Header rules - hyprnote
  • GitHub Check: Pages changed - hyprnote
  • GitHub Check: Devin
  • GitHub Check: desktop_ci (linux, depot-ubuntu-22.04-8)
  • GitHub Check: desktop_ci (linux, depot-ubuntu-24.04-8)
  • GitHub Check: desktop_ci (macos, depot-macos-14)
  • GitHub Check: fmt
🔇 Additional comments (10)
plugins/network/build.rs (1)

1-5: LGTM!

The build script correctly initializes the Tauri plugin builder with an empty commands array, which is appropriate since this plugin only emits events and doesn't expose IPC commands.

Cargo.toml (1)

129-129: LGTM!

The workspace dependency for tauri-plugin-network is correctly added following the established pattern and alphabetical ordering.

apps/desktop/src-tauri/src/lib.rs (1)

93-99: LGTM!

The network plugin initialization follows the established pattern used by tauri_plugin_local_stt, correctly wiring the parent supervisor for actor lifecycle management.

apps/desktop/src-tauri/Cargo.toml (1)

45-45: LGTM!

The dependency is correctly added following the workspace pattern and alphabetical ordering.

plugins/network/src/event.rs (1)

1-4: LGTM!

The NetworkStatusEvent struct is well-defined with appropriate derives for Tauri event emission and TypeScript type generation via Specta.

plugins/network/src/lib.rs (2)

1-22: LGTM!

The imports, module structure, and specta builder setup follow the established patterns used by other Tauri plugins in this workspace.


60-76: LGTM!

The test module for TypeScript type export follows the established pattern used elsewhere in the codebase.

plugins/network/src/actor.rs (3)

13-26: LGTM!

Clean struct definitions for message passing and state management.


28-32: LGTM!


53-77: LGTM!

The change-detection logic is efficient, emitting events only when the state actually changes. Error handling is appropriate.

@yujonglee yujonglee merged commit cd3ecd6 into main Dec 2, 2025
17 of 18 checks passed
@yujonglee yujonglee deleted the devin/1764677494-add-network-plugin branch December 2, 2025 12:35
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.

2 participants