Skip to content

Commit

Permalink
chore: Add ability to toggle restore window pos on desktop
Browse files Browse the repository at this point in the history
Affects #110
  • Loading branch information
qdot committed Jan 21, 2024
1 parent e35ffa3 commit 631676b
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 24 deletions.
12 changes: 12 additions & 0 deletions lib/bloc/configuration/intiface_configuration_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<IntifaceConfigurationState> {
Expand Down Expand Up @@ -204,6 +209,7 @@ class IntifaceConfigurationCubit extends Cubit<IntifaceConfigurationState> {
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;
Expand Down Expand Up @@ -279,6 +285,12 @@ class IntifaceConfigurationCubit extends Cubit<IntifaceConfigurationState> {
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);
Expand Down
7 changes: 6 additions & 1 deletion lib/intiface_central_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
57 changes: 34 additions & 23 deletions lib/page/settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<NavigationCubit>(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<NavigationCubit>(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.
Expand Down

0 comments on commit 631676b

Please sign in to comment.