Compare commits
No commits in common. "2c8e4da552f0d02f1a1d5615b257685ee33e1853" and "7138c941d93d80fe59b01a27f8614a021219765e" have entirely different histories.
2c8e4da552
...
7138c941d9
|
@ -1813,7 +1813,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "razer-battery-report"
|
name = "razer-battery-report"
|
||||||
version = "0.2.2"
|
version = "0.2.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"hidapi",
|
"hidapi",
|
||||||
"image",
|
"image",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "razer-battery-report"
|
name = "razer-battery-report"
|
||||||
version = "0.2.2"
|
version = "0.2.1"
|
||||||
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"
|
||||||
|
|
|
@ -12,7 +12,7 @@ Show your wireless Razer devices battery levels in your system tray.
|
||||||
|
|
||||||
> This is a work in progress and currently support only **Razer DeathAdder V3 Pro**.
|
> This is a work in progress and currently support only **Razer DeathAdder V3 Pro**.
|
||||||
|
|
||||||
> Currently, this works only on **Windows**, should work on **Linux** if you _add udev rule to get access to usb devices_ (see [here](https://github.com/libusb/hidapi/blob/master/udev/69-hid.rules)) and remove/`cfg(windows)` some platform-specific code. But I haven't tested yet.
|
> This works pretty well on **Windows**, should work on **Linux** if you _add udev rule to get access to usb devices_ (see [here](https://github.com/libusb/hidapi/blob/master/udev/69-hid.rules)). But I haven't tested yet.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
@ -43,7 +43,6 @@ To build, you must have [Rust](https://www.rust-lang.org/) and
|
||||||
- [ ] Force update devices button in tray menu
|
- [ ] Force update devices button in tray menu
|
||||||
- [ ] Colored tray icons for different battery levels
|
- [ ] Colored tray icons for different battery levels
|
||||||
- [x] Show log window button in tray menu
|
- [x] Show log window button in tray menu
|
||||||
- [ ] Further reduce CPU usage by using Event Loop Proxy events (more info [here](https://github.com/tauri-apps/tray-icon/issues/83#issuecomment-1697773065))
|
|
||||||
- [ ] Prebuilt Binary
|
- [ ] Prebuilt Binary
|
||||||
- [ ] Command Line Arguments for update frequency
|
- [ ] Command Line Arguments for update frequency
|
||||||
- [ ] Support for other Razer Devices (I only have DeathAdder V3 Pro, so I won't be able to test it with other devices)
|
- [ ] Support for other Razer Devices (I only have DeathAdder V3 Pro, so I won't be able to test it with other devices)
|
||||||
|
|
76
src/tray.rs
76
src/tray.rs
|
@ -3,7 +3,6 @@ use std::{
|
||||||
rc::Rc,
|
rc::Rc,
|
||||||
sync::{mpsc, Arc, Mutex},
|
sync::{mpsc, Arc, Mutex},
|
||||||
thread,
|
thread,
|
||||||
time::{Duration, Instant},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::manager::DeviceManager;
|
use crate::manager::DeviceManager;
|
||||||
|
@ -15,11 +14,11 @@ use tray_icon::{
|
||||||
};
|
};
|
||||||
use winapi::um::{
|
use winapi::um::{
|
||||||
wincon::GetConsoleWindow,
|
wincon::GetConsoleWindow,
|
||||||
winuser::{self, ShowWindow},
|
winuser::{self, ShowWindow, SW_SHOW},
|
||||||
};
|
};
|
||||||
|
|
||||||
const BATTERY_UPDATE_INTERVAL: Duration = Duration::from_secs(60);
|
const BATTERY_UPDATE_INTERVAL: std::time::Duration = std::time::Duration::from_secs(60);
|
||||||
const DEVICE_FETCH_INTERVAL: Duration = Duration::from_secs(5);
|
const DEVICE_FETCH_INTERVAL: std::time::Duration = std::time::Duration::from_secs(5);
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct MemoryDevice {
|
pub struct MemoryDevice {
|
||||||
|
@ -194,53 +193,46 @@ 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::Wait;
|
*control_flow = tao::event_loop::ControlFlow::WaitUntil(
|
||||||
|
std::time::Instant::now() + std::time::Duration::from_millis(100),
|
||||||
|
);
|
||||||
|
|
||||||
match event {
|
if let Ok(device_ids) = rx.try_recv() {
|
||||||
tao::event::Event::NewEvents(tao::event::StartCause::Init) => {
|
Self::update(&devices, &device_manager, &device_ids, &tray_icon);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
while let Ok(event) = menu_channel.try_recv() {
|
if let tao::event::Event::NewEvents(tao::event::StartCause::Init) = event {
|
||||||
let menu_items = menu_items.lock().unwrap();
|
// We create the icon once the event loop is actually running
|
||||||
let show_console_item = &menu_items[0];
|
// to prevent issues like https://github.com/tauri-apps/tray-icon/issues/90
|
||||||
let quit_item = &menu_items[1];
|
TrayInner::build_tray(&tray_icon, &tray_menu, icon.clone());
|
||||||
|
}
|
||||||
|
|
||||||
if event.id == show_console_item.id() {
|
if let Ok(event) = menu_channel.try_recv() {
|
||||||
let mut visible = console_state.lock().unwrap();
|
let menu_items = menu_items.lock().unwrap();
|
||||||
*visible = !*visible;
|
|
||||||
|
|
||||||
if *visible {
|
let show_console_item = &menu_items[0];
|
||||||
unsafe { ShowWindow(GetConsoleWindow(), winuser::SW_SHOW) };
|
let quit_item = &menu_items[1];
|
||||||
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 == quit_item.id() {
|
if event.id == show_console_item.id() {
|
||||||
*control_flow = tao::event_loop::ControlFlow::Exit;
|
let mut visible = console_state.lock().unwrap();
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
last_update = Instant::now();
|
if *visible {
|
||||||
|
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