dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.26k stars 1.76k forks source link

[Mac Catalyst] DeviceDisplay.KeepScreenOn not being respected on Mac OS #26059

Open DanOrlovsky opened 7 hours ago

DanOrlovsky commented 7 hours ago

Description

We have a Maui app targeting both Windows and MacCatalyst. There is a state the app can be in that requires us to keep the sceen on for the user so the app can function whether the user is at the computer or not.

To facilitate this, we are setting KeepScreenOn on DeviceDisplay:

await MainThread.InvokeOnMainThreadAsync(() =>
{
    DeviceDisplay.Current.KeepScreenOn = true;
});    

This is working fine in windows. The Mac build seems to be ignoring this setting completely.

Steps to Reproduce

Make sure your computer is set to sleep in a reasonable amount of time.

In a MacCatalyst maui app, set the DeviceDisplay.Current.KeepScreenOn to true.

Observe the screen will go to sleep.

Link to public reproduction project repository

https://github.com/DanOrlovsky/MauiBlazorNet9ScreenOnDemo

Version with bug

9.0.0 GA

Is this a regression from previous behavior?

No, this is something new

Last version that worked well

Unknown/Other

Affected platforms

macOS

Affected platform versions

MacOS 14 (Sonoma) and MacOS 15 (Sequoia) and both .Net 8 and .Net 9

Did you find any workaround?

No response

Relevant log output

MartyIX commented 6 hours ago

If you would like to check the issue more in detail, I think these pointers can be helpful:

By compiling and running https://github.com/dotnet/maui/tree/main/src/Essentials/samples project, you would see what is not working, I believe.

To verify, what is going on, perhaps pmset -g (man) can be used to check if MAUI actually did something or not.