-
Notifications
You must be signed in to change notification settings - Fork 433
feat: add tauri-plugin-network for network availability monitoring #2069
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- 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 EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
✅ Deploy Preview for hyprnote ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
📝 WalkthroughWalkthroughA 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
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
✅ Deploy Preview for hyprnote-storybook ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this 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 existingis_online()fromcrates/network.There's already an
is_online()function incrates/network/src/lib.rsthat 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: truebefore the first connectivity check could briefly show incorrect state to the frontend. Consider either:
- Performing an initial check before setting state, or
- Starting with
is_online: false(safer default) and emitting an event once confirmed onlineOk(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 returntruefor 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::Clientis created on every check. While the overhead is minimal given the 2+ second interval, you could store the client inNetworkStatefor better efficiency, asreqwest::Clientis designed to be reused and internally manages connection pooling.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
Cargo.lockis 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, runcodegen, updateplugins/<NAME>/permissions/default.toml, andapps/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.rsCargo.tomlplugins/network/build.rsplugins/network/Cargo.tomlapps/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-networkis 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
NetworkStatusEventstruct 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.
Summary
Adds a new
tauri-plugin-networkplugin that monitors network availability using an actor-based approach. The plugin:NetworkActorthat periodically checks network connectivity by fetchinghttps://www.google.com/generate_204every 2 secondsNetworkStatusEventwhen network status changes (online ↔ offline)parent_supervisoris provided inInitOptionsractor::time::send_afterfor scheduling periodic checks with minimal CPU/battery overheadReview & Testing Checklist for Human
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.NetworkStatusEventis properly emitted when toggling network connectivity (e.g., disable WiFi)is_online: true. First event only emits after first check if status differs. Verify this is acceptable behavior.Recommended test plan:
ONBOARDING=0 pnpm -F desktop tauri devNetworkStatusEventin the frontend (or check logs)Notes
pnpm -F @hypr/plugin-network codegenafter adding package.json/tsconfig.jsonRequested by: @yujonglee (yujonglee.dev@gmail.com)
Link to Devin run: https://app.devin.ai/sessions/6cdf968dba9e41d3bde5687ff85c5c0b