From fbc02a93220188b638541e552d1d3f5ad23c071d Mon Sep 17 00:00:00 2001 From: Abhishek Shroff Date: Thu, 1 May 2025 00:05:23 +0530 Subject: [PATCH] [client] Share on Android --- client/lib/ui/menu/menu_option.dart | 17 +++++-- client/lib/util/dialogs.dart | 15 +++--- .../flutter/generated_plugin_registrant.cc | 4 ++ client/linux/flutter/generated_plugins.cmake | 1 + .../Flutter/GeneratedPluginRegistrant.swift | 2 + client/pubspec.lock | 48 +++++++++++++++++++ client/pubspec.yaml | 1 + .../flutter/generated_plugin_registrant.cc | 6 +++ .../windows/flutter/generated_plugins.cmake | 2 + 9 files changed, 85 insertions(+), 11 deletions(-) diff --git a/client/lib/ui/menu/menu_option.dart b/client/lib/ui/menu/menu_option.dart index cd4b0f3f..fd35be6e 100644 --- a/client/lib/ui/menu/menu_option.dart +++ b/client/lib/ui/menu/menu_option.dart @@ -18,6 +18,9 @@ import 'package:phylum/ui/explorer/resource_permissions_view.dart'; import 'package:phylum/util/dialogs.dart'; import 'package:phylum/util/upload_utils.dart'; import 'package:provider/provider.dart'; +import 'package:path_provider/path_provider.dart'; +import 'package:path/path.dart' as path; +import 'package:share_plus/share_plus.dart'; enum MenuOption { details(Icons.info_outline, 'Details', isSingle), @@ -35,7 +38,7 @@ enum MenuOption { newFolder(Icons.create_new_folder_outlined, 'New Folder', isSingle), uploadFiles(Icons.upload_file_outlined, 'Upload File(s)', isSingle), uploadFolders(Icons.drive_folder_upload_outlined, 'Upload Folder(s)', isSingle), - share(Icons.share, 'share', all), + share(Icons.share, 'Share', all), ; const MenuOption(this.icon, this.text, this.filter); @@ -166,6 +169,7 @@ void handleOption(BuildContext context, Iterable resources, MenuOption displayName: r.name, group: 'immediate', priority: 0, + updates: Updates.progress, ); if (!context.mounted) { return; @@ -174,28 +178,33 @@ void handleOption(BuildContext context, Iterable resources, MenuOption bool dialogVisivle = true; showProgresIndicatorDialog( context, - title: 'Downloading ${r.name}', + title: r.name, barrierDismissible: true, progress: downloadStreamController.stream, ).then((value) { dialogVisivle = false; if (value != true) { // Task cancelled - print('Cancelled'); FileDownloader().cancelTaskWithId(task.taskId); } }); final status = await FileDownloader().download(task, onProgress: (progress) { downloadStreamController.add(progress); }); - print('Download Finished'); downloadStreamController.close(); if (context.mounted && dialogVisivle) Navigator.of(context).pop(true); if (status.status == TaskStatus.complete) { downloaded.add(task); } } + if (downloaded.isEmpty) return; + final directory = await getApplicationCacheDirectory(); + final params = ShareParams( + files: downloaded.map((task) => XFile(path.join(directory.path, task.filename))).toList(growable: false), + fileNameOverrides: downloaded.map((task) => task.filename).toList(growable: false), + ); + SharePlus.instance.share(params); break; case MenuOption.bookmarkAdd: if (resources.length == 1) { diff --git a/client/lib/util/dialogs.dart b/client/lib/util/dialogs.dart index 7978d285..142ebb48 100644 --- a/client/lib/util/dialogs.dart +++ b/client/lib/util/dialogs.dart @@ -47,8 +47,15 @@ Future showProgresIndicatorDialog( title: (title == null) ? null : Text(title), content: SizedBox( width: 360, - child: Row( + child: Column( + mainAxisSize: MainAxisSize.min, children: [ + if (message != null) + Text( + message, + softWrap: true, + overflow: TextOverflow.fade, + ), Padding( padding: const EdgeInsets.only(right: 16), child: StreamBuilder( @@ -56,12 +63,6 @@ Future showProgresIndicatorDialog( initialData: null, builder: (context, snapshot) => LinearProgressIndicator(value: snapshot.data)), ), - if (message != null) - Text( - message, - softWrap: true, - overflow: TextOverflow.fade, - ), ], ), ), diff --git a/client/linux/flutter/generated_plugin_registrant.cc b/client/linux/flutter/generated_plugin_registrant.cc index 82c61301..82319ca2 100644 --- a/client/linux/flutter/generated_plugin_registrant.cc +++ b/client/linux/flutter/generated_plugin_registrant.cc @@ -12,6 +12,7 @@ #include #include #include +#include void fl_register_plugins(FlPluginRegistry* registry) { g_autoptr(FlPluginRegistrar) file_selector_linux_registrar = @@ -32,4 +33,7 @@ void fl_register_plugins(FlPluginRegistry* registry) { g_autoptr(FlPluginRegistrar) super_native_extensions_registrar = fl_plugin_registry_get_registrar_for_plugin(registry, "SuperNativeExtensionsPlugin"); super_native_extensions_plugin_register_with_registrar(super_native_extensions_registrar); + g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar = + fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin"); + url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar); } diff --git a/client/linux/flutter/generated_plugins.cmake b/client/linux/flutter/generated_plugins.cmake index 80d046c0..03498139 100644 --- a/client/linux/flutter/generated_plugins.cmake +++ b/client/linux/flutter/generated_plugins.cmake @@ -9,6 +9,7 @@ list(APPEND FLUTTER_PLUGIN_LIST printing sqlite3_flutter_libs super_native_extensions + url_launcher_linux ) list(APPEND FLUTTER_FFI_PLUGIN_LIST diff --git a/client/macos/Flutter/GeneratedPluginRegistrant.swift b/client/macos/Flutter/GeneratedPluginRegistrant.swift index 94aaae13..29cade96 100644 --- a/client/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/client/macos/Flutter/GeneratedPluginRegistrant.swift @@ -11,6 +11,7 @@ import irondash_engine_context import open_file_mac import path_provider_foundation import printing +import share_plus import sqlite3_flutter_libs import super_native_extensions @@ -21,6 +22,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { OpenFilePlugin.register(with: registry.registrar(forPlugin: "OpenFilePlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) PrintingPlugin.register(with: registry.registrar(forPlugin: "PrintingPlugin")) + SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin")) Sqlite3FlutterLibsPlugin.register(with: registry.registrar(forPlugin: "Sqlite3FlutterLibsPlugin")) SuperNativeExtensionsPlugin.register(with: registry.registrar(forPlugin: "SuperNativeExtensionsPlugin")) } diff --git a/client/pubspec.lock b/client/pubspec.lock index ba3149c1..97b82008 100644 --- a/client/pubspec.lock +++ b/client/pubspec.lock @@ -905,6 +905,22 @@ packages: url: "https://pub.dev" source: hosted version: "4.1.0" + share_plus: + dependency: "direct main" + description: + name: share_plus + sha256: b2961506569e28948d75ec346c28775bb111986bb69dc6a20754a457e3d97fa0 + url: "https://pub.dev" + source: hosted + version: "11.0.0" + share_plus_platform_interface: + dependency: transitive + description: + name: share_plus_platform_interface + sha256: "1032d392bc5d2095a77447a805aa3f804d2ae6a4d5eef5e6ebb3bd94c1bc19ef" + url: "https://pub.dev" + source: hosted + version: "6.0.0" shelf: dependency: transitive description: @@ -1078,6 +1094,38 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.0" + url_launcher_linux: + dependency: transitive + description: + name: url_launcher_linux + sha256: "4e9ba368772369e3e08f231d2301b4ef72b9ff87c31192ef471b380ef29a4935" + url: "https://pub.dev" + source: hosted + version: "3.2.1" + url_launcher_platform_interface: + dependency: transitive + description: + name: url_launcher_platform_interface + sha256: "552f8a1e663569be95a8190206a38187b531910283c3e982193e4f2733f01029" + url: "https://pub.dev" + source: hosted + version: "2.3.2" + url_launcher_web: + dependency: transitive + description: + name: url_launcher_web + sha256: "4bd2b7b4dc4d4d0b94e5babfffbca8eac1a126c7f3d6ecbc1a11013faa3abba2" + url: "https://pub.dev" + source: hosted + version: "2.4.1" + url_launcher_windows: + dependency: transitive + description: + name: url_launcher_windows + sha256: "3284b6d2ac454cf34f114e1d3319866fdd1e19cdc329999057e44ffe936cfa77" + url: "https://pub.dev" + source: hosted + version: "3.1.4" uuid: dependency: transitive description: diff --git a/client/pubspec.yaml b/client/pubspec.yaml index e362877f..eb03c0dd 100644 --- a/client/pubspec.yaml +++ b/client/pubspec.yaml @@ -31,6 +31,7 @@ dependencies: permission_handler: printing: provider: + share_plus: sqlite3: state_notifier: super_clipboard: diff --git a/client/windows/flutter/generated_plugin_registrant.cc b/client/windows/flutter/generated_plugin_registrant.cc index 2b9772ce..96038746 100644 --- a/client/windows/flutter/generated_plugin_registrant.cc +++ b/client/windows/flutter/generated_plugin_registrant.cc @@ -10,8 +10,10 @@ #include #include #include +#include #include #include +#include void RegisterPlugins(flutter::PluginRegistry* registry) { FileSelectorWindowsRegisterWithRegistrar( @@ -22,8 +24,12 @@ void RegisterPlugins(flutter::PluginRegistry* registry) { registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin")); PrintingPluginRegisterWithRegistrar( registry->GetRegistrarForPlugin("PrintingPlugin")); + SharePlusWindowsPluginCApiRegisterWithRegistrar( + registry->GetRegistrarForPlugin("SharePlusWindowsPluginCApi")); Sqlite3FlutterLibsPluginRegisterWithRegistrar( registry->GetRegistrarForPlugin("Sqlite3FlutterLibsPlugin")); SuperNativeExtensionsPluginCApiRegisterWithRegistrar( registry->GetRegistrarForPlugin("SuperNativeExtensionsPluginCApi")); + UrlLauncherWindowsRegisterWithRegistrar( + registry->GetRegistrarForPlugin("UrlLauncherWindows")); } diff --git a/client/windows/flutter/generated_plugins.cmake b/client/windows/flutter/generated_plugins.cmake index aa91374a..3b090dea 100644 --- a/client/windows/flutter/generated_plugins.cmake +++ b/client/windows/flutter/generated_plugins.cmake @@ -7,8 +7,10 @@ list(APPEND FLUTTER_PLUGIN_LIST irondash_engine_context permission_handler_windows printing + share_plus sqlite3_flutter_libs super_native_extensions + url_launcher_windows ) list(APPEND FLUTTER_FFI_PLUGIN_LIST