Skip to content

Commit

Permalink
removes unnecessary thread spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
kondinskis committed Nov 10, 2021
1 parent 502308e commit 26f2dc3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cloud-flight"
version = "0.1.1"
version = "0.1.2"
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Once created replug the wireless dongle.
Download the latest binary from the releases and run it.

```console
foo@bar:~$ curl -LO https://github.com/kondinskis/hyperx-cloud-flight/releases/download/0.1.0/cloud-flight_amd64
foo@bar:~$ curl -LO https://github.com/kondinskis/hyperx-cloud-flight/releases/download/0.1.2/cloud-flight_amd64
foo@bar:~$ chmod +x cloud-flight_amd64
foo@bar:~$ ./cloud-flight_amd64
```
Expand Down
56 changes: 26 additions & 30 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use clokwerk::{Scheduler, TimeUnits};
use simple_logger::SimpleLogger;
use std::sync::Arc;
use std::thread;

const BATTERY_REFRESH_ON_MUTE: bool = true;

Expand All @@ -16,36 +15,33 @@ fn main() {

let mut scheduler = Scheduler::new();

let handle = thread::spawn(move || {
let s_cf = cf.clone();
scheduler.every(3.minutes()).run(move || {
s_cf.battery();
});

cf.battery();

loop {
scheduler.run_pending();
let event = cf.read();
match event {
cloud_flight::Event::BatteryCharging => (),
cloud_flight::Event::Battery { value: _ } => (),
cloud_flight::Event::VolumeUp => (),
cloud_flight::Event::VolumeDown => (),
cloud_flight::Event::Muted => {
if BATTERY_REFRESH_ON_MUTE {
cf.battery();
}
let s_cf = cf.clone();
scheduler.every(3.minutes()).run(move || {
s_cf.battery();
});

cf.battery();

loop {
scheduler.run_pending();
let event = cf.read();
match event {
cloud_flight::Event::BatteryCharging => (),
cloud_flight::Event::Battery { value: _ } => (),
cloud_flight::Event::VolumeUp => (),
cloud_flight::Event::VolumeDown => (),
cloud_flight::Event::Muted => {
if BATTERY_REFRESH_ON_MUTE {
cf.battery();
}
cloud_flight::Event::Unmuted => (),
cloud_flight::Event::PowerOff => (),
cloud_flight::Event::PowerOn => (),
cloud_flight::Event::Ignored => (),
};
if !matches!(event, cloud_flight::Event::Ignored) {
svc.update();
}
cloud_flight::Event::Unmuted => (),
cloud_flight::Event::PowerOff => (),
cloud_flight::Event::PowerOn => (),
cloud_flight::Event::Ignored => (),
};
if !matches!(event, cloud_flight::Event::Ignored) {
svc.update();
}
});
handle.join().unwrap();
}
}

0 comments on commit 26f2dc3

Please sign in to comment.