diff --git a/lib/main.dart b/lib/main.dart index b9c417dc2..5e2e04995 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -66,9 +66,14 @@ void main() async { await windowManager.ensureInitialized(); bool isLowResolution = await Utils.isLowResolution(); WindowOptions windowOptions = WindowOptions( - size: isLowResolution ? const Size(840, 600) : const Size(1280, 860), - center: true, skipTaskbar: false, + minimumSize: const Size(320, 270), + center: Platform.isWindows ? true : false, + size: Platform.isWindows + ? isLowResolution + ? const Size(840, 600) + : null + : null, // macOS always hide title bar regardless of showWindowButton setting titleBarStyle: (Platform.isMacOS || !showWindowButton) ? TitleBarStyle.hidden diff --git a/lib/utils/utils.dart b/lib/utils/utils.dart index 91f4ce6e0..e08f04278 100644 --- a/lib/utils/utils.dart +++ b/lib/utils/utils.dart @@ -21,6 +21,8 @@ import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_pla class Utils { static final Random random = Random(); + static Size? _previousWindowSize; + static bool? _isDocumentStartScriptSupported; /// 检查 Android WebView 是否支持 DOCUMENT_START_SCRIPT 特性 @@ -495,16 +497,18 @@ class Utils { // 进入桌面设备小窗模式 static Future enterDesktopPIPWindow() async { + _previousWindowSize = await windowManager.getSize(); await windowManager.setAlwaysOnTop(true); + await windowManager.setAspectRatio(16 / 9); await windowManager.setSize(const Size(480, 270)); } // 退出桌面设备小窗模式 static Future exitDesktopPIPWindow() async { - bool isLowResolution = await Utils.isLowResolution(); await windowManager.setAlwaysOnTop(false); - await windowManager.setSize( - isLowResolution ? const Size(800, 600) : const Size(1280, 860)); + await windowManager.setSize(_previousWindowSize!); + _previousWindowSize = null; + await windowManager.setAspectRatio(0); await windowManager.center(); } diff --git a/macos/Runner/AppDelegate.swift b/macos/Runner/AppDelegate.swift index ab6a64d74..e767ff1f4 100644 --- a/macos/Runner/AppDelegate.swift +++ b/macos/Runner/AppDelegate.swift @@ -130,7 +130,7 @@ class AppDelegate: FlutterAppDelegate { } @objc func openWithAVPlayer () { - let window = NSWindow(contentRect: NSRect(x: 0, y: 0, width: 1280, height: 860), + let window = NSWindow(contentRect: NSRect(x: 0, y: 0, width: 1280, height: 720), styleMask: [.titled, .closable, .resizable], backing: .buffered, defer: false) window.center()