Skip to content

Commit

Permalink
feat: Add new UI Setting to Keep Screen on
Browse files Browse the repository at this point in the history
Added the KeepScreenOn lib, alongside the keep screen on UI-Setting on the settings page, which allows a user to keep the screen active if he wishes todo so!

fix #432
  • Loading branch information
Clon1998 committed Dec 14, 2024
1 parent 6c02d5d commit 9ae1b52
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 3 deletions.
2 changes: 2 additions & 0 deletions assets/translations/de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,8 @@ pages:
eta_sources_hint: Wählen Sie die Quellen, die zur Berechnung der ETA verwendet werden sollen
medium_ui: Tablet UI
medium_ui_hint: Aktiviert das Tablet-UI für größere Bildschirme
keep_screen_on: Bildschirm aktiviert lassen
keep_screen_on_hint: Verhindert, dass sich der Bildschirm ausschaltet, solange die App aktiv ist
notification:
title: Benachrichtigung
progress_label: Druckfortschritt Benachrichtigungen
Expand Down
2 changes: 2 additions & 0 deletions assets/translations/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,8 @@ pages:
medium_ui: Tablet UI
medium_ui_hint: Toggle if the tablet UI should be used on larger screens or
landscape mode
keep_screen_on: Keep Screen Awake
keep_screen_on_hint: Prevent the screen from turning off while the app is active
notification:
title: Notification
progress_label: Print-Progress Notification
Expand Down
2 changes: 1 addition & 1 deletion common/lib/service/misc_providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Future<ServiceStatus> permissionServiceStatus(Ref ref, PermissionWithService per
class AppLifecycle extends _$AppLifecycle {
@override
AppLifecycleState build() {
ref.listenSelf((previous, next) {
listenSelf((previous, next) {
logger.i('AppLifecycleState changed from $previous to $next');
});

Expand Down
1 change: 1 addition & 0 deletions common/lib/service/setting_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ enum AppSettingKeys implements KeyValueStoreKey {
useProgressbarNotifications('useProgressNotifications'),
etaSources('etaCalS', ['slicer', 'filament']),
useMediumUI('useMediumUI', true),
keepScreenOn('keepScreenOn', false),
;

@override
Expand Down
55 changes: 55 additions & 0 deletions common/lib/ui/components/keep_screen_on_trigger.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2024. Patrick Schmidt.
* All rights reserved.
*/

import 'package:common/service/setting_service.dart';
import 'package:common/util/logger.dart';
import 'package:flutter/cupertino.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:keep_screen_on/keep_screen_on.dart';

class KeepScreenOnTrigger extends ConsumerStatefulWidget {
const KeepScreenOnTrigger({super.key, required this.child});

final Widget child;

@override
ConsumerState createState() => _KeepScreenOnTriggerState();
}

class _KeepScreenOnTriggerState extends ConsumerState<KeepScreenOnTrigger> {
ProviderSubscription? _providerSubscription;

@override
void initState() {
super.initState();
_providerSubscription = ref.listenManual(
boolSettingProvider(AppSettingKeys.keepScreenOn, false),
(_, val) {
logger.i('Keep screen on: $val');
if (val) {
logger.i('User requested to keep screen on at all times');
KeepScreenOn.turnOn();
} else {
logger.i('User requested to NOT keep screen on at all times');
KeepScreenOn.turnOn();
}
},
fireImmediately: true,
);
}

@override
Widget build(BuildContext context) {
return widget.child;
}

@override
void dispose() {
super.dispose();
_providerSubscription?.close();
logger.i('Dispose KeepScreenOnTrigger, disabled keep screen on');
KeepScreenOn.turnOff();
}
}
1 change: 1 addition & 0 deletions common/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ dependencies:
package_info_plus: ^8.1.1
vector_math: ^2.1.4
form_builder_validators: ^11.0.0
keep_screen_on: ^3.0.0

#crypto
hashlib_codecs: ^2.2.0
Expand Down
7 changes: 7 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## [2.8.4] - 2025-01-xx

### Enhancements

- **Keep Screen Awake**: Added a new setting to keep the screen on while the app is open. This feature is especially
useful
for users who want to keep their device awake while monitoring a print job or using the app for an extended period. To
enable this feature, navigate to the app settings and toggle the "Keep Screen Awake" option.

### Bug Fixes

- **Keyboard Input Spoolman**: Fixed an issue that prevented users from entering decimal values on the spool form
Expand Down
5 changes: 4 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:common/service/ui/dialog_service_interface.dart';
import 'package:common/service/ui/snackbar_service_interface.dart';
import 'package:common/service/ui/theme_service.dart';
import 'package:common/ui/components/error_card.dart';
import 'package:common/ui/components/keep_screen_on_trigger.dart';
import 'package:common/ui/locale_spy.dart';
import 'package:common/util/logger.dart';
import 'package:easy_localization/easy_localization.dart';
Expand Down Expand Up @@ -155,7 +156,9 @@ class _WarmUp extends HookConsumerWidget {
child: ref.watch(warmupProvider).when(
data: (step) {
if (step == StartUpStep.complete) {
return ResponsiveBuilder(childBuilder: (context) => const MyApp());
return KeepScreenOnTrigger(
child: ResponsiveBuilder(childBuilder: (context) => const MyApp()),
);
}
return const _LoadingSplashScreen();
},
Expand Down
1 change: 1 addition & 0 deletions lib/routing/app_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ GoRouter goRouterImpl(GoRouterRef ref) {
GoTransition.observer,
MobilerakerRouteObserver('Main'),
],

// redirect: (state) {
//
// return null;
Expand Down
17 changes: 17 additions & 0 deletions lib/ui/screens/setting/setting_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,23 @@ class _UiSection extends ConsumerWidget {
const _ThemeSelector(),
const _ThemeModeSelector(),
if (context.canBecomeLargerThanCompact) const _ToggleMediumUI(),
FormBuilderSwitch(
name: 'keepScreenOn',
title: const Text('pages.setting.general.keep_screen_on').tr(),
subtitle: const Text('pages.setting.general.keep_screen_on_hint').tr(),
onChanged: (b) => settingService.writeBool(
AppSettingKeys.keepScreenOn,
b ?? false,
),
initialValue: ref.read(
boolSettingProvider(AppSettingKeys.keepScreenOn),
),
decoration: const InputDecoration(
border: InputBorder.none,
isCollapsed: true,
),
activeColor: themeData.colorScheme.primary,
),
FormBuilderSwitch(
name: 'alwaysShowBaby',
title: const Text('pages.setting.general.always_baby').tr(),
Expand Down
1 change: 0 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ dependencies:
geekyants_flutter_gauges: ^1.0.3
pretty_qr_code: ^3.3.0


dev_dependencies:
flutter_test:
sdk: flutter
Expand Down

0 comments on commit 9ae1b52

Please sign in to comment.