diff --git a/lib/main.dart b/lib/main.dart index 3441fb4b..a07d6b12 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -50,14 +50,27 @@ void main(List args) async { if (!Platform.isAndroid) { await windowManager.ensureInitialized(); - WindowOptions windowOptions = const WindowOptions( - size: Size(1280, 720), - minimumSize: Size(600, 500), + final sizeArr = MiruStorage.getSetting(SettingKey.windowSize).split(","); + final size = Size(double.parse(sizeArr[0]), double.parse(sizeArr[1])); + WindowOptions windowOptions = WindowOptions( + size: size, center: true, + minimumSize: const Size(600, 500), skipTaskbar: false, titleBarStyle: TitleBarStyle.hidden, ); windowManager.waitUntilReadyToShow(windowOptions, () async { + final position = MiruStorage.getSetting(SettingKey.windowPosition); + if (position != null) { + final offsetArr = position.split(","); + final offset = Offset( + double.parse(offsetArr[0]), + double.parse(offsetArr[1]), + ); + await windowManager.setPosition( + offset, + ); + } await windowManager.show(); await windowManager.focus(); }); diff --git a/lib/utils/miru_storage.dart b/lib/utils/miru_storage.dart index 1d6aa795..10cecba3 100644 --- a/lib/utils/miru_storage.dart +++ b/lib/utils/miru_storage.dart @@ -118,6 +118,7 @@ class MiruStorage { await _initSetting(SettingKey.arrowLeft, -2.0); await _initSetting(SettingKey.arrowRight, 2.0); await _initSetting(SettingKey.readingMode, "standard"); + await _initSetting(SettingKey.windowSize, "1280,720"); } static _initSetting(String key, dynamic value) async { @@ -151,4 +152,6 @@ class SettingKey { static String arrowLeft = 'Arrowleft'; static String arrowRight = 'Arrowright'; static String readingMode = 'ReadingMode'; + static String windowSize = 'WindowsSize'; + static String windowPosition = 'WindowsPosition'; } diff --git a/lib/views/pages/main_page.dart b/lib/views/pages/main_page.dart index 306d0c6b..f94b4a15 100644 --- a/lib/views/pages/main_page.dart +++ b/lib/views/pages/main_page.dart @@ -30,7 +30,7 @@ class DesktopMainPage extends StatefulWidget { State createState() => _DesktopMainPageState(); } -class _DesktopMainPageState extends State { +class _DesktopMainPageState extends State with WindowListener { late MainController c; @override @@ -39,9 +39,16 @@ class _DesktopMainPageState extends State { if (MiruStorage.getSetting(SettingKey.autoCheckUpdate)) { ApplicationUtils.checkUpdate(context); } + windowManager.addListener(this); super.initState(); } + @override + void dispose() { + windowManager.removeListener(this); + super.dispose(); + } + Widget _title() { return const DragToMoveArea( child: Align( @@ -147,6 +154,26 @@ class _DesktopMainPageState extends State { ), ); } + + @override + void onWindowResize() { + WindowManager.instance.getSize().then((value) { + MiruStorage.setSetting( + SettingKey.windowSize, + "${value.width},${value.height}", + ); + }); + } + + @override + void onWindowMove() { + WindowManager.instance.getPosition().then((value) { + MiruStorage.setSetting( + SettingKey.windowPosition, + "${value.dx},${value.dy}", + ); + }); + } } class AndroidMainPage extends fluent.StatefulWidget {