starship-battery-0.10.0/.cargo_vcs_info.json0000644000000001360000000000100144170ustar { "git": { "sha1": "7d4a0166c2ee1d0d26db67c67b6e39c5ce171bac" }, "path_in_vcs": "" }starship-battery-0.10.0/.editorconfig000064400000000000000000000002531046102023000156640ustar 00000000000000root = true [*] end_of_line = lf insert_final_newline = true charset = utf-8 indent_style = space indent_size = 4 trim_trailing_whitespace = true [*.yml] indent_size = 2 starship-battery-0.10.0/.github/renovate.json5000064400000000000000000000021541046102023000173540ustar 00000000000000{ "$schema": "https://docs.renovatebot.com/renovate-schema.json", "extends": [ // stripped-down config:recommended ":prHourlyLimit2", ":prConcurrentLimit10", "group:monorepos", "group:recommended", "replacements:all", "workarounds:all", // automerge minor updates ":automergeMinor", ":automergeBranch" ], "labels": ["📦 dependencies"], "semanticCommits": "enabled", "semanticCommitType": "build", "rangeStrategy": "bump", "rebaseWhen": "conflicted", // custom regex update managers "regexManagers": [ { "fileMatch": ["(^|\\/)\\.?dprint.json"], "matchStrings": ["\"https://github.com/(?.+)/releases/download/(?.+)/plugin.wasm\""], "datasourceTemplate": "github-releases" }, { "fileMatch": ["^(workflow-templates|\\.github\\/workflows)\\/[^/]+\\.ya?ml$"], "matchStrings": ["cargo install.*--version (?\\S+).*\\s(?\\S+)"], "datasourceTemplate": "crate" } ] } starship-battery-0.10.0/.github/workflows/ci.yml000064400000000000000000000075311046102023000177300ustar 00000000000000on: [push, pull_request] name: Continuous integration env: CARGO_INCREMENTAL: 0 CARGO_NET_RETRY: 10 RUST_BACKTRACE: short RUSTUP_MAX_RETRIES: 10 CARGO: cargo jobs: test: name: Test strategy: matrix: toolchain: - stable - 1.69.0 # MSRV target: - i686-unknown-linux-gnu - x86_64-unknown-linux-gnu - x86_64-unknown-linux-musl - i686-pc-windows-msvc - x86_64-pc-windows-msvc - x86_64-apple-darwin include: - target: i686-unknown-linux-gnu os: ubuntu-latest - target: x86_64-unknown-linux-gnu os: ubuntu-latest - target: x86_64-unknown-linux-musl os: ubuntu-latest - target: i686-pc-windows-msvc os: windows-latest - target: x86_64-pc-windows-msvc os: windows-latest - target: x86_64-apple-darwin os: macos-latest runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4.1.7 - uses: dtolnay/rust-toolchain@master with: toolchain: ${{ matrix.toolchain }} target: ${{ matrix.target }} - uses: Swatinem/rust-cache@v2.7.3 with: key: ${{ matrix.target }} - name: Setup | Install cross [Linux] if: matrix.os == 'ubuntu-latest' uses: taiki-e/install-action@cross - name: Setup | Use cross [Linux] if: matrix.os == 'ubuntu-latest' run: echo "CARGO=cross" >> $GITHUB_ENV - name: Build run: ${{ env.CARGO }} build --target ${{ matrix.target }} --all-features --all-targets - name: Run tests run: ${{ env.CARGO }} test --target ${{ matrix.target }} --all-features --all-targets - name: Run clippy if: matrix.toolchain == 'stable' run: ${{ env.CARGO }} clippy --target ${{ matrix.target }} -- -D clippy::all build_only: name: Test [Build only] strategy: matrix: toolchain: - stable - 1.69.0 # MSRV target: - x86_64-unknown-freebsd - x86_64-unknown-netbsd - aarch64-unknown-linux-gnu - aarch64-unknown-linux-musl - aarch64-pc-windows-msvc - aarch64-apple-darwin include: - target: x86_64-unknown-freebsd os: ubuntu-latest - target: x86_64-unknown-netbsd os: ubuntu-latest - target: aarch64-unknown-linux-gnu os: ubuntu-latest - target: aarch64-unknown-linux-musl os: ubuntu-latest - target: aarch64-pc-windows-msvc os: windows-latest - target: aarch64-apple-darwin os: macos-latest runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4.1.7 - uses: dtolnay/rust-toolchain@master with: toolchain: ${{ matrix.toolchain }} target: ${{ matrix.target }} - uses: Swatinem/rust-cache@v2.7.3 with: key: ${{ matrix.target }} - name: Setup | Install cross [Linux] if: matrix.os == 'ubuntu-latest' uses: taiki-e/install-action@cross - name: Setup | Use cross [Linux] if: matrix.os == 'ubuntu-latest' run: echo "CARGO=cross" >> $GITHUB_ENV - name: Build run: ${{ env.CARGO }} build --target ${{ matrix.target }} --all-features --all-targets - name: Run clippy if: matrix.toolchain == 'stable' run: ${{ env.CARGO }} clippy --target ${{ matrix.target }} -- -D clippy::all rustfmt: name: Rustfmt [Formatter] runs-on: ubuntu-latest steps: - name: Setup | Checkout uses: actions/checkout@v4 - name: Setup | Rust uses: dtolnay/rust-toolchain@stable with: components: rustfmt - name: Build | Format run: cargo fmt --all -- --check starship-battery-0.10.0/.github/workflows/deploy.yml000064400000000000000000000021231046102023000206210ustar 00000000000000name: Deploy on: push: branches: - main env: CARGO_INCREMENTAL: 0 CARGO_NET_RETRY: 10 RUST_BACKTRACE: short RUSTUP_MAX_RETRIES: 10 jobs: # Update release PR release_please: name: Release Please runs-on: ubuntu-latest if: github.repository == 'starship/rust-battery' outputs: release_created: ${{ steps.release.outputs.release_created }} steps: - uses: google-github-actions/release-please-action@v3 id: release with: token: ${{ secrets.GITHUB_TOKEN }} release-type: rust bump-minor-pre-major: true # Publish starship-battery to Crates.io cargo_publish: name: Publish Cargo Package runs-on: ubuntu-latest needs: release_please if: ${{ needs.release_please.outputs.release_created == 'true' }} steps: - name: Setup | Checkout uses: actions/checkout@v4.1.7 - name: Setup | Rust uses: dtolnay/rust-toolchain@stable - name: Build | Publish run: cargo publish env: CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} starship-battery-0.10.0/.github/workflows/security-audit.yml000064400000000000000000000012431046102023000223020ustar 00000000000000name: Security audit on: pull_request: paths: - "**/Cargo.toml" - "**/Cargo.lock" push: paths: - "**/Cargo.toml" - "**/Cargo.lock" jobs: security_audit: runs-on: ubuntu-latest strategy: matrix: checks: - advisories - bans licenses sources # Prevent sudden announcement of a new advisory from failing ci: continue-on-error: ${{ matrix.checks == 'advisories' }} steps: - name: Setup | Checkout uses: actions/checkout@v4 - name: Test | Security Audit uses: EmbarkStudios/cargo-deny-action@v2.0.1 with: command: check ${{ matrix.checks }} starship-battery-0.10.0/.gitignore000064400000000000000000000000771046102023000152030ustar 00000000000000/target **/target **/*.rs.bk Cargo.lock *.orig local_build.sh starship-battery-0.10.0/CHANGELOG.md000064400000000000000000000160601046102023000150230ustar 00000000000000# Changelog All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [0.10.0](https://github.com/starship/rust-battery/compare/v0.9.1...v0.10.0) (2024-08-31) ### Features * replace winapi with windows-sys ([#70](https://github.com/starship/rust-battery/issues/70)) ([7f69364](https://github.com/starship/rust-battery/commit/7f69364803b855d7abc6272c4b02b6499099c60e)) ## [0.9.1](https://github.com/starship/rust-battery/compare/v0.9.0...v0.9.1) (2024-07-25) ### Bug Fixes * remove `netbsd` keyword ([#72](https://github.com/starship/rust-battery/issues/72)) ([764972b](https://github.com/starship/rust-battery/commit/764972bd0c5145f8eb472acb06a9af1f8e626a85)) ## [0.9.0](https://github.com/starship/rust-battery/compare/v0.8.3...v0.9.0) (2024-06-08) ### Features * NetBSD support with envsys ioctl and plist ([#69](https://github.com/starship/rust-battery/issues/69)) ([87b8cc4](https://github.com/starship/rust-battery/commit/87b8cc45ec2b25922069f1dbb6bb7b27cb655e35)) ## [0.8.3](https://github.com/starship/rust-battery/compare/v0.8.2...v0.8.3) (2024-04-02) ### Bug Fixes * **linux:** be more permissive on invalid UTF-8 file content ([#60](https://github.com/starship/rust-battery/issues/60)) ([3a229ec](https://github.com/starship/rust-battery/commit/3a229ec4a240ffaed99706c315a29e3ece691e5b)) ## [0.8.2](https://github.com/starship/rust-battery/compare/v0.8.1...v0.8.2) (2023-08-05) ### Bug Fixes * **darwin:** allow fallback to non-raw key & permit errors ([#41](https://github.com/starship/rust-battery/issues/41)) ([19f12f0](https://github.com/starship/rust-battery/commit/19f12f04c1194515131b6edd7a1f155e3c954573)) ## [0.8.1](https://github.com/starship/rust-battery/compare/v0.8.0...v0.8.1) (2023-06-08) ### Bug Fixes * use correct data source for querying max capacity on arm64-macOS ([#33](https://github.com/starship/rust-battery/issues/33)) ([fadcee6](https://github.com/starship/rust-battery/commit/fadcee6c5e052ba58e92ea0290e1d582b2609e4f)) ## [0.8.0](https://github.com/starship/rust-battery/compare/v0.7.9...v0.8.0) (2023-04-12) ### ⚠ BREAKING CHANGES * rework ci & code cleanup * rework ci & code cleanup ### Features * derive `serde` and `schemars` traits for `State` enum ([#2](https://github.com/starship/rust-battery/issues/2)) ([487ebc2](https://github.com/starship/rust-battery/commit/487ebc2f7fbd30c346c13f82a1f721fa0256d43a)) ### Bug Fixes * bump msrv ([26bea66](https://github.com/starship/rust-battery/commit/26bea66aea58ccfd8df6005a54c403bf89554b6d)) * bump msrv ([bfcf16d](https://github.com/starship/rust-battery/commit/bfcf16db3297b05565b853e2dc19cdfd03c32986)) * bump msrv further ([#27](https://github.com/starship/rust-battery/issues/27)) ([79f1359](https://github.com/starship/rust-battery/commit/79f1359b3d4ca2f3247f04b6f72a0ca2a6db5811)) * replace `mach` with `mach2` fork ([#28](https://github.com/starship/rust-battery/issues/28)) ([ada2f1b](https://github.com/starship/rust-battery/commit/ada2f1b2ab0fd8c8c6bea7ff47e623d5fa0c94ea)) ### Code Refactoring * rework ci & code cleanup ([2330404](https://github.com/starship/rust-battery/commit/2330404d7b0f57be47f733905c735f96e866e401)) * rework ci & code cleanup ([b507347](https://github.com/starship/rust-battery/commit/b507347036b237405e292c23f7ce50dfb4ab8e58)) ## [0.7.9] - 2021-11-09 - Update `nix` dependency version - Allow empty `FullyCharged` and `DesignCapacity` ## [0.7.8] - 2020-11-01 ### Fixed - Add `nix` dependency back for FreeBSD build (#76) ## [0.7.7] - 2020-10-19 ### Fixed - Update dependencies versions to fix `nightly` toolchain compilation ## [0.7.6] - 2020-08-24 - MSRV changed to Rust `1.36.0` ### Fixed - Zero energy rate is not considered as an error for Windows [#63](https://github.com/svartalf/rust-battery/issues/63) ## [0.7.5] - 2019-11-26 ### Fixed - Handling missing `energy_full_design` source files for Linux [#40](https://github.com/svartalf/rust-battery/issues/40) ## [0.7.4] - 2019-06-03 ### Fixed - `Manager::refresh` method in Linux implementation checks if battery folder is exists [#29](https://github.com/svartalf/rust-battery/issues/29) - `Battery::energy_full_design` is not falling into a infinite recursion anymore [#30](https://github.com/svartalf/rust-battery/issues/30) ## [0.7.3] - 2019-05-30 ### Fixed - `ENODEV` errors for Linux are now handled the same as `ENOENT` [#28](https://github.com/svartalf/rust-battery/issues/28) ### Changed - Relaxing `uom` dependency version to `^0.23` for `battery` crate - Relaxing `libc` dependency version to `^0.2` for `battery-ffi` crate ## [0.7.2] - 2019-05-21 ### Fixed - `Battery::state_of_health` and `Battery::state_of_charge` are always returning values in `0.0 ≤ x ≤ 1.0` interval ## [0.7.1] - 2019-03-31 ### Changed - `uom`, `core-foundation` and `libc` dependencies were updated to latest versions - Zero cycles count is considered as non-existing value for Linux [#23](https://github.com/svartalf/rust-battery/issues/23) ### Removed - `battery-cli` crate was yanked and replaced with `battop` crate (https://crates.io/crates/battop) ## [0.7.0] - 2019-03-10 ### Changed - Propagate all errors happened from `battery` and `battery-ffi` crates to the caller - Return SI measurement units from `uom` crate for almost all public `Battery` methods - Re-export used `uom` quantities and measurement units in public `battery::units` module - Rename `Battery::percentage` method into `Battery::state_of_charge` - Rename `Battery::capacity` method into `Battery::state_of_health` - Mark `battery::State` and `battery::Technology` enums as a non-exhaustive - Support multiple devices for FreeBSD and DragonFlyBSD [#17](https://github.com/svartalf/rust-battery/issues/17) - Ignore devices with `scope` attributes different from `System` for Linux [#18](https://github.com/svartalf/rust-battery/issues/18) - Update outdated `mach` dependency for Mac OS ## [0.6.2] - 2019-02-28 ### Changed - Replace looks-to-be-abandoned `CoreFoundation-sys` and `IOKit-sys` dependencies [#2](https://github.com/svartalf/rust-battery/issues/2) ### Fixed - Free hanging mach port used for communication with Mac OS IOKit ## [0.6.1] - 2019-02-27 ### Fixed - Fix energy and remaining time calculations for MacOS [#8](https://github.com/svartalf/rust-battery/issues/8), [#11](https://github.com/svartalf/rust-battery/pull/11) - Fix multiplication overflow while calculating battery percentage in Mac OS by [@mindriot101](https://github.com/mindriot101) [#10](https://github.com/svartalf/rust-battery/pull/10) - Fix wrong units for consumption graph in `battery-cli`, should be `W` instead of `Wh` [#9](https://github.com/svartalf/rust-battery/issues/9) - Fix non-uniform path import that was breaking compilation for Rust<1.32 [#6](https://github.com/svartalf/rust-battery/issues/6) - Fix `time_to_empty` and `time_to_full` calculations for Linux when charger is unplugged but driver still reports zero `energy_rate` by [@kerhong](https://github.com/kerhong) [#5](https://github.com/svartalf/rust-battery/pull/5) starship-battery-0.10.0/Cargo.lock0000644000000314250000000000100123770ustar # This file is automatically @generated by Cargo. # It is not intended for manual editing. version = 3 [[package]] name = "approx" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cab112f0a86d568ea0e627cc1d6be74a1e9cd55214684db5561995f6dad897c6" dependencies = [ "num-traits", ] [[package]] name = "autocfg" version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "base64" version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" [[package]] name = "bitflags" version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cfg_aliases" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" [[package]] name = "core-foundation" version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b55271e5c8c478ad3f38ad24ef34923091e0548492a266d19b3c0b4d82574c63" dependencies = [ "core-foundation-sys", "libc", ] [[package]] name = "core-foundation-sys" version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] name = "deranged" version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" dependencies = [ "powerfmt", ] [[package]] name = "dyn-clone" version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" [[package]] name = "equivalent" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" dependencies = [ "libc", "windows-sys 0.52.0", ] [[package]] name = "fastrand" version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" [[package]] name = "hashbrown" version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" [[package]] name = "indexmap" version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" dependencies = [ "equivalent", "hashbrown", ] [[package]] name = "itoa" version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "lazycell" version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" [[package]] name = "linux-raw-sys" version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" [[package]] name = "mach2" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19b955cdeb2a02b9117f121ce63aa52d08ade45de53e48fe6a38b39c10f6f709" dependencies = [ "libc", ] [[package]] name = "memchr" version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "nix" version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "71e2746dc3a24dd78b3cfcb7be93368c6de9963d30f43a6a73998a9cf4b17b46" dependencies = [ "bitflags", "cfg-if", "cfg_aliases", "libc", ] [[package]] name = "num-conv" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" [[package]] name = "num-traits" version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] [[package]] name = "once_cell" version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "plist" version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42cf17e9a1800f5f396bc67d193dc9411b59012a5876445ef450d449881e1016" dependencies = [ "base64", "indexmap", "quick-xml", "serde", "time", ] [[package]] name = "powerfmt" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" [[package]] name = "proc-macro2" version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] [[package]] name = "quick-xml" version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d3a6e5838b60e0e8fa7a43f22ade549a37d61f8bdbe636d0d7816191de969c2" dependencies = [ "memchr", ] [[package]] name = "quote" version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] [[package]] name = "rustix" version = "0.38.36" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f55e80d50763938498dd5ebb18647174e0c76dc38c5505294bb224624f30f36" dependencies = [ "bitflags", "errno", "libc", "linux-raw-sys", "windows-sys 0.52.0", ] [[package]] name = "ryu" version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "schemars" version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09c024468a378b7e36765cd36702b7a90cc3cba11654f6685c8f233408e89e92" dependencies = [ "dyn-clone", "schemars_derive", "serde", "serde_json", ] [[package]] name = "schemars_derive" version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1eee588578aff73f856ab961cd2f79e36bc45d7ded33a7562adba4667aecc0e" dependencies = [ "proc-macro2", "quote", "serde_derive_internals", "syn", ] [[package]] name = "serde" version = "1.0.209" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "99fce0ffe7310761ca6bf9faf5115afbc19688edd00171d81b1bb1b116c63e09" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" version = "1.0.209" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170" dependencies = [ "proc-macro2", "quote", "syn", ] [[package]] name = "serde_derive_internals" version = "0.29.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" dependencies = [ "proc-macro2", "quote", "syn", ] [[package]] name = "serde_json" version = "1.0.128" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" dependencies = [ "itoa", "memchr", "ryu", "serde", ] [[package]] name = "starship-battery" version = "0.10.0" dependencies = [ "approx", "cfg-if", "core-foundation", "lazycell", "libc", "mach2", "nix", "num-traits", "plist", "schemars", "serde", "tempfile", "uom", "windows-sys 0.59.0", ] [[package]] name = "syn" version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] [[package]] name = "tempfile" version = "3.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" dependencies = [ "cfg-if", "fastrand", "once_cell", "rustix", "windows-sys 0.59.0", ] [[package]] name = "time" version = "0.3.36" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" dependencies = [ "deranged", "itoa", "num-conv", "powerfmt", "serde", "time-core", "time-macros", ] [[package]] name = "time-core" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" dependencies = [ "num-conv", "time-core", ] [[package]] name = "typenum" version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "uom" version = "0.36.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ffd36e5350a65d112584053ee91843955826bf9e56ec0d1351214e01f6d7cd9c" dependencies = [ "num-traits", "typenum", ] [[package]] name = "windows-sys" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ "windows-targets", ] [[package]] name = "windows-sys" version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" dependencies = [ "windows-targets", ] [[package]] name = "windows-targets" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", "windows_i686_gnu", "windows_i686_gnullvm", "windows_i686_msvc", "windows_x86_64_gnu", "windows_x86_64_gnullvm", "windows_x86_64_msvc", ] [[package]] name = "windows_aarch64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" [[package]] name = "windows_i686_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" starship-battery-0.10.0/Cargo.toml0000644000000056660000000000100124320ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2021" rust-version = "1.69" name = "starship-battery" version = "0.10.0" authors = ["Starship Contributors"] build = "build.rs" autobins = false autoexamples = false autotests = false autobenches = false description = "Cross-platform information about the notebook batteries" readme = "README.md" keywords = [ "battery", "linux", "macos", "windows", "freebsd", ] categories = ["os"] license = "ISC" repository = "https://github.com/starship/rust-battery" [lib] name = "starship_battery" path = "src/lib.rs" [[example]] name = "all" path = "examples/all.rs" [[example]] name = "oneshot" path = "examples/oneshot.rs" [[example]] name = "simple" path = "examples/simple.rs" [dependencies.cfg-if] version = "1.0" [dependencies.num-traits] version = "0.2.19" default-features = false [dependencies.schemars] version = "0.8.21" optional = true [dependencies.serde] version = "1.0.209" features = ["derive"] optional = true [dependencies.uom] version = "0.36" features = [ "autoconvert", "f32", "si", ] [dev-dependencies.approx] version = "0.5.1" [dev-dependencies.tempfile] version = "^3.12.0" [features] config-schema = [ "schemars", "serde", ] [target.'cfg(any(target_os = "dragonfly", target_os = "freebsd"))'.dependencies.libc] version = "~0.2.158" [target.'cfg(any(target_os = "dragonfly", target_os = "freebsd"))'.dependencies.nix] version = "~0.29.0" features = ["ioctl"] default-features = false [target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies.core-foundation] version = "~0.10.0" [target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies.libc] version = "^0.2.158" [target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies.mach] version = "^0.4.2" package = "mach2" [target.'cfg(target_os = "linux")'.dependencies.lazycell] version = "~1.3" [target.'cfg(target_os = "netbsd")'.dependencies.libc] version = "~0.2.158" [target.'cfg(target_os = "netbsd")'.dependencies.nix] version = "~0.29.0" features = [ "ioctl", "mman", ] default-features = false [target.'cfg(target_os = "netbsd")'.dependencies.plist] version = "~1.7.0" [target.'cfg(target_os = "windows")'.dependencies.windows-sys] version = "0.59.0" features = [ "Win32_Devices", "Win32_Devices_DeviceAndDriverInstallation", "Win32_Foundation", "Win32_Security", "Win32_Storage", "Win32_Storage_FileSystem", "Win32_System", "Win32_System_IO", "Win32_System_Memory", "Win32_System_Power", ] starship-battery-0.10.0/Cargo.toml.orig000064400000000000000000000033561046102023000161050ustar 00000000000000[package] name = "starship-battery" version = "0.10.0" # remember to update html_root_url authors = ["Starship Contributors"] build = "build.rs" categories = ["os"] edition = "2021" keywords = ["battery", "linux", "macos", "windows", "freebsd"] license = "ISC" readme = "README.md" repository = "https://github.com/starship/rust-battery" rust-version = "1.69" description = "Cross-platform information about the notebook batteries" [features] config-schema = ["schemars", "serde"] [dependencies] cfg-if = "1.0" num-traits = { version = "0.2.19", default-features = false } schemars = { version = "0.8.21", optional = true } serde = { version = "1.0.209", features = ["derive"], optional = true } uom = { version = "0.36", features = ["autoconvert", "f32", "si"] } [target.'cfg(target_os = "linux")'.dependencies] lazycell = "~1.3" [target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies] libc = "^0.2.158" mach = { version = "^0.4.2", package = "mach2" } core-foundation = "~0.10.0" [target.'cfg(target_os = "windows")'.dependencies.windows-sys] version = "0.59.0" features = [ "Win32_Devices", "Win32_Devices_DeviceAndDriverInstallation", "Win32_Foundation", "Win32_Security", "Win32_Storage", "Win32_Storage_FileSystem", "Win32_System", "Win32_System_IO", "Win32_System_Memory", "Win32_System_Power", ] [target.'cfg(any(target_os = "dragonfly", target_os = "freebsd"))'.dependencies] libc = "~0.2.158" nix = { version = "~0.29.0", default-features = false, features = ["ioctl"] } [target.'cfg(target_os = "netbsd")'.dependencies] libc = "~0.2.158" nix = { version = "~0.29.0", default-features = false, features = ["ioctl", "mman"] } plist = "~1.7.0" [dev-dependencies] approx = "0.5.1" tempfile = "^3.12.0" starship-battery-0.10.0/Cross.toml000064400000000000000000000005011046102023000151710ustar 00000000000000[build.env] passthrough = [ "RUST_BACKTRACE", "RUST_LOG", ] # Fix already here https://github.com/cross-rs/cross/blob/main/docker/netbsd.sh # But no new release so temporary fix here instead # Remove once next cross release is out [target.x86_64-unknown-netbsd] image = "ghcr.io/cross-rs/x86_64-unknown-netbsd:main" starship-battery-0.10.0/LICENSE000064400000000000000000000013661046102023000142220ustar 00000000000000ISC License Copyright (c) 2019-2021, Starship Contributors Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. starship-battery-0.10.0/README.md000064400000000000000000000062211046102023000144670ustar 00000000000000# battery [![Latest Version](https://img.shields.io/crates/v/starship-battery.svg)](https://crates.io/crates/starship-battery) [![Latest Version](https://docs.rs/starship-battery/badge.svg)](https://docs.rs/starship-battery) [![Build Status](https://github.com/starship/rust-battery/workflows/Continuous%20integration/badge.svg)](https://github.com/starship/rust-battery/actions?workflow=Continuous+integration) ![Minimum rustc version](https://img.shields.io/badge/rustc-1.69+-yellow.svg) ![ISC licensed](https://img.shields.io/badge/license-ISC-blue.svg) > Rust crate providing cross-platform information about the notebook batteries. ## Table of contents - [Overview](#overview) - [Supported platforms](#supported-platforms) - [Install](#install) - [Examples](#examples) - [FFI bindings](#ffi-bindings) - [Users](#users) - [License](#license) - [Donations](#donations) - [Contributors](#contributors) - [Backers](#backers) - [Sponsors](#sponsors) ## Overview `battery` provides a cross-platform unified API to a notebook batteries state. Its main goal is to wrap the OS-specific interfaces, cover all the hacks and legacy cases and get the batteries information (such as state of charge, energy rate, voltage and temperature) as a typed values, recalculated as necessary to be returned as a [SI measurement units](https://www.bipm.org/en/measurement-units/). ## Supported platforms - Linux 2.6.39+ - MacOS 10.10+ - iOS - Windows 7+ - FreeBSD - DragonFlyBSD - NetBSD Do note that iOS implementation uses IOKit bindings, your application might be automatically rejected by Apple based on that fact. Use it on your own risk. ## Install As a prerequisite, `battery` crate requires at least Rustc version **1.69** or greater. Add the following line into a `Cargo.toml`: ```toml [dependencies] battery = "0.8.3" ``` ## Examples ```rust fn main() -> Result<(), battery::Error> { let manager = battery::Manager::new()?; for (idx, maybe_battery) in manager.batteries()?.enumerate() { let battery = maybe_battery?; println!("Battery #{}:", idx); println!("Vendor: {:?}", battery.vendor()); println!("Model: {:?}", battery.model()); println!("State: {:?}", battery.state()); println!("Time to full charge: {:?}", battery.time_to_full()); println!(""); } Ok(()) } ``` See the `battery/examples/` folder in the [repository](https://github.com/starship/rust-battery/blob/main/battery/examples/simple.rs) for additional examples. ## Users This an incomplete list of the `battery` crate users. If you are using it too, send me a message and I'll add your project here! ### starship [`starship`](https://github.com/starship/starship) is a Rust port of the minimalistic, powerful, and extremely customizable prompt Spaceship ZSH.\ It is using the `battery` crate to show the the current battery level and status in a shell prompt. Here is what [@matchai](https://github.com/matchai) says: > I really appreciate how easily we were able to get your library up and running! > Battery APIs were a headache for us in predecessors of this project 😅 And there is [this tweet](https://twitter.com/matchai/status/1135906726392283136) also! starship-battery-0.10.0/build.rs000064400000000000000000000003431046102023000146540ustar 00000000000000use std::env; fn main() { match env::var("CARGO_CFG_TARGET_OS").as_ref().map(|x| &**x) { Ok("macos") | Ok("ios") => { println!("cargo:rustc-link-lib=framework=IOKit"); } _ => {} } } starship-battery-0.10.0/deny.toml000064400000000000000000000011151046102023000150410ustar 00000000000000[graph] all-features = true [advisories] version = 2 # A list of advisory IDs to ignore. Note that ignored advisories will still # output a note when they are encountered. ignore = [ # { id = "RUSTSEC-0000-0000", reason = "" }, ] [licenses] version = 2 # List of explicitly allowed licenses allow = [ "Apache-2.0", "ISC", "MIT", "Unicode-DFS-2016", ] confidence-threshold = 0.8 [bans] multiple-versions = "allow" wildcards = "warn" [sources] unknown-registry = "warn" unknown-git = "warn" allow-registry = ["https://github.com/rust-lang/crates.io-index"] allow-git = [] starship-battery-0.10.0/examples/all.rs000064400000000000000000000013711046102023000161450ustar 00000000000000extern crate starship_battery as battery; use std::thread; use std::time::Duration; use std::vec::Vec; use battery::Battery; fn main() -> battery::Result<()> { let manager = battery::Manager::new()?; let mut vc: Vec = Vec::::new(); let iter = manager.batteries()?; for bat in iter { vc.push(match bat { Ok(battery) => battery, Err(e) => { eprintln!("Unable to access battery information"); return Err(e); } }) } loop { for bat in &mut vc { println!("{:?}", bat); thread::sleep(Duration::from_secs(1)); manager.refresh(bat)?; } println!("Back to the beginning") } } starship-battery-0.10.0/examples/oneshot.rs000064400000000000000000000010621046102023000170510ustar 00000000000000extern crate starship_battery as battery; use std::io; fn main() -> battery::Result<()> { let manager = battery::Manager::new()?; let battery = match manager.batteries()?.next() { Some(Ok(battery)) => battery, Some(Err(e)) => { eprintln!("Unable to access battery information"); return Err(e); } None => { eprintln!("Unable to find any batteries"); return Err(io::Error::from(io::ErrorKind::NotFound).into()); } }; println!("{:?}", battery); Ok(()) } starship-battery-0.10.0/examples/simple.rs000064400000000000000000000013011046102023000166570ustar 00000000000000extern crate starship_battery as battery; use std::io; use std::thread; use std::time::Duration; fn main() -> battery::Result<()> { let manager = battery::Manager::new()?; let mut battery = match manager.batteries()?.next() { Some(Ok(battery)) => battery, Some(Err(e)) => { eprintln!("Unable to access battery information"); return Err(e); } None => { eprintln!("Unable to find any batteries"); return Err(io::Error::from(io::ErrorKind::NotFound).into()); } }; loop { println!("{:?}", battery); thread::sleep(Duration::from_secs(1)); manager.refresh(&mut battery)?; } } starship-battery-0.10.0/src/errors.rs000064400000000000000000000050511046102023000156610ustar 00000000000000//! Errors handling use std::borrow::Cow; use std::error::Error as StdError; use std::fmt; use std::io; use std::result; pub type Result = result::Result; /// Battery routines error. /// /// Since all operations are basically I/O of some kind, /// this is a thin wrapper around `::std::io::Error` with option /// to store custom description for debugging purposes. #[derive(Debug)] pub struct Error { source: io::Error, description: Option>, } impl Error { #[allow(unused)] pub(crate) fn new(e: io::Error, description: T) -> Error where T: Into>, { Error { source: e, description: Some(description.into()), } } #[allow(unused)] pub(crate) fn not_found(description: T) -> Error where T: Into>, { Error { source: io::Error::from(io::ErrorKind::NotFound), description: Some(description.into()), } } #[allow(unused)] pub(crate) fn invalid_data(description: T) -> Error where T: Into>, { Error { source: io::Error::from(io::ErrorKind::InvalidData), description: Some(description.into()), } } } impl StdError for Error { fn source(&self) -> Option<&(dyn StdError + 'static)> { Some(&self.source) } } impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match &self.description { Some(desc) => write!(f, "{}", desc), None => self.source.fmt(f), } } } impl From for Error { fn from(e: io::Error) -> Self { Error { source: e, description: None, } } } #[cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd"))] mod nix_impl { use std::io; use super::Error; impl From for Error { fn from(errno: nix::Error) -> Self { Error { source: io::Error::from_raw_os_error(errno as i32), description: Some(errno.desc().into()), } } } } #[cfg(target_os = "netbsd")] mod plist_impl { use super::Error; impl From for Error { fn from(e: plist::Error) -> Self { let desc = e.to_string(); match e.into_io() { Ok(ioerr) => Error::new(ioerr, desc), Err(_) => Error::invalid_data("Problem while processing plist"), } } } } starship-battery-0.10.0/src/lib.rs000064400000000000000000000024621046102023000151160ustar 00000000000000//! This crate provides cross-platform information about batteries. //! //! Gives access to a system independent battery state, capacity, charge and voltage values //! recalculated as necessary to be returned in [SI measurement units](https://www.bipm.org/en/measurement-units/). //! //! ## Supported platforms //! //! * Linux 2.6.39+ //! * MacOS 10.10+ //! * Windows 7+ //! * FreeBSD //! * DragonFlyBSD //! * NetBSD //! //! ## Examples //! //! For a quick example see the [Manager](struct.Manager.html) type documentation //! or [`simple.rs`](https://github.com/starship/rust-battery/blob/main/battery/examples/simple.rs) //! file in the `examples/` folder. //! //! [battop](https://crates.io/crates/battop) crate is using this library as a knowledge source, //! so check it out too for a real-life example. #![deny(unused)] #![deny(unstable_features)] #![deny(bare_trait_objects)] #![doc(html_root_url = "https://docs.rs/starship-battery/0.7.9")] #[macro_use] extern crate cfg_if; #[cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd"))] #[macro_use] extern crate nix; #[cfg(target_os = "netbsd")] extern crate plist; mod types; #[macro_use] pub mod units; pub mod errors; mod platform; pub use self::errors::{Error, Result}; pub use self::types::{Batteries, Battery, Manager, State, Technology}; starship-battery-0.10.0/src/platform/darwin/device.rs000064400000000000000000000056471046102023000207270ustar 00000000000000// For keys reference see: https://developer.apple.com/documentation/kernel/iopmpowersource?language=objc // Additional keys worth to implement later: // * "ChargerData" -> // - ChargingVoltage // - ChargingCurrent // - NotChargingReason (?) use num_traits::identities::Zero; use std::boxed::Box; use std::fmt; use std::str; use super::traits::DataSource; use crate::platform::traits::BatteryDevice; use crate::types::{State, Technology}; use crate::units::{ElectricPotential, Energy, Power, ThermodynamicTemperature, Time}; use crate::Result; pub struct IoKitDevice { source: Box, } impl IoKitDevice { pub fn get_mut_ref(&mut self) -> &mut dyn DataSource { &mut self.source } pub fn refresh(&mut self) -> Result<()> { self.source.refresh() } } impl BatteryDevice for IoKitDevice { fn energy(&self) -> Energy { self.source.current_capacity() * self.source.voltage() } fn energy_full(&self) -> Energy { self.source.max_capacity() * self.source.voltage() } fn energy_full_design(&self) -> Energy { self.source.design_capacity() * self.source.voltage() } fn energy_rate(&self) -> Power { self.source.amperage() * self.source.voltage() } fn state(&self) -> State { match () { _ if !self.source.external_connected() => State::Discharging, _ if self.source.is_charging() => State::Charging, _ if self.source.current_capacity().is_zero() => State::Empty, _ if self.source.fully_charged() => State::Full, _ => State::Unknown, } } fn voltage(&self) -> ElectricPotential { self.source.voltage() } fn temperature(&self) -> Option { self.source.temperature() } fn vendor(&self) -> Option<&str> { self.source.manufacturer() } fn model(&self) -> Option<&str> { self.source.device_name() } fn serial_number(&self) -> Option<&str> { self.source.serial_number() } fn technology(&self) -> Technology { Technology::Unknown } fn cycle_count(&self) -> Option { self.source.cycle_count() } fn time_to_full(&self) -> Option