diff --git a/applets/cosmic-applet-power-battery/Cargo.lock b/applets/cosmic-applet-power-battery/Cargo.lock index 62363089..c0f34d64 100644 --- a/applets/cosmic-applet-power-battery/Cargo.lock +++ b/applets/cosmic-applet-power-battery/Cargo.lock @@ -2,6 +2,15 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "aho-corasick" +version = "0.7.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +dependencies = [ + "memchr", +] + [[package]] name = "anyhow" version = "1.0.57" @@ -20,6 +29,59 @@ dependencies = [ "parking_lot", ] +[[package]] +name = "async-channel" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2114d64672151c0c5eaa5e131ec84a74f06e1e559830dabba01ca30605d66319" +dependencies = [ + "concurrent-queue", + "event-listener", + "futures-core", +] + +[[package]] +name = "async-executor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "871f9bb5e0a22eeb7e8cf16641feb87c9dc67032ccf8ff49e772eb9941d3a965" +dependencies = [ + "async-task", + "concurrent-queue", + "fastrand", + "futures-lite", + "once_cell", + "slab", +] + +[[package]] +name = "async-io" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5e18f61464ae81cde0a23e713ae8fd299580c54d697a35820cfd0625b8b0e07" +dependencies = [ + "concurrent-queue", + "futures-lite", + "libc", + "log", + "once_cell", + "parking", + "polling", + "slab", + "socket2", + "waker-fn", + "winapi", +] + +[[package]] +name = "async-lock" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e97a171d191782fba31bb902b14ad94e24a68145032b7eedf871ab0bc0d077b6" +dependencies = [ + "event-listener", +] + [[package]] name = "async-oneshot" version = "0.5.0" @@ -29,6 +91,34 @@ dependencies = [ "futures-micro", ] +[[package]] +name = "async-recursion" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7d78656ba01f1b93024b7c3a0467f1608e4be67d725749fdcd7d2c7678fd7a2" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "async-task" +version = "4.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30696a84d817107fc028e049980e09d5e140e8da8f1caeb17e8e950658a3cea9" + +[[package]] +name = "async-trait" +version = "0.1.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96cf8829f67d2eab0b2dfa42c5d0ef737e0724e4a82b01b3e292456202b19716" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "autocfg" version = "1.1.0" @@ -47,6 +137,18 @@ version = "3.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37ccbd214614c6783386c1af30caf03192f17891059cecc394b4fb119e363de3" +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + +[[package]] +name = "cache-padded" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1db59621ec70f09c5e9b597b220c7a2b43611f4710dc03ceb8748637775692c" + [[package]] name = "cairo-rs" version = "0.16.0" @@ -70,6 +172,12 @@ dependencies = [ "system-deps", ] +[[package]] +name = "cc" +version = "1.0.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" + [[package]] name = "cfg-expr" version = "0.10.3" @@ -85,12 +193,54 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "concurrent-queue" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30ed07550be01594c6026cff2a1d7fe9c8f683caa798e12b68694ac9e88286a3" +dependencies = [ + "cache-padded", +] + [[package]] name = "cosmic-applet-power-battery" version = "0.1.0" dependencies = [ + "futures", "gtk4", "relm4", + "zbus", +] + +[[package]] +name = "derivative" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "dirs" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" +dependencies = [ + "libc", + "redox_users", + "winapi", ] [[package]] @@ -99,12 +249,42 @@ version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6907e25393cdcc1f4f3f513d9aac1e840eb1cc341a0fccb01171f7d14d10b946" +[[package]] +name = "enumflags2" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e75d4cd21b95383444831539909fbb14b9dc3fdceb2a6f5d36577329a1f55ccb" +dependencies = [ + "enumflags2_derive", + "serde", +] + +[[package]] +name = "enumflags2_derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f58dc3c5e468259f19f2d46304a6b28f1c3d034442e14b322d2b850e36f6d5ae" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "event-listener" version = "2.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77f3309417938f28bf8228fcff79a4a37103981e3e186d2ccd19c74b38f4eb71" +[[package]] +name = "fastrand" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3fcf0cee53519c866c09b5de1f6c56ff9d647101f81c1964fa632e148896cdf" +dependencies = [ + "instant", +] + [[package]] name = "field-offset" version = "0.3.4" @@ -176,6 +356,21 @@ version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b" +[[package]] +name = "futures-lite" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7694489acd39452c77daa48516b894c153f192c3578d5a839b62c58099fcbf48" +dependencies = [ + "fastrand", + "futures-core", + "futures-io", + "memchr", + "parking", + "pin-project-lite", + "waker-fn", +] + [[package]] name = "futures-macro" version = "0.3.21" @@ -496,6 +691,12 @@ dependencies = [ "libc", ] +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + [[package]] name = "instant" version = "0.1.12" @@ -569,6 +770,19 @@ dependencies = [ "getrandom", ] +[[package]] +name = "nix" +version = "0.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f866317acbd3a240710c63f065ffb1e4fd466259045ccb504130b7f668f35c6" +dependencies = [ + "bitflags", + "cc", + "cfg-if", + "libc", + "memoffset", +] + [[package]] name = "num_cpus" version = "1.13.1" @@ -585,6 +799,16 @@ version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7709cef83f0c1f58f666e746a08b21e0085f7440fa6a29cc194d68aac97a4225" +[[package]] +name = "ordered-stream" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44630c059eacfd6e08bdaa51b1db2ce33119caa4ddc1235e923109aa5f25ccb1" +dependencies = [ + "futures-core", + "pin-project-lite", +] + [[package]] name = "pango" version = "0.16.0" @@ -608,6 +832,12 @@ dependencies = [ "system-deps", ] +[[package]] +name = "parking" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72" + [[package]] name = "parking_lot" version = "0.11.2" @@ -680,6 +910,25 @@ version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" +[[package]] +name = "polling" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "685404d509889fade3e86fe3a5803bca2ec09b0c0778d5ada6ec8bf7a8de5259" +dependencies = [ + "cfg-if", + "libc", + "log", + "wepoll-ffi", + "winapi", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" + [[package]] name = "proc-macro-crate" version = "1.1.3" @@ -741,6 +990,36 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" +dependencies = [ + "getrandom", +] + [[package]] name = "redox_syscall" version = "0.2.13" @@ -750,6 +1029,34 @@ dependencies = [ "bitflags", ] +[[package]] +name = "redox_users" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" +dependencies = [ + "getrandom", + "redox_syscall", + "thiserror", +] + +[[package]] +name = "regex" +version = "1.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d83f127d94bdbcda4c8cc2e50f6f84f4b611f69c902699ca385a39c3a75f9ff1" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49b3de9ec5dc0a3417da371aab17d729997c15010e7fd24ff707773a33bddb64" + [[package]] name = "relm4" version = "0.5.0-beta.1" @@ -776,6 +1083,15 @@ dependencies = [ "syn", ] +[[package]] +name = "remove_dir_all" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" +dependencies = [ + "winapi", +] + [[package]] name = "rustc_version" version = "0.3.3" @@ -814,6 +1130,46 @@ name = "serde" version = "1.0.137" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.137" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578be" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_repr" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2ad84e47328a31223de7fed7a4f5087f2d6ddfe586cf3ca25b7a165bc0a5aed" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "sha1" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1da05c97445caa12d05e848c4a4fcbbea29e748ac28f7e80e9b010392063770" +dependencies = [ + "sha1_smol", +] + +[[package]] +name = "sha1_smol" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012" [[package]] name = "slab" @@ -827,6 +1183,16 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" +[[package]] +name = "socket2" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "spin" version = "0.9.3" @@ -836,6 +1202,12 @@ dependencies = [ "lock_api", ] +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + [[package]] name = "syn" version = "1.0.96" @@ -860,6 +1232,20 @@ dependencies = [ "version-compare", ] +[[package]] +name = "tempfile" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" +dependencies = [ + "cfg-if", + "fastrand", + "libc", + "redox_syscall", + "remove_dir_all", + "winapi", +] + [[package]] name = "thiserror" version = "1.0.31" @@ -900,12 +1286,54 @@ dependencies = [ "serde", ] +[[package]] +name = "tracing" +version = "0.1.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a400e31aa60b9d44a52a8ee0343b5b18566b03a8321e0d321f695cf56e940160" +dependencies = [ + "cfg-if", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc6b8ad3567499f98a1db7a752b07a7c8c7c7c34c332ec00effb2b0027974b7c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7709595b8878a4965ce5e87ebf880a7d39c9afc6837721b21a5a816a8117d921" +dependencies = [ + "once_cell", +] + [[package]] name = "ucd-trie" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" +[[package]] +name = "uds_windows" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce65604324d3cce9b966701489fbd0cf318cb1f7bd9dd07ac9a4ee6fb791930d" +dependencies = [ + "tempfile", + "winapi", +] + [[package]] name = "unicode-ident" version = "1.0.1" @@ -924,6 +1352,12 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "waker-fn" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -984,6 +1418,15 @@ version = "0.2.81" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a89911bd99e5f3659ec4acf9c4d93b0a90fe4a2a11f15328472058edc5261be" +[[package]] +name = "wepoll-ffi" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d743fdedc5c64377b5fc2bc036b01c7fd642205a0d96356034ae3404d49eb7fb" +dependencies = [ + "cc", +] + [[package]] name = "winapi" version = "0.3.9" @@ -1005,3 +1448,93 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "zbus" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79fa581173f081cddb0a5fdf5bd93a1c2e0d18f912e877abeac345cc506438ad" +dependencies = [ + "async-broadcast", + "async-channel", + "async-executor", + "async-io", + "async-lock", + "async-recursion", + "async-task", + "async-trait", + "byteorder", + "derivative", + "dirs", + "enumflags2", + "event-listener", + "futures-core", + "futures-sink", + "futures-util", + "hex", + "lazy_static", + "nix", + "once_cell", + "ordered-stream", + "rand", + "serde", + "serde_repr", + "sha1", + "static_assertions", + "tracing", + "uds_windows", + "winapi", + "zbus_macros", + "zbus_names", + "zvariant", +] + +[[package]] +name = "zbus_macros" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1aeebcf4bcee4668f64e1de231464a81ace79dd651cbe1b567007b48ad31862" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "regex", + "syn", +] + +[[package]] +name = "zbus_names" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45dfcdcf87b71dad505d30cc27b1b7b88a64b6d1c435648f48f9dbc1fdc4b7e1" +dependencies = [ + "serde", + "static_assertions", + "zvariant", +] + +[[package]] +name = "zvariant" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e374c6fc8c84bd5392281285ec9ac003b0a1159d985d8e93ea17c8796d03354d" +dependencies = [ + "byteorder", + "enumflags2", + "libc", + "serde", + "static_assertions", + "zvariant_derive", +] + +[[package]] +name = "zvariant_derive" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af4062552b13f1097b5e53ac7369c34efee5912fdc19c76805244f5e4ed5fa0e" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn", +] diff --git a/applets/cosmic-applet-power-battery/Cargo.toml b/applets/cosmic-applet-power-battery/Cargo.toml index 5250302a..d6fef239 100644 --- a/applets/cosmic-applet-power-battery/Cargo.toml +++ b/applets/cosmic-applet-power-battery/Cargo.toml @@ -4,5 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -relm4 = { git = "https://github.com/relm4/relm4", branch = "next", features = ["macros"] } +futures = "0.3" gtk4 = { git = "https://github.com/gtk-rs/gtk4-rs" } +relm4 = { git = "https://github.com/relm4/relm4", branch = "next", features = ["macros"] } +zbus = { version = "2", no-default-features = true } diff --git a/applets/cosmic-applet-power-battery/src/backlight.rs b/applets/cosmic-applet-power-battery/src/backlight.rs new file mode 100644 index 00000000..5683c62a --- /dev/null +++ b/applets/cosmic-applet-power-battery/src/backlight.rs @@ -0,0 +1,41 @@ +use std::{ + fs::{self, File}, + io::{self, Read}, + path::PathBuf, + str::FromStr, +}; + +struct Backlight(PathBuf); + +impl Backlight { + fn brightness(&self) -> Option { + self.prop("brightness") + } + + fn max_brightness(&self) -> Option { + self.prop("max_brightness") + } + + fn prop(&self, name: &str) -> Option { + let mut file = File::open(&self.0.join(name)).ok()?; + let mut s = String::new(); + file.read_to_string(&mut s).ok()?; + s.parse().ok() + } +} + +// Choose backlight with most "precision". This is what `light` does. +fn backlight() -> io::Result> { + let mut best_backlight = None; + let mut best_max_brightness = 0; + for i in fs::read_dir("/sys/class/backlight")? { + let backlight = Backlight(i?.path()); + if let Some(max_brightness) = backlight.max_brightness() { + if max_brightness > best_max_brightness { + best_backlight = Some(backlight); + best_max_brightness = max_brightness; + } + } + } + Ok(best_backlight) +} diff --git a/applets/cosmic-applet-power-battery/src/main.rs b/applets/cosmic-applet-power-battery/src/main.rs index c03355e8..0fe43062 100644 --- a/applets/cosmic-applet-power-battery/src/main.rs +++ b/applets/cosmic-applet-power-battery/src/main.rs @@ -1,7 +1,35 @@ -use gtk4::prelude::*; +use futures::prelude::*; +use gtk4::{glib, prelude::*}; use relm4::{ComponentParts, ComponentSender, RelmApp, SimpleComponent, WidgetPlus}; use std::time::Duration; +mod backlight; +mod upower; +use upower::UPowerProxy; +mod upower_device; +use upower_device::DeviceProxy; + +async fn display_device() -> zbus::Result> { + let connection = zbus::Connection::system().await?; + let upower = UPowerProxy::new(&connection).await?; + let device_path = upower.get_display_device().await?; + DeviceProxy::builder(&connection) + .path(device_path)? + .build() + .await +} + +async fn foo(device: &DeviceProxy<'static>) { + let mut icon_name_stream = device.receive_icon_name_changed().await; + let mut battery_level_stream = device.receive_battery_level_changed().await; + + glib::MainContext::default() + .spawn(async move { while let Some(evt) = icon_name_stream.next().await {} }); + + glib::MainContext::default() + .spawn(async move { while let Some(evt) = battery_level_stream.next().await {} }); +} + #[derive(Default)] struct AppModel { icon_name: String, @@ -171,6 +199,6 @@ impl SimpleComponent for AppModel { } fn main() { - let app: RelmApp = RelmApp::new("relm4.test.simple"); + let app: RelmApp = RelmApp::new("com.system76.CosmicAppletBattery"); app.run(()); } diff --git a/applets/cosmic-applet-power-battery/src/upower.rs b/applets/cosmic-applet-power-battery/src/upower.rs new file mode 100644 index 00000000..c3166b82 --- /dev/null +++ b/applets/cosmic-applet-power-battery/src/upower.rs @@ -0,0 +1,42 @@ +//! # DBus interface proxy for: `org.freedesktop.UPower` +//! +//! This code was generated by `zbus-xmlgen` `2.0.1` from DBus introspection data. +//! Source: `Interface '/org/freedesktop/UPower' from service 'org.freedesktop.UPower' on system bus`. + +use zbus::dbus_proxy; + +#[dbus_proxy(interface = "org.freedesktop.UPower")] +trait UPower { + /// EnumerateDevices method + fn enumerate_devices(&self) -> zbus::Result>; + + /// GetCriticalAction method + fn get_critical_action(&self) -> zbus::Result; + + /// GetDisplayDevice method + fn get_display_device(&self) -> zbus::Result; + + /// DeviceAdded signal + #[dbus_proxy(signal)] + fn device_added(&self, device: zbus::zvariant::ObjectPath<'_>) -> zbus::Result<()>; + + /// DeviceRemoved signal + #[dbus_proxy(signal)] + fn device_removed(&self, device: zbus::zvariant::ObjectPath<'_>) -> zbus::Result<()>; + + /// DaemonVersion property + #[dbus_proxy(property)] + fn daemon_version(&self) -> zbus::Result; + + /// LidIsClosed property + #[dbus_proxy(property)] + fn lid_is_closed(&self) -> zbus::Result; + + /// LidIsPresent property + #[dbus_proxy(property)] + fn lid_is_present(&self) -> zbus::Result; + + /// OnBattery property + #[dbus_proxy(property)] + fn on_battery(&self) -> zbus::Result; +} diff --git a/applets/cosmic-applet-power-battery/src/upower_device.rs b/applets/cosmic-applet-power-battery/src/upower_device.rs new file mode 100644 index 00000000..a9fe68e3 --- /dev/null +++ b/applets/cosmic-applet-power-battery/src/upower_device.rs @@ -0,0 +1,143 @@ +//! # DBus interface proxy for: `org.freedesktop.UPower.Device` +//! +//! This code was generated by `zbus-xmlgen` `2.0.1` from DBus introspection data. +//! Source: `Interface '/org/freedesktop/UPower/devices/DisplayDevice' from service 'org.freedesktop.UPower' on system bus`. + +use zbus::dbus_proxy; + +#[dbus_proxy(interface = "org.freedesktop.UPower.Device")] +trait Device { + /// GetHistory method + fn get_history( + &self, + type_: &str, + timespan: u32, + resolution: u32, + ) -> zbus::Result>; + + /// GetStatistics method + fn get_statistics(&self, type_: &str) -> zbus::Result>; + + /// Refresh method + fn refresh(&self) -> zbus::Result<()>; + + /// BatteryLevel property + #[dbus_proxy(property)] + fn battery_level(&self) -> zbus::Result; + + /// Capacity property + #[dbus_proxy(property)] + fn capacity(&self) -> zbus::Result; + + /// ChargeCycles property + #[dbus_proxy(property)] + fn charge_cycles(&self) -> zbus::Result; + + /// Energy property + #[dbus_proxy(property)] + fn energy(&self) -> zbus::Result; + + /// EnergyEmpty property + #[dbus_proxy(property)] + fn energy_empty(&self) -> zbus::Result; + + /// EnergyFull property + #[dbus_proxy(property)] + fn energy_full(&self) -> zbus::Result; + + /// EnergyFullDesign property + #[dbus_proxy(property)] + fn energy_full_design(&self) -> zbus::Result; + + /// EnergyRate property + #[dbus_proxy(property)] + fn energy_rate(&self) -> zbus::Result; + + /// HasHistory property + #[dbus_proxy(property)] + fn has_history(&self) -> zbus::Result; + + /// HasStatistics property + #[dbus_proxy(property)] + fn has_statistics(&self) -> zbus::Result; + + /// IconName property + #[dbus_proxy(property)] + fn icon_name(&self) -> zbus::Result; + + /// IsPresent property + #[dbus_proxy(property)] + fn is_present(&self) -> zbus::Result; + + /// IsRechargeable property + #[dbus_proxy(property)] + fn is_rechargeable(&self) -> zbus::Result; + + /// Luminosity property + #[dbus_proxy(property)] + fn luminosity(&self) -> zbus::Result; + + /// Model property + #[dbus_proxy(property)] + fn model(&self) -> zbus::Result; + + /// NativePath property + #[dbus_proxy(property)] + fn native_path(&self) -> zbus::Result; + + /// Online property + #[dbus_proxy(property)] + fn online(&self) -> zbus::Result; + + /// Percentage property + #[dbus_proxy(property)] + fn percentage(&self) -> zbus::Result; + + /// PowerSupply property + #[dbus_proxy(property)] + fn power_supply(&self) -> zbus::Result; + + /// Serial property + #[dbus_proxy(property)] + fn serial(&self) -> zbus::Result; + + /// State property + #[dbus_proxy(property)] + fn state(&self) -> zbus::Result; + + /// Technology property + #[dbus_proxy(property)] + fn technology(&self) -> zbus::Result; + + /// Temperature property + #[dbus_proxy(property)] + fn temperature(&self) -> zbus::Result; + + /// TimeToEmpty property + #[dbus_proxy(property)] + fn time_to_empty(&self) -> zbus::Result; + + /// TimeToFull property + #[dbus_proxy(property)] + fn time_to_full(&self) -> zbus::Result; + + /// Type property + #[dbus_proxy(property)] + fn type_(&self) -> zbus::Result; + + /// UpdateTime property + #[dbus_proxy(property)] + fn update_time(&self) -> zbus::Result; + + /// Vendor property + #[dbus_proxy(property)] + fn vendor(&self) -> zbus::Result; + + /// Voltage property + #[dbus_proxy(property)] + fn voltage(&self) -> zbus::Result; + + /// WarningLevel property + #[dbus_proxy(property)] + fn warning_level(&self) -> zbus::Result; +}