fix, macos, close sessions, confirm dialog and then hide

Signed-off-by: dignow <linlong1265@gmail.com>
This commit is contained in:
dignow 2023-10-20 09:15:53 +08:00
parent 4a03b3d7d9
commit 676b02c8de
5 changed files with 36 additions and 26 deletions

View File

@ -1495,7 +1495,7 @@ Future<void> saveWindowPosition(WindowType type, {int? windowId}) async {
late Size sz; late Size sz;
late bool isMaximized; late bool isMaximized;
bool isFullscreen = stateGlobal.fullscreen.isTrue || bool isFullscreen = stateGlobal.fullscreen.isTrue ||
(Platform.isMacOS && stateGlobal.closeOnFullscreen); (Platform.isMacOS && stateGlobal.closeOnFullscreen == true);
setFrameIfMaximized() { setFrameIfMaximized() {
if (isMaximized) { if (isMaximized) {
final pos = bind.getLocalFlutterOption(k: kWindowPrefix + type.name); final pos = bind.getLocalFlutterOption(k: kWindowPrefix + type.name);

View File

@ -125,9 +125,12 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
windowOnTop(windowId()); windowOnTop(windowId());
tryMoveToScreenAndSetFullscreen(screenRect); tryMoveToScreenAndSetFullscreen(screenRect);
if (tabController.length == 0) { if (tabController.length == 0) {
if (Platform.isMacOS && stateGlobal.closeOnFullscreen) { // Show the hidden window.
if (Platform.isMacOS && stateGlobal.closeOnFullscreen == true) {
stateGlobal.setFullscreen(true); stateGlobal.setFullscreen(true);
} }
// Reset the state
stateGlobal.closeOnFullscreen = null;
} }
ConnectionTypeState.init(id); ConnectionTypeState.init(id);
_toolbarState.setShow( _toolbarState.setShow(

View File

@ -20,7 +20,6 @@ import 'package:desktop_multi_window/desktop_multi_window.dart';
import 'package:window_size/window_size.dart' as window_size; import 'package:window_size/window_size.dart' as window_size;
import '../../common.dart'; import '../../common.dart';
import '../../common/widgets/dialog.dart';
import '../../models/model.dart'; import '../../models/model.dart';
import '../../models/platform_model.dart'; import '../../models/platform_model.dart';
import '../../common/shared_state.dart'; import '../../common/shared_state.dart';
@ -1683,7 +1682,7 @@ class _CloseMenu extends StatelessWidget {
return _IconMenuButton( return _IconMenuButton(
assetName: 'assets/close.svg', assetName: 'assets/close.svg',
tooltip: 'Close', tooltip: 'Close',
onPressed: () => clientClose(ffi.sessionId, ffi.dialogManager), onPressed: () => closeConnection(id: id),
color: _ToolbarTheme.redColor, color: _ToolbarTheme.redColor,
hoverColor: _ToolbarTheme.hoverRedColor, hoverColor: _ToolbarTheme.hoverRedColor,
); );

View File

@ -581,18 +581,14 @@ class WindowActionPanelState extends State<WindowActionPanel>
mainWindowClose() async => await windowManager.hide(); mainWindowClose() async => await windowManager.hide();
notMainWindowClose(WindowController controller) async { notMainWindowClose(WindowController controller) async {
await controller.hide(); await controller.hide();
await Future.wait([ await rustDeskWinManager
rustDeskWinManager .call(WindowType.Main, kWindowEventHide, {"id": kWindowId!});
.call(WindowType.Main, kWindowEventHide, {"id": kWindowId!}),
widget.onClose?.call() ?? Future.microtask(() => null)
]);
} }
macOSWindowClose( macOSWindowClose(
Future<void> Function() restoreFunc, Future<bool> Function() checkFullscreen,
Future<bool> Function() checkFullscreen, Future<void> Function() closeFunc,
Future<void> Function() closeFunc) async { ) async {
await restoreFunc();
_macOSCheckRestoreCounter = 0; _macOSCheckRestoreCounter = 0;
_macOSCheckRestoreTimer = _macOSCheckRestoreTimer =
Timer.periodic(Duration(milliseconds: 30), (timer) async { Timer.periodic(Duration(milliseconds: 30), (timer) async {
@ -612,26 +608,38 @@ class WindowActionPanelState extends State<WindowActionPanel>
} }
// macOS specific workaround, the window is not hiding when in fullscreen. // macOS specific workaround, the window is not hiding when in fullscreen.
if (Platform.isMacOS && await windowManager.isFullScreen()) { if (Platform.isMacOS && await windowManager.isFullScreen()) {
stateGlobal.closeOnFullscreen = true; stateGlobal.closeOnFullscreen ??= true;
await windowManager.setFullScreen(false);
await macOSWindowClose( await macOSWindowClose(
() async => await windowManager.setFullScreen(false), () async => await windowManager.isFullScreen(),
() async => await windowManager.isFullScreen(), mainWindowClose,
mainWindowClose); );
} else { } else {
stateGlobal.closeOnFullscreen = false; stateGlobal.closeOnFullscreen ??= false;
await mainWindowClose(); await mainWindowClose();
} }
} else { } else {
// it's safe to hide the subwindow // it's safe to hide the subwindow
final controller = WindowController.fromWindowId(kWindowId!); final controller = WindowController.fromWindowId(kWindowId!);
if (Platform.isMacOS && await controller.isFullScreen()) { if (Platform.isMacOS) {
stateGlobal.closeOnFullscreen = true; // onWindowClose() maybe called multiple times as loopCloseWindow() in remote_tab_page.dart.
await macOSWindowClose( // use ??= to make sure the value is set on first call.
() async => await controller.setFullscreen(false),
() async => await controller.isFullScreen(), if (await widget.onClose?.call() ?? true) {
() async => await notMainWindowClose(controller)); if (await controller.isFullScreen()) {
stateGlobal.closeOnFullscreen ??= true;
await controller.setFullscreen(false);
stateGlobal.setFullscreen(false, procWnd: false);
await macOSWindowClose(
() async => await controller.isFullScreen(),
() async => await notMainWindowClose(controller),
);
} else {
stateGlobal.closeOnFullscreen ??= false;
await notMainWindowClose(controller);
}
}
} else { } else {
stateGlobal.closeOnFullscreen = false;
await notMainWindowClose(controller); await notMainWindowClose(controller);
} }
} }

View File

@ -20,7 +20,7 @@ class StateGlobal {
final RxBool showRemoteToolBar = false.obs; final RxBool showRemoteToolBar = false.obs;
final svcStatus = SvcStatus.notReady.obs; final svcStatus = SvcStatus.notReady.obs;
// Only used for macOS // Only used for macOS
bool closeOnFullscreen = false; bool? closeOnFullscreen;
// Use for desktop -> remote toolbar -> resolution // Use for desktop -> remote toolbar -> resolution
final Map<String, Map<int, String?>> _lastResolutionGroupValues = {}; final Map<String, Map<int, String?>> _lastResolutionGroupValues = {};