基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。
feat(linux): support external player (#2348)
Predidit1b443576841f
diff --git a/lib/services/player/external_playback_launcher.dart b/lib/services/player/external_playback_launcher.dartindex 2d3a8be4..5e0960cc 100644--- a/lib/services/player/external_playback_launcher.dart+++ b/lib/services/player/external_playback_launcher.dart@@ -2,7 +2,6 @@ import 'dart:io';import 'package:kazumi/bean/dialog/dialog_helper.dart';import 'package:kazumi/services/player/external_player.dart';-import 'package:url_launcher/url_launcher_string.dart';class ExternalPlaybackLauncher {final String Function() videoUrl;@@ -17,7 +16,7 @@ class ExternalPlaybackLauncher {final currentVideoUrl = videoUrl();final currentReferer = referer();if ((Platform.isAndroid || Platform.isWindows) && currentReferer.isEmpty) {- if (await ExternalPlayer.launchURLWithMIME(+ if (await ExternalPlayer.launchUrlWithMime(currentVideoUrl, 'video/mp4')) {KazumiDialog.dismiss();KazumiDialog.showToast(@@ -29,7 +28,7 @@ class ExternalPlaybackLauncher {);}} else if (Platform.isMacOS || Platform.isIOS) {- if (await ExternalPlayer.launchURLWithReferer(+ if (await ExternalPlayer.launchUrlWithReferer(currentVideoUrl, currentReferer)) {KazumiDialog.dismiss();KazumiDialog.showToast(@@ -42,15 +41,17 @@ class ExternalPlaybackLauncher {}} else if (Platform.isLinux && currentReferer.isEmpty) {KazumiDialog.dismiss();- if (await canLaunchUrlString(currentVideoUrl)) {- launchUrlString(currentVideoUrl);- KazumiDialog.showToast(- message: '尝试唤起外部播放器',- );- } else {- KazumiDialog.showToast(- message: '无法使用外部播放器',- );+ final result =+ await ExternalPlayer.launchLinuxDesktopPlayer(currentVideoUrl);+ switch (result) {+ case LinuxExternalPlayerResult.launched:+ KazumiDialog.showToast(message: '尝试唤起外部播放器');+ case LinuxExternalPlayerResult.cancelled:+ break;+ case LinuxExternalPlayerResult.unavailable:+ KazumiDialog.showToast(message: '系统应用选择器不可用');+ case LinuxExternalPlayerResult.failed:+ KazumiDialog.showToast(message: '唤起外部播放器失败');}} else {if (currentReferer.isEmpty) {diff --git a/lib/services/player/external_player.dart b/lib/services/player/external_player.dartindex c8ccb8b0..dbaca9e3 100644--- a/lib/services/player/external_player.dart+++ b/lib/services/player/external_player.dart@@ -1,15 +1,21 @@import 'package:flutter/services.dart';import 'package:kazumi/services/logging/logger.dart';+enum LinuxExternalPlayerResult {+ launched,+ cancelled,+ unavailable,+ failed,+}+class ExternalPlayer {- // 注意:仍需开发 iOS/Linux 设备的外部播放功能。- // 在 Windows 设备上,对于其他可能的实现,使用 scheme 的方案没有效果。VLC / PotPlayer 等主流播放器更倾向于使用 CLI 命令。- // 可行的 iOS 处理代码,请参见 ios/Runner/AppDelegate.swift 的注释部分。- static const platform = MethodChannel('com.predidit.kazumi/intent');+ ExternalPlayer._();- static Future<bool> launchURLWithMIME(String url, String mimeType) async {+ static const _platform = MethodChannel('com.predidit.kazumi/intent');++ static Future<bool> launchUrlWithMime(String url, String mimeType) async {try {- await platform.invokeMethod(+ await _platform.invokeMethod('openWithMime', <String, String>{'url': url, 'mimeType': mimeType});return true;} on PlatformException catch (e) {@@ -18,9 +24,9 @@ class ExternalPlayer {}}- static Future<bool> launchURLWithReferer(String url, String referer) async {+ static Future<bool> launchUrlWithReferer(String url, String referer) async {try {- await platform.invokeMethod(+ await _platform.invokeMethod('openWithReferer', <String, String>{'url': url, 'referer': referer});return true;} on PlatformException catch (e) {@@ -28,4 +34,26 @@ class ExternalPlayer {return false;}}++ static Future<LinuxExternalPlayerResult> launchLinuxDesktopPlayer(+ String url) async {+ try {+ final result = await _platform.invokeMethod<String>(+ 'openWithDesktopPlayer',+ <String, String>{'url': url},+ );+ return switch (result) {+ 'launched' => LinuxExternalPlayerResult.launched,+ 'cancelled' => LinuxExternalPlayerResult.cancelled,+ 'unavailable' => LinuxExternalPlayerResult.unavailable,+ _ => LinuxExternalPlayerResult.failed,+ };+ } on PlatformException catch (e) {+ KazumiLogger().e(+ "ExternalPlayer: failed to open Linux desktop player",+ error: e,+ );+ return LinuxExternalPlayerResult.failed;+ }+ }}diff --git a/linux/CMakeLists.txt b/linux/CMakeLists.txtindex 937404a0..9244e01e 100644--- a/linux/CMakeLists.txt+++ b/linux/CMakeLists.txt@@ -58,6 +58,7 @@ add_subdirectory(${FLUTTER_MANAGED_DIR})# System-level dependencies.find_package(PkgConfig REQUIRED)pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)+pkg_check_modules(GIO_UNIX REQUIRED IMPORTED_TARGET gio-unix-2.0)add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}")@@ -66,6 +67,7 @@ add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}")## Any new source files that you add to the application should be added here.add_executable(${BINARY_NAME}+ "external_player_portal.cc""main.cc""my_application.cc""${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"@@ -78,6 +80,7 @@ apply_standard_settings(${BINARY_NAME})# Add dependency libraries. Add any application-specific dependencies here.target_link_libraries(${BINARY_NAME} PRIVATE flutter)target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK)+target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GIO_UNIX)# Run the Flutter tool portions of the build. This must not be removed.add_dependencies(${BINARY_NAME} flutter_assemble)diff --git a/linux/external_player_portal.cc b/linux/external_player_portal.ccnew file mode 100644index 00000000..cf4f9db1--- /dev/null+++ b/linux/external_player_portal.cc@@ -0,0 +1,384 @@+#include "external_player_portal.h"++#include <errno.h>+#include <fcntl.h>+#include <gio/gio.h>+#include <gio/gunixfdlist.h>+#include <stdlib.h>+#include <string.h>+#include <unistd.h>++#include <set>+#include <vector>++namespace {++constexpr char kPortalBusName[] = "org.freedesktop.portal.Desktop";+constexpr char kPortalObjectPath[] = "/org/freedesktop/portal/desktop";+constexpr char kOpenUriInterface[] = "org.freedesktop.portal.OpenURI";+constexpr char kRequestInterface[] = "org.freedesktop.portal.Request";+constexpr char kPlaylistSuffix[] = ".m3u8";+constexpr guint32 kMinimumOpenUriPortalVersion = 3;++struct OpenPortalRequest {+ gint reference_count;+ GDBusConnection* connection;+ GCancellable* cancellable;+ guint response_subscription_id;+ gchar* request_path;+ gchar* url;+ ExternalPlayerPortalCallback callback;+ gpointer user_data;+ bool completed;+};++std::set<OpenPortalRequest*> active_requests;++OpenPortalRequest* ReferenceRequest(OpenPortalRequest* request) {+ ++request->reference_count;+ return request;+}++void UnreferenceRequest(OpenPortalRequest* request) {+ if (--request->reference_count != 0) {+ return;+ }++ g_clear_object(&request->connection);+ g_clear_object(&request->cancellable);+ g_free(request->request_path);+ g_free(request->url);+ delete request;+}++void DestroyRequestReference(gpointer user_data) {+ UnreferenceRequest(static_cast<OpenPortalRequest*>(user_data));+}++bool IsSupportedUrl(const gchar* url) {+ if (url == nullptr || url[0] == '\0' || strchr(url, '\r') != nullptr ||+ strchr(url, '\n') != nullptr) {+ return false;+ }++ g_autofree gchar* scheme = g_uri_parse_scheme(url);+ return scheme != nullptr &&+ (g_ascii_strcasecmp(scheme, "http") == 0 ||+ g_ascii_strcasecmp(scheme, "https") == 0);+}++gchar* CreatePlaylist(const gchar* url, GError** error) {+ g_autofree gchar* path =+ g_build_filename(g_get_tmp_dir(), "kazumi_stream_XXXXXX.m3u8", nullptr);+ const int fd = mkstemps(path, strlen(kPlaylistSuffix));+ if (fd == -1) {+ g_set_error(error, G_FILE_ERROR, g_file_error_from_errno(errno),+ "Failed to create playlist: %s", g_strerror(errno));+ return nullptr;+ }++ g_autofree gchar* contents = g_strdup_printf("#EXTM3U\n%s\n", url);+ const gsize contents_length = strlen(contents);+ gsize written = 0;+ while (written < contents_length) {+ const ssize_t count =+ write(fd, contents + written, contents_length - written);+ if (count < 0 && errno == EINTR) {+ continue;+ }+ if (count <= 0) {+ const int saved_errno = errno;+ close(fd);+ g_set_error(error, G_FILE_ERROR, g_file_error_from_errno(saved_errno),+ "Failed to write playlist: %s", g_strerror(saved_errno));+ return nullptr;+ }+ written += static_cast<gsize>(count);+ }++ if (close(fd) != 0) {+ const int saved_errno = errno;+ g_set_error(error, G_FILE_ERROR, g_file_error_from_errno(saved_errno),+ "Failed to close playlist: %s", g_strerror(saved_errno));+ return nullptr;+ }++ return g_steal_pointer(&path);+}++bool IsPortalUnavailableError(const GError* error) {+ return g_error_matches(error, G_DBUS_ERROR, G_DBUS_ERROR_SERVICE_UNKNOWN) ||+ g_error_matches(error, G_DBUS_ERROR, G_DBUS_ERROR_NAME_HAS_NO_OWNER) ||+ g_error_matches(error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD) ||+ g_error_matches(error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED);+}++ExternalPlayerPortalResult ResultForPortalError(const GError* error) {+ return IsPortalUnavailableError(error)+ ? ExternalPlayerPortalResult::kUnavailable+ : ExternalPlayerPortalResult::kFailed;+}++void CompleteRequest(OpenPortalRequest* request,+ ExternalPlayerPortalResult result,+ const gchar* error_message) {+ if (request->completed) {+ return;+ }++ request->completed = true;+ if (request->response_subscription_id != 0 &&+ request->connection != nullptr) {+ const guint subscription_id = request->response_subscription_id;+ request->response_subscription_id = 0;+ g_dbus_connection_signal_unsubscribe(request->connection, subscription_id);+ }+ active_requests.erase(request);+ request->callback(result, error_message, request->user_data);+ UnreferenceRequest(request);+}++gchar* CreateHandleToken() {+ g_autofree gchar* uuid = g_uuid_string_random();+ for (gchar* character = uuid; *character != '\0'; ++character) {+ if (*character == '-') {+ *character = '_';+ }+ }+ return g_strdup_printf("kazumi_%s", uuid);+}++gchar* CreateExpectedRequestPath(GDBusConnection* connection,+ const gchar* handle_token) {+ const gchar* unique_name = g_dbus_connection_get_unique_name(connection);+ if (unique_name == nullptr) {+ return nullptr;+ }++ g_autofree gchar* sender = g_strdup(unique_name[0] == ':' ? unique_name + 1+ : unique_name);+ for (gchar* character = sender; *character != '\0'; ++character) {+ if (*character == '.') {+ *character = '_';+ }+ }+ return g_strdup_printf("/org/freedesktop/portal/desktop/request/%s/%s",+ sender, handle_token);+}++void PortalResponseReceived(GDBusConnection*,+ const gchar*,+ const gchar*,+ const gchar*,+ const gchar*,+ GVariant* parameters,+ gpointer user_data) {+ auto* request = static_cast<OpenPortalRequest*>(user_data);+ guint32 response = 2;+ g_variant_get_child(parameters, 0, "u", &response);++ if (response == 0) {+ CompleteRequest(request, ExternalPlayerPortalResult::kLaunched, nullptr);+ } else if (response == 1) {+ CompleteRequest(request, ExternalPlayerPortalResult::kCancelled, nullptr);+ } else {+ CompleteRequest(request, ExternalPlayerPortalResult::kUnavailable,+ "The desktop portal could not open the playlist");+ }+}++guint SubscribeToResponse(OpenPortalRequest* request,+ const gchar* request_path) {+ return g_dbus_connection_signal_subscribe(+ request->connection, kPortalBusName, kRequestInterface, "Response",+ request_path, nullptr, G_DBUS_SIGNAL_FLAGS_NONE,+ PortalResponseReceived, ReferenceRequest(request),+ DestroyRequestReference);+}++void OpenFileFinished(GObject* source_object,+ GAsyncResult* result,+ gpointer user_data) {+ auto* request = static_cast<OpenPortalRequest*>(user_data);+ g_autoptr(GError) error = nullptr;+ g_autoptr(GVariant) response =+ g_dbus_connection_call_with_unix_fd_list_finish(+ G_DBUS_CONNECTION(source_object), nullptr, result, &error);++ if (!request->completed && response == nullptr) {+ CompleteRequest(request, ResultForPortalError(error), error->message);+ } else if (!request->completed) {+ const gchar* returned_path = nullptr;+ g_variant_get(response, "(&o)", &returned_path);+ if (g_strcmp0(returned_path, request->request_path) != 0) {+ const guint new_subscription_id =+ SubscribeToResponse(request, returned_path);+ const guint old_subscription_id = request->response_subscription_id;+ request->response_subscription_id = new_subscription_id;+ g_free(request->request_path);+ request->request_path = g_strdup(returned_path);+ g_dbus_connection_signal_unsubscribe(request->connection,+ old_subscription_id);+ }+ }++ UnreferenceRequest(request);+}++void StartPortalOpen(OpenPortalRequest* request) {+ g_autoptr(GError) error = nullptr;+ g_autofree gchar* playlist_path = CreatePlaylist(request->url, &error);+ if (playlist_path == nullptr) {+ CompleteRequest(request, ExternalPlayerPortalResult::kFailed,+ error->message);+ return;+ }++ const int playlist_fd = open(playlist_path, O_RDONLY | O_CLOEXEC);+ if (playlist_fd == -1) {+ const int saved_errno = errno;+ g_set_error(&error, G_FILE_ERROR, g_file_error_from_errno(saved_errno),+ "Failed to open playlist: %s", g_strerror(saved_errno));+ CompleteRequest(request, ExternalPlayerPortalResult::kFailed,+ error->message);+ return;+ }++ g_autoptr(GUnixFDList) fd_list = g_unix_fd_list_new();+ const gint fd_index = g_unix_fd_list_append(fd_list, playlist_fd, &error);+ close(playlist_fd);+ if (fd_index == -1) {+ CompleteRequest(request, ExternalPlayerPortalResult::kFailed,+ error->message);+ return;+ }++ g_autofree gchar* handle_token = CreateHandleToken();+ request->request_path =+ CreateExpectedRequestPath(request->connection, handle_token);+ if (request->request_path == nullptr) {+ CompleteRequest(request, ExternalPlayerPortalResult::kFailed,+ "The session bus did not provide a unique connection name");+ return;+ }+ request->response_subscription_id =+ SubscribeToResponse(request, request->request_path);++ GVariantBuilder options;+ g_variant_builder_init(&options, G_VARIANT_TYPE_VARDICT);+ g_variant_builder_add(&options, "{sv}", "handle_token",+ g_variant_new_string(handle_token));+ g_variant_builder_add(&options, "{sv}", "ask",+ g_variant_new_boolean(TRUE));++ g_dbus_connection_call_with_unix_fd_list(+ request->connection, kPortalBusName, kPortalObjectPath,+ kOpenUriInterface, "OpenFile",+ g_variant_new("(sh@a{sv})", "", fd_index,+ g_variant_builder_end(&options)),+ G_VARIANT_TYPE("(o)"), G_DBUS_CALL_FLAGS_NONE, -1, fd_list,+ request->cancellable, OpenFileFinished, ReferenceRequest(request));+}++void PortalVersionReady(GObject* source_object,+ GAsyncResult* result,+ gpointer user_data) {+ auto* request = static_cast<OpenPortalRequest*>(user_data);+ g_autoptr(GError) error = nullptr;+ g_autoptr(GVariant) response = g_dbus_connection_call_finish(+ G_DBUS_CONNECTION(source_object), result, &error);++ if (!request->completed && response == nullptr) {+ CompleteRequest(request, ResultForPortalError(error), error->message);+ } else if (!request->completed) {+ g_autoptr(GVariant) boxed_version = nullptr;+ g_variant_get(response, "(@v)", &boxed_version);+ g_autoptr(GVariant) version = g_variant_get_variant(boxed_version);+ if (!g_variant_is_of_type(version, G_VARIANT_TYPE_UINT32) ||+ g_variant_get_uint32(version) < kMinimumOpenUriPortalVersion) {+ CompleteRequest(+ request, ExternalPlayerPortalResult::kUnavailable,+ "The OpenURI portal does not support asking for an application");+ } else {+ StartPortalOpen(request);+ }+ }++ UnreferenceRequest(request);+}++void PortalBusReady(GObject*,+ GAsyncResult* result,+ gpointer user_data) {+ auto* request = static_cast<OpenPortalRequest*>(user_data);+ g_autoptr(GError) error = nullptr;+ request->connection = g_bus_get_finish(result, &error);++ if (!request->completed && request->connection == nullptr) {+ CompleteRequest(request, ExternalPlayerPortalResult::kUnavailable,+ error->message);+ } else if (!request->completed) {+ g_dbus_connection_call(+ request->connection, kPortalBusName, kPortalObjectPath,+ "org.freedesktop.DBus.Properties", "Get",+ g_variant_new("(ss)", kOpenUriInterface, "version"),+ G_VARIANT_TYPE("(v)"), G_DBUS_CALL_FLAGS_NONE, -1,+ request->cancellable, PortalVersionReady, ReferenceRequest(request));+ }++ UnreferenceRequest(request);+}++void ClosePortalRequest(OpenPortalRequest* request) {+ if (request->connection == nullptr || request->request_path == nullptr) {+ return;+ }++ g_dbus_connection_call(request->connection, kPortalBusName,+ request->request_path, kRequestInterface, "Close",+ nullptr, nullptr, G_DBUS_CALL_FLAGS_NONE, -1, nullptr,+ nullptr, nullptr);+}++} // namespace++void OpenExternalPlayerWithPortal(const gchar* url,+ ExternalPlayerPortalCallback callback,+ gpointer user_data) {+ if (!IsSupportedUrl(url)) {+ callback(ExternalPlayerPortalResult::kInvalidArgument,+ "A non-empty HTTP(S) URL without line breaks is required",+ user_data);+ return;+ }++ auto* request = new OpenPortalRequest{+ 1,+ nullptr,+ g_cancellable_new(),+ 0,+ nullptr,+ g_strdup(url),+ callback,+ user_data,+ false,+ };+ active_requests.insert(request);+ g_bus_get(G_BUS_TYPE_SESSION, request->cancellable, PortalBusReady,+ ReferenceRequest(request));+}++void CancelExternalPlayerPortalRequests() {+ std::vector<OpenPortalRequest*> requests;+ requests.reserve(active_requests.size());+ for (OpenPortalRequest* request : active_requests) {+ requests.push_back(ReferenceRequest(request));+ }++ for (OpenPortalRequest* request : requests) {+ ClosePortalRequest(request);+ g_cancellable_cancel(request->cancellable);+ CompleteRequest(request, ExternalPlayerPortalResult::kCancelled, nullptr);+ UnreferenceRequest(request);+ }+}diff --git a/linux/external_player_portal.h b/linux/external_player_portal.hnew file mode 100644index 00000000..dad4f330--- /dev/null+++ b/linux/external_player_portal.h@@ -0,0 +1,29 @@+#ifndef FLUTTER_EXTERNAL_PLAYER_PORTAL_H_+#define FLUTTER_EXTERNAL_PLAYER_PORTAL_H_++#include <glib.h>++enum class ExternalPlayerPortalResult {+ kLaunched,+ kCancelled,+ kUnavailable,+ kInvalidArgument,+ kFailed,+};++using ExternalPlayerPortalCallback = void (*)(+ ExternalPlayerPortalResult result,+ const gchar* error_message,+ gpointer user_data);++// Writes the URL to an M3U8 playlist in the system temporary directory and+// asks the desktop portal to open it with a user-selected application. The+// playlist is intentionally retained after the request completes.+void OpenExternalPlayerWithPortal(const gchar* url,+ ExternalPlayerPortalCallback callback,+ gpointer user_data);++// Cancels pending D-Bus calls and closes active portal requests during shutdown.+void CancelExternalPlayerPortalRequests();++#endif // FLUTTER_EXTERNAL_PLAYER_PORTAL_H_diff --git a/linux/my_application.cc b/linux/my_application.ccindex dcd9dfe3..de482cbf 100644--- a/linux/my_application.cc+++ b/linux/my_application.cc@@ -6,6 +6,7 @@#include <gdk/gdkx.h>#endif+#include "external_player_portal.h"#include "flutter/generated_plugin_registrant.h"struct _MyApplication {@@ -17,6 +18,51 @@ struct _MyApplication {G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION)+static void respond_to_method_call(FlMethodCall* method_call,+ FlMethodResponse* response) {+ g_autoptr(GError) error = nullptr;+ if (!fl_method_call_respond(method_call, response, &error)) {+ g_warning("Failed to send response: %s", error->message);+ }+}++static void external_player_portal_callback(+ ExternalPlayerPortalResult result,+ const gchar* error_message,+ gpointer user_data) {+ auto* method_call = FL_METHOD_CALL(user_data);+ g_autoptr(FlMethodResponse) response = nullptr;++ switch (result) {+ case ExternalPlayerPortalResult::kLaunched: {+ g_autoptr(FlValue) value = fl_value_new_string("launched");+ response = FL_METHOD_RESPONSE(fl_method_success_response_new(value));+ break;+ }+ case ExternalPlayerPortalResult::kCancelled: {+ g_autoptr(FlValue) value = fl_value_new_string("cancelled");+ response = FL_METHOD_RESPONSE(fl_method_success_response_new(value));+ break;+ }+ case ExternalPlayerPortalResult::kUnavailable: {+ g_autoptr(FlValue) value = fl_value_new_string("unavailable");+ response = FL_METHOD_RESPONSE(fl_method_success_response_new(value));+ break;+ }+ case ExternalPlayerPortalResult::kInvalidArgument:+ response = FL_METHOD_RESPONSE(fl_method_error_response_new(+ "INVALID_ARGUMENT", error_message, nullptr));+ break;+ case ExternalPlayerPortalResult::kFailed:+ response = FL_METHOD_RESPONSE(fl_method_error_response_new(+ "EXTERNAL_PLAYER_LAUNCH_FAILED", error_message, nullptr));+ break;+ }++ respond_to_method_call(method_call, response);+ g_object_unref(method_call);+}+static FlMethodResponse* is_running_on_x11() {GdkDisplay* display = gdk_display_get_default();gboolean is_x11 = GDK_IS_X11_DISPLAY(display);@@ -24,9 +70,9 @@ static FlMethodResponse* is_running_on_x11() {return FL_METHOD_RESPONSE(fl_method_success_response_new(result));}-static void storage_method_call_handler(FlMethodChannel* channel,- FlMethodCall* method_call,- gpointer user_data) {+static void storage_method_call_handler(FlMethodChannel*,+ FlMethodCall* method_call,+ gpointer) {g_autoptr(FlMethodResponse) response = nullptr;if (strcmp(fl_method_call_get_name(method_call), "getAvailableStorage") == 0) {const gchar* path = "/";@@ -51,26 +97,35 @@ static void storage_method_call_handler(FlMethodChannel* channel,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);- }+ respond_to_method_call(method_call, response);}-static void intent_method_call_handler(FlMethodChannel* channel,+static void intent_method_call_handler(FlMethodChannel*,FlMethodCall* method_call,- gpointer user_data) {+ gpointer) {g_autoptr(FlMethodResponse) response = nullptr;if (strcmp(fl_method_call_get_name(method_call), "isRunningOnX11") == 0) {response = is_running_on_x11();+ } else if (strcmp(fl_method_call_get_name(method_call),+ "openWithDesktopPlayer") == 0) {+ const gchar* url = nullptr;+ FlValue* args = fl_method_call_get_args(method_call);+ if (fl_value_get_type(args) == FL_VALUE_TYPE_MAP) {+ FlValue* url_value = fl_value_lookup_string(args, "url");+ if (url_value != nullptr &&+ fl_value_get_type(url_value) == FL_VALUE_TYPE_STRING) {+ url = fl_value_get_string(url_value);+ }+ }++ OpenExternalPlayerWithPortal(+ url, external_player_portal_callback, g_object_ref(method_call));+ return;} 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);- }+ respond_to_method_call(method_call, response);}// Implements GApplication::activate.@@ -151,20 +206,9 @@ static gboolean my_application_local_command_line(GApplication* application, gchreturn TRUE;}-// Implements GApplication::startup.-static void my_application_startup(GApplication* application) {- //MyApplication* self = MY_APPLICATION(object);-- // Perform any actions required at application startup.-- G_APPLICATION_CLASS(my_application_parent_class)->startup(application);-}-// Implements GApplication::shutdown.static void my_application_shutdown(GApplication* application) {- //MyApplication* self = MY_APPLICATION(object);-- // Perform any actions required at application shutdown.+ CancelExternalPlayerPortalRequests();G_APPLICATION_CLASS(my_application_parent_class)->shutdown(application);}@@ -181,7 +225,6 @@ static void my_application_dispose(GObject* object) {static void my_application_class_init(MyApplicationClass* klass) {G_APPLICATION_CLASS(klass)->activate = my_application_activate;G_APPLICATION_CLASS(klass)->local_command_line = my_application_local_command_line;- G_APPLICATION_CLASS(klass)->startup = my_application_startup;G_APPLICATION_CLASS(klass)->shutdown = my_application_shutdown;G_OBJECT_CLASS(klass)->dispose = my_application_dispose;}