feat, remember remote window fullscreen state

Signed-off-by: dignow <linlong1265@gmail.com>
This commit is contained in:
dignow 2023-09-07 13:39:20 +08:00
parent 92916d9820
commit 55fc0cb63b

View File

@ -1392,9 +1392,10 @@ class LastWindowPosition {
double? offsetWidth; double? offsetWidth;
double? offsetHeight; double? offsetHeight;
bool? isMaximized; bool? isMaximized;
bool? isFullscreen;
LastWindowPosition(this.width, this.height, this.offsetWidth, LastWindowPosition(this.width, this.height, this.offsetWidth,
this.offsetHeight, this.isMaximized); this.offsetHeight, this.isMaximized, this.isFullscreen);
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
return <String, dynamic>{ return <String, dynamic>{
@ -1403,6 +1404,7 @@ class LastWindowPosition {
"offsetWidth": offsetWidth, "offsetWidth": offsetWidth,
"offsetHeight": offsetHeight, "offsetHeight": offsetHeight,
"isMaximized": isMaximized, "isMaximized": isMaximized,
"isFullscreen": isFullscreen,
}; };
} }
@ -1418,7 +1420,7 @@ class LastWindowPosition {
try { try {
final m = jsonDecode(content); final m = jsonDecode(content);
return LastWindowPosition(m["width"], m["height"], m["offsetWidth"], return LastWindowPosition(m["width"], m["height"], m["offsetWidth"],
m["offsetHeight"], m["isMaximized"]); m["offsetHeight"], m["isMaximized"], m["isFullscreen"]);
} catch (e) { } catch (e) {
debugPrintStack( debugPrintStack(
label: label:
@ -1484,20 +1486,21 @@ Future<void> saveWindowPosition(WindowType type, {int? windowId}) async {
} }
final pos = LastWindowPosition( final pos = LastWindowPosition(
sz.width, sz.height, position.dx, position.dy, isMaximized); sz.width, sz.height, position.dx, position.dy, isMaximized, stateGlobal.fullscreen);
debugPrint( debugPrint(
"Saving frame: $windowId: ${pos.width}/${pos.height}, offset:${pos.offsetWidth}/${pos.offsetHeight}, isMaximized:${pos.isMaximized}"); "Saving frame: $windowId: ${pos.width}/${pos.height}, offset:${pos.offsetWidth}/${pos.offsetHeight}, isMaximized:${pos.isMaximized}, isFullscreen:${pos.isFullscreen}");
await bind.setLocalFlutterOption( await bind.setLocalFlutterOption(
k: kWindowPrefix + type.name, v: pos.toString()); k: kWindowPrefix + type.name, v: pos.toString());
if (type == WindowType.RemoteDesktop && windowId != null) { if (type == WindowType.RemoteDesktop && windowId != null) {
await _saveSessionWindowPosition(type, windowId, isMaximized, pos); await _saveSessionWindowPosition(
type, windowId, isMaximized, stateGlobal.fullscreen, pos);
} }
} }
Future _saveSessionWindowPosition(WindowType windowType, int windowId, Future _saveSessionWindowPosition(WindowType windowType, int windowId,
bool isMaximized, LastWindowPosition pos) async { bool isMaximized, bool isFullscreen, LastWindowPosition pos) async {
final remoteList = await DesktopMultiWindow.invokeMethod( final remoteList = await DesktopMultiWindow.invokeMethod(
windowId, kWindowEventGetRemoteList, null); windowId, kWindowEventGetRemoteList, null);
getPeerPos(String peerId) { getPeerPos(String peerId) {
@ -1510,7 +1513,8 @@ Future _saveSessionWindowPosition(WindowType windowType, int windowId,
lpos?.height ?? pos.offsetHeight, lpos?.height ?? pos.offsetHeight,
lpos?.offsetWidth ?? pos.offsetWidth, lpos?.offsetWidth ?? pos.offsetWidth,
lpos?.offsetHeight ?? pos.offsetHeight, lpos?.offsetHeight ?? pos.offsetHeight,
isMaximized) isMaximized,
isFullscreen)
.toString(); .toString();
} else { } else {
return pos.toString(); return pos.toString();
@ -1700,7 +1704,13 @@ Future<bool> restoreWindowPosition(WindowType type,
await wc.setFrame(frame); await wc.setFrame(frame);
} }
} }
if (lpos.isMaximized == true) { if (lpos.isFullscreen == true) {
await restoreFrame();
// An duration is needed to avoid the window being restored after fullscreen.
Future.delayed(Duration(milliseconds: 300), () async {
stateGlobal.setFullscreen(true);
});
} else if (lpos.isMaximized == true) {
await restoreFrame(); await restoreFrame();
// An duration is needed to avoid the window being restored after maximized. // An duration is needed to avoid the window being restored after maximized.
Future.delayed(Duration(milliseconds: 300), () async { Future.delayed(Duration(milliseconds: 300), () async {