mirror of
https://github.com/slint-ui/slint.git
synced 2025-11-01 20:31:27 +00:00
fix(node): prevent 100% CPU usage on Wayland by enforcing minimum event timeout (#7550)
This commit is contained in:
parent
4b8287bd0f
commit
417eaeb38a
1 changed files with 9 additions and 1 deletions
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
mod interpreter;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::LazyLock;
|
||||
|
||||
pub use interpreter::*;
|
||||
|
||||
|
|
@ -14,6 +15,8 @@ use napi::{Env, JsFunction, JsObject};
|
|||
#[macro_use]
|
||||
extern crate napi_derive;
|
||||
|
||||
static IS_WAYLAND: LazyLock<bool> = LazyLock::new(|| std::env::var("WAYLAND_DISPLAY").is_ok());
|
||||
|
||||
#[napi]
|
||||
pub fn mock_elapsed_time(ms: f64) {
|
||||
i_slint_core::tests::slint_mock_elapsed_time(ms as _);
|
||||
|
|
@ -32,8 +35,13 @@ pub enum ProcessEventsResult {
|
|||
|
||||
#[napi]
|
||||
pub fn process_events() -> napi::Result<ProcessEventsResult> {
|
||||
// Using std::time::Duration::Zero with the winit backend in wayland causes slint to consume 100% of a cpu core
|
||||
// https://github.com/slint-ui/slint/issues/5780
|
||||
let min_timeout = std::time::Duration::from_millis(16);
|
||||
let timeout = if *IS_WAYLAND { min_timeout } else { std::time::Duration::ZERO };
|
||||
|
||||
i_slint_backend_selector::with_platform(|b| {
|
||||
b.process_events(std::time::Duration::ZERO, i_slint_core::InternalToken)
|
||||
b.process_events(timeout, i_slint_core::InternalToken)
|
||||
})
|
||||
.map_err(|e| napi::Error::from_reason(e.to_string()))
|
||||
.and_then(|result| {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue