From 2705b08dca22af7ec798c3b795e92f222831e4ec Mon Sep 17 00:00:00 2001 From: "Luke D. Jones" Date: Sun, 4 Dec 2022 21:49:47 +1300 Subject: [PATCH] Cause great pain to self with cargo-deny + cargo-cranky --- .gitlab-ci.yml | 42 +++- Cargo.lock | 194 +++++++++++++----- Cargo.toml | 8 +- Cranky.toml | 121 +++++++++++ Makefile | 2 +- asusctl/Cargo.toml | 1 + asusctl/src/aura_cli.rs | 2 +- asusctl/src/main.rs | 42 ++-- daemon-user/Cargo.toml | 3 +- daemon-user/src/ctrl_anime.rs | 18 +- daemon-user/src/error.rs | 2 +- daemon-user/src/user_config.rs | 8 +- daemon/Cargo.toml | 4 +- daemon/src/ctrl_anime/mod.rs | 35 ++-- daemon/src/ctrl_anime/trait_impls.rs | 4 +- daemon/src/ctrl_profiles/config.rs | 3 +- daemon/src/ctrl_profiles/mod.rs | 2 +- daemon/src/ctrl_profiles/trait_impls.rs | 12 +- daemon/src/error.rs | 4 +- daemon/src/lib.rs | 2 +- deny.toml | 69 +++++++ rog-anime/Cargo.toml | 4 +- rog-anime/src/data.rs | 16 +- rog-anime/src/diagonal.rs | 32 +-- rog-anime/src/error.rs | 2 +- rog-anime/src/grid.rs | 2 +- rog-anime/src/image.rs | 18 +- rog-anime/src/lib.rs | 4 +- rog-anime/src/sequencer.rs | 6 +- rog-anime/src/usb.rs | 4 +- rog-aura/Cargo.toml | 4 +- rog-aura/src/builtin_modes.rs | 63 ++---- rog-aura/src/error.rs | 2 +- rog-aura/src/key_to_str.rs | 22 +- rog-aura/src/keys.rs | 26 +-- rog-aura/src/layouts/g513.rs | 2 +- rog-aura/src/layouts/ga401.rs | 2 +- rog-aura/src/layouts/gx502.rs | 2 +- rog-aura/src/layouts/mod.rs | 4 +- rog-aura/src/per_zone.rs | 3 +- rog-aura/src/sequencer/mod.rs | 6 +- rog-aura/src/usb.rs | 20 +- rog-control-center/Cargo.toml | 5 +- rog-control-center/src/error.rs | 2 +- rog-control-center/src/main.rs | 2 +- rog-control-center/src/notify.rs | 11 +- .../src/pages/fan_curve_page.rs | 4 +- rog-control-center/src/system_state.rs | 31 ++- rog-control-center/src/tray.rs | 20 +- rog-control-center/src/widgets/aura_power.rs | 2 +- rog-control-center/src/widgets/fan_graph.rs | 10 +- rog-control-center/src/widgets/rog_bios.rs | 4 +- rog-dbus/src/lib.rs | 4 +- rog-platform/Cargo.toml | 3 +- rog-platform/src/error.rs | 2 +- rog-platform/src/lib.rs | 8 +- rog-platform/src/platform.rs | 12 +- rog-platform/src/power.rs | 12 +- rog-platform/src/usb_raw.rs | 4 +- rog-profiles/Cargo.toml | 3 +- 60 files changed, 622 insertions(+), 339 deletions(-) create mode 100644 Cranky.toml create mode 100644 deny.toml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0143f747..558658ce 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,27 +1,57 @@ image: rust:latest +cache: + key: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG" + paths: + # Don't include `incremental` to save space + # Debug + - target/debug/build/ + - target/debug/deps/ + - target/debug/.fingerprint/ + - target/debug/.cargo-lock + - target/debug/df_storyteller + # Release + - target/release/build/ + - target/release/deps/ + - target/release/.fingerprint/ + - target/release/.cargo-lock + before_script: - apt-get update -qq && apt-get install -y -qq libudev-dev libgtk-3-dev stages: + - format + - check - test - - build + - release -test: +format: + image: rust:latest + script: + - echo "nightly" > rust-toolchain + - rustup component add rustfmt + - cargo fmt --check + +check: script: - rustup component add clippy - cargo check - - cargo clippy + # deny currently catches too much + #- cargo install cargo-deny && cargo deny + - cargo install cargo-cranky && cargo cranky + +test: + script: - cargo test -build: +release: only: - - main + - tags script: - make && make vendor artifacts: paths: - - vendor_asus-nb-ctrl_*.tar.xz + - vendor_asusctl_*.tar.xz - cargo-config variables: diff --git a/Cargo.lock b/Cargo.lock index 1cb2cd58..4d019ab0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -271,17 +271,6 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73b5e5f48b927f04e952dedc932f31995a65a0bf65ec971c74436e51bf6e970d" -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi", - "libc", - "winapi", -] - [[package]] name = "autocfg" version = "1.1.0" @@ -398,7 +387,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5bcf530afb40e45e14440701e5e996d7fd139e84a912a4d83a8d6a0fb3e58663" dependencies = [ "log", - "nix 0.25.0", + "nix 0.25.1", "slotmap", "thiserror", "vec_map", @@ -870,7 +859,7 @@ dependencies = [ "bytemuck", "egui", "glow", - "memoffset", + "memoffset 0.6.5", "tracing", "wasm-bindgen", "web-sys", @@ -930,12 +919,12 @@ dependencies = [ [[package]] name = "env_logger" -version = "0.9.3" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7" +checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0" dependencies = [ - "atty", "humantime", + "is-terminal", "log", "regex", "termcolor", @@ -955,6 +944,27 @@ dependencies = [ "parking_lot", ] +[[package]] +name = "errno" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" +dependencies = [ + "errno-dragonfly", + "libc", + "winapi", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "error-code" version = "2.3.1" @@ -996,7 +1006,7 @@ version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e1c54951450cbd39f3dbcf1005ac413b49487dabf18a720ad2383eccfeffb92" dependencies = [ - "memoffset", + "memoffset 0.6.5", "rustc_version", ] @@ -1265,9 +1275,9 @@ dependencies = [ [[package]] name = "gif" -version = "0.11.4" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3edd93c6756b4dfaf2709eafcc345ba2636565295c198a9cfbf75fa5e3e00b06" +checksum = "80792593675e051cf94a4b111980da2ba60d4a83e43e0048c5693baab3977045" dependencies = [ "color_quant", "weezl", @@ -1555,6 +1565,15 @@ dependencies = [ "libc", ] +[[package]] +name = "hermit-abi" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" +dependencies = [ + "libc", +] + [[package]] name = "hex" version = "0.4.3" @@ -1617,6 +1636,28 @@ dependencies = [ "web-sys", ] +[[package]] +name = "io-lifetimes" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46112a93252b123d31a119a8d1a1ac19deac4fac6e0e8b0df58f0d4e5870e63c" +dependencies = [ + "libc", + "windows-sys 0.42.0", +] + +[[package]] +name = "is-terminal" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "927609f78c2913a6f6ac3c27a4fe87f43e2a35367c0c4b0f8265e8f49a104330" +dependencies = [ + "hermit-abi 0.2.6", + "io-lifetimes", + "rustix", + "windows-sys 0.42.0", +] + [[package]] name = "itoa" version = "1.0.4" @@ -1726,6 +1767,12 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "linux-raw-sys" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f9f08d8963a6c613f4b1a78f4f4a4dbfadf8e6545b2d72861731e4858b8b47f" + [[package]] name = "lock_api" version = "0.4.9" @@ -1801,6 +1848,15 @@ dependencies = [ "autocfg", ] +[[package]] +name = "memoffset" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4" +dependencies = [ + "autocfg", +] + [[package]] name = "micromath" version = "1.1.1" @@ -1904,46 +1960,50 @@ dependencies = [ [[package]] name = "nix" -version = "0.24.2" +version = "0.24.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "195cdbc1741b8134346d515b3a56a1c94b0912758009cfd53f99ea0f57b065fc" +checksum = "fa52e972a9a719cecb6864fb88568781eb706bac2cd1d4f04a648542dbf78069" dependencies = [ "bitflags", "cfg-if", "libc", - "memoffset", + "memoffset 0.6.5", ] [[package]] name = "nix" -version = "0.25.0" +version = "0.25.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e322c04a9e3440c327fca7b6c8a63e6890a32fa2ad689db972425f07e0d22abb" +checksum = "f346ff70e7dbfd675fe90590b92d59ef2de15a8779ae305ebcbfd3f0caf59be4" dependencies = [ "autocfg", "bitflags", "cfg-if", "libc", - "memoffset", + "memoffset 0.6.5", "pin-utils", ] +[[package]] +name = "nix" +version = "0.26.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46a58d1d356c6597d08cde02c2f09d785b09e28711837b1ed667dc652c08a694" +dependencies = [ + "bitflags", + "cfg-if", + "libc", + "memoffset 0.7.1", + "pin-utils", + "static_assertions", +] + [[package]] name = "nohash-hasher" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451" -[[package]] -name = "nom" -version = "6.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7413f999671bd4745a7b624bd370a569fb6bc574b23c83a3c5ed2e453f3d5e2" -dependencies = [ - "memchr", - "version_check", -] - [[package]] name = "nom" version = "7.1.1" @@ -1980,7 +2040,7 @@ version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6058e64324c71e02bc2b150e4f3bc8286db6c83092132ffa3f6b1eab0f9def5" dependencies = [ - "hermit-abi", + "hermit-abi 0.1.19", "libc", ] @@ -2048,9 +2108,9 @@ checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" [[package]] name = "ordered-stream" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "034ce384018b245e8d8424bbe90577fbd91a533be74107e465e3474eb2285eef" +checksum = "01ca8c99d73c6e92ac1358f9f692c22c0bfd9c4701fa086f5d365c0d4ea818ea" dependencies = [ "futures-core", "pin-project-lite", @@ -2136,9 +2196,9 @@ checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" [[package]] name = "pest" -version = "2.5.0" +version = "2.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f400b0f7905bf702f9f3dc3df5a121b16c54e9e8012c082905fdf09a931861a" +checksum = "cc8bed3549e0f9b0a2a78bf7c0018237a2cdf085eecbbc048e52612438e4e9d0" dependencies = [ "thiserror", "ucd-trie", @@ -2378,7 +2438,7 @@ dependencies = [ "gtk", "libappindicator", "log", - "nix 0.25.0", + "nix 0.26.1", "notify-rust", "png_pong", "rog_anime", @@ -2445,7 +2505,7 @@ dependencies = [ "serde", "serde_derive", "sysfs-class", - "udev", + "udev 0.7.0", "zbus", ] @@ -2455,7 +2515,7 @@ version = "4.5.2" dependencies = [ "serde", "serde_derive", - "udev", + "udev 0.7.0", "zbus", ] @@ -2478,6 +2538,20 @@ dependencies = [ "semver", ] +[[package]] +name = "rustix" +version = "0.36.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb93e85278e08bb5788653183213d3a60fc242b10cb9be96586f5a73dcb67c23" +dependencies = [ + "bitflags", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys", + "windows-sys 0.42.0", +] + [[package]] name = "ryu" version = "1.0.11" @@ -2683,7 +2757,7 @@ dependencies = [ "lazy_static", "log", "memmap2", - "nix 0.24.2", + "nix 0.24.3", "pkg-config", "wayland-client", "wayland-cursor", @@ -2777,7 +2851,7 @@ dependencies = [ "serde_derive", "serde_json", "tokio", - "udev", + "udev 0.6.3", "zbus", "zvariant", "zvariant_derive", @@ -2913,12 +2987,11 @@ dependencies = [ [[package]] name = "tinybmp" -version = "0.3.3" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44873aee48dd30712dc2610209902a78b9033a0148ac03c6c3e73e4ca2f49838" +checksum = "0e959c507975d768a226a08227d56791f6e60bddcf714ad7ef67ae2d20bae743" dependencies = [ "embedded-graphics", - "nom 6.1.2", ] [[package]] @@ -3033,6 +3106,17 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "udev" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ebdbbd670373442a12fe9ef7aeb53aec4147a5a27a00bbc3ab639f08f48191a" +dependencies = [ + "libc", + "libudev-sys", + "pkg-config", +] + [[package]] name = "uds_windows" version = "1.0.2" @@ -3203,7 +3287,7 @@ dependencies = [ "bitflags", "downcast-rs", "libc", - "nix 0.24.2", + "nix 0.24.3", "scoped-tls", "wayland-commons", "wayland-scanner", @@ -3216,7 +3300,7 @@ version = "0.29.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8691f134d584a33a6606d9d717b95c4fa20065605f798a3f350d78dced02a902" dependencies = [ - "nix 0.24.2", + "nix 0.24.3", "once_cell", "smallvec", "wayland-sys", @@ -3228,7 +3312,7 @@ version = "0.29.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6865c6b66f13d6257bef1cd40cbfe8ef2f150fb8ebbdb1e8e873455931377661" dependencies = [ - "nix 0.24.2", + "nix 0.24.3", "wayland-client", "xcursor", ] @@ -3567,7 +3651,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "592b4883219f345e712b3209c62654ebda0bb50887f330cbd018d0f654bfd507" dependencies = [ "gethostname", - "nix 0.24.2", + "nix 0.24.3", "winapi", "winapi-wsapoll", "x11rb-protocol", @@ -3579,7 +3663,7 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56b245751c0ac9db0e006dc812031482784e434630205a93c73cfefcaabeac67" dependencies = [ - "nix 0.24.2", + "nix 0.24.3", ] [[package]] @@ -3588,7 +3672,7 @@ version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "463705a63313cd4301184381c5e8042f0a7e9b4bb63653f216311d4ae74690b7" dependencies = [ - "nom 7.1.1", + "nom", ] [[package]] @@ -3620,7 +3704,7 @@ dependencies = [ "futures-sink", "futures-util", "hex", - "nix 0.25.0", + "nix 0.25.1", "once_cell", "ordered-stream", "rand", diff --git a/Cargo.toml b/Cargo.toml index c1ff1e1d..14acc040 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,19 +20,19 @@ serde_json = "^1.0" toml = "^0.5.9" log = "^0.4" -env_logger = "^0.9.3" +env_logger = "^0.10.0" glam = { version = "^0.22", features = ["serde"] } gumdrop = "^0.8" -udev = "^0.6" +udev = "^0.7" rusb = "^0.9" sysfs-class = "^0.1.3" inotify = "^0.10.0" png_pong = "^0.8" pix = "^0.13" -tinybmp = "^0.3" -gif = "^0.11" +tinybmp = "^0.4.0" +gif = "^0.12.0" notify-rust = { git = "https://github.com/flukejones/notify-rust.git", default-features = false, features = ["z"] } diff --git a/Cranky.toml b/Cranky.toml new file mode 100644 index 00000000..34342341 --- /dev/null +++ b/Cranky.toml @@ -0,0 +1,121 @@ +# https://github.com/ericseppanen/cargo-cranky +# cargo install cargo-cranky && cargo cranky + +warn = [ + "clippy::all", + "clippy::await_holding_lock", + "clippy::bool_to_int_with_if", + "clippy::char_lit_as_u8", + "clippy::checked_conversions", + "clippy::dbg_macro", + "clippy::debug_assert_with_mut_call", + "clippy::disallowed_methods", + "clippy::disallowed_script_idents", + "clippy::doc_link_with_quotes", + "clippy::doc_markdown", + "clippy::empty_enum", + "clippy::enum_glob_use", + "clippy::equatable_if_let", + "clippy::exit", + "clippy::expl_impl_clone_on_copy", + "clippy::explicit_deref_methods", + "clippy::explicit_into_iter_loop", + "clippy::explicit_iter_loop", + "clippy::fallible_impl_from", + "clippy::filter_map_next", + "clippy::flat_map_option", + "clippy::float_cmp_const", + "clippy::fn_params_excessive_bools", + "clippy::fn_to_numeric_cast_any", + "clippy::from_iter_instead_of_collect", + "clippy::if_let_mutex", + "clippy::implicit_clone", + "clippy::imprecise_flops", + "clippy::index_refutable_slice", + "clippy::inefficient_to_string", + "clippy::invalid_upcast_comparisons", + "clippy::iter_not_returning_iterator", + "clippy::iter_on_empty_collections", + "clippy::iter_on_single_items", + "clippy::large_digit_groups", + "clippy::large_stack_arrays", + "clippy::large_types_passed_by_value", + "clippy::let_unit_value", + "clippy::linkedlist", + "clippy::lossy_float_literal", + "clippy::macro_use_imports", + "clippy::manual_assert", + "clippy::manual_instant_elapsed", + "clippy::manual_ok_or", + "clippy::manual_string_new", + "clippy::map_err_ignore", + "clippy::map_flatten", + "clippy::map_unwrap_or", + "clippy::match_on_vec_items", + "clippy::match_same_arms", + "clippy::match_wild_err_arm", + "clippy::match_wildcard_for_single_variants", + "clippy::mem_forget", + "clippy::mismatched_target_os", + "clippy::mismatching_type_param_order", + "clippy::missing_enforced_import_renames", + # "clippy::missing_errors_doc", + "clippy::missing_safety_doc", + "clippy::mut_mut", + "clippy::mutex_integer", + "clippy::needless_borrow", + "clippy::needless_continue", + "clippy::needless_for_each", + "clippy::needless_pass_by_value", + "clippy::negative_feature_names", + "clippy::nonstandard_macro_braces", + "clippy::option_option", + "clippy::path_buf_push_overwrite", + "clippy::ptr_as_ptr", + "clippy::rc_mutex", + "clippy::ref_option_ref", + "clippy::rest_pat_in_fully_bound_structs", + "clippy::same_functions_in_if_condition", + "clippy::semicolon_if_nothing_returned", + "clippy::single_match_else", + "clippy::str_to_string", + "clippy::string_add_assign", + "clippy::string_add", + "clippy::string_lit_as_bytes", + "clippy::string_to_string", + "clippy::todo", + "clippy::trailing_empty_array", + "clippy::trait_duplication_in_bounds", + "clippy::unimplemented", + "clippy::unnecessary_wraps", + "clippy::unnested_or_patterns", + "clippy::unused_peekable", + "clippy::unused_rounding", + # "clippy::unused_self", + "clippy::useless_transmute", + "clippy::verbose_file_reads", + "clippy::zero_sized_map_values", + "elided_lifetimes_in_paths", + "future_incompatible", + "nonstandard_style", + "rust_2018_idioms", + "rust_2021_prelude_collisions", + "rustdoc::missing_crate_level_docs", + "semicolon_in_expressions_from_macros", + "trivial_numeric_casts", + "unused_extern_crates", + "unused_import_braces", + "unused_lifetimes", +] + +allow = [ + # TODO(emilk): enable more lints + "clippy::cloned_instead_of_copied", + "clippy::derive_partial_eq_without_eq", + "clippy::type_complexity", + "clippy::undocumented_unsafe_blocks", + "trivial_casts", + "unsafe_op_in_unsafe_fn", # `unsafe_op_in_unsafe_fn` may become the default in future Rust versions: https://github.com/rust-lang/rust/issues/71668 + "unused_qualifications", +] + diff --git a/Makefile b/Makefile index 1fd72200..400c7a7f 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION := $(shell grep -Pm1 'version = "(\d.\d.\d)"' daemon/Cargo.toml | cut -d'"' -f2) +VERSION := $(shell /usr/bin/grep -Pm1 'version = "(\d.\d.\d)"' Cargo.toml | cut -d'"' -f2) INSTALL = install INSTALL_PROGRAM = ${INSTALL} -D -m 0755 diff --git a/asusctl/Cargo.toml b/asusctl/Cargo.toml index fda28a97..f3c5a8bc 100644 --- a/asusctl/Cargo.toml +++ b/asusctl/Cargo.toml @@ -1,5 +1,6 @@ [package] name = "asusctl" +license = "MPL-2.0" authors = ["Luke D Jones "] edition = "2021" version.workspace = true diff --git a/asusctl/src/aura_cli.rs b/asusctl/src/aura_cli.rs index 5d405afc..98b92c0f 100644 --- a/asusctl/src/aura_cli.rs +++ b/asusctl/src/aura_cli.rs @@ -105,7 +105,7 @@ impl ToString for LedBrightness { Some(0x02) => "high", _ => "unknown", }; - s.to_string() + s.to_owned() } } diff --git a/asusctl/src/main.rs b/asusctl/src/main.rs index 970ea018..f080fd94 100644 --- a/asusctl/src/main.rs +++ b/asusctl/src/main.rs @@ -134,9 +134,9 @@ fn do_parsed( Some(CliCommand::LedPow2(pow)) => handle_led_power2(dbus, &supported.keyboard_led, pow)?, Some(CliCommand::Profile(cmd)) => handle_profile(dbus, &supported.platform_profile, cmd)?, Some(CliCommand::FanCurve(cmd)) => { - handle_fan_curve(dbus, &supported.platform_profile, cmd)? + handle_fan_curve(dbus, &supported.platform_profile, cmd)?; } - Some(CliCommand::Graphics(_)) => do_gfx()?, + Some(CliCommand::Graphics(_)) => do_gfx(), Some(CliCommand::Anime(cmd)) => handle_anime(dbus, &supported.anime_ctrl, cmd)?, Some(CliCommand::Bios(cmd)) => handle_bios_option(dbus, &supported.rog_bios_ctrl, cmd)?, None => { @@ -214,14 +214,13 @@ fn do_parsed( Ok(()) } -fn do_gfx() -> Result<(), Box> { +fn do_gfx() { println!("Please use supergfxctl for graphics switching. supergfxctl is the result of making asusctl graphics switching generic so all laptops can use it"); println!("This command will be removed in future"); - Ok(()) } fn handle_anime( - dbus: &RogDbusClientBlocking, + dbus: &RogDbusClientBlocking<'_>, _supported: &AnimeSupportedFunctions, cmd: &AnimeCommand, ) -> Result<(), Box> { @@ -237,14 +236,14 @@ fn handle_anime( } } if let Some(anime_turn) = cmd.enable { - dbus.proxies().anime().set_on_off(anime_turn)? + dbus.proxies().anime().set_on_off(anime_turn)?; } if let Some(anime_boot) = cmd.boot_enable { - dbus.proxies().anime().set_boot_on_off(anime_boot)? + dbus.proxies().anime().set_boot_on_off(anime_boot)?; } if let Some(bright) = cmd.brightness { verify_brightness(bright); - dbus.proxies().anime().set_brightness(bright)? + dbus.proxies().anime().set_brightness(bright)?; } if cmd.clear { let anime_type = get_anime_type()?; @@ -381,7 +380,7 @@ fn verify_brightness(brightness: f32) { } fn handle_led_mode( - dbus: &RogDbusClientBlocking, + dbus: &RogDbusClientBlocking<'_>, supported: &LedSupportedFunctions, mode: &LedModeCommand, ) -> Result<(), Box> { @@ -438,7 +437,7 @@ fn handle_led_mode( } fn handle_led_power1( - dbus: &RogDbusClientBlocking, + dbus: &RogDbusClientBlocking<'_>, supported: &LedSupportedFunctions, power: &LedPowerCommand1, ) -> Result<(), Box> { @@ -473,7 +472,7 @@ fn handle_led_power1( } fn handle_led_power_1_do_1866( - dbus: &RogDbusClientBlocking, + dbus: &RogDbusClientBlocking<'_>, power: &LedPowerCommand1, ) -> Result<(), Box> { let mut enabled: Vec = Vec::new(); @@ -513,7 +512,7 @@ fn handle_led_power_1_do_1866( } fn handle_led_power_1_do_tuf( - dbus: &RogDbusClientBlocking, + dbus: &RogDbusClientBlocking<'_>, power: &LedPowerCommand1, ) -> Result<(), Box> { let mut enabled: Vec = Vec::new(); @@ -552,7 +551,7 @@ fn handle_led_power_1_do_tuf( } fn handle_led_power2( - dbus: &RogDbusClientBlocking, + dbus: &RogDbusClientBlocking<'_>, supported: &LedSupportedFunctions, power: &LedPowerCommand2, ) -> Result<(), Box> { @@ -564,8 +563,8 @@ fn handle_led_power2( println!("Commands available"); if let Some(cmdlist) = LedPowerCommand2::command_list() { - let commands: Vec = cmdlist.lines().map(|s| s.to_string()).collect(); - for command in commands.iter() { + let commands: Vec = cmdlist.lines().map(|s| s.to_owned()).collect(); + for command in &commands { println!("{}", command); } } @@ -581,7 +580,7 @@ fn handle_led_power2( } if supported.prod_id != AuraDevice::X19B6 { - println!("This option applies only to keyboards with product ID 0x19b6") + println!("This option applies only to keyboards with product ID 0x19b6"); } let mut enabled: Vec = Vec::new(); @@ -646,7 +645,7 @@ fn handle_led_power2( } fn handle_profile( - dbus: &RogDbusClientBlocking, + dbus: &RogDbusClientBlocking<'_>, supported: &PlatformProfileFunctions, cmd: &ProfileCommand, ) -> Result<(), Box> { @@ -687,7 +686,7 @@ fn handle_profile( } fn handle_fan_curve( - dbus: &RogDbusClientBlocking, + dbus: &RogDbusClientBlocking<'_>, supported: &PlatformProfileFunctions, cmd: &FanCurveCommand, ) -> Result<(), Box> { @@ -749,7 +748,7 @@ fn handle_fan_curve( } fn handle_bios_option( - dbus: &RogDbusClientBlocking, + dbus: &RogDbusClientBlocking<'_>, supported: &RogBiosSupportedFunctions, cmd: &BiosCommand, ) -> Result<(), Box> { @@ -764,10 +763,7 @@ fn handle_bios_option( { println!("Missing arg or command\n"); - let usage: Vec = BiosCommand::usage() - .lines() - .map(|s| s.to_string()) - .collect(); + let usage: Vec = BiosCommand::usage().lines().map(|s| s.to_owned()).collect(); for line in usage.iter().filter(|line| { line.contains("sound") && supported.post_sound diff --git a/daemon-user/Cargo.toml b/daemon-user/Cargo.toml index 78e6a3d3..0126276c 100644 --- a/daemon-user/Cargo.toml +++ b/daemon-user/Cargo.toml @@ -1,5 +1,6 @@ [package] name = "daemon-user" +license = "MPL-2.0" version.workspace = true authors = ["Luke D Jones "] edition = "2021" @@ -27,4 +28,4 @@ rog_aura = { path = "../rog-aura" } rog_dbus = { path = "../rog-dbus" } rog_platform = { path = "../rog-platform" } -zbus.workspace = true \ No newline at end of file +zbus.workspace = true diff --git a/daemon-user/src/ctrl_anime.rs b/daemon-user/src/ctrl_anime.rs index 1bac0495..05e9d077 100644 --- a/daemon-user/src/ctrl_anime.rs +++ b/daemon-user/src/ctrl_anime.rs @@ -103,7 +103,7 @@ impl<'a> CtrlAnimeInner<'static> { .write(output) .map_err(|e| AnimeError::Dbus(format!("{}", e))) .map(|_| false) - })?; + }); } ActionData::Image(image) => { self.client @@ -124,10 +124,10 @@ impl<'a> CtrlAnimeInner<'static> { sleep(Duration::from_millis(1)); } } - ActionData::AudioEq => {} - ActionData::SystemInfo => {} - ActionData::TimeDate => {} - ActionData::Matrix => {} + ActionData::AudioEq + | ActionData::SystemInfo + | ActionData::TimeDate + | ActionData::Matrix => {} } } @@ -143,7 +143,7 @@ pub struct CtrlAnime<'a> { inner_early_return: Arc, } -impl<'a> CtrlAnime<'static> { +impl CtrlAnime<'static> { pub fn new( config: Arc>, inner: Arc>>, @@ -185,7 +185,7 @@ impl CtrlAnime<'static> { pub fn insert_asus_gif( &mut self, index: u32, - file: String, + file: &str, time: Timer, brightness: f32, ) -> zbus::fdo::Result { @@ -223,7 +223,7 @@ impl CtrlAnime<'static> { pub fn insert_image_gif( &mut self, index: u32, - file: String, + file: &str, scale: f32, angle: f32, xy: (f32, f32), @@ -269,7 +269,7 @@ impl CtrlAnime<'static> { pub fn insert_image( &mut self, index: u32, - file: String, + file: &str, scale: f32, angle: f32, xy: (f32, f32), diff --git a/daemon-user/src/error.rs b/daemon-user/src/error.rs index 2ed8f90c..e6c0e33e 100644 --- a/daemon-user/src/error.rs +++ b/daemon-user/src/error.rs @@ -13,7 +13,7 @@ pub enum Error { impl fmt::Display for Error { // This trait requires `fmt` with this exact signature. - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Error::Io(err) => write!(f, "Failed to open: {}", err), Error::ConfigLoadFail => write!(f, "Failed to load user config"), diff --git a/daemon-user/src/user_config.rs b/daemon-user/src/user_config.rs index 002b9726..00045337 100644 --- a/daemon-user/src/user_config.rs +++ b/daemon-user/src/user_config.rs @@ -114,7 +114,7 @@ impl ConfigLoadSave for UserAnimeConfig { impl Default for UserAnimeConfig { fn default() -> Self { Self { - name: "default".to_string(), + name: "default".to_owned(), anime: vec![ ActionLoader::AsusImage { file: "/usr/share/asusd/anime/custom/diagonal-template.png".into(), @@ -233,7 +233,7 @@ impl Default for UserAuraConfig { seq.push(key); Self { - name: "default".to_string(), + name: "default".to_owned(), aura: seq, } } @@ -251,8 +251,8 @@ pub struct UserConfig { impl UserConfig { pub fn new() -> Self { Self { - active_anime: Some("anime-default".to_string()), - active_aura: Some("aura-default".to_string()), + active_anime: Some("anime-default".to_owned()), + active_aura: Some("aura-default".to_owned()), } } diff --git a/daemon/Cargo.toml b/daemon/Cargo.toml index 13532d54..eacc53ad 100644 --- a/daemon/Cargo.toml +++ b/daemon/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "daemon" -version.workspace = true license = "MPL-2.0" +version.workspace = true readme = "README.md" authors = ["Luke "] repository = "https://gitlab.com/asus-linux/asus-nb-ctrl" @@ -43,4 +43,4 @@ toml.workspace = true # Device control sysfs-class.workspace = true # used for backlight control and baord ID -concat-idents.workspace = true \ No newline at end of file +concat-idents.workspace = true diff --git a/daemon/src/ctrl_anime/mod.rs b/daemon/src/ctrl_anime/mod.rs index 7895ed07..b8d4a27e 100644 --- a/daemon/src/ctrl_anime/mod.rs +++ b/daemon/src/ctrl_anime/mod.rs @@ -1,5 +1,5 @@ pub mod config; -/// Implements CtrlTask, Reloadable, ZbusRun +/// Implements `CtrlTask`, Reloadable, `ZbusRun` pub mod trait_impls; use self::config::{AnimeConfig, AnimeConfigCached}; @@ -62,7 +62,7 @@ impl CtrlAnime { /// one running - so the thread uses atomics to signal run/exit. /// /// Because this also writes to the usb device, other write tries (display only) *must* - /// get the mutex lock and set the thread_exit atomic. + /// get the mutex lock and set the `thread_exit` atomic. fn run_thread(inner: Arc>, actions: Vec, mut once: bool) { if actions.is_empty() { warn!("AniMe system actions was empty"); @@ -106,13 +106,13 @@ impl CtrlAnime { 'main: loop { thread_running.store(true, Ordering::SeqCst); - for action in actions.iter() { + for action in &actions { if thread_exit.load(Ordering::SeqCst) { break 'main; } match action { ActionData::Animation(frames) => { - if let Err(err) = rog_anime::run_animation(frames, &|frame| { + rog_anime::run_animation(frames, &|frame| { if thread_exit.load(Ordering::Acquire) { info!("rog-anime: frame-loop was asked to exit"); return Ok(true); // Do safe exit @@ -130,15 +130,14 @@ impl CtrlAnime { .ok(); false // Don't exit yet }) - .map(Ok) - .unwrap_or_else(|| { - warn!("rog_anime::run_animation:callback failed"); - Err(AnimeError::NoFrames) - }) - }) { - warn!("rog_anime::run_animation:Animation {}", err); - break 'main; - }; + .map_or_else( + || { + warn!("rog_anime::run_animation:callback failed"); + Err(AnimeError::NoFrames) + }, + Ok, + ) + }); } ActionData::Image(image) => { once = false; @@ -149,10 +148,10 @@ impl CtrlAnime { } } ActionData::Pause(duration) => sleep(*duration), - ActionData::AudioEq => {} - ActionData::SystemInfo => {} - ActionData::TimeDate => {} - ActionData::Matrix => {} + ActionData::AudioEq + | ActionData::SystemInfo + | ActionData::TimeDate + | ActionData::Matrix => {} } } if thread_exit.load(Ordering::SeqCst) { @@ -194,7 +193,7 @@ impl CtrlAnime { *led = bright as u8; } let data = AnimePacketType::try_from(buffer)?; - for row in data.iter() { + for row in &data { self.node.write_bytes(row)?; } self.node.write_bytes(&pkt_for_flush())?; diff --git a/daemon/src/ctrl_anime/trait_impls.rs b/daemon/src/ctrl_anime/trait_impls.rs index 86f1e59c..095ca300 100644 --- a/daemon/src/ctrl_anime/trait_impls.rs +++ b/daemon/src/ctrl_anime/trait_impls.rs @@ -47,7 +47,7 @@ impl CtrlAnimeZbus { let mut lock = self.0.lock().await; let mut bright = bright; if bright < 0.0 { - bright = 0.0 + bright = 0.0; } else if bright > 1.0 { bright = 1.0; } @@ -149,7 +149,7 @@ impl crate::CtrlTask for CtrlAnimeZbus { async fn create_tasks(&self, _: SignalContext<'static>) -> Result<(), RogError> { let run_action = - |start: bool, lock: MutexGuard, inner: Arc>| { + |start: bool, lock: MutexGuard<'_, CtrlAnime>, inner: Arc>| { if start { info!("CtrlAnimeTask running sleep animation"); CtrlAnime::run_thread(inner, lock.cache.shutdown.clone(), true); diff --git a/daemon/src/ctrl_profiles/config.rs b/daemon/src/ctrl_profiles/config.rs index 28ec2761..a116f8fd 100644 --- a/daemon/src/ctrl_profiles/config.rs +++ b/daemon/src/ctrl_profiles/config.rs @@ -43,7 +43,8 @@ impl ProfileConfig { "Could not deserialise {}.\nWill rename to {}-old and recreate config", config_path, config_path ); - let cfg_old = config_path.clone() + "-old"; + let mut cfg_old = config_path.clone(); + cfg_old.push_str("-old"); std::fs::rename(config_path.clone(), cfg_old).unwrap_or_else(|err| { panic!( "Could not rename. Please remove {} then restart service: Error {}", diff --git a/daemon/src/ctrl_profiles/mod.rs b/daemon/src/ctrl_profiles/mod.rs index 9c365c20..d4212ff9 100644 --- a/daemon/src/ctrl_profiles/mod.rs +++ b/daemon/src/ctrl_profiles/mod.rs @@ -1,4 +1,4 @@ pub mod config; pub mod controller; -/// Implements CtrlTask, Reloadable, ZbusRun +/// Implements `CtrlTask`, Reloadable, `ZbusRun` pub mod trait_impls; diff --git a/daemon/src/ctrl_profiles/trait_impls.rs b/daemon/src/ctrl_profiles/trait_impls.rs index 4598f274..2e083c0b 100644 --- a/daemon/src/ctrl_profiles/trait_impls.rs +++ b/daemon/src/ctrl_profiles/trait_impls.rs @@ -32,7 +32,7 @@ impl ProfileZbus { return Ok(profiles); } Err(Error::Failed( - "Failed to get all profile details".to_string(), + "Failed to get all profile details".to_owned(), )) } @@ -85,9 +85,9 @@ impl ProfileZbus { let mut ctrl = self.0.lock().await; ctrl.config.read(); if let Some(curves) = &ctrl.config.fan_curves { - return Ok(curves.get_enabled_curve_profiles().to_vec()); + return Ok(curves.get_enabled_curve_profiles()); } - Err(Error::Failed(UNSUPPORTED_MSG.to_string())) + Err(Error::Failed(UNSUPPORTED_MSG.to_owned())) } /// Set a profile fan curve enabled status. Will also activate a fan curve if in the @@ -109,7 +109,7 @@ impl ProfileZbus { ctrl.save_config(); Ok(()) } else { - Err(Error::Failed(UNSUPPORTED_MSG.to_string())) + Err(Error::Failed(UNSUPPORTED_MSG.to_owned())) } } @@ -121,7 +121,7 @@ impl ProfileZbus { let curve = curves.get_fan_curves_for(profile); return Ok(curve.clone()); } - Err(Error::Failed(UNSUPPORTED_MSG.to_string())) + Err(Error::Failed(UNSUPPORTED_MSG.to_owned())) } /// Set the fan curve for the specified profile. @@ -134,7 +134,7 @@ impl ProfileZbus { .save_fan_curve(curve, profile) .map_err(|err| zbus::fdo::Error::Failed(err.to_string()))?; } else { - return Err(Error::Failed(UNSUPPORTED_MSG.to_string())); + return Err(Error::Failed(UNSUPPORTED_MSG.to_owned())); } ctrl.write_profile_curve_to_platform() .map_err(|e| warn!("Profile::set_profile, {}", e)) diff --git a/daemon/src/error.rs b/daemon/src/error.rs index 34166353..70a884b4 100644 --- a/daemon/src/error.rs +++ b/daemon/src/error.rs @@ -37,7 +37,7 @@ pub enum RogError { impl fmt::Display for RogError { // This trait requires `fmt` with this exact signature. - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { RogError::ParseVendor => write!(f, "Parse gfx vendor error"), RogError::ParseLed => write!(f, "Parse LED error"), @@ -51,7 +51,7 @@ impl fmt::Display for RogError { RogError::DoTask(deets) => write!(f, "Task error: {}", deets), RogError::MissingFunction(deets) => write!(f, "Missing functionality: {}", deets), RogError::MissingLedBrightNode(path, error) => write!(f, "Led node at {} is missing, please check you have the required patch or dkms module installed: {}", path, error), - RogError::ReloadFail(deets) => write!(f, "Task error: {}", deets), + RogError::ReloadFail(deets) => write!(f, "Reload error: {}", deets), RogError::Profiles(deets) => write!(f, "Profile error: {}", deets), RogError::Initramfs(detail) => write!(f, "Initiramfs error: {}", detail), RogError::Modprobe(detail) => write!(f, "Modprobe error: {}", detail), diff --git a/daemon/src/lib.rs b/daemon/src/lib.rs index 6766f3c8..5154e630 100644 --- a/daemon/src/lib.rs +++ b/daemon/src/lib.rs @@ -1,7 +1,7 @@ #![deny(unused_must_use)] /// Configuration loading, saving pub mod config; -/// Control of AniMe matrix display +/// Control of anime matrix display pub mod ctrl_anime; /// Keyboard LED brightness control, RGB, and LED display modes pub mod ctrl_aura; diff --git a/deny.toml b/deny.toml new file mode 100644 index 00000000..697fcf40 --- /dev/null +++ b/deny.toml @@ -0,0 +1,69 @@ +# https://embarkstudios.github.io/cargo-deny/ + +targets = [ + { triple = "aarch64-apple-darwin" }, + { triple = "aarch64-linux-android" }, + { triple = "wasm32-unknown-unknown" }, + { triple = "x86_64-apple-darwin" }, + { triple = "x86_64-pc-windows-msvc" }, + { triple = "x86_64-unknown-linux-gnu" }, + { triple = "x86_64-unknown-linux-musl" }, +] + +[advisories] +vulnerability = "deny" +unmaintained = "warn" +yanked = "deny" +ignore = [ + "RUSTSEC-2020-0071", # https://rustsec.org/advisories/RUSTSEC-2020-0071 - chrono/time: Potential segfault in the time crate + "RUSTSEC-2020-0159", # https://rustsec.org/advisories/RUSTSEC-2020-0159 - chrono/time: Potential segfault in localtime_r invocations + "RUSTSEC-2021-0127", # https://rustsec.org/advisories/RUSTSEC-2021-0127 - https://github.com/bheisler/criterion.rs/issues/534 +] + +[bans] +multiple-versions = "deny" +wildcards = "allow" # at least until https://github.com/EmbarkStudios/cargo-deny/issues/241 is fixed +deny = [ + { name = "openssl" }, # prefer rustls + { name = "openssl-sys" }, # prefer rustls +] + +skip-tree = [ + { name = "criterion" }, # dev-dependency + { name = "glium" }, # legacy crate, lots of old dependencies + { name = "rfd" }, # example dependency + { name = "three-d" }, # example dependency +] + + +[licenses] +unlicensed = "deny" +allow-osi-fsf-free = "neither" +confidence-threshold = 0.92 # We want really high confidence when inferring licenses from text +copyleft = "deny" +allow = [ + "Apache-2.0", # https://tldrlegal.com/license/apache-license-2.0-(apache-2.0) + "BSD-2-Clause", # https://tldrlegal.com/license/bsd-2-clause-license-(freebsd) + "BSD-3-Clause", # https://tldrlegal.com/license/bsd-3-clause-license-(revised) + "BSL-1.0", # https://tldrlegal.com/license/boost-software-license-1.0-explained + "CC0-1.0", # https://creativecommons.org/publicdomain/zero/1.0/ + "ISC", # https://tldrlegal.com/license/-isc-license + "LicenseRef-UFL-1.0", # https://tldrlegal.com/license/ubuntu-font-license,-1.0 - no official SPDX, see https://github.com/emilk/egui/issues/2321 + "MIT", # https://tldrlegal.com/license/mit-license + "MPL-2.0", # https://www.mozilla.org/en-US/MPL/2.0/FAQ/ - see Q11 + "OFL-1.1", # https://spdx.org/licenses/OFL-1.1.html + "OpenSSL", # https://www.openssl.org/source/license.html + "Unicode-DFS-2016", # https://spdx.org/licenses/Unicode-DFS-2016.html + "Zlib", # https://tldrlegal.com/license/zlib-libpng-license-(zlib) +] + +[[licenses.clarify]] +name = "webpki" +expression = "ISC" +license-files = [{ path = "LICENSE", hash = 0x001c7e6c }] + +[[licenses.clarify]] +name = "ring" +expression = "MIT AND ISC AND OpenSSL" +license-files = [{ path = "LICENSE", hash = 0xbd0eed23 }] + diff --git a/rog-anime/Cargo.toml b/rog-anime/Cargo.toml index f9c456c2..a5fa23ef 100644 --- a/rog-anime/Cargo.toml +++ b/rog-anime/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "rog_anime" -version.workspace = true license = "MPL-2.0" +version.workspace = true readme = "README.md" authors = ["Luke "] repository = "https://gitlab.com/asus-linux/asus-nb-ctrl" @@ -30,4 +30,4 @@ glam.workspace = true zbus = { workspace = true, optional = true } -sysfs-class = { workspace = true, optional = true } \ No newline at end of file +sysfs-class = { workspace = true, optional = true } diff --git a/rog-anime/src/data.rs b/rog-anime/src/data.rs index a06df930..e8b410e0 100644 --- a/rog-anime/src/data.rs +++ b/rog-anime/src/data.rs @@ -47,8 +47,7 @@ impl AnimeType { /// The width of diagonal images pub fn width(&self) -> usize { match self { - AnimeType::GA401 => 74, - AnimeType::GA402 => 74, + AnimeType::GA401 | AnimeType::GA402 => 74, } } @@ -103,8 +102,8 @@ impl AnimeDataBuffer { /// Create from a vector of bytes /// - /// # Panics - /// Will panic if the vector length is not `ANIME_DATA_LEN` + /// # Errors + /// Will error if the vector length is not `ANIME_DATA_LEN` #[inline] pub fn from_vec(anime: AnimeType, data: Vec) -> Result { if data.len() != anime.data_length() { @@ -147,10 +146,7 @@ impl TryFrom for AnimePacketType { /// This runs the animations as a blocking loop by using the `callback` to write data /// /// If `callback` is `Ok(true)` then `run_animation` will exit the animation loop early. -pub fn run_animation( - frames: &AnimeGif, - callback: &dyn Fn(AnimeDataBuffer) -> Result, -) -> Result<()> { +pub fn run_animation(frames: &AnimeGif, callback: &dyn Fn(AnimeDataBuffer) -> Result) { let mut count = 0; let start = Instant::now(); @@ -215,9 +211,10 @@ pub fn run_animation( } } + // TODO: Log this error if matches!(callback(output), Ok(true)) { info!("rog-anime: frame-loop callback asked to exit early"); - return Ok(()); + return; } if timed && Instant::now().duration_since(start) > run_time { @@ -232,5 +229,4 @@ pub fn run_animation( } } } - Ok(()) } diff --git a/rog-anime/src/diagonal.rs b/rog-anime/src/diagonal.rs index 10fa27a5..30932a5d 100644 --- a/rog-anime/src/diagonal.rs +++ b/rog-anime/src/diagonal.rs @@ -52,39 +52,43 @@ impl AnimeDiagonal { let mut matrix = AnimeDiagonal::new(anime_type, duration); - match raster { + match &raster { png_pong::PngRaster::Gray8(ras) => { - Self::pixels_from_8bit(ras, &mut matrix, bright, true) + Self::pixels_from_8bit(ras, &mut matrix, bright, true); } png_pong::PngRaster::Graya8(ras) => { - Self::pixels_from_8bit(ras, &mut matrix, bright, true) + Self::pixels_from_8bit(ras, &mut matrix, bright, true); } png_pong::PngRaster::Rgb8(ras) => { - Self::pixels_from_8bit(ras, &mut matrix, bright, false) + Self::pixels_from_8bit(ras, &mut matrix, bright, false); } png_pong::PngRaster::Rgba8(ras) => { - Self::pixels_from_8bit(ras, &mut matrix, bright, false) + Self::pixels_from_8bit(ras, &mut matrix, bright, false); } png_pong::PngRaster::Gray16(ras) => { - Self::pixels_from_16bit(ras, &mut matrix, bright, true) + Self::pixels_from_16bit(ras, &mut matrix, bright, true); } png_pong::PngRaster::Rgb16(ras) => { - Self::pixels_from_16bit(ras, &mut matrix, bright, false) + Self::pixels_from_16bit(ras, &mut matrix, bright, false); } png_pong::PngRaster::Graya16(ras) => { - Self::pixels_from_16bit(ras, &mut matrix, bright, true) + Self::pixels_from_16bit(ras, &mut matrix, bright, true); } png_pong::PngRaster::Rgba16(ras) => { - Self::pixels_from_16bit(ras, &mut matrix, bright, false) + Self::pixels_from_16bit(ras, &mut matrix, bright, false); } - _ => return Err(AnimeError::Format), + png_pong::PngRaster::Palette(..) => return Err(AnimeError::Format), }; Ok(matrix) } - fn pixels_from_8bit

(ras: pix::Raster

, matrix: &mut AnimeDiagonal, bright: f32, grey: bool) - where + fn pixels_from_8bit

( + ras: &pix::Raster

, + matrix: &mut AnimeDiagonal, + bright: f32, + grey: bool, + ) where P: pix::el::Pixel, { let width = ras.width(); @@ -105,7 +109,7 @@ impl AnimeDiagonal { } fn pixels_from_16bit

( - ras: pix::Raster

, + ras: &pix::Raster

, matrix: &mut AnimeDiagonal, bright: f32, grey: bool, @@ -136,7 +140,7 @@ impl AnimeDiagonal { } } - /// Do conversion from the nested Vec in AnimeMatrix to the two required + /// Do conversion from the nested Vec in `AnimeMatrix` to the two required /// packets suitable for sending over USB fn to_ga401_packets(&self) -> Result { let mut buf = vec![0u8; AnimeType::GA401.data_length()]; diff --git a/rog-anime/src/error.rs b/rog-anime/src/error.rs index 08c77bd9..b8c7c585 100644 --- a/rog-anime/src/error.rs +++ b/rog-anime/src/error.rs @@ -26,7 +26,7 @@ pub enum AnimeError { impl fmt::Display for AnimeError { #[inline] - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { AnimeError::NoFrames => write!(f, "No frames in PNG"), AnimeError::Io(e) => write!(f, "Could not open: {}", e), diff --git a/rog-anime/src/grid.rs b/rog-anime/src/grid.rs index b34a8b46..064de16f 100644 --- a/rog-anime/src/grid.rs +++ b/rog-anime/src/grid.rs @@ -93,7 +93,7 @@ impl AnimeGrid { impl TryFrom for AnimeDataBuffer { type Error = AnimeError; - /// Do conversion from the nested Vec in AniMeMatrix to the two required + /// Do conversion from the nested Vec in anime matrix to the two required /// packets suitable for sending over USB fn try_from(anime: AnimeGrid) -> Result { let mut buf = vec![0u8; anime.anime_type.data_length()]; diff --git a/rog-anime/src/image.rs b/rog-anime/src/image.rs index 376fe298..8d42e5a4 100644 --- a/rog-anime/src/image.rs +++ b/rog-anime/src/image.rs @@ -30,7 +30,7 @@ impl Default for Pixel { /// is to be used to sample an image and set the LED brightness. /// /// The position of the Led in `LedPositions` determines the placement in the final -/// data packets when written to the AniMe. +/// data packets when written to the `AniMe`. #[derive(Debug, Clone, Copy, PartialEq)] pub struct Led(f32, f32, u8); @@ -58,7 +58,7 @@ impl Led { /// Container of `Led`, each of which specifies a position within the image /// The main use of this is to position and sample colours for the final image -/// to show on AniMe +/// to show on `AniMe` pub struct AnimeImage { pub scale: Vec2, /// Angle in radians @@ -294,8 +294,8 @@ impl AnimeImage { let x0 = led_from_px.mul_vec3(pos + Vec3::new(0.0, -0.5, 0.0)); const GROUP: [f32; 4] = [0.0, 0.5, 1.0, 1.5]; - for u in GROUP.iter() { - for v in GROUP.iter() { + for u in &GROUP { + for v in &GROUP { let sample = x0 + *u * du + *v * dv; let x = sample.x as i32; @@ -399,7 +399,7 @@ impl AnimeImage { let png_pong::Step { raster, delay: _ } = decoder.last().ok_or(AnimeError::NoFrames)??; let width; - let pixels = match raster { + let pixels = match &raster { png_pong::PngRaster::Gray8(ras) => { width = ras.width(); Self::pixels_from_8bit(ras, true) @@ -432,7 +432,7 @@ impl AnimeImage { width = ras.width(); Self::pixels_from_16bit(ras, false) } - _ => return Err(AnimeError::Format), + png_pong::PngRaster::Palette(..) => return Err(AnimeError::Format), }; let mut matrix = AnimeImage::new( @@ -449,7 +449,7 @@ impl AnimeImage { Ok(matrix) } - fn pixels_from_8bit

(ras: pix::Raster

, grey: bool) -> Vec + fn pixels_from_8bit

(ras: &pix::Raster

, grey: bool) -> Vec where P: pix::el::Pixel, { @@ -468,7 +468,7 @@ impl AnimeImage { .collect() } - fn pixels_from_16bit

(ras: pix::Raster

, grey: bool) -> Vec + fn pixels_from_16bit

(ras: &pix::Raster

, grey: bool) -> Vec where P: pix::el::Pixel, { @@ -491,7 +491,7 @@ impl AnimeImage { impl TryFrom<&AnimeImage> for AnimeDataBuffer { type Error = AnimeError; - /// Do conversion from the nested Vec in AnimeDataBuffer to the two required + /// Do conversion from the nested Vec in `AnimeDataBuffer` to the two required /// packets suitable for sending over USB fn try_from(leds: &AnimeImage) -> Result { let mut l: Vec = leds diff --git a/rog-anime/src/lib.rs b/rog-anime/src/lib.rs index 8fcc034c..ed1f76d2 100644 --- a/rog-anime/src/lib.rs +++ b/rog-anime/src/lib.rs @@ -7,11 +7,11 @@ pub use data::*; mod grid; pub use grid::*; -/// Transform a PNG image for displaying on AniMe matrix display +/// Transform a PNG image for displaying on `AniMe` matrix display mod image; pub use image::*; -/// A grid of data that is intended to be read out and displayed on the ANiMe as +/// A grid of data that is intended to be read out and displayed on the `AniMe` as /// a diagonal mod diagonal; pub use diagonal::*; diff --git a/rog-anime/src/sequencer.rs b/rog-anime/src/sequencer.rs index 90db9ba0..a07ba9e8 100644 --- a/rog-anime/src/sequencer.rs +++ b/rog-anime/src/sequencer.rs @@ -7,7 +7,7 @@ use crate::{ error::Result, AnimTime, AnimeDataBuffer, AnimeDiagonal, AnimeGif, AnimeImage, AnimeType, }; -/// All the possible AniMe actions that can be used. This enum is intended to be +/// All the possible `AniMe` actions that can be used. This enum is intended to be /// a helper for loading up `ActionData`. #[derive(Debug, Clone, Deserialize, Serialize)] pub enum ActionLoader { @@ -44,7 +44,7 @@ pub enum ActionLoader { Pause(Duration), } -/// All the possible AniMe actions that can be used. The enum is intended to be +/// All the possible `AniMe` actions that can be used. The enum is intended to be /// used in a array allowing the user to cycle through a series of actions. #[derive(Debug, Clone, Deserialize, Serialize)] pub enum ActionData { @@ -194,7 +194,7 @@ impl Sequences { None } - pub fn iter(&self) -> ActionIterator { + pub fn iter(&self) -> ActionIterator<'_> { ActionIterator { actions: self, next_idx: 0, diff --git a/rog-anime/src/usb.rs b/rog-anime/src/usb.rs index dd0e8003..a3fa2a12 100644 --- a/rog-anime/src/usb.rs +++ b/rog-anime/src/usb.rs @@ -1,4 +1,4 @@ -//! Utils for writing to the AniMe USB device +//! Utils for writing to the `AniMe` USB device //! //! Use of the device requires a few steps: //! 1. Initialise the device by writing the two packets from `get_init_packets()` @@ -63,7 +63,7 @@ pub const fn pkt_for_flush() -> [u8; PACKET_SIZE] { } /// Get the packet required for setting the device to on, on boot. Requires -/// pkt_for_apply()` to be written after. +/// `pkt_for_apply()` to be written after. #[inline] pub const fn pkt_for_set_boot(status: bool) -> [u8; PACKET_SIZE] { let mut pkt = [0; PACKET_SIZE]; diff --git a/rog-aura/Cargo.toml b/rog-aura/Cargo.toml index 0ac5d6f3..54e4e9ed 100644 --- a/rog-aura/Cargo.toml +++ b/rog-aura/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "rog_aura" -version.workspace = true license = "MPL-2.0" +version.workspace = true readme = "README.md" authors = ["Luke "] repository = "https://gitlab.com/asus-linux/asusctl" @@ -23,4 +23,4 @@ toml = { workspace = true, optional = true } zbus = { workspace = true, optional = true } [dev-dependencies] -serde_json.workspace = true \ No newline at end of file +serde_json.workspace = true diff --git a/rog-aura/src/builtin_modes.rs b/rog-aura/src/builtin_modes.rs index 9c0e31f0..f16f7cc3 100644 --- a/rog-aura/src/builtin_modes.rs +++ b/rog-aura/src/builtin_modes.rs @@ -25,7 +25,6 @@ impl From for LedBrightness { match bright { 0 => LedBrightness::Off, 1 => LedBrightness::Low, - 2 => LedBrightness::Med, 3 => LedBrightness::High, _ => LedBrightness::Med, } @@ -179,21 +178,7 @@ impl Display for AuraModeNum { impl From for String { fn from(mode: AuraModeNum) -> Self { - match mode { - AuraModeNum::Static => "Static", - AuraModeNum::Breathe => "Breathe", - AuraModeNum::Strobe => "Strobe", - AuraModeNum::Rainbow => "Rainbow", - AuraModeNum::Star => "Stars", - AuraModeNum::Rain => "Rain", - AuraModeNum::Highlight => "Highlight", - AuraModeNum::Laser => "Laser", - AuraModeNum::Ripple => "Ripple", - AuraModeNum::Pulse => "Pulse", - AuraModeNum::Comet => "Comet", - AuraModeNum::Flash => "Flash", - } - .to_string() + <&str>::from(&mode).to_owned() } } @@ -218,7 +203,6 @@ impl From<&AuraModeNum> for &str { impl From<&str> for AuraModeNum { fn from(mode: &str) -> Self { match mode { - "Static" => AuraModeNum::Static, "Breathe" => AuraModeNum::Breathe, "Strobe" => AuraModeNum::Strobe, "Rainbow" => AuraModeNum::Rainbow, @@ -238,7 +222,6 @@ impl From<&str> for AuraModeNum { impl From for AuraModeNum { fn from(mode: u8) -> Self { match mode { - 0 => AuraModeNum::Static, 1 => AuraModeNum::Breathe, 2 => AuraModeNum::Strobe, 3 => AuraModeNum::Rainbow, @@ -284,22 +267,14 @@ impl FromStr for AuraZone { fn from_str(s: &str) -> Result { let s = s.to_lowercase(); match s.to_ascii_lowercase().as_str() { - "0" => Ok(AuraZone::None), - "none" => Ok(AuraZone::None), - "1" => Ok(AuraZone::Key1), - "one" => Ok(AuraZone::Key1), - "2" => Ok(AuraZone::Key2), - "two" => Ok(AuraZone::Key2), - "3" => Ok(AuraZone::Key3), - "three" => Ok(AuraZone::Key3), - "4" => Ok(AuraZone::Key4), - "four" => Ok(AuraZone::Key4), - "5" => Ok(AuraZone::Logo), - "logo" => Ok(AuraZone::Logo), - "6" => Ok(AuraZone::BarLeft), - "lightbar-left" => Ok(AuraZone::BarLeft), - "7" => Ok(AuraZone::BarRight), - "lightbar-right" => Ok(AuraZone::BarRight), + "0" | "none" => Ok(AuraZone::None), + "1" | "one" => Ok(AuraZone::Key1), + "2" | "two" => Ok(AuraZone::Key2), + "3" | "three" => Ok(AuraZone::Key3), + "4" | "four" => Ok(AuraZone::Key4), + "5" | "logo" => Ok(AuraZone::Logo), + "6" | "lightbar-left" => Ok(AuraZone::BarLeft), + "7" | "lightbar-right" => Ok(AuraZone::BarRight), _ => Err(Error::ParseSpeed), } } @@ -395,18 +370,20 @@ impl AuraEffect { /// factory mode accepts only one colour. pub const fn allowed_parameters(mode: AuraModeNum) -> AuraParameters { match mode { - AuraModeNum::Static => AuraParameters::new(true, true, false, false, false), + AuraModeNum::Static + | AuraModeNum::Highlight + | AuraModeNum::Pulse + | AuraModeNum::Comet + | AuraModeNum::Flash => AuraParameters::new(true, true, false, false, false), AuraModeNum::Breathe => AuraParameters::new(true, true, true, true, false), - AuraModeNum::Strobe => AuraParameters::new(true, false, false, true, false), + AuraModeNum::Strobe | AuraModeNum::Rain => { + AuraParameters::new(true, false, false, true, false) + } AuraModeNum::Rainbow => AuraParameters::new(true, false, false, true, true), AuraModeNum::Star => AuraParameters::new(true, true, true, true, true), - AuraModeNum::Rain => AuraParameters::new(true, false, false, true, false), - AuraModeNum::Highlight => AuraParameters::new(true, true, false, false, false), - AuraModeNum::Laser => AuraParameters::new(true, true, false, true, false), - AuraModeNum::Ripple => AuraParameters::new(true, true, false, true, false), - AuraModeNum::Pulse => AuraParameters::new(true, true, false, false, false), - AuraModeNum::Comet => AuraParameters::new(true, true, false, false, false), - AuraModeNum::Flash => AuraParameters::new(true, true, false, false, false), + AuraModeNum::Laser | AuraModeNum::Ripple => { + AuraParameters::new(true, true, false, true, false) + } } } } diff --git a/rog-aura/src/error.rs b/rog-aura/src/error.rs index b1961474..2d6c0b81 100644 --- a/rog-aura/src/error.rs +++ b/rog-aura/src/error.rs @@ -13,7 +13,7 @@ pub enum Error { impl fmt::Display for Error { // This trait requires `fmt` with this exact signature. - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Error::ParseColour => write!(f, "Could not parse colour"), Error::ParseSpeed => write!(f, "Could not parse speed"), diff --git a/rog-aura/src/key_to_str.rs b/rog-aura/src/key_to_str.rs index 56234272..e215a689 100644 --- a/rog-aura/src/key_to_str.rs +++ b/rog-aura/src/key_to_str.rs @@ -139,17 +139,17 @@ impl From<&Key> for &str { Key::MediaStop => "Media Stop", Key::MediaNext => "Media Next", Key::MediaPrev => "Media Previous", - Key::NormalBlank => "", - Key::NormalSpacer => "", - Key::FuncBlank => "", - Key::FuncSpacer => "", - Key::ArrowBlank => "", - Key::ArrowSpacer => "", - Key::ArrowRegularBlank => "", - Key::ArrowRegularSpacer => "", - Key::ArrowSplitBlank => "", - Key::ArrowSplitSpacer => "", - Key::RowEndSpacer => "", + Key::NormalBlank + | Key::NormalSpacer + | Key::FuncBlank + | Key::FuncSpacer + | Key::ArrowBlank + | Key::ArrowSpacer + | Key::ArrowRegularBlank + | Key::ArrowRegularSpacer + | Key::ArrowSplitBlank + | Key::ArrowSplitSpacer + | Key::RowEndSpacer => "", } } } diff --git a/rog-aura/src/keys.rs b/rog-aura/src/keys.rs index b41830f6..9e9c97ac 100644 --- a/rog-aura/src/keys.rs +++ b/rog-aura/src/keys.rs @@ -203,17 +203,22 @@ pub enum KeyShape { impl KeyShape { pub const fn width(&self) -> f32 { match self { - Self::Tilde => 0.8, - Self::Normal => 1.0, - Self::NormalBlank => 1.0, - Self::NormalSpacer => 1.0, - Self::Func => 1.0, - Self::FuncBlank => 1.0, + Self::Tilde | Self::Arrow => 0.8, + Self::Normal + | Self::NormalBlank + | Self::NormalSpacer + | Self::Func + | Self::FuncBlank + | Self::Space5 + | Self::ArrowBlank + | Self::ArrowSpacer + | Self::ArrowSplit + | Self::ArrowSplitBlank + | Self::ArrowSplitSpacer => 1.0, Self::FuncSpacer => 0.6, Self::Space => 5.0, - Self::Space5 => 1.0, Self::LCtrlMed => 1.1, - Self::LShift => 2.0, + Self::LShift | Self::Backspace => 2.0, Self::LShift3 => 0.67, Self::RShift => 2.8, Self::RshiftSmall => 1.8, @@ -222,12 +227,9 @@ impl KeyShape { Self::Return3 => 0.7333, Self::Tab => 1.4, Self::Caps => 1.6, - Self::Backspace => 2.0, Self::Backspace3 => 0.666, Self::ArrowRegularBlank | Self::ArrowRegularSpacer => 0.7, - Self::Arrow => 0.8, - Self::ArrowBlank | Self::ArrowSpacer => 1.0, - Self::ArrowSplit | Self::ArrowSplitBlank | Self::ArrowSplitSpacer => 1.0, + Self::RowEndSpacer => 0.1, } } diff --git a/rog-aura/src/layouts/g513.rs b/rog-aura/src/layouts/g513.rs index e8fc0f22..bb347b08 100644 --- a/rog-aura/src/layouts/g513.rs +++ b/rog-aura/src/layouts/g513.rs @@ -6,7 +6,7 @@ impl KeyLayout { pub fn g513_layout() -> Self { Self { matches: vec!["G513".into()], - locale: "US".to_string(), + locale: "US".to_owned(), rows: vec![ KeyRow::new( 0.8, diff --git a/rog-aura/src/layouts/ga401.rs b/rog-aura/src/layouts/ga401.rs index 5a8682db..f44556aa 100644 --- a/rog-aura/src/layouts/ga401.rs +++ b/rog-aura/src/layouts/ga401.rs @@ -5,7 +5,7 @@ impl KeyLayout { pub fn ga401_layout() -> Self { Self { matches: vec!["GA401".into(), "GA402".into()], - locale: "US".to_string(), + locale: "US".to_owned(), rows: vec![ KeyRow::new( 0.8, diff --git a/rog-aura/src/layouts/gx502.rs b/rog-aura/src/layouts/gx502.rs index f452b6b9..5b7fce6b 100644 --- a/rog-aura/src/layouts/gx502.rs +++ b/rog-aura/src/layouts/gx502.rs @@ -5,7 +5,7 @@ impl KeyLayout { pub fn gx502_layout() -> Self { Self { matches: vec!["GX502".into(), "GU502".into()], - locale: "US".to_string(), + locale: "US".to_owned(), rows: vec![ KeyRow::new( 0.8, diff --git a/rog-aura/src/layouts/mod.rs b/rog-aura/src/layouts/mod.rs index b168a8ec..f25656da 100644 --- a/rog-aura/src/layouts/mod.rs +++ b/rog-aura/src/layouts/mod.rs @@ -43,7 +43,7 @@ impl KeyLayout { pub fn matches(&self, board_name: &str) -> bool { let board = board_name.to_ascii_uppercase(); - for tmp in self.matches.iter() { + for tmp in &self.matches { if board.contains(tmp.as_str()) { return true; } @@ -91,7 +91,7 @@ impl KeyRow { Self { height, row } } - pub fn row(&self) -> Iter { + pub fn row(&self) -> Iter<'_, Key> { self.row.iter() } diff --git a/rog-aura/src/per_zone.rs b/rog-aura/src/per_zone.rs index d3a0a16b..b743c995 100644 --- a/rog-aura/src/per_zone.rs +++ b/rog-aura/src/per_zone.rs @@ -43,8 +43,7 @@ impl ZonedColourArray { pub fn rgb_for_zone(&mut self, zone: PerZone) -> &mut [u8] { match zone { - PerZone::None => &mut self.0[9..=11], - PerZone::KeyboardLeft => &mut self.0[9..=11], + PerZone::None | PerZone::KeyboardLeft => &mut self.0[9..=11], PerZone::KeyboardCenterLeft => &mut self.0[12..=14], PerZone::KeyboardCenterRight => &mut self.0[15..=17], PerZone::KeyboardRight => &mut self.0[18..=20], diff --git a/rog-aura/src/sequencer/mod.rs b/rog-aura/src/sequencer/mod.rs index 32c00ca0..9882dc4a 100644 --- a/rog-aura/src/sequencer/mod.rs +++ b/rog-aura/src/sequencer/mod.rs @@ -9,7 +9,7 @@ use serde_derive::{Deserialize, Serialize}; // static mut RNDINDEX: usize = 0; static mut PRNDINDEX: usize = 0; -/// Pseudo random table ripped straight out of Room4Doom +/// Pseudo random table ripped straight out of room4doom pub const RNDTABLE: [i32; 256] = [ 0, 8, 109, 220, 222, 241, 149, 107, 75, 248, 254, 140, 16, 66, 74, 21, 211, 47, 80, 242, 154, 27, 205, 128, 161, 89, 77, 36, 95, 110, 85, 48, 212, 140, 211, 249, 22, 79, 200, 50, 28, 188, @@ -88,7 +88,7 @@ impl Sequences { } pub fn next_state(&mut self, layout: &KeyLayout) { - for effect in self.0.iter_mut() { + for effect in &mut self.0 { effect.next_state(layout); } } @@ -97,7 +97,7 @@ impl Sequences { let mut keys = KeyColourArray::new(); let mut zones = ZonedColourArray::new(); let mut is_per_key = false; - for effect in self.0.iter() { + for effect in &self.0 { match effect.get_led_type() { LedType::Key(key) => { is_per_key = true; diff --git a/rog-aura/src/usb.rs b/rog-aura/src/usb.rs index 87e5f40f..ee074389 100644 --- a/rog-aura/src/usb.rs +++ b/rog-aura/src/usb.rs @@ -36,14 +36,10 @@ impl From<&str> for AuraDevice { fn from(s: &str) -> Self { match s.to_lowercase().as_str() { "tuf" => AuraDevice::Tuf, - "1866" => AuraDevice::X1866, - "1869" => AuraDevice::X1869, - "1854" => AuraDevice::X1854, - "19b6" => AuraDevice::X19B6, - "0x1866" => AuraDevice::X1866, - "0x1869" => AuraDevice::X1869, - "0x1854" => AuraDevice::X1854, - "0x19b6" => AuraDevice::X19B6, + "1866" | "0x1866" => AuraDevice::X1866, + "1869" | "0x1869" => AuraDevice::X1869, + "1854" | "0x1854" => AuraDevice::X1854, + "19b6" | "0x19b6" => AuraDevice::X19B6, _ => AuraDevice::Unknown, } } @@ -108,9 +104,9 @@ impl From for u32 { impl AuraDev1866 { pub fn to_bytes(control: &[Self]) -> [u8; 3] { let mut a: u32 = 0; - control.iter().for_each(|n| { + for n in control { a |= *n as u32; - }); + } [ ((a & 0xff0000) >> 16) as u8, ((a & 0xff00) >> 8) as u8, @@ -197,9 +193,9 @@ impl From for u32 { impl AuraDev19b6 { pub fn to_bytes(control: &[Self]) -> [u8; 3] { let mut a: u32 = 0; - control.iter().for_each(|n| { + for n in control { a |= *n as u32; - }); + } [ (a & 0xff) as u8, ((a & 0xff00) >> 8) as u8, diff --git a/rog-control-center/Cargo.toml b/rog-control-center/Cargo.toml index 69e7c4e6..01da148f 100644 --- a/rog-control-center/Cargo.toml +++ b/rog-control-center/Cargo.toml @@ -1,5 +1,6 @@ [package] name = "rog-control-center" +license = "MPL-2.0" version.workspace = true authors = ["Luke D. Jones "] edition = "2021" @@ -13,7 +14,7 @@ eframe= { git = "https://github.com/flukejones/egui" } #eframe= { git = "https://github.com/emilk/egui", default-features = false, features = ["dark-light", "default_fonts", "wgpu"] } libappindicator = "0.7" # Tray icon -gtk = "0.15" +gtk = "0.15.5" daemon = { path = "../daemon" } rog_anime = { path = "../rog-anime" } @@ -38,5 +39,5 @@ notify-rust.workspace = true png_pong.workspace = true -nix = "^0.25" +nix = "^0.26.1" tempfile = "3.3.0" diff --git a/rog-control-center/src/error.rs b/rog-control-center/src/error.rs index b2f839e8..b1310d21 100644 --- a/rog-control-center/src/error.rs +++ b/rog-control-center/src/error.rs @@ -15,7 +15,7 @@ pub enum Error { impl fmt::Display for Error { // This trait requires `fmt` with this exact signature. - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Error::Io(err) => write!(f, "Failed to open: {}", err), Error::Nix(err) => write!(f, "Error: {}", err), diff --git a/rog-control-center/src/main.rs b/rog-control-center/src/main.rs index 5827d956..414f5aea 100644 --- a/rog-control-center/src/main.rs +++ b/rog-control-center/src/main.rs @@ -206,7 +206,7 @@ fn load_icon() -> IconData { } } } else { - error!("Missing {APP_ICON_PATH}") + error!("Missing {APP_ICON_PATH}"); } IconData { diff --git a/rog-control-center/src/notify.rs b/rog-control-center/src/notify.rs index 5cfcbb09..5e6500f6 100644 --- a/rog-control-center/src/notify.rs +++ b/rog-control-center/src/notify.rs @@ -397,9 +397,9 @@ where fn ac_power_notification(message: &str, on: &bool) -> Result { let data = if *on { - "plugged".to_string() + "plugged".to_owned() } else { - "unplugged".to_string() + "unplugged".to_owned() }; Ok(base_notification(message, &data).show()?) } @@ -417,13 +417,12 @@ fn do_thermal_notif(message: &str, profile: &Profile) -> Result Result { // eww - let mut notif = base_notification(message, &<&str>::from(data).to_string()); + let mut notif = base_notification(message, &<&str>::from(data).to_owned()); let icon = match data { - GfxPower::Active => "asus_notif_red", GfxPower::Suspended => "asus_notif_blue", GfxPower::Off => "asus_notif_green", GfxPower::AsusDisabled => "asus_notif_white", - GfxPower::AsusMuxDiscreet => "asus_notif_red", + GfxPower::AsusMuxDiscreet | GfxPower::Active => "asus_notif_red", GfxPower::Unknown => "gpu-integrated", }; notif.icon(icon); @@ -452,7 +451,7 @@ where Ok(()) } -/// Actual GpuMode unused as data is never correct until switched by reboot +/// Actual `GpuMode` unused as data is never correct until switched by reboot fn do_mux_notification(message: &str, _: &GpuMode) -> Result { let mut notif = base_notification(message, &""); notif.urgency(Urgency::Critical); diff --git a/rog-control-center/src/pages/fan_curve_page.rs b/rog-control-center/src/pages/fan_curve_page.rs index 23b58618..f358db13 100644 --- a/rog-control-center/src/pages/fan_curve_page.rs +++ b/rog-control-center/src/pages/fan_curve_page.rs @@ -30,7 +30,7 @@ impl RogApp { supported: &SupportedFunctions, profiles: &mut ProfilesState, curves: &mut FanCurvesState, - dbus: &RogDbusClientBlocking, + dbus: &RogDbusClientBlocking<'_>, do_error: &mut Option, ui: &mut Ui, ) { @@ -62,7 +62,7 @@ impl RogApp { }; profiles.list.sort(); - for f in profiles.list.iter() { + for f in &profiles.list { item(*f, curves, curves.enabled.contains(f)); } }); diff --git a/rog-control-center/src/system_state.rs b/rog-control-center/src/system_state.rs index 88e95eee..91f891d6 100644 --- a/rog-control-center/src/system_state.rs +++ b/rog-control-center/src/system_state.rs @@ -27,7 +27,7 @@ pub struct BiosState { } impl BiosState { - pub fn new(supported: &SupportedFunctions, dbus: &RogDbusClientBlocking) -> Result { + pub fn new(supported: &SupportedFunctions, dbus: &RogDbusClientBlocking<'_>) -> Result { Ok(Self { post_sound: if supported.rog_bios_ctrl.post_sound { dbus.proxies().rog_bios().post_boot_sound()? != 0 @@ -58,7 +58,7 @@ pub struct ProfilesState { } impl ProfilesState { - pub fn new(supported: &SupportedFunctions, dbus: &RogDbusClientBlocking) -> Result { + pub fn new(supported: &SupportedFunctions, dbus: &RogDbusClientBlocking<'_>) -> Result { Ok(Self { list: if supported.platform_profile.platform_profile { let mut list = dbus.proxies().profile().profiles()?; @@ -86,26 +86,25 @@ pub struct FanCurvesState { } impl FanCurvesState { - pub fn new(supported: &SupportedFunctions, dbus: &RogDbusClientBlocking) -> Result { + pub fn new(supported: &SupportedFunctions, dbus: &RogDbusClientBlocking<'_>) -> Result { let profiles = if supported.platform_profile.platform_profile { dbus.proxies().profile().profiles()? } else { vec![Profile::Balanced, Profile::Quiet, Profile::Performance] }; let enabled = if supported.platform_profile.fan_curves { - HashSet::from_iter( - dbus.proxies() - .profile() - .enabled_fan_profiles()? - .iter() - .cloned(), - ) + dbus.proxies() + .profile() + .enabled_fan_profiles()? + .iter() + .cloned() + .collect::>() } else { HashSet::from([Profile::Balanced, Profile::Quiet, Profile::Performance]) }; let mut curves: BTreeMap = BTreeMap::new(); - profiles.iter().for_each(|p| { + for p in &profiles { if supported.platform_profile.fan_curves { if let Ok(curve) = dbus.proxies().profile().fan_curve_data(*p) { curves.insert(*p, curve); @@ -118,7 +117,7 @@ impl FanCurvesState { curve.gpu.temp = [20, 30, 40, 50, 70, 80, 90, 100]; curves.insert(*p, curve); } - }); + } let show_curve = if supported.platform_profile.fan_curves { dbus.proxies().profile().active_profile()? @@ -149,7 +148,7 @@ pub struct AuraState { } impl AuraState { - pub fn new(supported: &SupportedFunctions, dbus: &RogDbusClientBlocking) -> Result { + pub fn new(supported: &SupportedFunctions, dbus: &RogDbusClientBlocking<'_>) -> Result { Ok(Self { current_mode: if !supported.keyboard_led.stock_led_modes.is_empty() { dbus.proxies().led().led_mode().unwrap_or_default() @@ -198,7 +197,7 @@ pub struct AnimeState { } impl AnimeState { - pub fn new(supported: &SupportedFunctions, dbus: &RogDbusClientBlocking) -> Result { + pub fn new(supported: &SupportedFunctions, dbus: &RogDbusClientBlocking<'_>) -> Result { Ok(Self { boot: if supported.anime_ctrl.0 { dbus.proxies().anime().boot_enabled()? @@ -224,7 +223,7 @@ pub struct GfxState { } impl GfxState { - pub fn new(_supported: &SupportedFunctions, dbus: &GfxProxyBlocking) -> Result { + pub fn new(_supported: &SupportedFunctions, dbus: &GfxProxyBlocking<'_>) -> Result { Ok(Self { mode: dbus.mode()?, power_status: dbus.power()?, @@ -239,7 +238,7 @@ pub struct PowerState { } impl PowerState { - pub fn new(_supported: &SupportedFunctions, dbus: &RogDbusClientBlocking) -> Result { + pub fn new(_supported: &SupportedFunctions, dbus: &RogDbusClientBlocking<'_>) -> Result { Ok(Self { charge_limit: dbus.proxies().charge().charge_control_end_threshold()?, ac_power: dbus.proxies().charge().mains_online()?, diff --git a/rog-control-center/src/tray.rs b/rog-control-center/src/tray.rs index 3d14d47f..d67d6705 100644 --- a/rog-control-center/src/tray.rs +++ b/rog-control-center/src/tray.rs @@ -128,13 +128,18 @@ impl ROGTray { self.menu.show_all(); } - fn add_radio_sub_menu(&mut self, header_label: &str, active_label: &str, sub_menu: RadioGroup) { + fn add_radio_sub_menu( + &mut self, + header_label: &str, + active_label: &str, + sub_menu: &RadioGroup, + ) { let header_item = gtk::MenuItem::with_label(header_label); header_item.show_all(); self.menu.add(&header_item); let menu = gtk::Menu::new(); - for item in sub_menu.0.iter() { + for item in &sub_menu.0 { if let Some(label) = item.label() { item.set_active(label == active_label); } else { @@ -197,7 +202,7 @@ impl ROGTray { } fn _set_status(&mut self, status: AppIndicatorStatus) { - self.tray.set_status(status) + self.tray.set_status(status); } fn menu_add_base(&mut self) { @@ -319,13 +324,13 @@ impl ROGTray { } let active = match current_mode { - GfxMode::AsusMuxDiscreet => "Discreet".to_string(), + GfxMode::AsusMuxDiscreet => "Discreet".to_owned(), _ => current_mode.to_string(), }; self.add_radio_sub_menu( &format!("GPU Mode: {current_mode}"), active.as_str(), - gpu_menu, + &gpu_menu, ); debug!("ROGTray: appended gpu menu"); @@ -408,11 +413,12 @@ pub fn init_tray( debug!("ROGTray: rebuilt menus due to state change"); match lock.gfx_state.power_status { - GfxPower::Active => tray.set_icon("asus_notif_red"), GfxPower::Suspended => tray.set_icon("asus_notif_blue"), GfxPower::Off => tray.set_icon("asus_notif_green"), GfxPower::AsusDisabled => tray.set_icon("asus_notif_white"), - GfxPower::AsusMuxDiscreet => tray.set_icon("asus_notif_red"), + GfxPower::AsusMuxDiscreet | GfxPower::Active => { + tray.set_icon("asus_notif_red") + } GfxPower::Unknown => tray.set_icon("gpu-integrated"), }; } diff --git a/rog-control-center/src/widgets/aura_power.rs b/rog-control-center/src/widgets/aura_power.rs index 7acc1bca..54eb162c 100644 --- a/rog-control-center/src/widgets/aura_power.rs +++ b/rog-control-center/src/widgets/aura_power.rs @@ -12,7 +12,7 @@ pub fn aura_power_group(supported: &SupportedFunctions, states: &mut SystemState match supported.keyboard_led.prod_id { AuraDevice::X1854 | AuraDevice::X1869 | AuraDevice::X1866 => { - aura_power1(supported, states, ui) + aura_power1(supported, states, ui); } AuraDevice::X19B6 => aura_power2(supported, states, ui), AuraDevice::Tuf => aura_power1(supported, states, ui), diff --git a/rog-control-center/src/widgets/fan_graph.rs b/rog-control-center/src/widgets/fan_graph.rs index c84b9a48..2f64a5bb 100644 --- a/rog-control-center/src/widgets/fan_graph.rs +++ b/rog-control-center/src/widgets/fan_graph.rs @@ -11,7 +11,7 @@ pub fn fan_graphs( supported: &SupportedFunctions, profiles: &mut ProfilesState, curves: &mut FanCurvesState, - dbus: &RogDbusClientBlocking, + dbus: &RogDbusClientBlocking<'_>, do_error: &mut Option, ui: &mut Ui, ) { @@ -36,7 +36,7 @@ pub fn fan_graphs( }; ui.horizontal_wrapped(|ui| { - for a in curves.curves.iter() { + for a in &curves.curves { item(*a.0, ui); } }); @@ -57,8 +57,8 @@ pub fn fan_graphs( [x, y] }); - let line = Line::new(PlotPoints::from_iter(points.clone())).width(2.0); - let points = Points::new(PlotPoints::from_iter(points)).radius(3.0); + let line = Line::new(points.clone().collect::()).width(2.0); + let points = Points::new(points.collect::()).radius(3.0); Plot::new("fan_curves") .view_aspect(1.666) @@ -107,7 +107,7 @@ pub fn fan_graphs( } } plot_ui.line(line); - plot_ui.points(points) + plot_ui.points(points); }); let mut set = false; diff --git a/rog-control-center/src/widgets/rog_bios.rs b/rog-control-center/src/widgets/rog_bios.rs index c5414ee8..456c59db 100644 --- a/rog-control-center/src/widgets/rog_bios.rs +++ b/rog-control-center/src/widgets/rog_bios.rs @@ -17,7 +17,7 @@ pub fn platform_profile(states: &mut SystemState, ui: &mut Ui) { }; ui.horizontal_wrapped(|ui| { - for a in states.profiles.list.iter() { + for a in &states.profiles.list { item(*a, ui); } }); @@ -46,7 +46,7 @@ pub fn rog_bios_group(supported: &SupportedFunctions, states: &mut SystemState, .asus_dbus .proxies() .charge() - .set_charge_control_end_threshold(states.power_state.charge_limit as u8) + .set_charge_control_end_threshold(states.power_state.charge_limit) .map_err(|err| { states.error = Some(err.to_string()); }) diff --git a/rog-dbus/src/lib.rs b/rog-dbus/src/lib.rs index 1bd15dd7..ca9de9f7 100644 --- a/rog-dbus/src/lib.rs +++ b/rog-dbus/src/lib.rs @@ -81,7 +81,7 @@ impl<'a> RogDbusClientBlocking<'a> { Ok((RogDbusClientBlocking { proxies }, conn)) } - pub fn proxies(&self) -> &DbusProxiesBlocking { + pub fn proxies(&self) -> &DbusProxiesBlocking<'_> { &self.proxies } } @@ -150,7 +150,7 @@ impl<'a> RogDbusClient<'a> { Ok((RogDbusClient { proxies }, conn)) } - pub fn proxies(&self) -> &DbusProxies { + pub fn proxies(&self) -> &DbusProxies<'_> { &self.proxies } } diff --git a/rog-platform/Cargo.toml b/rog-platform/Cargo.toml index 272245b3..af2b29e1 100644 --- a/rog-platform/Cargo.toml +++ b/rog-platform/Cargo.toml @@ -1,5 +1,6 @@ [package] name = "rog_platform" +license = "MPL-2.0" version.workspace = true edition = "2021" @@ -14,4 +15,4 @@ concat-idents.workspace = true udev.workspace = true inotify.workspace = true -rusb.workspace = true \ No newline at end of file +rusb.workspace = true diff --git a/rog-platform/src/error.rs b/rog-platform/src/error.rs index 08be205b..992e8a5b 100644 --- a/rog-platform/src/error.rs +++ b/rog-platform/src/error.rs @@ -23,7 +23,7 @@ pub enum PlatformError { impl fmt::Display for PlatformError { // This trait requires `fmt` with this exact signature. - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { PlatformError::ParseVendor => write!(f, "Parse gfx vendor error"), PlatformError::ParseNum => write!(f, "Parse number error"), diff --git a/rog-platform/src/lib.rs b/rog-platform/src/lib.rs index bb86ab3b..c4c030d6 100644 --- a/rog-platform/src/lib.rs +++ b/rog-platform/src/lib.rs @@ -19,7 +19,7 @@ pub const VERSION: &str = env!("CARGO_PKG_VERSION"); pub(crate) fn to_device(sys_path: &Path) -> Result { Device::from_syspath(sys_path) - .map_err(|e| PlatformError::Udev("Couldn't transform syspath to device".to_string(), e)) + .map_err(|e| PlatformError::Udev("Couldn't transform syspath to device".to_owned(), e)) } pub fn has_attr(device: &Device, attr_name: &str) -> bool { @@ -39,7 +39,7 @@ pub fn read_attr_bool(device: &Device, attr_name: &str) -> Result { } return Ok(true); } - Err(PlatformError::AttrNotFound(attr_name.to_string())) + Err(PlatformError::AttrNotFound(attr_name.to_owned())) } pub fn write_attr_bool(device: &mut Device, attr: &str, value: bool) -> Result<()> { @@ -53,7 +53,7 @@ pub fn read_attr_u8(device: &Device, attr_name: &str) -> Result { let tmp = value.to_string_lossy(); return tmp.parse::().map_err(|_| PlatformError::ParseNum); } - Err(PlatformError::AttrNotFound(attr_name.to_string())) + Err(PlatformError::AttrNotFound(attr_name.to_owned())) } pub fn write_attr_u8(device: &mut Device, attr: &str, value: u8) -> Result<()> { @@ -71,7 +71,7 @@ pub fn read_attr_u8_array(device: &Device, attr_name: &str) -> Result> { .collect(); return Ok(tmp); } - Err(PlatformError::AttrNotFound(attr_name.to_string())) + Err(PlatformError::AttrNotFound(attr_name.to_owned())) } pub fn write_attr_u8_array(device: &mut Device, attr: &str, values: &[u8]) -> Result<()> { diff --git a/rog-platform/src/platform.rs b/rog-platform/src/platform.rs index d86e38dd..a98b5e21 100644 --- a/rog-platform/src/platform.rs +++ b/rog-platform/src/platform.rs @@ -11,12 +11,12 @@ use crate::{ }; /// The "platform" device provides access to things like: -/// - dgpu_disable -/// - egpu_enable -/// - panel_od -/// - gpu_mux -/// - keyboard_mode, set keyboard RGB mode and speed -/// - keyboard_state, set keyboard power states +/// - `dgpu_disable` +/// - `egpu_enable` +/// - `panel_od` +/// - `gpu_mux` +/// - `keyboard_mode`, set keyboard RGB mode and speed +/// - `keyboard_state`, set keyboard power states #[derive(Debug, PartialEq, Eq, PartialOrd, Clone)] pub struct AsusPlatform { path: PathBuf, diff --git a/rog-platform/src/power.rs b/rog-platform/src/power.rs index a7979166..a4b80c4d 100644 --- a/rog-platform/src/power.rs +++ b/rog-platform/src/power.rs @@ -9,12 +9,12 @@ use crate::{ }; /// The "platform" device provides access to things like: -/// - dgpu_disable -/// - egpu_enable -/// - panel_od -/// - gpu_mux -/// - keyboard_mode, set keyboard RGB mode and speed -/// - keyboard_state, set keyboard power states +/// - `dgpu_disable` +/// - `egpu_enable` +/// - `panel_od` +/// - `gpu_mux` +/// - `keyboard_mode`, set keyboard RGB mode and speed +/// - `keyboard_state`, set keyboard power states #[derive(Debug, PartialEq, Eq, PartialOrd, Clone)] pub struct AsusPower { mains: PathBuf, diff --git a/rog-platform/src/usb_raw.rs b/rog-platform/src/usb_raw.rs index 3e1fa053..b28db657 100644 --- a/rog-platform/src/usb_raw.rs +++ b/rog-platform/src/usb_raw.rs @@ -11,7 +11,7 @@ impl USBRaw { for device in rusb::devices()?.iter() { let device_desc = device.device_descriptor()?; if device_desc.vendor_id() == 0x0b05 && device_desc.product_id() == id_product { - let handle = Self::get_dev_handle(device)?; + let handle = Self::get_dev_handle(&device)?; return Ok(Self(handle)); } } @@ -23,7 +23,7 @@ impl USBRaw { } fn get_dev_handle( - device: Device, + device: &Device, ) -> Result> { // We don't expect this ID to ever change let mut device = device.open()?; diff --git a/rog-profiles/Cargo.toml b/rog-profiles/Cargo.toml index d303137f..2af824d1 100644 --- a/rog-profiles/Cargo.toml +++ b/rog-profiles/Cargo.toml @@ -1,5 +1,6 @@ [package] name = "rog_profiles" +license = "MPL-2.0" version.workspace = true authors = ["Luke D. Jones "] edition = "2021" @@ -13,4 +14,4 @@ udev.workspace = true serde.workspace = true serde_derive.workspace = true -zbus = { workspace = true, optional = true } \ No newline at end of file +zbus = { workspace = true, optional = true }