Skip to content
This repository has been archived by the owner on Nov 7, 2023. It is now read-only.

Commit

Permalink
refactor(watch_page): wakelock
Browse files Browse the repository at this point in the history
  • Loading branch information
zyrouge committed Oct 21, 2021
1 parent 8df97fe commit 54aa28a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/pages/anime_page/watch_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ class WatchPageState extends State<WatchPage>
TickerProviderStateMixin,
FullscreenMixin,
DidLoadStater,
OrientationMixin {
OrientationMixin,
WakelockMixin {
List<extensions.EpisodeSource>? sources;
int? currentIndex;
player_model.Player? player;
Expand Down Expand Up @@ -100,6 +101,7 @@ class WatchPageState extends State<WatchPage>
super.initState();

initFullscreen();
enableWakelock();

if (AppState.settings.current.animeAutoFullscreen) {
enterFullscreen();
Expand Down Expand Up @@ -157,6 +159,8 @@ class WatchPageState extends State<WatchPage>
exitFullscreen();
}

disableWakelock();

player?.destroy();
playerChild = null;

Expand Down
19 changes: 19 additions & 0 deletions lib/plugins/helpers/screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:utilx/utilities/window.dart';
import 'package:wakelock/wakelock.dart';
import 'package:window_manager/window_manager.dart';
import './eventer.dart';
import '../state.dart';
Expand Down Expand Up @@ -54,6 +55,12 @@ mixin OrientationMixin {
Screen.setOrientation(ScreenOrientation.unlock);
}

mixin WakelockMixin {
Future<void> enableWakelock() => Screen.enableWakelock();

Future<void> disableWakelock() => Screen.disableWakelock();
}

class OnFullscreenChange {
OnFullscreenChange(this.duration) {
Screen.uiChangeNotifier.subscribe(onUiChange);
Expand Down Expand Up @@ -184,4 +191,16 @@ abstract class Screen {
await SystemChrome.setPreferredOrientations(to);
}
}

static Future<void> enableWakelock() async {
if (!Platform.isLinux) {
await Wakelock.enable();
}
}

static Future<void> disableWakelock() async {
if (!Platform.isLinux) {
await Wakelock.disable();
}
}
}
2 changes: 1 addition & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ packages:
source: hosted
version: "0.2.2"
wakelock:
dependency: transitive
dependency: "direct main"
description:
name: wakelock
url: "https://pub.dartlang.org"
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ dependencies:
url: https://github.com/yukino-app/yukino.git
path: packages/utilx
version: ^2.0.0
wakelock: ^0.5.6
window_manager:
git:
url: https://github.com/leanflutter/window_manager.git
Expand Down

0 comments on commit 54aa28a

Please sign in to comment.