From 631676b4395f93f1f0e4a0b6b80664d0868767cc Mon Sep 17 00:00:00 2001 From: Kyle Machulis Date: Sun, 21 Jan 2024 14:43:19 -0800 Subject: [PATCH] chore: Add ability to toggle restore window pos on desktop Affects #110 --- .../intiface_configuration_cubit.dart | 12 ++++ lib/intiface_central_app.dart | 7 ++- lib/page/settings_page.dart | 57 +++++++++++-------- 3 files changed, 52 insertions(+), 24 deletions(-) diff --git a/lib/bloc/configuration/intiface_configuration_cubit.dart b/lib/bloc/configuration/intiface_configuration_cubit.dart index b5baef1..9b80d83 100644 --- a/lib/bloc/configuration/intiface_configuration_cubit.dart +++ b/lib/bloc/configuration/intiface_configuration_cubit.dart @@ -163,6 +163,11 @@ class AppModeState extends IntifaceConfigurationState { AppModeState(this.value); } +class RestoreWindowLocation extends IntifaceConfigurationState { + final bool value; + RestoreWindowLocation(this.value); +} + class ConfigurationResetState extends IntifaceConfigurationState {} class IntifaceConfigurationCubit extends Cubit { @@ -204,6 +209,7 @@ class IntifaceConfigurationCubit extends Cubit { unreadNews = _prefs.getBool("unreadNews") ?? false; useSideNavigationBar = _prefs.getBool("useSideNavigationBar") ?? isDesktop(); useLightTheme = _prefs.getBool("useLightTheme") ?? true; + restoreWindowLocation = _prefs.getBool("restoreWindowLocation") ?? true; // True on all platforms useBluetoothLE = _prefs.getBool("useBluetoothLE") ?? true; @@ -279,6 +285,12 @@ class IntifaceConfigurationCubit extends Cubit { emit(UseLightThemeState(value)); } + bool get restoreWindowLocation => _prefs.getBool("restoreWindowLocation")!; + set restoreWindowLocation(bool value) { + _prefs.setBool("restoreWindowLocation", value); + emit(RestoreWindowLocation(value)); + } + String get serverName => _prefs.getString("serverName")!; set serverName(String value) { _prefs.setString("serverName", value); diff --git a/lib/intiface_central_app.dart b/lib/intiface_central_app.dart index a21638f..0d6977e 100644 --- a/lib/intiface_central_app.dart +++ b/lib/intiface_central_app.dart @@ -145,9 +145,14 @@ class IntifaceCentralApp extends StatelessWidget with WindowListener { if (!windowInBounds) { logInfo("Window position out of bounds, resetting position"); guiSettingsCubit.setWindowPosition(const Offset(0.0, 0.0)); - } else { + } else if (configCubit.restoreWindowLocation) { + // Only restore the window location if the option to do so is on. + logInfo("Restoring window position to ${guiSettingsCubit.getWindowPosition()}"); await windowManager.setPosition(guiSettingsCubit.getWindowPosition()); + } else { + logInfo("Window location not restored due to configuration settings"); } + windowDisplayModeResize(configCubit.useCompactDisplay, guiSettingsCubit); await windowManager.waitUntilReadyToShow(windowOptions, () async { await windowManager.show(); diff --git a/lib/page/settings_page.dart b/lib/page/settings_page.dart index fcdf0b5..d49598b 100644 --- a/lib/page/settings_page.dart +++ b/lib/page/settings_page.dart @@ -67,31 +67,42 @@ class SettingPage extends StatelessWidget { title: const Text("Device Config Version"), value: Text(cubit.currentDeviceConfigVersion)), ]); + var appSettingsTiles = [ + SettingsTile.switchTile( + initialValue: cubit.useLightTheme, + onToggle: (value) => cubit.useLightTheme = value, + title: const Text("Light Theme")), + SettingsTile.switchTile( + initialValue: cubit.useSideNavigationBar, + onToggle: (value) => cubit.useSideNavigationBar = value, + title: const Text("Side Navigation Bar")), + SettingsTile.switchTile( + initialValue: cubit.checkForUpdateOnStart, + onToggle: (value) => cubit.checkForUpdateOnStart = value, + title: const Text("Check For Updates when Intiface Central Launches")), + SettingsTile.switchTile( + initialValue: cubit.crashReporting, + onToggle: cubit.canUseCrashReporting ? ((value) => cubit.crashReporting = value) : null, + title: const Text("Crash Reporting")), + SettingsTile.navigation( + title: const Text("Send Logs to Developers"), + onPressed: cubit.canUseCrashReporting + ? ((context) => BlocProvider.of(context).goSendLogs()) + : null) + ]; + + if (isDesktop()) { + appSettingsTiles.insert( + 2, + SettingsTile.switchTile( + initialValue: cubit.restoreWindowLocation, + onToggle: (value) => cubit.restoreWindowLocation = value, + title: const Text("Restore Window Location on Start"))); + } + tiles.addAll([ SettingsSection(title: const Text("Versions and Updates"), tiles: versionTiles), - SettingsSection(title: const Text("App Settings"), tiles: [ - SettingsTile.switchTile( - initialValue: cubit.useLightTheme, - onToggle: (value) => cubit.useLightTheme = value, - title: const Text("Light Theme")), - SettingsTile.switchTile( - initialValue: cubit.useSideNavigationBar, - onToggle: (value) => cubit.useSideNavigationBar = value, - title: const Text("Side Navigation Bar")), - SettingsTile.switchTile( - initialValue: cubit.checkForUpdateOnStart, - onToggle: (value) => cubit.checkForUpdateOnStart = value, - title: const Text("Check For Updates when Intiface Central Launches")), - SettingsTile.switchTile( - initialValue: cubit.crashReporting, - onToggle: cubit.canUseCrashReporting ? ((value) => cubit.crashReporting = value) : null, - title: const Text("Crash Reporting")), - SettingsTile.navigation( - title: const Text("Send Logs to Developers"), - onPressed: cubit.canUseCrashReporting - ? ((context) => BlocProvider.of(context).goSendLogs()) - : null) - ]), + SettingsSection(title: const Text("App Settings"), tiles: appSettingsTiles), SettingsSection(title: const Text("Server Settings"), tiles: [ // Turn this off until we know the server is mostly stable, or have a way to handle crash on startup // gracefully.