基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。
feat(linux): x11 warning dialog
Predidit3b16d9d0e82d
diff --git a/lib/pages/init_page.dart b/lib/pages/init_page.dartindex eeceecbf..5fd04b25 100644--- a/lib/pages/init_page.dart+++ b/lib/pages/init_page.dart@@ -11,6 +11,7 @@ import 'package:kazumi/pages/collect/collect_controller.dart';import 'package:logger/logger.dart';import 'package:flutter/services.dart' show rootBundle;import 'package:kazumi/utils/logger.dart';+import 'package:kazumi/utils/utils.dart';import 'package:provider/provider.dart';import 'package:kazumi/bean/settings/theme_provider.dart';import 'package:kazumi/shaders/shaders_controller.dart';@@ -32,14 +33,30 @@ class _InitPageState extends State<InitPage> {@overridevoid initState() {- _pluginInit();- _webDavInit();+ super.initState();+ themeProvider = Provider.of<ThemeProvider>(context, listen: false);+ _initializeApp();+ }++ Future<void> _initializeApp() async {_migrateStorage();_loadShaders();_loadDanmakuShield();+ _webDavInit();++ await _checkRunningOnX11();+ await _pluginInit();++ _navigateToHome();_update();- themeProvider = Provider.of<ThemeProvider>(context, listen: false);- super.initState();+ }++ void _navigateToHome() {+ // Workaround for dynamic_color. dynamic_color need PlatformChannel to get color, it takes time.+ // setDynamic here to avoid white screen flash when themeMode is dark.+ themeProvider.setDynamic(+ setting.get(SettingBoxKey.useDynamicColor, defaultValue: false));+ Modular.to.navigate('/tab/popular/');}// migrate collect from old version (favorites)@@ -67,16 +84,54 @@ class _InitPageState extends State<InitPage> {await webDav.downloadAndPatchHistory();KazumiLogger().log(Level.info, '同步观看记录完成');} catch (e) {- KazumiDialog.showToast(message:"同步观看记录失败 ${e.toString()}");- //KazumiLogger().log(Level.error, '同步观看记录失败 ${e.toString()}');+ KazumiDialog.showToast(message: "同步观看记录失败 ${e.toString()}");}} catch (e) {- KazumiDialog.showToast(message:"初始化WebDav失败 ${e.toString()}");- //KazumiLogger().log(Level.error, '初始化WebDav失败 ${e.toString()}');+ KazumiDialog.showToast(message: "初始化WebDav失败 ${e.toString()}");}}}+ Future<void> _checkRunningOnX11() async {+ if (!Platform.isLinux) {+ return;+ }+ bool isRunningOnX11 = await Utils.isRunningOnX11();+ if (isRunningOnX11) {+ await KazumiDialog.show(+ clickMaskDismiss: false,+ builder: (context) {+ return PopScope(+ canPop: false,+ child: AlertDialog(+ title: const Text('X11环境检测'),+ content: const Text(+ '检测到您当前运行在X11环境下,Kazumi在X11环境下可能出现性能问题或界面异常,建议切换到Wayland以获得更好的体验。您是否希望在X11下继续使用Kazumi?'),+ actions: [+ TextButton(+ onPressed: () {+ exit(0);+ },+ child: Text(+ '退出',+ style:+ TextStyle(color: Theme.of(context).colorScheme.outline),+ ),+ ),+ TextButton(+ onPressed: () {+ KazumiDialog.dismiss();+ },+ child: const Text('继续'),+ ),+ ],+ ),+ );+ },+ );+ }+ }+Future<void> _pluginInit() async {String statementsText = '';try {@@ -113,10 +168,9 @@ class _InitPageState extends State<InitPage> {} catch (_) {}KazumiDialog.dismiss();if (!Platform.isAndroid) {- Modular.to.navigate('/tab/popular/');return;}- _switchUpdateMirror();+ await _switchUpdateMirror();},child: const Text('已阅读并同意'),),@@ -125,12 +179,6 @@ class _InitPageState extends State<InitPage> {);},);- } else {- // Workaround for dynamic_color. dynamic_color need PlatformChannel to get color, it takes time.- // setDynamic here to avoid white screen flash when themeMode is dark.- themeProvider.setDynamic(- setting.get(SettingBoxKey.useDynamicColor, defaultValue: false));- Modular.to.navigate('/tab/popular/');}}@@ -171,7 +219,6 @@ class _InitPageState extends State<InitPage> {onPressed: () {setting.put(SettingBoxKey.autoUpdate, true);KazumiDialog.dismiss();- Modular.to.navigate('/tab/popular/');},child: const Text('Github',@@ -181,7 +228,6 @@ class _InitPageState extends State<InitPage> {onPressed: () {setting.put(SettingBoxKey.autoUpdate, false);KazumiDialog.dismiss();- Modular.to.navigate('/tab/popular/');},child: Text('F-Droid',@@ -199,7 +245,6 @@ class _InitPageState extends State<InitPage> {Future<void> _update() async {// Don't check update when there is no plugin.// We will progress init workflow instead.- await Future.delayed(const Duration(seconds: 1));if (pluginsController.pluginList.isNotEmpty) {bool autoUpdate =setting.get(SettingBoxKey.autoUpdate, defaultValue: true);diff --git a/lib/utils/utils.dart b/lib/utils/utils.dartindex 4b465875..b3f04b89 100644--- a/lib/utils/utils.dart+++ b/lib/utils/utils.dart@@ -355,6 +355,22 @@ class Utils {return false;}+ /// 判定是否运行在X11环境下 (Linux only)+ static Future<bool> isRunningOnX11() async {+ if (Platform.isLinux) {+ const platform = MethodChannel('com.predidit.kazumi/intent');+ try {+ final bool result =+ await platform.invokeMethod('isRunningOnX11');+ return result;+ } on PlatformException catch (e) {+ print("Failed to check X11 environment: '${e.message}'.");+ return false;+ }+ }+ return false;+ }+// Deprecatedstatic Future<void> enterWindowsFullscreen() async {if (Platform.isWindows) {diff --git a/linux/my_application.cc b/linux/my_application.ccindex c7bb8d3e..83a5357d 100644--- a/linux/my_application.cc+++ b/linux/my_application.cc@@ -10,10 +10,34 @@struct _MyApplication {GtkApplication parent_instance;char** dart_entrypoint_arguments;+ FlMethodChannel* intent_method_channel;};G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION)+static FlMethodResponse* is_running_on_x11() {+ GdkDisplay* display = gdk_display_get_default();+ gboolean is_x11 = GDK_IS_X11_DISPLAY(display);+ g_autoptr(FlValue) result = fl_value_new_bool(is_x11);+ return FL_METHOD_RESPONSE(fl_method_success_response_new(result));+}++static void intent_method_call_handler(FlMethodChannel* channel,+ FlMethodCall* method_call,+ gpointer user_data) {+ g_autoptr(FlMethodResponse) response = nullptr;+ if (strcmp(fl_method_call_get_name(method_call), "isRunningOnX11") == 0) {+ response = is_running_on_x11();+ } else {+ response = FL_METHOD_RESPONSE(fl_method_not_implemented_response_new());+ }++ g_autoptr(GError) error = nullptr;+ if (!fl_method_call_respond(method_call, response, &error)) {+ g_warning("Failed to send response: %s", error->message);+ }+}+// Implements GApplication::activate.static void my_application_activate(GApplication* application) {MyApplication* self = MY_APPLICATION(application);@@ -45,6 +69,12 @@ static void my_application_activate(GApplication* application) {fl_register_plugins(FL_PLUGIN_REGISTRY(view));+ g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();+ self->intent_method_channel = fl_method_channel_new(+ fl_engine_get_binary_messenger(fl_view_get_engine(view)), "com.predidit.kazumi/intent", FL_METHOD_CODEC(codec));+ fl_method_channel_set_method_call_handler(+ self->intent_method_channel, intent_method_call_handler, self, nullptr);+gtk_widget_grab_focus(GTK_WIDGET(view));}@@ -89,6 +119,7 @@ static void my_application_shutdown(GApplication* application) {static void my_application_dispose(GObject* object) {MyApplication* self = MY_APPLICATION(object);g_clear_pointer(&self->dart_entrypoint_arguments, g_strfreev);+ g_clear_object(&self->intent_method_channel);G_OBJECT_CLASS(my_application_parent_class)->dispose(object);}