fix: windows size overflow (#5103)

This commit is contained in:
Lucas.Xu 2024-04-10 11:36:22 +08:00 committed by GitHub
parent 1aa4646433
commit 17df31a512
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 8 deletions

View File

@ -1,5 +1,4 @@
import 'dart:convert';
import 'dart:math';
import 'dart:ui';
import 'package:appflowy/core/config/kv.dart';
@ -9,6 +8,9 @@ import 'package:appflowy/startup/startup.dart';
class WindowSizeManager {
static const double minWindowHeight = 600.0;
static const double minWindowWidth = 800.0;
// Preventing failed assertion due to Texture Descriptor Validation
static const double maxWindowHeight = 8192.0;
static const double maxWindowWidth = 8192.0;
static const width = 'width';
static const height = 'height';
@ -18,8 +20,8 @@ class WindowSizeManager {
Future<void> setSize(Size size) async {
final windowSize = {
height: max(size.height, minWindowHeight),
width: max(size.width, minWindowWidth),
height: size.height.clamp(minWindowHeight, maxWindowHeight),
width: size.width.clamp(minWindowWidth, maxWindowWidth),
};
await getIt<KeyValueStorage>().set(
@ -29,12 +31,19 @@ class WindowSizeManager {
}
Future<Size> getSize() async {
final defaultWindowSize = jsonEncode({height: 600.0, width: 800.0});
final defaultWindowSize = jsonEncode(
{WindowSizeManager.height: 600.0, WindowSizeManager.width: 800.0},
);
final windowSize = await getIt<KeyValueStorage>().get(KVKeys.windowSize);
final size = json.decode(
windowSize ?? defaultWindowSize,
);
return Size(size[width]!, size[height]!);
final double width = size[WindowSizeManager.width] ?? minWindowWidth;
final double height = size[WindowSizeManager.height] ?? minWindowHeight;
return Size(
width.clamp(minWindowWidth, maxWindowWidth),
height.clamp(minWindowHeight, maxWindowHeight),
);
}
Future<void> setPosition(Offset offset) async {

View File

@ -9,11 +9,9 @@ import 'package:window_manager/window_manager.dart';
class InitAppWindowTask extends LaunchTask with WindowListener {
const InitAppWindowTask({
this.minimumSize = const Size(800, 600),
this.title = 'AppFlowy',
});
final Size minimumSize;
final String title;
@override
@ -27,13 +25,16 @@ class InitAppWindowTask extends LaunchTask with WindowListener {
windowManager.addListener(this);
final windowSize = await WindowSizeManager().getSize();
final windowOptions = WindowOptions(
size: windowSize,
minimumSize: const Size(
WindowSizeManager.minWindowWidth,
WindowSizeManager.minWindowHeight,
),
maximumSize: const Size(
WindowSizeManager.maxWindowWidth,
WindowSizeManager.maxWindowHeight,
),
title: title,
);