Skip to content

Commit

Permalink
Feat: Remember danmaku status
Browse files Browse the repository at this point in the history
  • Loading branch information
songbirdzz committed May 25, 2024
1 parent 396493b commit f415837
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/pages/play/player_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:knkpanime/models/episode.dart';
import 'package:knkpanime/models/series.dart';
import 'package:knkpanime/models/source.dart';
import 'package:knkpanime/pages/history/history_controller.dart';
import 'package:knkpanime/pages/settings/settings_controller.dart';
import 'package:knkpanime/utils/danmaku.dart';
import 'package:knkpanime/utils/utils.dart';
import 'package:logger/logger.dart';
Expand All @@ -30,7 +31,7 @@ abstract class _PlayerController with Store {
@observable
late Episode playingEpisode = Episode('', 0);
@observable
bool danmakuEnabled = true;
late bool danmakuEnabled = settingsController.danmakuEnabled;
@computed
List<DanmakuAnimeInfo> get danmakuSources {
var temp = (selectedDanmakuSource == null
Expand All @@ -56,6 +57,7 @@ abstract class _PlayerController with Store {
late final historyController = Modular.get<HistoryController>();
late final player = _IntegratedPlayer();
late final playerController = VideoController(player);
late final settingsController = Modular.get<SettingsController>();
late DanmakuController danmakuController;
final videoSources = ObservableList<Source>();
bool _playStateInitialized = true;
Expand Down Expand Up @@ -314,6 +316,7 @@ abstract class _PlayerController with Store {
void toggleDanmaku() {
danmakuController.clear();
danmakuEnabled = !danmakuEnabled;
settingsController.danmakuEnabled = danmakuEnabled;
}

void setDanmakuController(DanmakuController c) {
Expand Down
5 changes: 5 additions & 0 deletions lib/pages/settings/settings_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class SettingsController {
bool get disableGithubProxy => prefs.getBool('disableGithubProxy') ?? false;
bool get useWebViewAdapters => prefs.getBool('useWebViewAdapters') ?? true;
List<String> get jsAdapters => prefs.getStringList('jsAdapters') ?? [];
bool get danmakuEnabled => prefs.getBool('danmakuEnabled') ?? true;

set fontSize(double size) {
prefs.setDouble('fontSize', size);
Expand Down Expand Up @@ -72,6 +73,10 @@ class SettingsController {
prefs.setStringList('jsAdapters', value);
}

set danmakuEnabled(bool value) {
prefs.setBool('danmakuEnabled', value);
}

SettingsController() {
SharedPreferences.getInstance().then((v) {
prefs = v;
Expand Down

0 comments on commit f415837

Please sign in to comment.