Skip to content

Commit

Permalink
修复切换剧集不切换弹幕
Browse files Browse the repository at this point in the history
  • Loading branch information
iris1598 committed Sep 3, 2024
1 parent 001c489 commit 827fe9e
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 55 deletions.
31 changes: 0 additions & 31 deletions lib/bean/appbar/sys_app_bar.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dart:io';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:miru_app/utils/utils.dart';
import 'package:flutter/material.dart';
import 'package:window_manager/window_manager.dart';
Expand All @@ -24,42 +22,13 @@ class SysAppBar extends StatelessWidget implements PreferredSizeWidget {

const SysAppBar({super.key, this.toolbarHeight, this.title, this.backgroundColor, this.elevation, this.shape, this.actions, this.leading, this.bottom});

void _handleCloseEvent() {
SmartDialog.show(
useAnimation: false,
builder: (context) {
return AlertDialog(
title: const Text('退出确认'),
content: const Text('您想要退出 Kazumi 吗?'),
actions: [
TextButton(
onPressed: () => exit(0),
child: const Text('退出 Kazumi')),
TextButton(
onPressed: () {
SmartDialog.dismiss();
windowManager.hide();
},
child: const Text('最小化至托盘')),
const TextButton(
onPressed: SmartDialog.dismiss,
child: Text('取消')),
],
);
}
);
}

@override
Widget build(BuildContext context) {
List<Widget> acs = [];
if (actions != null) {
acs.addAll(actions!);
}
if (Utils.isDesktop()) {
// acs.add(IconButton(onPressed: () => windowManager.minimize(), icon: const Icon(Icons.minimize)));
acs.add(CloseButton(onPressed: () => _handleCloseEvent()));
}
return GestureDetector(
// behavior: HitTestBehavior.translucent,
onPanStart: (_) => (Utils.isDesktop()) ? windowManager.startDragging() : null,
Expand Down
18 changes: 18 additions & 0 deletions lib/controllers/detail_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ import 'dart:io';
import 'package:fluent_ui/fluent_ui.dart' as fluent;
import 'package:flutter/material.dart';
import 'package:flutter_i18n/flutter_i18n.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:flutter_windows_webview/flutter_windows_webview.dart';
import 'package:get/get.dart';
import 'package:hive/hive.dart';
import 'package:logger/logger.dart';
import 'package:miru_app/data/providers/tmdb_provider.dart';
import 'package:miru_app/models/index.dart';
import 'package:miru_app/utils/storage.dart';
import 'package:miru_app/utils/webdav.dart';
import 'package:miru_app/views/dialogs/tmdb_binding.dart';
import 'package:miru_app/controllers/home_controller.dart';
import 'package:miru_app/controllers/main_controller.dart';
Expand All @@ -23,6 +28,8 @@ import 'package:miru_app/utils/i18n.dart';
import 'package:miru_app/utils/miru_storage.dart';
import 'package:miru_app/views/widgets/messenger.dart';

import '../utils/logger.dart';

class DetailPageController extends GetxController {
DetailPageController({
required this.package,
Expand Down Expand Up @@ -327,6 +334,17 @@ class DetailPageController extends GetxController {
rethrow;
}
await refreshFavorite();
Box setting = GStorage.setting;
late bool webDavEnable = setting.get(SettingBoxKey.webDavEnable, defaultValue: false);
if (webDavEnable) {
try {
var webDav = WebDav();
webDav.uploadDefaultIsar();
} catch (e) {
SmartDialog.showToast('同步记录失败 ${e.toString()}');
KazumiLogger().log(Level.error, '同步记录失败 ${e.toString()}');
}
}
Get.find<HomePageController>().onRefresh();
}

Expand Down
3 changes: 2 additions & 1 deletion lib/controllers/watch/reader_controller.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:async';

import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:hive/hive.dart';
import 'package:logger/logger.dart';
Expand Down Expand Up @@ -90,7 +91,7 @@ class ReaderController<T> extends GetxController {
var webDav = WebDav();
webDav.uploadDefaultIsar();
} catch (e) {
//SmartDialog.showToast('同步记录失败 ${e.toString()}');
SmartDialog.showToast('同步记录失败 ${e.toString()}');
KazumiLogger().log(Level.error, '同步记录失败 ${e.toString()}');
}
}
Expand Down
10 changes: 8 additions & 2 deletions lib/controllers/watch/video_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:flutter/material.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/services.dart';
import 'package:flutter_i18n/flutter_i18n.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:hive/hive.dart';
import 'package:logger/logger.dart';
Expand Down Expand Up @@ -136,6 +137,7 @@ void toggleDanmaku() {
.setProperty('demuxer-max-bytes', '30MiB');
}
play();
danmakuController.pause();
getDanDanmaku(title,playIndex);
getPlayerTimer() {
return Timer.periodic(const Duration(seconds: 1), (timer) {
Expand Down Expand Up @@ -193,10 +195,13 @@ void toggleDanmaku() {
// 切换剧集
ever(index, (callback) {
play();
danmakuController.pause();
danmakuController.clear();
getDanDanmaku(title,index.value);
});
// 播放状态监听,当开始播放时启动计时器
player.stream.playing.listen((playing) {
if (playing) {
if (playing&&!player.state.buffering) {
danmakuController.resume();
getPlayerTimer();
}
Expand Down Expand Up @@ -470,6 +475,7 @@ void toggleDanmaku() {
await Future.delayed(const Duration(seconds: 3));

play();
danmakuController.pause();

return;
}
Expand Down Expand Up @@ -553,7 +559,7 @@ void toggleDanmaku() {
var webDav = WebDav();
webDav.uploadDefaultIsar();
} catch (e) {
//SmartDialog.showToast('同步记录失败 ${e.toString()}');
SmartDialog.showToast('同步记录失败 ${e.toString()}');
KazumiLogger().log(Level.error, '同步记录失败 ${e.toString()}');
}
}
Expand Down
3 changes: 3 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:desktop_multi_window/desktop_multi_window.dart';
import 'package:fluent_ui/fluent_ui.dart' as fluent;
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:media_kit/media_kit.dart';
import 'package:miru_app/controllers/application_controller.dart';
Expand Down Expand Up @@ -127,6 +128,7 @@ class _MainAppState extends State<MainApp> {
localizationsDelegates: [
I18nUtils.flutterI18nDelegate,
],
builder: FlutterSmartDialog.init(),
);
}

Expand All @@ -148,6 +150,7 @@ class _MainAppState extends State<MainApp> {
localizationsDelegates: [
I18nUtils.flutterI18nDelegate,
],
builder: FlutterSmartDialog.init(),
);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/views/pages/settings/settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ class _SettingsPageState extends State<SettingsPage> {
}
},
),
const SizedBox(height: 10),
const SizedBox(height: 10),
SettingsTile(
isCard: true,
icon: Container(
Expand Down
8 changes: 4 additions & 4 deletions lib/webdav_editor/webdav_editor_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,16 @@ class _WebDavEditorPageState extends State<WebDavEditorPage> {
try {
await webDav.init();
} catch (e) {
debugPrint('配置失败 ${e.toString()}');
SmartDialog.showToast('配置失败 ${e.toString()}');
await setting.put(SettingBoxKey.webDavEnable, false);
return;
}
debugPrint('配置成功, 开始测试');
SmartDialog.showToast('配置成功, 开始测试');
try {
await webDav.ping();
debugPrint('测试成功');
SmartDialog.showToast('测试成功');
} catch (e) {
debugPrint('测试失败 ${e.toString()}');
SmartDialog.showToast('测试失败 ${e.toString()}');
await setting.put(SettingBoxKey.webDavEnable, false);
}
},
Expand Down
29 changes: 13 additions & 16 deletions lib/webdav_editor/webdav_setting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@ import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';
import 'package:miru_app/router/router.dart';
import 'package:miru_app/utils/utils.dart';
import 'package:miru_app/bean/settings/settings.dart';
import 'package:miru_app/utils/storage.dart';
import 'package:miru_app/utils/webdav.dart';
import 'package:hive/hive.dart';
import 'package:flutter_modular/flutter_modular.dart';
import 'package:miru_app/bean/appbar/sys_app_bar.dart';
import 'package:miru_app/webdav_editor/webdav_editor_page.dart';

Expand Down Expand Up @@ -41,19 +38,19 @@ class _PlayerSettingsPageState extends State<WebDavSettingsPage> {
await setting.get(SettingBoxKey.webDavURL, defaultValue: '');
if (webDavURL == '') {
await setting.put(SettingBoxKey.webDavEnable, false);
debugPrint('未找到有效的webdav配置');
SmartDialog.showToast('未找到有效的webdav配置');
return;
}
try {
debugPrint('尝试从WebDav同步');
SmartDialog.showToast('尝试从WebDav同步');
var webDav = WebDav();
await webDav.downloadAndMigrateIsar();
debugPrint('同步成功');
SmartDialog.showToast('同步成功');
} catch (e) {
if (e.toString().contains('Error: Not Found')) {
debugPrint('配置成功, 这是一个不存在已有同步文件的全新WebDav');
SmartDialog.showToast('配置成功, 这是一个不存在已有同步文件的全新WebDav');
} else {
debugPrint('同步失败 ${e.toString()}');
SmartDialog.showToast('同步失败 ${e.toString()}');
}
}
}
Expand All @@ -63,15 +60,15 @@ class _PlayerSettingsPageState extends State<WebDavSettingsPage> {
await setting.get(SettingBoxKey.webDavEnable, defaultValue: false);
if (webDavEnable) {
try {
debugPrint('尝试上传到WebDav');
SmartDialog.showToast('尝试上传到WebDav');
var webDav = WebDav();
await webDav.uploadDefaultIsar();
debugPrint('同步成功');
SmartDialog.showToast('同步成功');
} catch (e) {
debugPrint('同步失败 ${e.toString()}');
SmartDialog.showToast('同步失败 ${e.toString()}');
}
} else {
debugPrint('未开启WebDav同步或配置无效');
SmartDialog.showToast('未开启WebDav同步或配置无效');
}
}

Expand All @@ -80,15 +77,15 @@ class _PlayerSettingsPageState extends State<WebDavSettingsPage> {
await setting.get(SettingBoxKey.webDavEnable, defaultValue: false);
if (webDavEnable) {
try {
debugPrint('尝试从WebDav同步');
SmartDialog.showToast('尝试从WebDav同步');
var webDav = WebDav();
await webDav.downloadAndMigrateIsar();
debugPrint('同步成功');
SmartDialog.showToast('同步成功');
} catch (e) {
debugPrint('同步失败 ${e.toString()}');
SmartDialog.showToast('同步失败 ${e.toString()}');
}
} else {
debugPrint('未开启WebDav同步或配置无效');
SmartDialog.showToast('未开启WebDav同步或配置无效');
}
}

Expand Down

0 comments on commit 827fe9e

Please sign in to comment.