make badges resetable

This commit is contained in:
Ward from fusion-voyager-3 2024-06-17 08:36:38 +03:00
parent 4028338d6d
commit 12c6c1d287
5 changed files with 294 additions and 14 deletions

249
Cargo.lock generated
View File

@ -2,12 +2,46 @@
# It is not intended for manual editing.
version = 3
[[package]]
name = "aho-corasick"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
dependencies = [
"memchr",
]
[[package]]
name = "autocfg"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0"
[[package]]
name = "bindgen"
version = "0.51.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ebd71393f1ec0509b553aa012b9b58e81dadbdff7130bd3b8cba576e69b32f75"
dependencies = [
"bitflags 1.3.2",
"cexpr",
"cfg-if",
"clang-sys",
"lazy_static",
"peeking_take_while",
"proc-macro2",
"quote",
"regex",
"rustc-hash",
"shlex",
]
[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bitflags"
version = "2.5.0"
@ -20,7 +54,7 @@ version = "0.19.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2ac2a4d0e69036cf0062976f6efcba1aaee3e448594e6514bb2ddf87acce562"
dependencies = [
"bitflags",
"bitflags 2.5.0",
"cairo-sys-rs",
"glib",
"libc",
@ -38,6 +72,21 @@ dependencies = [
"system-deps",
]
[[package]]
name = "cc"
version = "1.0.99"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695"
[[package]]
name = "cexpr"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fce5b5fb86b0c57c20c834c1b412fd09c77c8a59b9473f86272709e78874cd1d"
dependencies = [
"nom",
]
[[package]]
name = "cfg-expr"
version = "0.15.8"
@ -48,6 +97,23 @@ dependencies = [
"target-lexicon",
]
[[package]]
name = "cfg-if"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]]
name = "clang-sys"
version = "0.28.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81de550971c976f176130da4b2978d3b524eaa0fd9ac31f3ceb5ae1231fb4853"
dependencies = [
"glob",
"libc",
"libloading",
]
[[package]]
name = "equivalent"
version = "1.0.1"
@ -61,6 +127,8 @@ dependencies = [
"glib-build-tools",
"gtk4",
"libadwaita",
"linux-version",
"serde_json",
]
[[package]]
@ -230,7 +298,7 @@ version = "0.19.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e52355166df21c7ed16b6a01f615669c7911ed74e27ef60eba339c0d2da12490"
dependencies = [
"bitflags",
"bitflags 2.5.0",
"futures-channel",
"futures-core",
"futures-executor",
@ -278,6 +346,12 @@ dependencies = [
"system-deps",
]
[[package]]
name = "glob"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
[[package]]
name = "gobject-sys"
version = "0.19.5"
@ -417,6 +491,18 @@ dependencies = [
"hashbrown",
]
[[package]]
name = "itoa"
version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b"
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libadwaita"
version = "0.6.0"
@ -455,6 +541,27 @@ version = "0.2.155"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c"
[[package]]
name = "libloading"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2b111a074963af1d37a139918ac6d49ad1d0d5e47f72fd55388619691a7d753"
dependencies = [
"cc",
"winapi",
]
[[package]]
name = "linux-version"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "550e9ee19d3aaf145d93293ae69687db77c4d34515c44c197bffbcbafcf3ae29"
dependencies = [
"bindgen",
"nix",
"semver 0.9.0",
]
[[package]]
name = "memchr"
version = "2.7.4"
@ -470,6 +577,29 @@ dependencies = [
"autocfg",
]
[[package]]
name = "nix"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50e4785f2c3b7589a0d0c1dd60285e1188adac4006e8abd6dd578e1567027363"
dependencies = [
"bitflags 1.3.2",
"cc",
"cfg-if",
"libc",
"void",
]
[[package]]
name = "nom"
version = "4.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ad2a91a8e869eeb30b9cb3119ae87773a8f4ae617f41b1eb9c154b2905f7bd6"
dependencies = [
"memchr",
"version_check",
]
[[package]]
name = "pango"
version = "0.19.5"
@ -494,6 +624,12 @@ dependencies = [
"system-deps",
]
[[package]]
name = "peeking_take_while"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099"
[[package]]
name = "pin-project-lite"
version = "0.2.14"
@ -539,13 +675,63 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "regex"
version = "1.10.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f"
dependencies = [
"aho-corasick",
"memchr",
"regex-automata",
"regex-syntax",
]
[[package]]
name = "regex-automata"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
]
[[package]]
name = "regex-syntax"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b"
[[package]]
name = "rustc-hash"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
name = "rustc_version"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366"
dependencies = [
"semver",
"semver 1.0.23",
]
[[package]]
name = "ryu"
version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f"
[[package]]
name = "semver"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
dependencies = [
"semver-parser",
]
[[package]]
@ -554,6 +740,12 @@ version = "1.0.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b"
[[package]]
name = "semver-parser"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
[[package]]
name = "serde"
version = "1.0.203"
@ -574,6 +766,17 @@ dependencies = [
"syn",
]
[[package]]
name = "serde_json"
version = "1.0.117"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3"
dependencies = [
"itoa",
"ryu",
"serde",
]
[[package]]
name = "serde_spanned"
version = "0.6.6"
@ -583,6 +786,12 @@ dependencies = [
"serde",
]
[[package]]
name = "shlex"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2"
[[package]]
name = "slab"
version = "0.4.9"
@ -705,6 +914,40 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "852e951cb7832cb45cb1169900d19760cfa39b82bc0ea9c0e5a14ae88411c98b"
[[package]]
name = "version_check"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd"
[[package]]
name = "void"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
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 = "windows-sys"
version = "0.52.0"

