Files
plezy/test/services/fullscreen_state_manager_test.dart
T
Vincent Vallee 8879941d29 fix(player): keep app-owned fullscreen when Escape leaves the player (#1791)
Physical Escape inside the player resolved to exitFullscreenIfActive on
Windows and Linux whenever HTPC-style player navigation was off, so it dropped
the window out of fullscreen regardless of who put it there. For anyone running
with "start in fullscreen" (or who had toggled fullscreen from the browse UI),
backing out of a movie left the app windowed, with "exit fullscreen on player
close" switched off.

Track fullscreen ownership instead: FullscreenStateManager now exposes a scope
that the player opens in initState and closes in dispose, and setFullscreen —
the single funnel every desktop platform reports through (window_manager on
Linux, the Win32 runner callback on Windows, NSWindowDelegate on macOS) —
records whether the fullscreen currently active was entered inside that scope.
Escape only exits fullscreen the player itself entered; otherwise it is plain
Back. The scope is depth-counted so the next-episode swap, where the incoming
screen's initState runs before the outgoing screen's dispose, carries ownership
across rather than resetting it.

Nothing changes for a user who fullscreens from inside the player: Escape still
exits fullscreen first, then acts as Back. The fullscreen toggle button and its
shortcut are untouched, as is exitFullscreenOnPlayerClose.

Fixes #1624.
2026-08-05 07:14:11 +02:00

82 lines
2.1 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:plezy/services/fullscreen_state_manager.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
late FullscreenStateManager manager;
setUp(() {
manager = FullscreenStateManager();
});
// The manager is a singleton, so every case has to hand it back windowed with
// no scope open. No test below leaves more than one scope on the stack.
tearDown(() {
manager.endScope();
manager.setFullscreen(false);
});
group('scope ownership', () {
test('fullscreen predating the scope is not owned by it', () {
manager.setFullscreen(true);
manager.beginScope();
expect(manager.scopeOwnsFullscreen, isFalse);
});
test('fullscreen entered inside the scope is owned by it', () {
manager.beginScope();
manager.setFullscreen(true);
expect(manager.scopeOwnsFullscreen, isTrue);
});
test('leaving fullscreen inside the scope drops ownership', () {
manager.beginScope();
manager.setFullscreen(true);
manager.setFullscreen(false);
expect(manager.scopeOwnsFullscreen, isFalse);
});
test('ownership does not survive the scope closing', () {
manager.beginScope();
manager.setFullscreen(true);
manager.endScope();
expect(manager.scopeOwnsFullscreen, isFalse);
});
test('ownership carries across a nested scope swap', () {
manager.beginScope();
manager.setFullscreen(true);
// The next episode's player is constructed before the outgoing one is
// disposed, so the scopes overlap rather than nest cleanly.
manager.beginScope();
manager.endScope();
expect(manager.scopeOwnsFullscreen, isTrue);
});
test('fullscreen entered with no scope open is owned by nobody', () {
manager.setFullscreen(true);
expect(manager.scopeOwnsFullscreen, isFalse);
});
test('unbalanced endScope does not open a scope', () {
manager.endScope();
manager.setFullscreen(true);
expect(manager.scopeOwnsFullscreen, isFalse);
});
});
}