screen orientation and awake

This commit is contained in:
Paul Schneider 2026-11-05 10:44:19 +00:00
commit fa8038c676
Signed by: notazof
GPG key ID: AD4B9B545FBD7D12
25 changed files with 941 additions and 110 deletions

View file

@ -39,6 +39,18 @@ public class MainActivity : AvaloniaMainActivity
PlatformBootstrap.InitPlatform();
Current = this;
base.OnCreate(savedInstanceState);
PostIt.Services.Platform.ScreenAwake.Changed += OnScreenAwakeChanged;
}
private void OnScreenAwakeChanged() => RunOnUiThread(UpdateScreenAwake);
private void UpdateScreenAwake()
{
if (Window is not { } window) return;
if (ReferenceEquals(Current, this) && IsForeground && PostIt.Services.Platform.ScreenAwake.IsRequested)
window.AddFlags(WindowManagerFlags.KeepScreenOn);
else
window.ClearFlags(WindowManagerFlags.KeepScreenOn);
}
/// <summary>
/// Receives the deep-link Intent fired by the system browser after the
@ -72,17 +84,21 @@ public class MainActivity : AvaloniaMainActivity
base.OnResume();
IsForeground = true;
PostIt.Services.Platform.IsApplicationActive = true;
UpdateScreenAwake();
}
protected override void OnPause()
{
IsForeground = false;
PostIt.Services.Platform.IsApplicationActive = false;
UpdateScreenAwake();
base.OnPause();
}
protected override void OnDestroy()
{
PostIt.Services.Platform.ScreenAwake.Changed -= OnScreenAwakeChanged;
Window?.ClearFlags(WindowManagerFlags.KeepScreenOn);
if (ReferenceEquals(Current, this))
{
Current = null;