diff --git a/auth/lib/app/view/app.dart b/auth/lib/app/view/app.dart index c8e9051e6..1d3d99017 100644 --- a/auth/lib/app/view/app.dart +++ b/auth/lib/app/view/app.dart @@ -12,11 +12,13 @@ import 'package:ente_auth/locale.dart'; import "package:ente_auth/onboarding/view/onboarding_page.dart"; import 'package:ente_auth/services/update_service.dart'; import 'package:ente_auth/services/user_service.dart'; +import 'package:ente_auth/services/window_listener_service.dart'; import 'package:ente_auth/ui/home_page.dart'; import 'package:ente_auth/ui/settings/app_update_dialog.dart'; import 'package:flutter/foundation.dart'; import "package:flutter/material.dart"; import 'package:flutter_localizations/flutter_localizations.dart'; +import 'package:window_manager/window_manager.dart'; class App extends StatefulWidget { final Locale locale; @@ -31,7 +33,7 @@ class App extends StatefulWidget { State createState() => _AppState(); } -class _AppState extends State { +class _AppState extends State with WindowListener { late StreamSubscription _signedOutEvent; late StreamSubscription _signedInEvent; Locale? locale; @@ -43,6 +45,7 @@ class _AppState extends State { @override void initState() { + windowManager.addListener(this); _signedOutEvent = Bus.instance.on().listen((event) { if (mounted) { setState(() {}); @@ -76,6 +79,7 @@ class _AppState extends State { @override void dispose() { super.dispose(); + windowManager.removeListener(this); _signedOutEvent.cancel(); _signedInEvent.cancel(); } @@ -134,4 +138,9 @@ class _AppState extends State { : const OnboardingPage(), }; } + + @override + void onWindowResize() { + WindowListenerService.instance.onWindowResize().ignore(); + } } diff --git a/auth/lib/main.dart b/auth/lib/main.dart index 0c9dc7887..7cab45651 100644 --- a/auth/lib/main.dart +++ b/auth/lib/main.dart @@ -16,6 +16,7 @@ import 'package:ente_auth/services/preference_service.dart'; import 'package:ente_auth/services/update_service.dart'; import 'package:ente_auth/services/user_remote_flag_service.dart'; import 'package:ente_auth/services/user_service.dart'; +import 'package:ente_auth/services/window_listener_service.dart'; import 'package:ente_auth/store/code_store.dart'; import 'package:ente_auth/ui/tools/app_lock.dart'; import 'package:ente_auth/ui/tools/lock_screen.dart'; @@ -39,8 +40,9 @@ void main() async { if (PlatformUtil.isDesktop()) { await windowManager.ensureInitialized(); - WindowOptions windowOptions = const WindowOptions( - size: Size(450, 800), + await WindowListenerService.instance.init(); + WindowOptions windowOptions = WindowOptions( + size: WindowListenerService.instance.getWindowSize(), ); await windowManager.waitUntilReadyToShow(windowOptions, () async { await windowManager.show(); diff --git a/auth/lib/services/window_listener_service.dart b/auth/lib/services/window_listener_service.dart new file mode 100644 index 000000000..9ceefef9a --- /dev/null +++ b/auth/lib/services/window_listener_service.dart @@ -0,0 +1,36 @@ +import 'dart:async'; +import 'dart:ui'; + +import 'package:shared_preferences/shared_preferences.dart'; +import 'package:window_manager/window_manager.dart'; + +class WindowListenerService { + late SharedPreferences _preferences; + + WindowListenerService._privateConstructor(); + + static final WindowListenerService instance = + WindowListenerService._privateConstructor(); + + Future init() async { + _preferences = await SharedPreferences.getInstance(); + } + + Size getWindowSize() { + final double windowWidth = _preferences.getDouble('windowWidth') ?? 450.0; + final double windowHeight = _preferences.getDouble('windowHeight') ?? 800.0; + return Size(windowWidth, windowHeight); + } + + Future onWindowResize() async { + // Save the window size to shared preferences + await _preferences.setDouble( + 'windowWidth', + (await windowManager.getSize()).width, + ); + await _preferences.setDouble( + 'windowHeight', + (await windowManager.getSize()).height, + ); + } +}