mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: windows size overflow (#5103)
This commit is contained in:
parent
1aa4646433
commit
17df31a512
@ -1,5 +1,4 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:math';
|
|
||||||
import 'dart:ui';
|
import 'dart:ui';
|
||||||
|
|
||||||
import 'package:appflowy/core/config/kv.dart';
|
import 'package:appflowy/core/config/kv.dart';
|
||||||
@ -9,6 +8,9 @@ import 'package:appflowy/startup/startup.dart';
|
|||||||
class WindowSizeManager {
|
class WindowSizeManager {
|
||||||
static const double minWindowHeight = 600.0;
|
static const double minWindowHeight = 600.0;
|
||||||
static const double minWindowWidth = 800.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 width = 'width';
|
||||||
static const height = 'height';
|
static const height = 'height';
|
||||||
@ -18,8 +20,8 @@ class WindowSizeManager {
|
|||||||
|
|
||||||
Future<void> setSize(Size size) async {
|
Future<void> setSize(Size size) async {
|
||||||
final windowSize = {
|
final windowSize = {
|
||||||
height: max(size.height, minWindowHeight),
|
height: size.height.clamp(minWindowHeight, maxWindowHeight),
|
||||||
width: max(size.width, minWindowWidth),
|
width: size.width.clamp(minWindowWidth, maxWindowWidth),
|
||||||
};
|
};
|
||||||
|
|
||||||
await getIt<KeyValueStorage>().set(
|
await getIt<KeyValueStorage>().set(
|
||||||
@ -29,12 +31,19 @@ class WindowSizeManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<Size> getSize() async {
|
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 windowSize = await getIt<KeyValueStorage>().get(KVKeys.windowSize);
|
||||||
final size = json.decode(
|
final size = json.decode(
|
||||||
windowSize ?? defaultWindowSize,
|
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 {
|
Future<void> setPosition(Offset offset) async {
|
||||||
|
@ -9,11 +9,9 @@ import 'package:window_manager/window_manager.dart';
|
|||||||
|
|
||||||
class InitAppWindowTask extends LaunchTask with WindowListener {
|
class InitAppWindowTask extends LaunchTask with WindowListener {
|
||||||
const InitAppWindowTask({
|
const InitAppWindowTask({
|
||||||
this.minimumSize = const Size(800, 600),
|
|
||||||
this.title = 'AppFlowy',
|
this.title = 'AppFlowy',
|
||||||
});
|
});
|
||||||
|
|
||||||
final Size minimumSize;
|
|
||||||
final String title;
|
final String title;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -27,13 +25,16 @@ class InitAppWindowTask extends LaunchTask with WindowListener {
|
|||||||
windowManager.addListener(this);
|
windowManager.addListener(this);
|
||||||
|
|
||||||
final windowSize = await WindowSizeManager().getSize();
|
final windowSize = await WindowSizeManager().getSize();
|
||||||
|
|
||||||
final windowOptions = WindowOptions(
|
final windowOptions = WindowOptions(
|
||||||
size: windowSize,
|
size: windowSize,
|
||||||
minimumSize: const Size(
|
minimumSize: const Size(
|
||||||
WindowSizeManager.minWindowWidth,
|
WindowSizeManager.minWindowWidth,
|
||||||
WindowSizeManager.minWindowHeight,
|
WindowSizeManager.minWindowHeight,
|
||||||
),
|
),
|
||||||
|
maximumSize: const Size(
|
||||||
|
WindowSizeManager.maxWindowWidth,
|
||||||
|
WindowSizeManager.maxWindowHeight,
|
||||||
|
),
|
||||||
title: title,
|
title: title,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user