Skip to content

Commit

Permalink
feat: record window position (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
No06 authored Feb 5, 2025
1 parent 487168d commit b6ec5d7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
12 changes: 10 additions & 2 deletions lib/data/store/setting.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:convert';

import 'package:fl_lib/fl_lib.dart';

class SettingStore extends HiveStore {
Expand Down Expand Up @@ -64,8 +66,14 @@ class SettingStore extends HiveStore {

late final scrollSwitchChat = propertyDefault('scrollSwitchChat', isMobile);

/// {width}x{height}
late final windowSize = propertyDefault('windowSize', '');
/// For desktop only.
/// Record the position and size of the window.
late final windowState = property<WindowState>(
'windowState',
fromStr: (jsonStr) =>
WindowState.fromJson(jsonDecode(jsonStr) as Map<String, dynamic>),
toStr: (state) => state == null ? null : jsonEncode(state.toJson()),
);

late final avatar = propertyDefault('avatar', '🧐');

Expand Down
8 changes: 5 additions & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,13 @@ Future<void> _initAppComponents() async {
UserApi.init();

final sets = Stores.setting;
final size = sets.windowSize;
final windowStateProp = sets.windowState;
final windowState = windowStateProp.fetch();
SystemUIs.initDesktopWindow(
hideTitleBar: sets.hideTitleBar.get(),
size: size.get().toSize(),
listener: WindowSizeListener(size),
size: windowState?.size,
position: windowState?.position,
listener: WindowStateListener(windowStateProp),
);

Cfg.applyClient();
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ dependencies:
fl_lib:
git:
url: https://github.com/lppcg/fl_lib
ref: v1.0.236
ref: v1.0.243

dependency_overrides:
# fl_lib:
Expand Down

0 comments on commit b6ec5d7

Please sign in to comment.