fix: web fullscreen (#9577)

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou 2024-10-07 00:01:14 +08:00 committed by GitHub
parent 560c1effe8
commit 83aba804d0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 80 additions and 18 deletions

View File

@ -436,6 +436,7 @@ class _RemoteToolbarState extends State<RemoteToolbar> {
shadowColor: MyTheme.color(context).shadow, shadowColor: MyTheme.color(context).shadow,
borderRadius: borderRadius, borderRadius: borderRadius,
child: _DraggableShowHide( child: _DraggableShowHide(
id: widget.id,
sessionId: widget.ffi.sessionId, sessionId: widget.ffi.sessionId,
dragging: _dragging, dragging: _dragging,
fractionX: _fractionX, fractionX: _fractionX,
@ -2218,6 +2219,7 @@ class RdoMenuButton<T> extends StatelessWidget {
} }
class _DraggableShowHide extends StatefulWidget { class _DraggableShowHide extends StatefulWidget {
final String id;
final SessionID sessionId; final SessionID sessionId;
final RxDouble fractionX; final RxDouble fractionX;
final RxBool dragging; final RxBool dragging;
@ -2229,6 +2231,7 @@ class _DraggableShowHide extends StatefulWidget {
const _DraggableShowHide({ const _DraggableShowHide({
Key? key, Key? key,
required this.id,
required this.sessionId, required this.sessionId,
required this.fractionX, required this.fractionX,
required this.dragging, 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( return TextButtonTheme(

View File

@ -48,6 +48,12 @@ class PlatformFFI {
static get isMain => instance._appType == kAppTypeMain; static get isMain => instance._appType == kAppTypeMain;
static String getByName(String name, [String arg = '']) {
return '';
}
static void setByName(String name, [String value = '']) {}
static Future<String> getVersion() async { static Future<String> getVersion() async {
PackageInfo packageInfo = await PackageInfo.fromPlatform(); PackageInfo packageInfo = await PackageInfo.fromPlatform();
return packageInfo.version; return packageInfo.version;
@ -276,4 +282,6 @@ class PlatformFFI {
void syncAndroidServiceAppDirConfigPath() { void syncAndroidServiceAppDirConfigPath() {
invokeMethod(AndroidChannel.kSyncAppDirConfigPath, _dir); invokeMethod(AndroidChannel.kSyncAppDirConfigPath, _dir);
} }
void setFullscreenCallback(void Function(bool) fun) {}
} }

View File

@ -2,6 +2,7 @@ import 'package:desktop_multi_window/desktop_multi_window.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_hbb/common.dart'; import 'package:flutter_hbb/common.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'native_model.dart' if (dart.library.html) 'web_model.dart';
import '../consts.dart'; import '../consts.dart';
import './platform_model.dart'; import './platform_model.dart';
@ -73,15 +74,36 @@ class StateGlobal {
if (_fullscreen.value != v) { if (_fullscreen.value != v) {
_fullscreen.value = v; _fullscreen.value = v;
_showTabBar.value = !_fullscreen.value; _showTabBar.value = !_fullscreen.value;
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(); refreshResizeEdgeSize();
print( print("fullscreen: $fullscreen, resizeEdgeSize: ${_resizeEdgeSize.value}");
"fullscreen: $fullscreen, resizeEdgeSize: ${_resizeEdgeSize.value}");
_windowBorderWidth.value = fullscreen.isTrue ? 0 : kWindowBorderWidth; _windowBorderWidth.value = fullscreen.isTrue ? 0 : kWindowBorderWidth;
if (procWnd) { if (procWnd) {
final wc = WindowController.fromWindowId(windowId); final wc = WindowController.fromWindowId(windowId);
wc.setFullscreen(_fullscreen.isTrue).then((_) { wc.setFullscreen(_fullscreen.isTrue).then((_) {
// https://github.com/leanflutter/window_manager/issues/131#issuecomment-1111587982 // https://github.com/leanflutter/window_manager/issues/131#issuecomment-1111587982
if (isWindows && !v) { if (isWindows && _fullscreen.isFalse) {
Future.delayed(Duration.zero, () async { Future.delayed(Duration.zero, () async {
final frame = await wc.getFrame(); final frame = await wc.getFrame();
final newRect = Rect.fromLTWH( final newRect = Rect.fromLTWH(
@ -92,7 +114,6 @@ class StateGlobal {
}); });
} }
} }
}
refreshResizeEdgeSize() => _resizeEdgeSize.value = fullscreen.isTrue refreshResizeEdgeSize() => _resizeEdgeSize.value = fullscreen.isTrue
? kFullScreenEdgeSize ? kFullScreenEdgeSize
@ -112,7 +133,13 @@ class StateGlobal {
_inputSource = bind.mainGetInputSource(); _inputSource = bind.mainGetInputSource();
} }
StateGlobal._(); StateGlobal._() {
if (isWebDesktop) {
platformFFI.setFullscreenCallback((v) {
_fullscreen.value = v;
});
}
}
static final StateGlobal instance = StateGlobal._(); static final StateGlobal instance = StateGlobal._();
} }

View File

@ -166,4 +166,10 @@ class PlatformFFI {
// just for compilation // just for compilation
void syncAndroidServiceAppDirConfigPath() {} void syncAndroidServiceAppDirConfigPath() {}
void setFullscreenCallback(void Function(bool) fun) {
context["onFullscreenChanged"] = (bool v) {
fun(v);
};
}
} }