Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable macOS app nap in winit #1569

Open
aircloud opened this issue May 15, 2020 · 3 comments
Open

Disable macOS app nap in winit #1569

aircloud opened this issue May 15, 2020 · 3 comments
Labels

Comments

@aircloud
Copy link

Currently I have a problem about the process not executed for serval seconds in 'app nap' mode,

more information about 'app nap' is there

and there is the problem: https://stackoverflow.com/questions/61810703/a-very-strange-problem-that-winit-block-the-output-from-other-threads

Is there currently a way to abandon the app nap mode?

@ryanisaacg ryanisaacg added DS - macos C - needs discussion Direction must be ironed out labels May 16, 2020
@madsmtm
Copy link
Member

madsmtm commented Jun 24, 2024

A bit of a necropost, but you can use the objc2-foundation v0.2.2 crate and the activity API:

use objc2_foundation::{NSProcessInfo, NSActivityOptions, NSString};

// Disable app-nap
let activity = NSProcessInfo::processInfo().beginActivityWithOptions_reason(
    NSActivityOptions::NSActivityUserInitiatedAllowingIdleSystemSleep,
    &NSString::from_str("No napping on the job!"),
);

// Keep the `activity` around while having app-nap disabled

// Re-enable app-nap
NSProcessInfo::processInfo().endActivity(&activity);

None of this is specific to Winit.

@madsmtm madsmtm closed this as completed Jun 24, 2024
@daxpedda
Copy link
Member

Web has implemented a few ways to manage throttling.
I also plan to expose a way to prevent screen dimming or system sleep (see #3351).

I think that this area, after all these are a lot of different things, is in scope for Winit, considering that it is related to managing the event loop.

I don't know about other backends, but Web has something similar to app nap: most browsers start freezing apps when not focused or not in use, so I will be adding an API that prevents that. Maybe this could be a cross-platform API?

WDYT?

@madsmtm
Copy link
Member

madsmtm commented Jun 24, 2024

Hmm, yeah, I can see the similarity, I'm not opposed to making some of this a more general (instead of a platform-specific) API.

@madsmtm madsmtm reopened this Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

4 participants