mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-04-16 01:11:29 +03:00
fix: save frame, LateInitializationError (#13265)
Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
@@ -1736,22 +1736,29 @@ final Debouncer _saveWindowDebounce = Debouncer(delay: Duration(seconds: 1));
|
|||||||
|
|
||||||
/// Save window position and size on exit
|
/// Save window position and size on exit
|
||||||
/// Note that windowId must be provided if it's subwindow
|
/// Note that windowId must be provided if it's subwindow
|
||||||
Future<void> saveWindowPosition(WindowType type, {int? windowId, bool? flush}) async {
|
Future<void> saveWindowPosition(WindowType type,
|
||||||
|
{int? windowId, bool? flush}) async {
|
||||||
if (type != WindowType.Main && windowId == null) {
|
if (type != WindowType.Main && windowId == null) {
|
||||||
debugPrint(
|
debugPrint(
|
||||||
"Error: windowId cannot be null when saving positions for sub window");
|
"Error: windowId cannot be null when saving positions for sub window");
|
||||||
}
|
}
|
||||||
|
|
||||||
late Offset position;
|
Offset? position;
|
||||||
late Size sz;
|
Size? sz;
|
||||||
late bool isMaximized;
|
late bool isMaximized;
|
||||||
bool isFullscreen = stateGlobal.fullscreen.isTrue;
|
bool isFullscreen = stateGlobal.fullscreen.isTrue;
|
||||||
|
|
||||||
setPreFrame() {
|
setPreFrame() {
|
||||||
final pos = bind.getLocalFlutterOption(k: windowFramePrefix + type.name);
|
final pos = bind.getLocalFlutterOption(k: windowFramePrefix + type.name);
|
||||||
var lpos = LastWindowPosition.loadFromString(pos);
|
var lpos = LastWindowPosition.loadFromString(pos);
|
||||||
position = Offset(
|
if (lpos != null) {
|
||||||
lpos?.offsetWidth ?? position.dx, lpos?.offsetHeight ?? position.dy);
|
if (lpos.offsetWidth != null && lpos.offsetHeight != null) {
|
||||||
sz = Size(lpos?.width ?? sz.width, lpos?.height ?? sz.height);
|
position = Offset(lpos.offsetWidth!, lpos.offsetHeight!);
|
||||||
|
}
|
||||||
|
if (lpos.width != null && lpos.height != null) {
|
||||||
|
sz = Size(lpos.width!, lpos.height!);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@@ -1791,20 +1798,20 @@ Future<void> saveWindowPosition(WindowType type, {int? windowId, bool? flush}) a
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (isWindows) {
|
if (isWindows && position != null) {
|
||||||
const kMinOffset = -10000;
|
const kMinOffset = -10000;
|
||||||
const kMaxOffset = 10000;
|
const kMaxOffset = 10000;
|
||||||
if (position.dx < kMinOffset ||
|
if (position!.dx < kMinOffset ||
|
||||||
position.dy < kMinOffset ||
|
position!.dy < kMinOffset ||
|
||||||
position.dx > kMaxOffset ||
|
position!.dx > kMaxOffset ||
|
||||||
position.dy > kMaxOffset) {
|
position!.dy > kMaxOffset) {
|
||||||
debugPrint("Invalid position: $position, ignore saving position");
|
debugPrint("Invalid position: $position, ignore saving position");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final pos = LastWindowPosition(
|
final pos = LastWindowPosition(sz?.width, sz?.height, position?.dx,
|
||||||
sz.width, sz.height, position.dx, position.dy, isMaximized, isFullscreen);
|
position?.dy, isMaximized, isFullscreen);
|
||||||
|
|
||||||
final WindowKey key = (type: type, windowId: windowId);
|
final WindowKey key = (type: type, windowId: windowId);
|
||||||
|
|
||||||
|
|||||||
@@ -405,10 +405,15 @@ class _DesktopTabState extends State<DesktopTab>
|
|||||||
}
|
}
|
||||||
|
|
||||||
_saveFrame({bool? flush}) async {
|
_saveFrame({bool? flush}) async {
|
||||||
if (tabType == DesktopTabType.main) {
|
try {
|
||||||
await saveWindowPosition(WindowType.Main, flush: flush);
|
if (tabType == DesktopTabType.main) {
|
||||||
} else if (kWindowType != null && kWindowId != null) {
|
await saveWindowPosition(WindowType.Main, flush: flush);
|
||||||
await saveWindowPosition(kWindowType!, windowId: kWindowId, flush: flush);
|
} else if (kWindowType != null && kWindowId != null) {
|
||||||
|
await saveWindowPosition(kWindowType!,
|
||||||
|
windowId: kWindowId, flush: flush);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint('Error saving window position: $e');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -475,7 +475,11 @@ class RustDeskMultiWindowManager {
|
|||||||
final shouldSavePos = type != WindowType.Terminal || i == windows.length - 1;
|
final shouldSavePos = type != WindowType.Terminal || i == windows.length - 1;
|
||||||
if (shouldSavePos) {
|
if (shouldSavePos) {
|
||||||
debugPrint("closing multi window, type: ${type.toString()} id: $wId");
|
debugPrint("closing multi window, type: ${type.toString()} id: $wId");
|
||||||
await saveWindowPosition(type, windowId: wId);
|
try {
|
||||||
|
await saveWindowPosition(type, windowId: wId);
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint('Failed to save window position of $wId, $e');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await WindowController.fromWindowId(wId).setPreventClose(false);
|
await WindowController.fromWindowId(wId).setPreventClose(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user