diff options
Diffstat (limited to '')
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | examples/system_information/Cargo.toml | 10 | ||||
-rw-r--r-- | examples/system_information/src/main.rs | 119 | ||||
-rw-r--r-- | native/src/system/information.rs | 4 | ||||
-rw-r--r-- | winit/src/application.rs | 2 |
5 files changed, 130 insertions, 6 deletions
@@ -96,6 +96,7 @@ members = [ "examples/pure/todos", "examples/pure/tour", "examples/websocket", + "examples/system_information" ] [dependencies] diff --git a/examples/system_information/Cargo.toml b/examples/system_information/Cargo.toml new file mode 100644 index 00000000..d3d76182 --- /dev/null +++ b/examples/system_information/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "system_information" +version = "0.1.0" +authors = ["Richard <richardsoncusto@gmail.com>"] +edition = "2021" +publish = false + +[dependencies] +iced = { path = "../..", features = ["sysinfo"] } +bytesize = { version = "1.1.0" }
\ No newline at end of file diff --git a/examples/system_information/src/main.rs b/examples/system_information/src/main.rs new file mode 100644 index 00000000..f8ae1aaf --- /dev/null +++ b/examples/system_information/src/main.rs @@ -0,0 +1,119 @@ +use iced::{ + executor, system, Application, Column, Command, Container, Element, Length, + Settings, Text, +}; + +use bytesize::ByteSize; + +pub fn main() -> iced::Result { + Example::run(Settings::default()) +} + +enum Example { + Loading, + Loaded { information: system::Information }, + Unsupported, +} + +#[derive(Debug)] +enum Message { + InformationReceived(Option<system::Information>), +} + +impl Application for Example { + type Message = Message; + type Executor = executor::Default; + type Flags = (); + + fn new(_flags: ()) -> (Self, Command<Message>) { + ( + Self::Loading, + system::information(Message::InformationReceived), + ) + } + + fn title(&self) -> String { + String::from("System Information - Iced") + } + + fn update(&mut self, message: Message) -> Command<Message> { + match message { + Message::InformationReceived(information) => { + if let Some(information) = information { + *self = Self::Loaded { information }; + } else { + *self = Self::Unsupported; + } + } + } + + Command::none() + } + + fn view(&mut self) -> Element<Message> { + let content: Element<Message> = match self { + Example::Loading => Text::new("Loading...").size(40).into(), + Example::Loaded { information } => { + let system_name = Text::new(format!( + "System name: {}", + information + .system_name + .as_ref() + .unwrap_or(&"unknown".to_string()) + )); + + let system_kernel = Text::new(format!( + "System kernel: {}", + information + .system_kernel + .as_ref() + .unwrap_or(&"unknown".to_string()) + )); + + let system_version = Text::new(format!( + "System version: {}", + information + .system_version + .as_ref() + .unwrap_or(&"unknown".to_string()) + )); + + let cpu_brand = Text::new(format!( + "Processor brand: {}", + information.cpu_brand + )); + + let cpu_cores = Text::new(format!( + "Processor cores: {}", + information + .cpu_cores + .map_or("unknown".to_string(), |cores| cores + .to_string()) + )); + + let memory_total = Text::new(format!( + "Memory (total): {}", + ByteSize::kb(information.memory_total).to_string() + )); + + Column::with_children(vec![ + system_name.into(), + system_kernel.into(), + system_version.into(), + cpu_brand.into(), + cpu_cores.into(), + memory_total.into(), + ]) + .into() + } + Example::Unsupported => Text::new("Unsupported!").size(20).into(), + }; + + Container::new(content) + .center_x() + .center_y() + .width(Length::Fill) + .height(Length::Fill) + .into() + } +} diff --git a/native/src/system/information.rs b/native/src/system/information.rs index a2abec93..e614f11e 100644 --- a/native/src/system/information.rs +++ b/native/src/system/information.rs @@ -9,10 +9,6 @@ pub struct Information { pub system_version: Option<String>, /// Contains the processor brand. pub cpu_brand: String, - /// Contains the processor vendor id. - pub cpu_vendor: String, - /// Contains the processor name. - pub cpu_name: String, /// Contains the number of physical cores on the processor. pub cpu_cores: Option<usize>, /// Contains the total RAM size in KB. diff --git a/winit/src/application.rs b/winit/src/application.rs index b2f9be29..f5a58f2f 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -589,8 +589,6 @@ pub fn run_command<Message: 'static + std::fmt::Debug + Send, E: Executor>( system_kernel: system.kernel_version(), system_version: system.long_os_version(), cpu_brand: cpu.brand().into(), - cpu_vendor: cpu.vendor_id().into(), - cpu_name: cpu.name().into(), cpu_cores: system.physical_core_count(), memory_total: system.total_memory(), }; |