Skip to content

Commit

Permalink
Merge branch 'rustdesk:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangbo8418 authored Oct 6, 2024
2 parents 065ab9a + 83aba80 commit d6a5f79
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 18 deletions.
21 changes: 21 additions & 0 deletions flutter/lib/desktop/widgets/remote_toolbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ class _RemoteToolbarState extends State<RemoteToolbar> {
shadowColor: MyTheme.color(context).shadow,
borderRadius: borderRadius,
child: _DraggableShowHide(
id: widget.id,
sessionId: widget.ffi.sessionId,
dragging: _dragging,
fractionX: _fractionX,
Expand Down Expand Up @@ -2218,6 +2219,7 @@ class RdoMenuButton<T> extends StatelessWidget {
}

class _DraggableShowHide extends StatefulWidget {
final String id;
final SessionID sessionId;
final RxDouble fractionX;
final RxBool dragging;
Expand All @@ -2229,6 +2231,7 @@ class _DraggableShowHide extends StatefulWidget {

const _DraggableShowHide({
Key? key,
required this.id,
required this.sessionId,
required this.fractionX,
required this.dragging,
Expand Down Expand Up @@ -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(
Expand Down
8 changes: 8 additions & 0 deletions flutter/lib/models/native_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> getVersion() async {
PackageInfo packageInfo = await PackageInfo.fromPlatform();
return packageInfo.version;
Expand Down Expand Up @@ -276,4 +282,6 @@ class PlatformFFI {
void syncAndroidServiceAppDirConfigPath() {
invokeMethod(AndroidChannel.kSyncAppDirConfigPath, _dir);
}

void setFullscreenCallback(void Function(bool) fun) {}
}
63 changes: 45 additions & 18 deletions flutter/lib/models/state_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand All @@ -112,7 +133,13 @@ class StateGlobal {
_inputSource = bind.mainGetInputSource();
}

StateGlobal._();
StateGlobal._() {
if (isWebDesktop) {
platformFFI.setFullscreenCallback((v) {
_fullscreen.value = v;
});
}
}

static final StateGlobal instance = StateGlobal._();
}
Expand Down
6 changes: 6 additions & 0 deletions flutter/lib/models/web_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,10 @@ class PlatformFFI {

// just for compilation
void syncAndroidServiceAppDirConfigPath() {}

void setFullscreenCallback(void Function(bool) fun) {
context["onFullscreenChanged"] = (bool v) {
fun(v);
};
}
}

0 comments on commit d6a5f79

Please sign in to comment.