Skip to content

feat: implement Windows support for connectivity detection (#3)#6

Merged
jjhafer merged 6 commits into
silvermine:masterfrom
gabref:gabref/windows-connectivity-status
May 6, 2026
Merged

feat: implement Windows support for connectivity detection (#3)#6
jjhafer merged 6 commits into
silvermine:masterfrom
gabref:gabref/windows-connectivity-status

Conversation

@gabref
Copy link
Copy Markdown

@gabref gabref commented Apr 16, 2026

Adds Windows support for connection_status() in tauri-plugin-connectivity.

  • implement the Windows backend using WinRT NetworkInformation
  • map connectivity, metered, constrained, and transport status into the existing plugin types
  • include BackgroundDataUsageRestricted in the Windows constrained check
  • split platform handling into per-platform modules
  • add structured tracing logs for plugin setup, command handling, and Windows status resolution
  • update docs to reflect Windows support
  • add a small examples/tauri-app app for manual testing

Closes #3

Comment thread src/platform/windows.rs Outdated

let profile = match NetworkInformation::GetInternetConnectionProfile() {
Ok(profile) => profile,
Err(error) if error.code().0 == 0 => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Instead of checking for a magic number 0, we should be able to use is_ok() on the HRESULT returned by error.code().

Then our usage becomes:

Err(error) if error.code().is_ok() => { ... }  

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks, I updated this. I checked our current windows crate version and error.code().is_ok() is supported there, and it handles the Error::empty() / no-profile case we get from GetInternetConnectionProfile(). I replaced the 0 check and added tests to cover both the missing-profile case and a real failure HRESULT.

@@ -0,0 +1,3 @@
node_modules
dist
src-tauri/target
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we please ignore src-tauri/gen and remove this folder from source control? This is ignored in our other plugin repositories.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Updated the example app ignore rules to include src-tauri/gen, and removed that generated directory from source control so it won’t keep showing up in the repo.

Comment thread package.json Outdated
"build": "rollup -c",
"check-node-version": "check-node-version --npm 11.8.0",
"commitlint": "commitlint --from ${COMMITLINT_FROM:-710707e} --to ${COMMITLINT_TO:-HEAD}",
"commitlint": "commitlint --from 710707e",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we please undo this unrelated change?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes, I’ll drop this from the PR. I changed it because the ${...:-...} expansion doesn’t work in PowerShell, but that’s separate from the scope here. I’ll keep the local workaround for now and we can handle a cross-shell commitlint fix in a follow-up PR.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Interesting. We may need to revisit this elsewhere; Mac vs Windows I guess.

Comment thread Cargo.toml Outdated
tauri = { version = "2.9.3" }
thiserror = "2.0.17"
tracing = { version = "0.1.41", default-features = false, features = ["std", "log", "release_max_level_warn"] }
tracing = { version = "0.1.44", default-features = false, features = ["std", "log", "release_max_level_warn"] }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we please roll this back to 0.1.41 to match our other plugins?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Rolled back to 0.1.41 to match the other plugins.

One note: our main app currently has tracing = "0.1.44", so that may be intentional there, but I’ve aligned this plugin with the plugin repos as requested.

Comment thread src/platform/windows.rs Outdated
return Ok(ConnectionStatus::disconnected());
}

let connection_cost = match profile.GetConnectionCost() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: This pattern can be simplified using inspect_err:

let connection_cost = profile   
   .GetConnectionCost()                                                                                                                                                                              
   .inspect_err(|error| warn!(%error, "failed to query Windows connection cost"))?;

This could be applied also to the other properties too.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good suggestion! Updated the straightforward error paths.

@gabref gabref force-pushed the gabref/windows-connectivity-status branch from 2fcb6bf to c3de9bf Compare April 17, 2026 08:54
@gabref gabref requested a review from velocitysystems April 17, 2026 08:55
Comment thread src/platform/windows.rs Outdated
Comment thread src/platform/windows.rs Outdated
Comment thread src/platform/windows.rs
Comment thread src/platform/windows.rs
Comment thread src/platform/windows.rs Outdated
Comment thread src/commands.rs Outdated
Comment thread src/error.rs
Comment thread examples/tauri-app/src/main.ts
Comment thread examples/tauri-app/.gitignore Outdated
@gabref gabref force-pushed the gabref/windows-connectivity-status branch 5 times, most recently from 9115e38 to 1f3fb93 Compare May 5, 2026 07:44
@gabref gabref force-pushed the gabref/windows-connectivity-status branch 2 times, most recently from 614f4b7 to c707f3e Compare May 5, 2026 08:19
@gabref gabref force-pushed the gabref/windows-connectivity-status branch from c707f3e to 1c4e5c0 Compare May 5, 2026 08:23
@gabref gabref requested a review from jjhafer May 5, 2026 08:27
@jjhafer jjhafer merged commit 4f62f26 into silvermine:master May 6, 2026
1 check passed
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.

Implement Windows support for connectivity detection

3 participants