-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
239 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
[package] | ||
name = "cosmic-ext-applet-sysinfo" | ||
version = "0.1.0" | ||
edition = "2021" | ||
license = "GPL-3.0" | ||
authors = ["rwxroot <[email protected]>"] | ||
homepage = "https://github.com/rwxroot/cosmic-ext-applet-sysinfo/" | ||
repository = "https://github.com/rwxroot/cosmic-ext-applet-sysinfo.git" | ||
|
||
[profile.release] | ||
lto = "fat" | ||
|
||
[dependencies] | ||
sysinfo = { version = "0.33.1", default-features = false, features = [ | ||
"system", | ||
"network", | ||
] } | ||
|
||
tracing = "0.1" | ||
tracing-log = "0.2.0" | ||
tracing-subscriber = { version = "0.3", default-features = false, features = [ | ||
"fmt", | ||
"env-filter", | ||
"ansi", | ||
] } | ||
|
||
libcosmic = { git = "https://github.com/pop-os/libcosmic", default-features = false, features = [ | ||
"applet", | ||
"tokio", | ||
"wayland", | ||
] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Simple system info applet for cosmic | ||
|
||
<p align="center"> | ||
<img alt="Applet Screenshot" src="https://github.com/rwxroot/cosmic-ext-applet-sysinfo/blob/main/extra/applet_screenshot.png"> | ||
</p> | ||
|
||
## Install | ||
|
||
```sh | ||
sudo apt install libxkbcommon-dev | ||
git clone https://github.com/rwxroot/cosmic-ext-applet-sysinfo.git | ||
cd cosmic-ext-applet-sysinfo | ||
just build | ||
sudo just install | ||
``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[Desktop Entry] | ||
Name=Simple System Monitor | ||
Keywords=Cosmic;Iced; | ||
Categories=Cosmic;Iced; | ||
|
||
Type=Application | ||
Icon=io.github.rwxroot.cosmic-ext-applet-sysinfo-symbolic | ||
Exec=cosmic-ext-applet-sysinfo | ||
Terminal=false | ||
StartupNotify=true | ||
NoDisplay=true | ||
X-CosmicApplet=true | ||
X-CosmicHoverPopup=Auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
default: build | ||
|
||
build: | ||
cargo build --release | ||
|
||
export NAME := 'cosmic-ext-applet-sysinfo' | ||
export APPID := 'io.github.rwxroot.' + NAME | ||
|
||
cargo-target-dir := env('CARGO_TARGET_DIR', 'target') | ||
bin-src := cargo-target-dir / 'release' / NAME | ||
|
||
base-dir := '/usr' | ||
share-dst := base-dir / 'share' | ||
|
||
bin-dst := base-dir / 'bin' / NAME | ||
desktop-dst := share-dst / 'applications' / APPID + '.desktop' | ||
icon-dst := share-dst / 'icons/hicolor/scalable/apps' / APPID + '-symbolic.svg' | ||
|
||
install: | ||
install -Dm0755 {{ bin-src }} {{ bin-dst }} | ||
install -Dm0644 extra/applet_icon.svg {{ icon-dst }} | ||
install -Dm0644 extra/applet_sysinfo.desktop {{ desktop-dst }} | ||
|
||
uninstall: | ||
rm {{ bin-dst }} | ||
rm {{ icon-dst }} | ||
rm {{ desktop-dst }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
use std::time::Duration; | ||
|
||
use cosmic::{ | ||
app, | ||
iced::{ | ||
widget::{row, text}, | ||
Alignment, Subscription, | ||
}, | ||
widget::{autosize, button}, | ||
Element, | ||
}; | ||
use sysinfo::{CpuRefreshKind, MemoryRefreshKind, Networks, RefreshKind, System}; | ||
|
||
pub fn run() -> cosmic::iced::Result { | ||
cosmic::applet::run::<SysInfo>(()) | ||
} | ||
|
||
struct SysInfo { | ||
core: cosmic::app::Core, | ||
system: System, | ||
networks: Networks, | ||
pub cpu_usage: f32, | ||
pub ram_usage: u64, | ||
pub download_speed: f64, | ||
pub upload_speed: f64, | ||
} | ||
|
||
impl SysInfo { | ||
fn update(&mut self) { | ||
self.system.refresh_specifics( | ||
RefreshKind::nothing() | ||
.with_memory(MemoryRefreshKind::nothing().with_ram()) | ||
.with_cpu(CpuRefreshKind::nothing().with_cpu_usage()), | ||
); | ||
|
||
self.networks.refresh(true); | ||
|
||
self.cpu_usage = self.system.global_cpu_usage(); | ||
self.ram_usage = (self.system.used_memory() * 100) / self.system.total_memory(); | ||
|
||
let mut upload = 0; | ||
let mut download = 0; | ||
|
||
for (_, data) in self.networks.iter() { | ||
upload += data.transmitted(); | ||
download += data.received(); | ||
} | ||
|
||
self.upload_speed = (upload as f64) / 1_000_000.0; | ||
self.download_speed = (download as f64) / 1_000_000.0; | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub enum Message { | ||
Tick, | ||
} | ||
|
||
impl cosmic::Application for SysInfo { | ||
type Flags = (); | ||
type Message = Message; | ||
type Executor = cosmic::SingleThreadExecutor; | ||
|
||
const APP_ID: &'static str = "io.github.rwxroot.cosmic-ext-applet-sysinfo"; | ||
|
||
fn init( | ||
core: app::Core, | ||
_flags: Self::Flags, | ||
) -> (Self, cosmic::iced::Task<app::Message<Self::Message>>) { | ||
let system = System::new_with_specifics( | ||
RefreshKind::nothing() | ||
.with_memory(MemoryRefreshKind::nothing().with_ram()) | ||
.with_cpu(CpuRefreshKind::nothing().with_cpu_usage()), | ||
); | ||
|
||
let networks = Networks::new(); | ||
|
||
( | ||
Self { | ||
core, | ||
system, | ||
networks, | ||
cpu_usage: 0.0, | ||
ram_usage: 0, | ||
download_speed: 0.00, | ||
upload_speed: 0.00, | ||
}, | ||
cosmic::iced::Task::none(), | ||
) | ||
} | ||
|
||
fn core(&self) -> &cosmic::app::Core { | ||
&self.core | ||
} | ||
|
||
fn core_mut(&mut self) -> &mut cosmic::app::Core { | ||
&mut self.core | ||
} | ||
|
||
fn subscription(&self) -> Subscription<Message> { | ||
cosmic::iced::time::every(Duration::from_secs(2)).map(|_| Message::Tick) | ||
} | ||
|
||
fn update(&mut self, message: Message) -> cosmic::iced::Task<app::Message<Self::Message>> { | ||
match message { | ||
Message::Tick => { | ||
self.update(); | ||
} | ||
} | ||
|
||
cosmic::iced::Task::none() | ||
} | ||
|
||
fn view(&self) -> Element<Message> { | ||
let content = { | ||
row![ | ||
text(format!("C: {:.0}%", self.cpu_usage)), | ||
text(format!("R: {}%", self.ram_usage)), | ||
text(format!( | ||
"N: ↓{:.2}MB/s ↑{:.2}MB/s", | ||
self.download_speed, self.upload_speed | ||
)), | ||
] | ||
.spacing(8) | ||
.align_y(Alignment::Center) | ||
}; | ||
|
||
let button = button::custom(content) | ||
.padding([ | ||
self.core.applet.suggested_padding(false), | ||
self.core.applet.suggested_padding(false), | ||
]) | ||
.class(cosmic::theme::Button::AppletIcon); | ||
|
||
autosize::autosize(button, cosmic::widget::Id::unique()).into() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pub mod applet; | ||
|
||
pub fn run() -> cosmic::iced::Result { | ||
applet::run() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
fn main() -> cosmic::iced::Result { | ||
tracing_subscriber::fmt::init(); | ||
let _ = tracing_log::LogTracer::init(); | ||
|
||
tracing::info!("Starting sysinfo applet"); | ||
|
||
cosmic_ext_applet_sysinfo::run() | ||
} |