diff --git a/CHANGELOG.en-US.md b/CHANGELOG.en-US.md index 869c6b2..cb8afce 100644 --- a/CHANGELOG.en-US.md +++ b/CHANGELOG.en-US.md @@ -8,6 +8,7 @@ English (US) release notes, mirroring CHANGELOG.md (Brazilian Portuguese). Befor ### Fixes - Displays: a monitor turned to portrait (rotated) keeps its rotation in the layout backup, so restoring the desk puts it back in portrait. Before, the rotation was never saved or restored. (#108) +- Playnite: a slow start no longer sends you back to the PC after a few seconds. When Playnite swaps its loading window for the main one, Console Mode now follows the new window and only restores the desk once Playnite actually closes. (#81) ### Behind the scenes - Publishing a stable release now also opens the update PR on winget (`winget install lippdev.ConsoleMode`). Test versions are skipped. (#106) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2741a2b..75825b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ Notas em português do Brasil; a versão em inglês (Estados Unidos) fica em `CH ### Correções - Telas: um monitor girado (em retrato) mantém a rotação no backup do layout, então restaurar a mesa devolve o monitor em retrato. Antes a rotação nunca era salva nem restaurada. (#108) +- Playnite: quando ele demora para abrir, o app não volta mais para o PC depois de alguns segundos. Se o Playnite troca a janela de carregamento pela principal, o Console Mode passa a acompanhar a nova e só restaura a mesa quando o Playnite fecha de verdade. (#81) ### Por trás dos panos - Publicar uma versão estável agora também abre o PR de atualização no winget (`winget install lippdev.ConsoleMode`). Versões de teste ficam de fora. (#106) diff --git a/src/ConsoleMode/Models/Models.cs b/src/ConsoleMode/Models/Models.cs index d4cfa46..c1e25e4 100644 --- a/src/ConsoleMode/Models/Models.cs +++ b/src/ConsoleMode/Models/Models.cs @@ -256,6 +256,7 @@ public sealed class ConsoleRuntimeState public string? LastAudioSwitchName { get; set; } public bool AudioPendingTarget { get; set; } public nint CachedBigPictureHandle { get; set; } + public DateTime? PlayniteWindowMissingSince { get; set; } public nint CachedXboxHandle { get; set; } public bool BigPictureWatchActive { get; set; } public bool AudioWatchComplete { get; set; } diff --git a/src/ConsoleMode/Services/ConsoleEngine.cs b/src/ConsoleMode/Services/ConsoleEngine.cs index 21574b3..4148f74 100644 --- a/src/ConsoleMode/Services/ConsoleEngine.cs +++ b/src/ConsoleMode/Services/ConsoleEngine.cs @@ -55,6 +55,7 @@ public void Start(AppConfig config, MonitorInfo? focusInfo, Func= 2; } + /// + /// Playnite may replace the window being watched (loading screen → main window). Follow the new + /// window while the process runs, and end the session only when it exits or stays windowless. + /// + private bool IsPlayniteExitSignaled(bool watchedGone) + { + if (watchedGone) State.CachedBigPictureHandle = 0; + var showing = Launch.IsPlayniteActive(State); + if (showing && watchedGone) + { + var handle = State.CachedBigPictureHandle; + AppLog.Write("Loop: Playnite trocou de janela; acompanhando a nova"); + OnUi(() => State.BigPictureWatchActive = NativeWindows.StartBigPictureExitWatch(handle)); + } + + if (showing) State.PlayniteWindowMissingSince = null; + else State.PlayniteWindowMissingSince ??= DateTime.Now; + var exit = PlayniteExitPolicy.IsExit(Launch.IsPlayniteRunning(), showing, State.PlayniteWindowMissingSince, DateTime.Now); + if (exit) AppLog.Write("Loop: Playnite fechou"); + return exit; + } + private bool AudioWatchNeeded() { if (State.AudioWatchComplete) return false; diff --git a/src/ConsoleMode/Services/LaunchService.cs b/src/ConsoleMode/Services/LaunchService.cs index 561c49c..3eeca58 100644 --- a/src/ConsoleMode/Services/LaunchService.cs +++ b/src/ConsoleMode/Services/LaunchService.cs @@ -107,6 +107,8 @@ public nint[] GetPlayniteHandles() .ToArray(); } + public bool IsPlayniteRunning() => Process.GetProcessesByName("Playnite.FullscreenApp").Length > 0; + public nint[] GetFullscreenHandles(string mode) => mode == "playnite" ? GetPlayniteHandles() : GetBigPictureHandles(); diff --git a/src/ConsoleMode/Services/PlayniteExitPolicy.cs b/src/ConsoleMode/Services/PlayniteExitPolicy.cs new file mode 100644 index 0000000..24895a0 --- /dev/null +++ b/src/ConsoleMode/Services/PlayniteExitPolicy.cs @@ -0,0 +1,19 @@ +namespace ConsoleMode.Services; + +/// +/// When a Playnite session counts as over. Playnite can swap its first big window (a loading +/// screen on slow starts) for the main one, so a vanished window alone is not an exit. Pure, so it's tested. +/// +public static class PlayniteExitPolicy +{ + /// How long Playnite may run without a big window before the session ends anyway. + public static readonly TimeSpan WindowGrace = TimeSpan.FromSeconds(20); + + /// When the big window went missing, or null if it is showing. + public static bool IsExit(bool processRunning, bool bigWindowShowing, DateTime? windowMissingSince, DateTime now) + { + if (!processRunning) return true; + if (bigWindowShowing || windowMissingSince is null) return false; + return now - windowMissingSince.Value >= WindowGrace; + } +} diff --git a/tests/ConsoleMode.Tests/ConsoleMode.Tests.csproj b/tests/ConsoleMode.Tests/ConsoleMode.Tests.csproj index 1ef0c8b..5448440 100644 --- a/tests/ConsoleMode.Tests/ConsoleMode.Tests.csproj +++ b/tests/ConsoleMode.Tests/ConsoleMode.Tests.csproj @@ -28,6 +28,7 @@ + diff --git a/tests/ConsoleMode.Tests/PlayniteExitPolicyTests.cs b/tests/ConsoleMode.Tests/PlayniteExitPolicyTests.cs new file mode 100644 index 0000000..536a98c --- /dev/null +++ b/tests/ConsoleMode.Tests/PlayniteExitPolicyTests.cs @@ -0,0 +1,24 @@ +using ConsoleMode.Services; + +namespace ConsoleMode.Tests; + +public class PlayniteExitPolicyTests +{ + private static readonly DateTime T0 = new(2026, 1, 1, 12, 0, 0, DateTimeKind.Utc); + + [Fact] + public void Exits_when_the_process_is_gone() => + Assert.True(PlayniteExitPolicy.IsExit(processRunning: false, bigWindowShowing: false, windowMissingSince: null, T0)); + + [Fact] + public void Stays_while_the_big_window_shows() => + Assert.False(PlayniteExitPolicy.IsExit(processRunning: true, bigWindowShowing: true, windowMissingSince: null, T0)); + + [Fact] + public void Waits_while_the_loading_window_is_swapped_for_the_main_one() => + Assert.False(PlayniteExitPolicy.IsExit(processRunning: true, bigWindowShowing: false, windowMissingSince: T0, T0 + TimeSpan.FromSeconds(5))); + + [Fact] + public void Exits_when_the_process_stays_windowless_past_the_grace() => + Assert.True(PlayniteExitPolicy.IsExit(processRunning: true, bigWindowShowing: false, windowMissingSince: T0, T0 + PlayniteExitPolicy.WindowGrace)); +}