diff --git a/flutter/lib/desktop/widgets/remote_toolbar.dart b/flutter/lib/desktop/widgets/remote_toolbar.dart index 2d20d5931..d0fbc4673 100644 --- a/flutter/lib/desktop/widgets/remote_toolbar.dart +++ b/flutter/lib/desktop/widgets/remote_toolbar.dart @@ -436,6 +436,7 @@ class _RemoteToolbarState extends State { shadowColor: MyTheme.color(context).shadow, borderRadius: borderRadius, child: _DraggableShowHide( + id: widget.id, sessionId: widget.ffi.sessionId, dragging: _dragging, fractionX: _fractionX, @@ -2218,6 +2219,7 @@ class RdoMenuButton extends StatelessWidget { } class _DraggableShowHide extends StatefulWidget { + final String id; final SessionID sessionId; final RxDouble fractionX; final RxBool dragging; @@ -2229,6 +2231,7 @@ class _DraggableShowHide extends StatefulWidget { const _DraggableShowHide({ Key? key, + required this.id, required this.sessionId, required this.fractionX, required this.dragging, @@ -2364,6 +2367,24 @@ class _DraggableShowHideState extends State<_DraggableShowHide> { ), ))), ), + if (isWebDesktop) + Obx(() { + if (show.isTrue) { + return Offstage(); + } else { + return TextButton( + onPressed: () => closeConnection(id: widget.id), + child: Tooltip( + message: translate('Close'), + child: Icon( + Icons.close, + size: iconSize, + color: _ToolbarTheme.redColor, + ), + ), + ); + } + }) ], ); return TextButtonTheme( diff --git a/flutter/lib/models/native_model.dart b/flutter/lib/models/native_model.dart index b99cf2e7f..c8d5085e8 100644 --- a/flutter/lib/models/native_model.dart +++ b/flutter/lib/models/native_model.dart @@ -48,6 +48,12 @@ class PlatformFFI { static get isMain => instance._appType == kAppTypeMain; + static String getByName(String name, [String arg = '']) { + return ''; + } + + static void setByName(String name, [String value = '']) {} + static Future getVersion() async { PackageInfo packageInfo = await PackageInfo.fromPlatform(); return packageInfo.version; @@ -276,4 +282,6 @@ class PlatformFFI { void syncAndroidServiceAppDirConfigPath() { invokeMethod(AndroidChannel.kSyncAppDirConfigPath, _dir); } + + void setFullscreenCallback(void Function(bool) fun) {} } diff --git a/flutter/lib/models/state_model.dart b/flutter/lib/models/state_model.dart index a1b5fc736..62f92db12 100644 --- a/flutter/lib/models/state_model.dart +++ b/flutter/lib/models/state_model.dart @@ -2,6 +2,7 @@ import 'package:desktop_multi_window/desktop_multi_window.dart'; import 'package:flutter/material.dart'; import 'package:flutter_hbb/common.dart'; import 'package:get/get.dart'; +import 'native_model.dart' if (dart.library.html) 'web_model.dart'; import '../consts.dart'; import './platform_model.dart'; @@ -73,27 +74,47 @@ class StateGlobal { if (_fullscreen.value != v) { _fullscreen.value = v; _showTabBar.value = !_fullscreen.value; - refreshResizeEdgeSize(); - print( - "fullscreen: $fullscreen, resizeEdgeSize: ${_resizeEdgeSize.value}"); - _windowBorderWidth.value = fullscreen.isTrue ? 0 : kWindowBorderWidth; - if (procWnd) { - final wc = WindowController.fromWindowId(windowId); - wc.setFullscreen(_fullscreen.isTrue).then((_) { - // https://github.com/leanflutter/window_manager/issues/131#issuecomment-1111587982 - if (isWindows && !v) { - Future.delayed(Duration.zero, () async { - final frame = await wc.getFrame(); - final newRect = Rect.fromLTWH( - frame.left, frame.top, frame.width + 1, frame.height + 1); - await wc.setFrame(newRect); - }); - } - }); + if (isWebDesktop) { + procFullscreenWeb(); + } else { + procFullscreenNative(procWnd); } } } + procFullscreenWeb() { + final isFullscreen = PlatformFFI.getByName('fullscreen') == 'Y'; + String fullscreenValue = ''; + if (isFullscreen && _fullscreen.isFalse) { + fullscreenValue = 'N'; + } else if (!isFullscreen && fullscreen.isTrue) { + fullscreenValue = 'Y'; + } + if (fullscreenValue.isNotEmpty) { + PlatformFFI.setByName('fullscreen', fullscreenValue); + } + } + + procFullscreenNative(bool procWnd) { + refreshResizeEdgeSize(); + print("fullscreen: $fullscreen, resizeEdgeSize: ${_resizeEdgeSize.value}"); + _windowBorderWidth.value = fullscreen.isTrue ? 0 : kWindowBorderWidth; + if (procWnd) { + final wc = WindowController.fromWindowId(windowId); + wc.setFullscreen(_fullscreen.isTrue).then((_) { + // https://github.com/leanflutter/window_manager/issues/131#issuecomment-1111587982 + if (isWindows && _fullscreen.isFalse) { + Future.delayed(Duration.zero, () async { + final frame = await wc.getFrame(); + final newRect = Rect.fromLTWH( + frame.left, frame.top, frame.width + 1, frame.height + 1); + await wc.setFrame(newRect); + }); + } + }); + } + } + refreshResizeEdgeSize() => _resizeEdgeSize.value = fullscreen.isTrue ? kFullScreenEdgeSize : isMaximized.isTrue @@ -112,7 +133,13 @@ class StateGlobal { _inputSource = bind.mainGetInputSource(); } - StateGlobal._(); + StateGlobal._() { + if (isWebDesktop) { + platformFFI.setFullscreenCallback((v) { + _fullscreen.value = v; + }); + } + } static final StateGlobal instance = StateGlobal._(); } diff --git a/flutter/lib/models/web_model.dart b/flutter/lib/models/web_model.dart index ff0d1b806..a5740af61 100644 --- a/flutter/lib/models/web_model.dart +++ b/flutter/lib/models/web_model.dart @@ -166,4 +166,10 @@ class PlatformFFI { // just for compilation void syncAndroidServiceAppDirConfigPath() {} + + void setFullscreenCallback(void Function(bool) fun) { + context["onFullscreenChanged"] = (bool v) { + fun(v); + }; + } }