Skip to content

Commit

Permalink
Merge pull request #248 from lichess-org/wakelock
Browse files Browse the repository at this point in the history
Add wakelock
  • Loading branch information
veloce authored Jul 31, 2023
2 parents 9687303 + 852f965 commit a776c69
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 3 deletions.
6 changes: 6 additions & 0 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ PODS:
- Flutter
- url_launcher_ios (0.0.1):
- Flutter
- wakelock_plus (0.0.1):
- Flutter

DEPENDENCIES:
- connectivity_plus (from `.symlinks/plugins/connectivity_plus/ios`)
Expand All @@ -119,6 +121,7 @@ DEPENDENCIES:
- sqflite (from `.symlinks/plugins/sqflite/ios`)
- stockfish (from `.symlinks/plugins/stockfish/ios`)
- url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`)
- wakelock_plus (from `.symlinks/plugins/wakelock_plus/ios`)

SPEC REPOS:
trunk:
Expand Down Expand Up @@ -171,6 +174,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/stockfish/ios"
url_launcher_ios:
:path: ".symlinks/plugins/url_launcher_ios/ios"
wakelock_plus:
:path: ".symlinks/plugins/wakelock_plus/ios"

SPEC CHECKSUMS:
AppAuth: 3bb1d1cd9340bd09f5ed189fb00b1cc28e1e8570
Expand Down Expand Up @@ -204,6 +209,7 @@ SPEC CHECKSUMS:
sqflite: 31f7eba61e3074736dff8807a9b41581e4f7f15a
stockfish: 614d240ac2cd05a462dad552c7b5937bb14604fd
url_launcher_ios: 08a3dfac5fb39e8759aeb0abbd5d9480f30fc8b4
wakelock_plus: 8b09852c8876491e4b6d179e17dfe2a0b5f60d47

PODFILE CHECKSUM: 76a583f8d75b3a8c6e4bdc97ae8783ef36cc7984

Expand Down
2 changes: 2 additions & 0 deletions lib/src/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:lichess_mobile/src/model/settings/general_preferences.dart';
import 'package:lichess_mobile/src/model/settings/board_preferences.dart';
import 'package:lichess_mobile/src/widgets/bottom_navigation.dart';
import 'package:lichess_mobile/src/utils/immersive_mode.dart';
import 'package:lichess_mobile/src/utils/wakelock.dart';

class LoadApp extends ConsumerWidget {
const LoadApp({super.key});
Expand Down Expand Up @@ -106,6 +107,7 @@ class _AppState extends ConsumerState<App> {
home: const BottomNavScaffold(),
navigatorObservers: [
immersiveModeRouteObserver,
wakelockRouteObserver,
],
);
}
Expand Down
43 changes: 43 additions & 0 deletions lib/src/utils/wakelock.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import 'package:flutter/widgets.dart';
import 'package:wakelock_plus/wakelock_plus.dart';

final RouteObserver<PageRoute<void>> wakelockRouteObserver =
RouteObserver<PageRoute<void>>();

/// State mixin that enables wakelock when the route is active.
mixin Wakelock<T extends StatefulWidget> on State<T> implements RouteAware {
@override
void didChangeDependencies() {
super.didChangeDependencies();
final route = ModalRoute.of(context);
if (route != null && route is PageRoute) {
wakelockRouteObserver.subscribe(this, route);
}
}

@override
void dispose() {
wakelockRouteObserver.unsubscribe(this);
super.dispose();
}

@override
void didPopNext() {
WakelockPlus.enable();
}

@override
void didPush() {
WakelockPlus.enable();
}

@override
void didPop() {
WakelockPlus.disable();
}

@override
void didPushNext() {
WakelockPlus.disable();
}
}
3 changes: 2 additions & 1 deletion lib/src/view/game/game_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import 'package:lichess_mobile/src/widgets/player.dart';
import 'package:lichess_mobile/src/widgets/adaptive_dialog.dart';
import 'package:lichess_mobile/src/widgets/settings.dart';
import 'package:lichess_mobile/src/utils/immersive_mode.dart';
import 'package:lichess_mobile/src/utils/wakelock.dart';
import 'package:lichess_mobile/src/utils/l10n_context.dart';
import 'package:lichess_mobile/src/utils/chessground_compat.dart';

Expand All @@ -46,7 +47,7 @@ class GameScreen extends ConsumerStatefulWidget {
}

class _GameScreenState extends ConsumerState<GameScreen>
with AndroidImmersiveMode, RouteAware {
with AndroidImmersiveMode, RouteAware, Wakelock {
@override
void didChangeDependencies() {
super.didChangeDependencies();
Expand Down
4 changes: 3 additions & 1 deletion lib/src/view/puzzle/puzzle_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import 'package:lichess_mobile/src/model/engine/engine_evaluation.dart';
import 'package:lichess_mobile/src/utils/immersive_mode.dart';
import 'package:lichess_mobile/src/utils/l10n_context.dart';
import 'package:lichess_mobile/src/utils/chessground_compat.dart';
import 'package:lichess_mobile/src/utils/wakelock.dart';
import 'package:lichess_mobile/src/view/engine/engine_gauge.dart';
import 'package:lichess_mobile/src/view/settings/toggle_sound_button.dart';

Expand Down Expand Up @@ -140,7 +141,8 @@ class _Body extends ConsumerStatefulWidget {
ConsumerState<_Body> createState() => _BodyState();
}

class _BodyState extends ConsumerState<_Body> with AndroidImmersiveMode {
class _BodyState extends ConsumerState<_Body>
with AndroidImmersiveMode, Wakelock {
@override
Widget build(BuildContext context) {
final ctrlProvider = puzzleCtrlProvider(widget.initialPuzzleContext);
Expand Down
4 changes: 3 additions & 1 deletion lib/src/view/puzzle/storm_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import 'package:lichess_mobile/src/widgets/list.dart';
import 'package:lichess_mobile/src/utils/chessground_compat.dart';
import "package:lichess_mobile/src/utils/l10n_context.dart";
import "package:lichess_mobile/src/utils/immersive_mode.dart";
import 'package:lichess_mobile/src/utils/wakelock.dart';
import 'package:lichess_mobile/src/view/settings/toggle_sound_button.dart';

import 'history_boards.dart';
Expand Down Expand Up @@ -109,7 +110,8 @@ class _Body extends ConsumerStatefulWidget {
ConsumerState<_Body> createState() => _BodyState();
}

class _BodyState extends ConsumerState<_Body> with AndroidImmersiveMode {
class _BodyState extends ConsumerState<_Body>
with AndroidImmersiveMode, Wakelock {
@override
Widget build(BuildContext context) {
final ctrlProvider = stormCtrlProvider(widget.data.puzzles);
Expand Down
16 changes: 16 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1499,6 +1499,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "11.8.0"
wakelock_plus:
dependency: "direct main"
description:
name: wakelock_plus
sha256: aac3f3258f01781ec9212df94eecef1eb9ba9350e106728def405baa096ba413
url: "https://pub.dev"
source: hosted
version: "1.1.1"
wakelock_plus_platform_interface:
dependency: transitive
description:
name: wakelock_plus_platform_interface
sha256: "40fabed5da06caff0796dc638e1f07ee395fb18801fbff3255a2372db2d80385"
url: "https://pub.dev"
source: hosted
version: "1.1.0"
watcher:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ dependencies:
crypto: ^3.0.3
signal_strength_indicator: ^0.4.1
flutter_spinkit: ^5.2.0
wakelock_plus: ^1.1.1

dev_dependencies:
build_runner: ^2.3.2
Expand Down

0 comments on commit a776c69

Please sign in to comment.