View File

@ -9,6 +9,8 @@ edition = "2021"
[dependencies]
adw = { version = "0.6.0", package = "libadwaita", features = ["v1_5"] }
gtk = { version = "0.8.2", package = "gtk4", features = ["v4_14"] }
linux-version = "0.1.1"
serde_json = "1.0.117"
[build-dependencies]
glib-build-tools = "0.19.0"

View File

@ -14,7 +14,7 @@
padding: 5px;
}
.background-salmon-bg {
.background-red-bg {
background: #ff2a03;
border-radius: 10px;
padding: 5px;

View File

@ -2,7 +2,8 @@ use adw::prelude::ActionRowExt;
use gtk::{Align, IconSize, Orientation, SelectionMode, SizeGroupMode};
use gtk::prelude::{BoxExt, WidgetExt};
use std::process::{Command, Stdio};
use crate::RunningKernelInfo;
use crate::{KernelBranch, RunningKernelInfo};
use Vec;
pub fn content() -> gtk::Box {
@ -28,14 +29,15 @@ pub fn content() -> gtk::Box {
tux_icon.add_css_class("symbolic-accent-bg");
let kernel_badges_size_group = gtk::SizeGroup::new(SizeGroupMode::Both);
let kernel_badges_size_group0 = gtk::SizeGroup::new(SizeGroupMode::Both);
let kernel_badges_size_group1 = gtk::SizeGroup::new(SizeGroupMode::Both);
let kernel_badge_box = gtk::Box::builder()
.hexpand(true)
.vexpand(true)
.orientation(Orientation::Vertical)
.build();
content_box.append(&create_kernel_badge("Kernel Branch", "cachy", "background-accent-bg", &kernel_badges_size_group, &kernel_badges_size_group0, &kernel_badges_size_group1));
content_box.append(&create_kernel_badge("Latest Version", "6.9", "background-accent-bg", &kernel_badges_size_group, &kernel_badges_size_group0, &kernel_badges_size_group1));
content_box.append(&create_kernel_badge("Running Version", &running_kernel_info.version, "background-salmon-bg", &kernel_badges_size_group, &kernel_badges_size_group0, &kernel_badges_size_group1));
content_box.append(&create_kernel_badge("Running Sched", &running_kernel_info.sched, "background-accent-bg", &kernel_badges_size_group, &kernel_badges_size_group0, &kernel_badges_size_group1));
create_kernel_badges(&kernel_badge_box, &running_kernel_info);
content_box.append(&kernel_badge_box);
content_box.append(&tux_icon);
content_box
@ -92,18 +94,45 @@ fn create_kernel_badge(label0_text: &str, label1_text: &str, css_style: &str, gr
boxedlist
}
//fn get_kernel_branches() -> Vec<KernelBranch> {}
fn get_running_kernel_info() -> RunningKernelInfo {
let version = match Command::new("uname").arg("-r").stdout(Stdio::piped()).output() {
let kernel = match Command::new("uname").arg("-r").stdout(Stdio::piped()).output() {
Ok(t) => String::from_utf8(t.stdout).unwrap().trim().to_owned(),
Err(_) => "Unknown".to_string()
};
println!("{}", version);
let version = match linux_version::linux_kernel_version() {
Ok(t) => format!("{}.{}.{}", t.major, t.minor, t.patch),
Err(_) => "Unknown".to_string()
};
let info = RunningKernelInfo {
kernel: kernel,
version: version,
// didn't find a way to accurately get this, outside of sched-ext (https://github.com/CachyOS/kernel-manager/blob/develop/src/schedext-window.cpp)
sched: "TODO".to_owned()
};
info
}
fn create_kernel_badges(badge_box: &gtk::Box, running_kernel_info: &RunningKernelInfo) {
let kernel_badges_size_group = gtk::SizeGroup::new(SizeGroupMode::Both);
let kernel_badges_size_group0 = gtk::SizeGroup::new(SizeGroupMode::Both);
let kernel_badges_size_group1 = gtk::SizeGroup::new(SizeGroupMode::Both);
let kernel_version = "6.9";
let version_css_style = if &running_kernel_info.version.as_str() == &kernel_version {
"background-green-bg"
}
else {
"background-red-bg"
};
badge_box.append(&create_kernel_badge("Kernel Branch", "cachy", "background-accent-bg", &kernel_badges_size_group, &kernel_badges_size_group0, &kernel_badges_size_group1));
badge_box.append(&create_kernel_badge("Latest Version", "6.9", "background-accent-bg", &kernel_badges_size_group, &kernel_badges_size_group0, &kernel_badges_size_group1));
badge_box.append(&create_kernel_badge("Running Version", &running_kernel_info.version, &version_css_style, &kernel_badges_size_group, &kernel_badges_size_group0, &kernel_badges_size_group1));
badge_box.append(&create_kernel_badge("Running Kernel", &running_kernel_info.kernel, &version_css_style, &kernel_badges_size_group, &kernel_badges_size_group0, &kernel_badges_size_group1));
badge_box.append(&create_kernel_badge("Running Sched", &running_kernel_info.sched, "background-accent-bg", &kernel_badges_size_group, &kernel_badges_size_group0, &kernel_badges_size_group1));
}

View File

@ -10,10 +10,16 @@ const APP_ID: &str = "com.github.cosmicfusion.fedora-kernel-manager";
const PRETTY_NAME: &str = "Fedora Kernel Manager";
struct RunningKernelInfo {
kernel: String,
version: String,
sched: String,
}
struct KernelBranch {
name: String,
db: String,
}
fn main() -> glib::ExitCode {
let app = adw::Application::builder()