Skip to content

Commit

Permalink
v0.1.2: add autoupdate
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisheib committed Apr 12, 2023
1 parent 242be27 commit 50404e8
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 28 deletions.
95 changes: 89 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ststat"
version = "0.1.0"
version = "0.1.2"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -21,10 +21,10 @@ lazy_static = "1"
nvml-wrapper = "0.9"
parking_lot = "0.12"
reqwest = { version = "0.11", features = ["blocking", "serde_json", "json"] }
self_update = "0.36"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
# sysinfo = "0.28"
sysinfo = {path = "../rust/sysinfo/sysinfo" }
tokio = { version = "1", features = ["rt-multi-thread", "process"] }
windows = { version = "0.46", features = ["Win32_UI_Shell", "Win32_Foundation", "Win32_Graphics_Dwm", "Win32_UI_WindowsAndMessaging", "Win32_System_Performance", "Win32_Storage_FileSystem", "Win32_System_SystemInformation", "Win32_Graphics_Gdi"] }
winreg = "0.11"
winreg = "0.50"
78 changes: 60 additions & 18 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use std::{
collections::HashMap,
panic::{self},
sync::Arc,
sync::{atomic::AtomicBool, Arc},
thread,
time::Instant,
};
Expand All @@ -20,6 +20,7 @@ use ekko::{Ekko, EkkoResponse};
use nvml_wrapper::Nvml;
use parking_lot::Mutex;
use process::{Process, ProcessMetricHandles};
use self_update::{backends::github::Update, cargo_crate_version};
use settings::{show_settings, MySettings};
use sidebar::dispose_sidebar;
use sysinfo::{System, SystemExt};
Expand Down Expand Up @@ -58,6 +59,7 @@ fn main() -> Result<(), eframe::Error> {

let settings = Arc::new(Mutex::new(MySettings::load()));
let cancel_settings = settings.clone();
let update_available = Arc::new(AtomicBool::new(false));

ctrlc::set_handler(move || {
println!("received Ctrl+C, removing sidebar");
Expand All @@ -73,24 +75,10 @@ fn main() -> Result<(), eframe::Error> {
let ohw_info: Arc<Mutex<Option<OHWNode>>> = Default::default();
let thread_ohw = ohw_info.clone();

thread::spawn(move || {
let ekko = Ekko::with_target([8, 8, 8, 8]).unwrap();
loop {
if let EkkoResponse::Destination(res) = ekko.send(32).unwrap() {
thread_pb.add(res.elapsed.as_millis() as u64);
}
thread::sleep(
Duration::milliseconds(
(1000 - Local::now().naive_local().timestamp_subsec_millis() as i64)
.min(1000)
.max(520),
)
.to_std()
.unwrap(),
);
}
});
rt.spawn(ping_thread(thread_pb));
rt.spawn(ohw_thread(thread_ohw));
let thread_update_available = update_available.clone();
thread::spawn(move || check_update_thread(thread_update_available));

let s = settings.lock();
let initial_window_size = (
Expand Down Expand Up @@ -146,6 +134,7 @@ fn main() -> Result<(), eframe::Error> {
disk_buffer: Default::default(),
processes: vec![],
process_metric_handles: Default::default(),
update_available,
};

get_screen_size(&appstate);
Expand All @@ -171,6 +160,25 @@ fn main() -> Result<(), eframe::Error> {
Ok(())
}

async fn ping_thread(thread_pb: Arc<CircleVec<u64, 100>>) -> ! {
let ekko = Ekko::with_target([8, 8, 8, 8]).unwrap();
loop {
if let EkkoResponse::Destination(res) = ekko.send(32).unwrap() {
thread_pb.add(res.elapsed.as_millis() as u64);
}
sleep(
Duration::milliseconds(
(1000 - Local::now().naive_local().timestamp_subsec_millis() as i64)
.min(1000)
.max(520),
)
.to_std()
.unwrap(),
)
.await;
}
}

async fn ohw_thread(thread_ohw: Arc<Mutex<Option<OHWNode>>>) -> ! {
loop {
if let Ok(data) = reqwest::get("http://localhost:8085/data.json").await {
Expand All @@ -195,6 +203,26 @@ async fn ohw_thread(thread_ohw: Arc<Mutex<Option<OHWNode>>>) -> ! {
}
}

fn check_update_thread(update_available: Arc<AtomicBool>) -> ! {
loop {
if let Ok(status) = Update::configure()
.repo_owner("chrisheib")
.repo_name("ststat")
.bin_name("ststat.exe")
.current_version(cargo_crate_version!())
.build()
{
let cur_ver = status.current_version();
let new_ver = status.get_latest_release().unwrap_or_default();
update_available.store(
dbg!(cur_ver) != dbg!(new_ver.version),
std::sync::atomic::Ordering::Relaxed,
);
}
thread::sleep(std::time::Duration::from_secs(60 * 60));
}
}

#[derive(Debug, PartialEq, Eq, Clone, Copy, Default)]
pub enum CurrentStep {
#[default]
Expand Down Expand Up @@ -254,6 +282,7 @@ pub struct MyApp {
pub disk_buffer: HashMap<String, Arc<CircleVec<f64, 100>>>,
pub processes: Vec<Process>,
pub process_metric_handles: ProcessMetricHandles,
pub update_available: Arc<AtomicBool>,
}

impl eframe::App for MyApp {
Expand Down Expand Up @@ -326,6 +355,19 @@ impl eframe::App for MyApp {
});
ui.separator();

if self
.update_available
.load(std::sync::atomic::Ordering::Relaxed)
{
ui.hyperlink_to(
RichText::new("Update available!")
.color(Color32::RED)
.strong(),
"https://github.com/chrisheib/ststat/releases",
);
ui.separator();
}

ScrollArea::vertical().show(ui, |ui| {
system_info::set_system_info_components(self, ui);
ui.checkbox(&mut self.show_settings, "Show settings");
Expand Down
2 changes: 1 addition & 1 deletion src/sidebar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub(crate) fn setup_sidebar(appdata: &MyApp) {

let title = PCSTR::from_raw(INTERNAL_WINDOW_TITLE.as_bytes().as_ptr());
let hwnd = unsafe { FindWindowA(None, title) };
dbg!(hwnd);
// dbg!(hwnd);

// let active_window = active_win_pos_rs::get_active_window().expect("Active window should exist");
// println!("active window: {active_window:#?}");
Expand Down

0 comments on commit 50404e8

Please sign in to comment.