fix: unmaximize window before entering fullscreen on Windows
This commit is contained in:
@@ -26,6 +26,7 @@ import '../models/companion_remote/remote_command_type.dart';
|
|||||||
import '../providers/companion_remote_provider.dart';
|
import '../providers/companion_remote_provider.dart';
|
||||||
import '../services/companion_remote/companion_remote_receiver.dart';
|
import '../services/companion_remote/companion_remote_receiver.dart';
|
||||||
import '../services/macos_window_service.dart';
|
import '../services/macos_window_service.dart';
|
||||||
|
import '../services/fullscreen_state_manager.dart';
|
||||||
import '../services/discord_rpc_service.dart';
|
import '../services/discord_rpc_service.dart';
|
||||||
import '../services/episode_navigation_service.dart';
|
import '../services/episode_navigation_service.dart';
|
||||||
import '../services/media_controls_manager.dart';
|
import '../services/media_controls_manager.dart';
|
||||||
@@ -1270,16 +1271,7 @@ class VideoPlayerScreenState extends State<VideoPlayerScreen> with WidgetsBindin
|
|||||||
|
|
||||||
Future<void> _toggleFullscreen() async {
|
Future<void> _toggleFullscreen() async {
|
||||||
if (PlatformDetector.isMobile(context)) return;
|
if (PlatformDetector.isMobile(context)) return;
|
||||||
final isCurrentlyFullscreen = await windowManager.isFullScreen();
|
await FullscreenStateManager().toggleFullscreen();
|
||||||
if (Platform.isMacOS) {
|
|
||||||
if (isCurrentlyFullscreen) {
|
|
||||||
await MacOSWindowService.exitFullscreen();
|
|
||||||
} else {
|
|
||||||
await MacOSWindowService.enterFullscreen();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
await windowManager.setFullScreen(!isCurrentlyFullscreen);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Exit fullscreen before leaving the player (Windows/Linux only).
|
/// Exit fullscreen before leaving the player (Windows/Linux only).
|
||||||
@@ -1289,7 +1281,7 @@ class VideoPlayerScreenState extends State<VideoPlayerScreen> with WidgetsBindin
|
|||||||
if (Platform.isWindows || Platform.isLinux) {
|
if (Platform.isWindows || Platform.isLinux) {
|
||||||
final isFullscreen = await windowManager.isFullScreen();
|
final isFullscreen = await windowManager.isFullScreen();
|
||||||
if (isFullscreen) {
|
if (isFullscreen) {
|
||||||
await windowManager.setFullScreen(false);
|
await FullscreenStateManager().exitFullscreen();
|
||||||
await Future.delayed(const Duration(milliseconds: 100));
|
await Future.delayed(const Duration(milliseconds: 100));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import 'dart:io' show Platform;
|
import 'dart:io' show Platform;
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:window_manager/window_manager.dart';
|
import 'package:window_manager/window_manager.dart';
|
||||||
|
import 'macos_window_service.dart';
|
||||||
|
|
||||||
/// Global manager for tracking fullscreen state across the app
|
/// Global manager for tracking fullscreen state across the app
|
||||||
class FullscreenStateManager extends ChangeNotifier with WindowListener {
|
class FullscreenStateManager extends ChangeNotifier with WindowListener {
|
||||||
@@ -12,6 +13,7 @@ class FullscreenStateManager extends ChangeNotifier with WindowListener {
|
|||||||
|
|
||||||
bool _isFullscreen = false;
|
bool _isFullscreen = false;
|
||||||
bool _isListening = false;
|
bool _isListening = false;
|
||||||
|
bool _wasMaximized = false;
|
||||||
|
|
||||||
bool get isFullscreen => _isFullscreen;
|
bool get isFullscreen => _isFullscreen;
|
||||||
|
|
||||||
@@ -23,6 +25,46 @@ class FullscreenStateManager extends ChangeNotifier with WindowListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Toggle fullscreen state, handling maximized-to-fullscreen transition on Windows/Linux
|
||||||
|
Future<void> toggleFullscreen() async {
|
||||||
|
final isCurrentlyFullscreen = await windowManager.isFullScreen();
|
||||||
|
|
||||||
|
if (Platform.isMacOS) {
|
||||||
|
if (isCurrentlyFullscreen) {
|
||||||
|
await MacOSWindowService.exitFullscreen();
|
||||||
|
} else {
|
||||||
|
await MacOSWindowService.enterFullscreen();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (isCurrentlyFullscreen) {
|
||||||
|
await windowManager.setFullScreen(false);
|
||||||
|
if (_wasMaximized) {
|
||||||
|
await windowManager.maximize();
|
||||||
|
_wasMaximized = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_wasMaximized = await windowManager.isMaximized();
|
||||||
|
if (_wasMaximized) {
|
||||||
|
await windowManager.unmaximize();
|
||||||
|
}
|
||||||
|
await windowManager.setFullScreen(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Exit fullscreen, restoring maximized state if needed
|
||||||
|
Future<void> exitFullscreen() async {
|
||||||
|
if (Platform.isMacOS) {
|
||||||
|
await MacOSWindowService.exitFullscreen();
|
||||||
|
} else {
|
||||||
|
await windowManager.setFullScreen(false);
|
||||||
|
if (_wasMaximized) {
|
||||||
|
await windowManager.maximize();
|
||||||
|
_wasMaximized = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Start monitoring fullscreen state
|
/// Start monitoring fullscreen state
|
||||||
void startMonitoring() {
|
void startMonitoring() {
|
||||||
if (!_shouldMonitor() || _isListening) return;
|
if (!_shouldMonitor() || _isListening) return;
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import 'package:flutter/services.dart'
|
|||||||
KeyEvent,
|
KeyEvent,
|
||||||
KeyDownEvent,
|
KeyDownEvent,
|
||||||
HardwareKeyboard;
|
HardwareKeyboard;
|
||||||
|
import '../../services/fullscreen_state_manager.dart';
|
||||||
import '../../services/macos_window_service.dart';
|
import '../../services/macos_window_service.dart';
|
||||||
import '../../services/pip_service.dart';
|
import '../../services/pip_service.dart';
|
||||||
import 'package:window_manager/window_manager.dart';
|
import 'package:window_manager/window_manager.dart';
|
||||||
@@ -1236,27 +1237,7 @@ class _PlexVideoControlsState extends State<PlexVideoControls> with WindowListen
|
|||||||
|
|
||||||
Future<void> _toggleFullscreen() async {
|
Future<void> _toggleFullscreen() async {
|
||||||
if (!PlatformDetector.isMobile(context)) {
|
if (!PlatformDetector.isMobile(context)) {
|
||||||
// Query actual window state to determine what action to take
|
await FullscreenStateManager().toggleFullscreen();
|
||||||
// This ensures we always toggle correctly regardless of local state
|
|
||||||
final isCurrentlyFullscreen = await windowManager.isFullScreen();
|
|
||||||
|
|
||||||
if (Platform.isMacOS) {
|
|
||||||
// Use native macOS fullscreen - titlebar is handled automatically
|
|
||||||
// Window listener will update _isFullscreen for UI
|
|
||||||
if (isCurrentlyFullscreen) {
|
|
||||||
await MacOSWindowService.exitFullscreen();
|
|
||||||
} else {
|
|
||||||
await MacOSWindowService.enterFullscreen();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// For Windows/Linux, use window_manager
|
|
||||||
// Window listener will update _isFullscreen for UI
|
|
||||||
if (isCurrentlyFullscreen) {
|
|
||||||
await windowManager.setFullScreen(false);
|
|
||||||
} else {
|
|
||||||
await windowManager.setFullScreen(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user