Compare commits
No commits in common. "1532c45342ef2c078ff72d5e732f895fa1c8a7ae" and "2c8e4da552f0d02f1a1d5615b257685ee33e1853" have entirely different histories.
1532c45342
...
2c8e4da552
|
@ -1813,7 +1813,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "razer-battery-report"
|
name = "razer-battery-report"
|
||||||
version = "0.2.1"
|
version = "0.2.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"hidapi",
|
"hidapi",
|
||||||
"image",
|
"image",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "razer-battery-report"
|
name = "razer-battery-report"
|
||||||
version = "0.2.1"
|
version = "0.2.2"
|
||||||
authors = ["xzeldon <contact@zeldon.ru>"]
|
authors = ["xzeldon <contact@zeldon.ru>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "Razer Battery Level Tray Indicator"
|
description = "Razer Battery Level Tray Indicator"
|
||||||
|
|
73
src/tray.rs
73
src/tray.rs
|
@ -15,10 +15,10 @@ use tray_icon::{
|
||||||
};
|
};
|
||||||
use winapi::um::{
|
use winapi::um::{
|
||||||
wincon::GetConsoleWindow,
|
wincon::GetConsoleWindow,
|
||||||
winuser::{self, ShowWindow, SW_SHOW},
|
winuser::{self, ShowWindow},
|
||||||
};
|
};
|
||||||
|
|
||||||
const BATTERY_UPDATE_INTERVAL: Duration = Duration::from_secs(5);
|
const BATTERY_UPDATE_INTERVAL: Duration = Duration::from_secs(60);
|
||||||
const DEVICE_FETCH_INTERVAL: Duration = Duration::from_secs(5);
|
const DEVICE_FETCH_INTERVAL: Duration = Duration::from_secs(5);
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -194,46 +194,53 @@ impl TrayApp {
|
||||||
|
|
||||||
let menu_channel = MenuEvent::receiver();
|
let menu_channel = MenuEvent::receiver();
|
||||||
|
|
||||||
|
let mut last_update = Instant::now();
|
||||||
|
let update_interval = Duration::from_millis(100);
|
||||||
|
|
||||||
event_loop.run(move |event, _, control_flow| {
|
event_loop.run(move |event, _, control_flow| {
|
||||||
*control_flow = tao::event_loop::ControlFlow::WaitUntil(
|
*control_flow = tao::event_loop::ControlFlow::Wait;
|
||||||
Instant::now() + Duration::from_millis(100),
|
|
||||||
);
|
|
||||||
|
|
||||||
if let Ok(device_ids) = rx.try_recv() {
|
match event {
|
||||||
Self::update(&devices, &device_manager, &device_ids, &tray_icon);
|
tao::event::Event::NewEvents(tao::event::StartCause::Init) => {
|
||||||
}
|
TrayInner::build_tray(&tray_icon, &tray_menu, icon.clone());
|
||||||
|
}
|
||||||
|
tao::event::Event::MainEventsCleared => {
|
||||||
|
// Check if it's time to process updates
|
||||||
|
if last_update.elapsed() >= update_interval {
|
||||||
|
while let Ok(device_ids) = rx.try_recv() {
|
||||||
|
Self::update(&devices, &device_manager, &device_ids, &tray_icon);
|
||||||
|
}
|
||||||
|
|
||||||
if let tao::event::Event::NewEvents(tao::event::StartCause::Init) = event {
|
while let Ok(event) = menu_channel.try_recv() {
|
||||||
// We create the icon once the event loop is actually running
|
let menu_items = menu_items.lock().unwrap();
|
||||||
// to prevent issues like https://github.com/tauri-apps/tray-icon/issues/90
|
let show_console_item = &menu_items[0];
|
||||||
TrayInner::build_tray(&tray_icon, &tray_menu, icon.clone());
|
let quit_item = &menu_items[1];
|
||||||
}
|
|
||||||
|
|
||||||
if let Ok(event) = menu_channel.try_recv() {
|
if event.id == show_console_item.id() {
|
||||||
let menu_items = menu_items.lock().unwrap();
|
let mut visible = console_state.lock().unwrap();
|
||||||
|
*visible = !*visible;
|
||||||
|
|
||||||
let show_console_item = &menu_items[0];
|
if *visible {
|
||||||
let quit_item = &menu_items[1];
|
unsafe { ShowWindow(GetConsoleWindow(), winuser::SW_SHOW) };
|
||||||
|
show_console_item.set_text("Hide Log Window");
|
||||||
|
trace!("showing log window");
|
||||||
|
} else {
|
||||||
|
unsafe { ShowWindow(GetConsoleWindow(), winuser::SW_HIDE) };
|
||||||
|
show_console_item.set_text("Show Log Window");
|
||||||
|
trace!("hiding log window");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if event.id == show_console_item.id() {
|
if event.id == quit_item.id() {
|
||||||
let mut visible = console_state.lock().unwrap();
|
*control_flow = tao::event_loop::ControlFlow::Exit;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if *visible {
|
last_update = Instant::now();
|
||||||
unsafe { ShowWindow(GetConsoleWindow(), winuser::SW_HIDE) };
|
|
||||||
show_console_item.set_text("Show Log Window");
|
|
||||||
trace!("hiding log window");
|
|
||||||
*visible = false;
|
|
||||||
} else {
|
|
||||||
unsafe { ShowWindow(GetConsoleWindow(), SW_SHOW) };
|
|
||||||
show_console_item.set_text("Hide Log Window");
|
|
||||||
trace!("showing log window");
|
|
||||||
*visible = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_ => (),
|
||||||
if event.id == quit_item.id() {
|
|
||||||
*control_flow = tao::event_loop::ControlFlow::Exit;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue