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}
|
/// {'height': 600.0, 'width': 800.0}
|
||||||
static const String windowSize = 'windowSize';
|
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 =
|
static const String kDocumentAppearanceFontSize =
|
||||||
'kDocumentAppearanceFontSize';
|
'kDocumentAppearanceFontSize';
|
||||||
static const String kDocumentAppearanceFontFamily =
|
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 {
|
extension TargetPlatformHelper on TargetPlatform {
|
||||||
/// Convenience function to check if the app is running on a desktop computer.
|
/// Convenience function to check if the app is running on a desktop computer.
|
||||||
///
|
///
|
||||||
/// Easily check if on desktop by checking `defaultTargetPlatform.isDesktop`.
|
/// Easily check if on desktop by checking `defaultTargetPlatform.isDesktop`.
|
||||||
bool get isDesktop =>
|
bool get isDesktop =>
|
||||||
this == TargetPlatform.linux ||
|
!kIsWeb &&
|
||||||
|
(this == TargetPlatform.linux ||
|
||||||
this == TargetPlatform.macOS ||
|
this == TargetPlatform.macOS ||
|
||||||
this == TargetPlatform.windows;
|
this == TargetPlatform.windows);
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,10 @@ class WindowSizeManager {
|
|||||||
static const width = 'width';
|
static const width = 'width';
|
||||||
static const height = 'height';
|
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 = {
|
final windowSize = {
|
||||||
height: max(size.height, minWindowHeight),
|
height: max(size.height, minWindowHeight),
|
||||||
width: max(size.width, minWindowWidth),
|
width: max(size.width, minWindowWidth),
|
||||||
@ -33,4 +36,25 @@ class WindowSizeManager {
|
|||||||
);
|
);
|
||||||
return Size(size[width]!, size[height]!);
|
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 {
|
windowManager.waitUntilReadyToShow(windowOptions, () async {
|
||||||
await windowManager.show();
|
await windowManager.show();
|
||||||
await windowManager.focus();
|
await windowManager.focus();
|
||||||
|
|
||||||
|
final position = await WindowSizeManager().getPosition();
|
||||||
|
if (position != null) {
|
||||||
|
await windowManager.setPosition(position);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> onWindowResize() async {
|
Future<void> onWindowResize() async {
|
||||||
|
super.onWindowResize();
|
||||||
|
|
||||||
final currentWindowSize = await windowManager.getSize();
|
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…
x
Reference in New Issue
Block a user