Skip to content

Commit bc590aa

Browse files
committed
Fix cpu overheating on idle: https://xkcd.com/1172/
1 parent fb5cd9d commit bc590aa

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

.nix/flake.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

desktop/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ authors = ["Graphite Authors <contact@graphite.rs>"]
66
license = "Apache-2.0"
77
repository = ""
88
edition = "2024"
9-
rust-version = "1.85"
9+
rust-version = "1.87"
1010

1111
[features]
1212
default = ["gpu"]

desktop/src/app.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub(crate) struct WinitApp {
1919
pub(crate) window_state: WindowStateHandle,
2020
pub(crate) cef_context: cef::Context<cef::Initialized>,
2121
pub(crate) window: Option<Arc<Window>>,
22-
cef_schedule: Instant,
22+
cef_schedule: Option<Instant>,
2323
}
2424

2525
impl WinitApp {
@@ -28,20 +28,23 @@ impl WinitApp {
2828
window_state,
2929
cef_context,
3030
window: None,
31-
cef_schedule: Instant::now(),
31+
cef_schedule: Some(Instant::now()),
3232
}
3333
}
3434
}
3535

3636
impl ApplicationHandler<CustomEvent> for WinitApp {
3737
fn about_to_wait(&mut self, event_loop: &ActiveEventLoop) {
3838
let timeout = Instant::now() + Duration::from_millis(10);
39-
let wait_until = timeout.min(self.cef_schedule);
39+
let wait_until = timeout.min(self.cef_schedule.unwrap_or(timeout));
4040
event_loop.set_control_flow(ControlFlow::WaitUntil(wait_until));
4141
}
4242

4343
fn new_events(&mut self, _event_loop: &ActiveEventLoop, _cause: StartCause) {
44-
if Instant::now() > self.cef_schedule {
44+
if let Some(schedule) = self.cef_schedule
45+
&& schedule < Instant::now()
46+
{
47+
self.cef_schedule = None;
4548
self.cef_context.work();
4649
}
4750
}
@@ -78,7 +81,7 @@ impl ApplicationHandler<CustomEvent> for WinitApp {
7881
}
7982
}
8083
CustomEvent::ScheduleBrowserWork(instant) => {
81-
self.cef_schedule = instant;
84+
self.cef_schedule = Some(instant);
8285
}
8386
}
8487
}

0 commit comments

Comments
 (0)