mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: the application remembers being resized (#2907)
This commit is contained in:
parent
7dcc7c221f
commit
a00dd5498e
@ -19,6 +19,12 @@ class KVKeys {
|
||||
/// {'height': 600.0, 'width': 800.0}
|
||||
static const String windowSize = 'windowSize';
|
||||
|
||||
/// The key for saving the window position
|
||||
///
|
||||
/// The value is a json string with the following format:
|
||||
/// {'dx': 10.0, 'dy': 10.0}
|
||||
static const String windowPosition = 'windowPosition';
|
||||
|
||||
static const String kDocumentAppearanceFontSize =
|
||||
'kDocumentAppearanceFontSize';
|
||||
static const String kDocumentAppearanceFontFamily =
|
||||
|
@ -1,11 +1,12 @@
|
||||
import 'package:flutter/foundation.dart' show TargetPlatform;
|
||||
import 'package:flutter/foundation.dart' show TargetPlatform, kIsWeb;
|
||||
|
||||
extension TargetPlatformHelper on TargetPlatform {
|
||||
/// Convenience function to check if the app is running on a desktop computer.
|
||||
///
|
||||
/// Easily check if on desktop by checking `defaultTargetPlatform.isDesktop`.
|
||||
bool get isDesktop =>
|
||||
this == TargetPlatform.linux ||
|
||||
this == TargetPlatform.macOS ||
|
||||
this == TargetPlatform.windows;
|
||||
!kIsWeb &&
|
||||
(this == TargetPlatform.linux ||
|
||||
this == TargetPlatform.macOS ||
|
||||
this == TargetPlatform.windows);
|
||||
}
|
||||
|
@ -13,7 +13,10 @@ class WindowSizeManager {
|
||||
static const width = 'width';
|
||||
static const height = 'height';
|
||||
|
||||
Future<void> saveSize(Size size) async {
|
||||
static const String dx = 'dx';
|
||||
static const String dy = 'dy';
|
||||
|
||||
Future<void> setSize(Size size) async {
|
||||
final windowSize = {
|
||||
height: max(size.height, minWindowHeight),
|
||||
width: max(size.width, minWindowWidth),
|
||||
@ -33,4 +36,25 @@ class WindowSizeManager {
|
||||
);
|
||||
return Size(size[width]!, size[height]!);
|
||||
}
|
||||
|
||||
Future<void> setPosition(Offset offset) async {
|
||||
await getIt<KeyValueStorage>().set(
|
||||
KVKeys.windowPosition,
|
||||
jsonEncode({
|
||||
dx: offset.dx,
|
||||
dy: offset.dy,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
Future<Offset?> getPosition() async {
|
||||
final position = await getIt<KeyValueStorage>().get(KVKeys.windowPosition);
|
||||
return position.fold(
|
||||
(l) => null,
|
||||
(r) {
|
||||
final offset = json.decode(r);
|
||||
return Offset(offset[dx], offset[dy]);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -40,12 +40,35 @@ class InitAppWindowTask extends LaunchTask with WindowListener {
|
||||
windowManager.waitUntilReadyToShow(windowOptions, () async {
|
||||
await windowManager.show();
|
||||
await windowManager.focus();
|
||||
|
||||
final position = await WindowSizeManager().getPosition();
|
||||
if (position != null) {
|
||||
await windowManager.setPosition(position);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> onWindowResize() async {
|
||||
super.onWindowResize();
|
||||
|
||||
final currentWindowSize = await windowManager.getSize();
|
||||
WindowSizeManager().saveSize(currentWindowSize);
|
||||
WindowSizeManager().setSize(currentWindowSize);
|
||||
}
|
||||
|
||||
@override
|
||||
void onWindowMaximize() async {
|
||||
super.onWindowMaximize();
|
||||
|
||||
final currentWindowSize = await windowManager.getSize();
|
||||
WindowSizeManager().setSize(currentWindowSize);
|
||||
}
|
||||
|
||||
@override
|
||||
void onWindowMoved() async {
|
||||
super.onWindowMoved();
|
||||
|
||||
final position = await windowManager.getPosition();
|
||||
WindowSizeManager().setPosition(position);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user