From 55d006ab625e533bafc06e4073a528153af52309 Mon Sep 17 00:00:00 2001 From: Joachim Nohl <43643339+nohli@users.noreply.github.com> Date: Thu, 13 Oct 2022 17:55:03 +0200 Subject: [PATCH 1/9] Unfederate share_plus --- .../share_plus/example/lib/main.dart | 36 +++++--------- .../share_plus/example/pubspec.yaml | 10 +--- .../share_plus/share_plus/lib/share_plus.dart | 3 ++ .../lib/src}/share_plus_linux.dart | 14 +++--- .../lib/src}/share_plus_macos.dart | 0 .../lib/src}/share_plus_web.dart | 12 ++--- .../lib/src}/share_plus_windows.dart | 16 +++---- .../lib/src/windows_version_helper.dart} | 0 .../macos/Classes/SharePlusMacosPlugin.swift | 0 .../share_plus/macos/share_plus.podspec | 1 + packages/share_plus/share_plus/pubspec.yaml | 21 +++++---- .../test/share_plus_linux_test.dart | 14 +++--- .../test/share_plus_windows_test.dart | 22 ++++----- .../windows/.gitignore | 0 .../windows/CMakeLists.txt | 0 .../share_plus_windows_plugin_c_api.h | 0 .../windows/share_plus_windows_plugin.cpp | 0 .../windows/share_plus_windows_plugin.h | 0 .../share_plus_windows_plugin_c_api.cpp | 0 .../windows/vector.h | 0 .../share_plus/share_plus_linux/.gitignore | 47 ------------------- .../share_plus/share_plus_linux/.metadata | 10 ---- .../share_plus/share_plus_linux/CHANGELOG.md | 35 -------------- packages/share_plus/share_plus_linux/LICENSE | 21 --------- .../share_plus/share_plus_linux/README.md | 12 ----- .../share_plus/share_plus_linux/pubspec.yaml | 32 ------------- .../share_plus/share_plus_macos/.gitignore | 7 --- .../share_plus/share_plus_macos/.metadata | 10 ---- .../share_plus/share_plus_macos/CHANGELOG.md | 20 -------- packages/share_plus/share_plus_macos/LICENSE | 27 ----------- .../share_plus/share_plus_macos/README.md | 12 ----- .../macos/share_plus_macos.podspec | 22 --------- .../share_plus/share_plus_macos/pubspec.yaml | 25 ---------- .../share_plus/share_plus_web/CHANGELOG.md | 39 --------------- packages/share_plus/share_plus_web/LICENSE | 27 ----------- packages/share_plus/share_plus_web/README.md | 12 ----- .../share_plus/share_plus_web/pubspec.yaml | 32 ------------- 37 files changed, 66 insertions(+), 473 deletions(-) rename packages/share_plus/{share_plus_linux/lib => share_plus/lib/src}/share_plus_linux.dart (85%) rename packages/share_plus/{share_plus_macos/lib => share_plus/lib/src}/share_plus_macos.dart (100%) rename packages/share_plus/{share_plus_web/lib => share_plus/lib/src}/share_plus_web.dart (90%) rename packages/share_plus/{share_plus_windows/lib => share_plus/lib/src}/share_plus_windows.dart (85%) rename packages/share_plus/{share_plus_windows/lib/src/version_helper.dart => share_plus/lib/src/windows_version_helper.dart} (100%) rename packages/share_plus/{share_plus_macos => share_plus}/macos/Classes/SharePlusMacosPlugin.swift (100%) rename packages/share_plus/{share_plus_linux => share_plus}/test/share_plus_linux_test.dart (81%) rename packages/share_plus/{share_plus_windows => share_plus}/test/share_plus_windows_test.dart (81%) rename packages/share_plus/{share_plus_windows => share_plus}/windows/.gitignore (100%) rename packages/share_plus/{share_plus_windows => share_plus}/windows/CMakeLists.txt (100%) rename packages/share_plus/{share_plus_windows => share_plus}/windows/include/share_plus_windows/share_plus_windows_plugin_c_api.h (100%) rename packages/share_plus/{share_plus_windows => share_plus}/windows/share_plus_windows_plugin.cpp (100%) rename packages/share_plus/{share_plus_windows => share_plus}/windows/share_plus_windows_plugin.h (100%) rename packages/share_plus/{share_plus_windows => share_plus}/windows/share_plus_windows_plugin_c_api.cpp (100%) rename packages/share_plus/{share_plus_windows => share_plus}/windows/vector.h (100%) delete mode 100644 packages/share_plus/share_plus_linux/.gitignore delete mode 100644 packages/share_plus/share_plus_linux/.metadata delete mode 100644 packages/share_plus/share_plus_linux/CHANGELOG.md delete mode 100644 packages/share_plus/share_plus_linux/LICENSE delete mode 100644 packages/share_plus/share_plus_linux/README.md delete mode 100644 packages/share_plus/share_plus_linux/pubspec.yaml delete mode 100644 packages/share_plus/share_plus_macos/.gitignore delete mode 100644 packages/share_plus/share_plus_macos/.metadata delete mode 100644 packages/share_plus/share_plus_macos/CHANGELOG.md delete mode 100644 packages/share_plus/share_plus_macos/LICENSE delete mode 100644 packages/share_plus/share_plus_macos/README.md delete mode 100644 packages/share_plus/share_plus_macos/macos/share_plus_macos.podspec delete mode 100644 packages/share_plus/share_plus_macos/pubspec.yaml delete mode 100644 packages/share_plus/share_plus_web/CHANGELOG.md delete mode 100644 packages/share_plus/share_plus_web/LICENSE delete mode 100644 packages/share_plus/share_plus_web/README.md delete mode 100644 packages/share_plus/share_plus_web/pubspec.yaml diff --git a/packages/share_plus/share_plus/example/lib/main.dart b/packages/share_plus/share_plus/example/lib/main.dart index 3972e617e1..b226596556 100644 --- a/packages/share_plus/share_plus/example/lib/main.dart +++ b/packages/share_plus/share_plus/example/lib/main.dart @@ -5,10 +5,11 @@ // ignore_for_file: public_member_api_docs import 'dart:io'; + import 'package:file_selector/file_selector.dart'; import 'package:flutter/material.dart'; -import 'package:share_plus/share_plus.dart'; import 'package:image_picker/image_picker.dart'; +import 'package:share_plus/share_plus.dart'; import 'image_previews.dart'; @@ -70,16 +71,13 @@ class DemoAppState extends State { title: const Text('Add image'), onTap: () async { // Using `package:image_picker` to get image from gallery. - if (Platform.isMacOS || - Platform.isLinux || - Platform.isWindows) { + if (Platform.isMacOS || Platform.isLinux || Platform.isWindows) { // Using `package:file_selector` on windows, macos & Linux, since `package:image_picker` is not supported. const XTypeGroup typeGroup = XTypeGroup( label: 'images', extensions: ['jpg', 'jpeg', 'png', 'gif'], ); - final file = await openFile( - acceptedTypeGroups: [typeGroup]); + final file = await openFile(acceptedTypeGroups: [typeGroup]); if (file != null) { setState(() { imagePaths.add(file.path); @@ -104,9 +102,7 @@ class DemoAppState extends State { Builder( builder: (BuildContext context) { return ElevatedButton( - onPressed: text.isEmpty && imagePaths.isEmpty - ? null - : () => _onShare(context), + onPressed: text.isEmpty && imagePaths.isEmpty ? null : () => _onShare(context), child: const Text('Share'), ); }, @@ -115,9 +111,7 @@ class DemoAppState extends State { Builder( builder: (BuildContext context) { return ElevatedButton( - onPressed: text.isEmpty && imagePaths.isEmpty - ? null - : () => _onShareWithResult(context), + onPressed: text.isEmpty && imagePaths.isEmpty ? null : () => _onShareWithResult(context), child: const Text('Share With Result'), ); }, @@ -152,18 +146,15 @@ class DemoAppState extends State { files.add(XFile(imagePaths[i], name: imageNames[i])); } await Share.shareXFiles(files, - text: text, - subject: subject, - sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size); + text: text, subject: subject, sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size); } else { - await Share.share(text, - subject: subject, - sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size); + await Share.share(text, subject: subject, sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size); } } void _onShareWithResult(BuildContext context) async { final box = context.findRenderObject() as RenderBox?; + final scaffoldMessenger = ScaffoldMessenger.of(context); ShareResult result; if (imagePaths.isNotEmpty) { final files = []; @@ -171,15 +162,12 @@ class DemoAppState extends State { files.add(XFile(imagePaths[i], name: imageNames[i])); } result = await Share.shareXFiles(files, - text: text, - subject: subject, - sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size); + text: text, subject: subject, sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size); } else { result = await Share.shareWithResult(text, - subject: subject, - sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size); + subject: subject, sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size); } - ScaffoldMessenger.of(context).showSnackBar(SnackBar( + scaffoldMessenger.showSnackBar(SnackBar( content: Text("Share result: ${result.status}"), )); } diff --git a/packages/share_plus/share_plus/example/pubspec.yaml b/packages/share_plus/share_plus/example/pubspec.yaml index 39d97cf1b2..4d029287dc 100644 --- a/packages/share_plus/share_plus/example/pubspec.yaml +++ b/packages/share_plus/share_plus/example/pubspec.yaml @@ -10,20 +10,14 @@ dependencies: file_selector: ^0.9.2+1 dependency_overrides: - share_plus_linux: - path: ../../share_plus_linux - share_plus_macos: - path: ../../share_plus_macos share_plus_platform_interface: path: ../../share_plus_platform_interface - share_plus_web: - path: ../../share_plus_web - share_plus_windows: - path: ../../share_plus_windows dev_dependencies: flutter_driver: sdk: flutter + flutter_test: + sdk: flutter integration_test: sdk: flutter flutter_lints: ^2.0.1 diff --git a/packages/share_plus/share_plus/lib/share_plus.dart b/packages/share_plus/share_plus/lib/share_plus.dart index 754888ad91..ac8266ab4c 100644 --- a/packages/share_plus/share_plus/lib/share_plus.dart +++ b/packages/share_plus/share_plus/lib/share_plus.dart @@ -11,6 +11,9 @@ import 'package:share_plus_platform_interface/share_plus_platform_interface.dart export 'package:share_plus_platform_interface/share_plus_platform_interface.dart' show ShareResult, ShareResultStatus; +export 'src/share_plus_linux.dart'; +export 'src/share_plus_web.dart'; + /// Plugin for summoning a platform share sheet. class Share { static SharePlatform get _platform => SharePlatform.instance; diff --git a/packages/share_plus/share_plus_linux/lib/share_plus_linux.dart b/packages/share_plus/share_plus/lib/src/share_plus_linux.dart similarity index 85% rename from packages/share_plus/share_plus_linux/lib/share_plus_linux.dart rename to packages/share_plus/share_plus/lib/src/share_plus_linux.dart index 9a3c4daac6..a51f08a39a 100644 --- a/packages/share_plus/share_plus_linux/lib/share_plus_linux.dart +++ b/packages/share_plus/share_plus/lib/src/share_plus_linux.dart @@ -2,16 +2,16 @@ library share_plus_linux; import 'dart:ui'; -import 'package:cross_file/cross_file.dart'; -import 'package:url_launcher/url_launcher.dart'; +import 'package:cross_file/cross_file.dart'; import 'package:share_plus_platform_interface/share_plus_platform_interface.dart'; +import 'package:url_launcher/url_launcher.dart'; /// The Linux implementation of SharePlatform. -class ShareLinux extends SharePlatform { +class SharePlusLinuxPlugin extends SharePlatform { /// Register this dart class as the platform implementation for linux static void registerWith() { - SharePlatform.instance = ShareLinux(); + SharePlatform.instance = SharePlusLinuxPlugin(); } /// Share text. @@ -30,10 +30,8 @@ class ShareLinux extends SharePlatform { // see https://github.com/dart-lang/sdk/issues/43838#issuecomment-823551891 final uri = Uri( scheme: 'mailto', - query: queryParameters.entries - .map((e) => - '${Uri.encodeComponent(e.key)}=${Uri.encodeComponent(e.value)}') - .join('&'), + query: + queryParameters.entries.map((e) => '${Uri.encodeComponent(e.key)}=${Uri.encodeComponent(e.value)}').join('&'), ); await launchUrl(uri); diff --git a/packages/share_plus/share_plus_macos/lib/share_plus_macos.dart b/packages/share_plus/share_plus/lib/src/share_plus_macos.dart similarity index 100% rename from packages/share_plus/share_plus_macos/lib/share_plus_macos.dart rename to packages/share_plus/share_plus/lib/src/share_plus_macos.dart diff --git a/packages/share_plus/share_plus_web/lib/share_plus_web.dart b/packages/share_plus/share_plus/lib/src/share_plus_web.dart similarity index 90% rename from packages/share_plus/share_plus_web/lib/share_plus_web.dart rename to packages/share_plus/share_plus/lib/src/share_plus_web.dart index afb301b6f0..552efe6a4b 100644 --- a/packages/share_plus/share_plus_web/lib/share_plus_web.dart +++ b/packages/share_plus/share_plus/lib/src/share_plus_web.dart @@ -9,16 +9,16 @@ import 'package:share_plus_platform_interface/share_plus_platform_interface.dart import 'package:url_launcher/url_launcher.dart'; /// The web implementation of [SharePlatform]. -class SharePlusPlugin extends SharePlatform { +class SharePlusWebPlugin extends SharePlatform { /// Registers this class as the default instance of [SharePlatform]. static void registerWith(Registrar registrar) { - SharePlatform.instance = SharePlusPlugin(); + SharePlatform.instance = SharePlusWebPlugin(); } final html.Navigator _navigator; /// A constructor that allows tests to override the window object used by the plugin. - SharePlusPlugin({@visibleForTesting html.Navigator? debugNavigator}) + SharePlusWebPlugin({@visibleForTesting html.Navigator? debugNavigator}) : _navigator = debugNavigator ?? html.window.navigator; /// Share text @@ -41,8 +41,7 @@ class SharePlusPlugin extends SharePlatform { final uri = Uri( scheme: 'mailto', query: queryParameters.entries - .map((e) => - '${Uri.encodeComponent(e.key)}=${Uri.encodeComponent(e.value)}') + .map((e) => '${Uri.encodeComponent(e.key)}=${Uri.encodeComponent(e.value)}') .join('&'), ); @@ -117,8 +116,7 @@ class SharePlusPlugin extends SharePlatform { } static String _mimeTypeForPath(XFile file, Uint8List bytes) { - return lookupMimeType(file.name, headerBytes: bytes) ?? - 'application/octet-stream'; + return lookupMimeType(file.name, headerBytes: bytes) ?? 'application/octet-stream'; } } diff --git a/packages/share_plus/share_plus_windows/lib/share_plus_windows.dart b/packages/share_plus/share_plus/lib/src/share_plus_windows.dart similarity index 85% rename from packages/share_plus/share_plus_windows/lib/share_plus_windows.dart rename to packages/share_plus/share_plus/lib/src/share_plus_windows.dart index f4b857fa69..166dc0f4e3 100644 --- a/packages/share_plus/share_plus_windows/lib/share_plus_windows.dart +++ b/packages/share_plus/share_plus/lib/src/share_plus_windows.dart @@ -2,20 +2,20 @@ library share_plus_windows; import 'dart:ui'; -import 'package:cross_file/cross_file.dart'; -import 'package:url_launcher/url_launcher.dart'; -import 'package:share_plus_windows/src/version_helper.dart'; +import 'package:cross_file/cross_file.dart'; +import 'package:share_plus/src/windows_version_helper.dart'; import 'package:share_plus_platform_interface/share_plus_platform_interface.dart'; +import 'package:url_launcher/url_launcher.dart'; /// The fallback Windows implementation of [SharePlatform], for older Windows versions. /// -class ShareWindows extends SharePlatform { +class SharePlusWindowsPlugin extends SharePlatform { /// If the modern Share UI i.e. `DataTransferManager` is not available, then use this Dart class instead of platform specific implementation. /// static void registerWith() { if (!VersionHelper.instance.isWindows10RS5OrGreater) { - SharePlatform.instance = ShareWindows(); + SharePlatform.instance = SharePlusWindowsPlugin(); } } @@ -34,10 +34,8 @@ class ShareWindows extends SharePlatform { // see https://github.com/dart-lang/sdk/issues/43838#issuecomment-823551891 final uri = Uri( scheme: 'mailto', - query: queryParameters.entries - .map((e) => - '${Uri.encodeComponent(e.key)}=${Uri.encodeComponent(e.value)}') - .join('&'), + query: + queryParameters.entries.map((e) => '${Uri.encodeComponent(e.key)}=${Uri.encodeComponent(e.value)}').join('&'), ); if (await canLaunchUrl(uri)) { diff --git a/packages/share_plus/share_plus_windows/lib/src/version_helper.dart b/packages/share_plus/share_plus/lib/src/windows_version_helper.dart similarity index 100% rename from packages/share_plus/share_plus_windows/lib/src/version_helper.dart rename to packages/share_plus/share_plus/lib/src/windows_version_helper.dart diff --git a/packages/share_plus/share_plus_macos/macos/Classes/SharePlusMacosPlugin.swift b/packages/share_plus/share_plus/macos/Classes/SharePlusMacosPlugin.swift similarity index 100% rename from packages/share_plus/share_plus_macos/macos/Classes/SharePlusMacosPlugin.swift rename to packages/share_plus/share_plus/macos/Classes/SharePlusMacosPlugin.swift diff --git a/packages/share_plus/share_plus/macos/share_plus.podspec b/packages/share_plus/share_plus/macos/share_plus.podspec index 92827e005c..af109e9dfb 100644 --- a/packages/share_plus/share_plus/macos/share_plus.podspec +++ b/packages/share_plus/share_plus/macos/share_plus.podspec @@ -15,6 +15,7 @@ https://github.com/flutter/flutter/issues/46618 s.source = { :path => '.' } s.source_files = 'Classes/**/*' s.public_header_files = 'Classes/**/*.h' + s.dependency 'FlutterMacOS' s.platform = :osx s.osx.deployment_target = '10.11' diff --git a/packages/share_plus/share_plus/pubspec.yaml b/packages/share_plus/share_plus/pubspec.yaml index 2163a41386..1a6ec1c76f 100644 --- a/packages/share_plus/share_plus/pubspec.yaml +++ b/packages/share_plus/share_plus/pubspec.yaml @@ -14,13 +14,15 @@ flutter: ios: pluginClass: FLTSharePlusPlugin linux: - default_package: share_plus_linux + dartPluginClass: SharePlusLinuxPlugin macos: - default_package: share_plus_macos + pluginClass: SharePlusMacosPlugin web: - default_package: share_plus_web + pluginClass: SharePlusWebPlugin + fileName: share_plus_web.dart windows: - default_package: share_plus_windows + dartPluginClass: SharePlusWindowsPlugin + pluginClass: SharePlusWindowsPluginCApi dependencies: cross_file: ^0.3.3+2 @@ -28,16 +30,19 @@ dependencies: mime: ^1.0.2 flutter: sdk: flutter + flutter_web_plugins: + sdk: flutter share_plus_platform_interface: ^3.1.1 - share_plus_linux: ^3.0.1 - share_plus_macos: ^3.0.1 - share_plus_windows: ^4.0.0 - share_plus_web: ^3.1.0 + file: ^6.0.0 + url_launcher: ^6.1.2 + ffi: ^2.0.1 + win32: ^3.0.0 dev_dependencies: flutter_test: sdk: flutter flutter_lints: ^2.0.1 + url_launcher_platform_interface: ^2.0.2 environment: sdk: ">=2.12.0 <3.0.0" diff --git a/packages/share_plus/share_plus_linux/test/share_plus_linux_test.dart b/packages/share_plus/share_plus/test/share_plus_linux_test.dart similarity index 81% rename from packages/share_plus/share_plus_linux/test/share_plus_linux_test.dart rename to packages/share_plus/share_plus/test/share_plus_linux_test.dart index 1b990673ed..71024f6c02 100644 --- a/packages/share_plus/share_plus_linux/test/share_plus_linux_test.dart +++ b/packages/share_plus/share_plus/test/share_plus_linux_test.dart @@ -1,19 +1,19 @@ import 'package:flutter_test/flutter_test.dart'; -import 'package:share_plus_linux/share_plus_linux.dart'; +import 'package:share_plus/share_plus.dart'; import 'package:share_plus_platform_interface/share_plus_platform_interface.dart'; -import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart'; import 'package:url_launcher_platform_interface/link.dart'; +import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart'; void main() { test('registered instance', () { - ShareLinux.registerWith(); - expect(SharePlatform.instance, isA()); + SharePlusLinuxPlugin.registerWith(); + expect(SharePlatform.instance, isA()); }); test('url encoding is correct for &', () async { final mock = MockUrlLauncherPlatform(); UrlLauncherPlatform.instance = mock; - await ShareLinux().share('foo&bar', subject: 'bar&foo'); + await SharePlusLinuxPlugin().share('foo&bar', subject: 'bar&foo'); expect(mock.url, 'mailto:?subject=bar%26foo&body=foo%26bar'); }); @@ -23,7 +23,7 @@ void main() { final mock = MockUrlLauncherPlatform(); UrlLauncherPlatform.instance = mock; - await ShareLinux().share('foo bar', subject: 'bar foo'); + await SharePlusLinuxPlugin().share('foo bar', subject: 'bar foo'); expect(mock.url, 'mailto:?subject=bar%20foo&body=foo%20bar'); }); @@ -33,7 +33,7 @@ void main() { mock.canLaunchMockValue = false; UrlLauncherPlatform.instance = mock; - expect(() async => await ShareLinux().share('foo bar'), throwsException); + expect(() async => await SharePlusLinuxPlugin().share('foo bar'), throwsException); }); } diff --git a/packages/share_plus/share_plus_windows/test/share_plus_windows_test.dart b/packages/share_plus/share_plus/test/share_plus_windows_test.dart similarity index 81% rename from packages/share_plus/share_plus_windows/test/share_plus_windows_test.dart rename to packages/share_plus/share_plus/test/share_plus_windows_test.dart index fffa7c93e4..eb07377b1a 100644 --- a/packages/share_plus/share_plus_windows/test/share_plus_windows_test.dart +++ b/packages/share_plus/share_plus/test/share_plus_windows_test.dart @@ -1,18 +1,17 @@ import 'package:flutter_test/flutter_test.dart'; -import 'package:share_plus_windows/share_plus_windows.dart'; -import 'package:share_plus_windows/src/version_helper.dart'; -import 'package:share_plus_platform_interface/share_plus_platform_interface.dart'; +import 'package:share_plus/src/share_plus_windows.dart'; +import 'package:share_plus/src/windows_version_helper.dart'; import 'package:share_plus_platform_interface/method_channel/method_channel_share.dart'; - -import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart'; +import 'package:share_plus_platform_interface/share_plus_platform_interface.dart'; import 'package:url_launcher_platform_interface/link.dart'; +import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart'; void main() { test( 'registered instance', () { - ShareWindows.registerWith(); - expect(SharePlatform.instance, isA()); + SharePlusWindowsPlugin.registerWith(); + expect(SharePlatform.instance, isA()); }, skip: VersionHelper.instance.isWindows10RS5OrGreater, ); @@ -20,7 +19,7 @@ void main() { test( 'registered instance', () { - ShareWindows.registerWith(); + SharePlusWindowsPlugin.registerWith(); expect(SharePlatform.instance, isA()); }, skip: !VersionHelper.instance.isWindows10RS5OrGreater, @@ -34,7 +33,7 @@ void main() { final mock = MockUrlLauncherPlatform(); UrlLauncherPlatform.instance = mock; - await ShareWindows().share('foo&bar', subject: 'bar&foo'); + await SharePlusWindowsPlugin().share('foo&bar', subject: 'bar&foo'); expect(mock.url, 'mailto:?subject=bar%26foo&body=foo%26bar'); }, @@ -48,7 +47,7 @@ void main() { final mock = MockUrlLauncherPlatform(); UrlLauncherPlatform.instance = mock; - await ShareWindows().share('foo bar', subject: 'bar foo'); + await SharePlusWindowsPlugin().share('foo bar', subject: 'bar foo'); expect(mock.url, 'mailto:?subject=bar%20foo&body=foo%20bar'); }, @@ -62,8 +61,7 @@ void main() { mock.canLaunchMockValue = false; UrlLauncherPlatform.instance = mock; - expect( - () async => await ShareWindows().share('foo bar'), throwsException); + expect(() async => await SharePlusWindowsPlugin().share('foo bar'), throwsException); }, skip: VersionHelper.instance.isWindows10RS5OrGreater, ); diff --git a/packages/share_plus/share_plus_windows/windows/.gitignore b/packages/share_plus/share_plus/windows/.gitignore similarity index 100% rename from packages/share_plus/share_plus_windows/windows/.gitignore rename to packages/share_plus/share_plus/windows/.gitignore diff --git a/packages/share_plus/share_plus_windows/windows/CMakeLists.txt b/packages/share_plus/share_plus/windows/CMakeLists.txt similarity index 100% rename from packages/share_plus/share_plus_windows/windows/CMakeLists.txt rename to packages/share_plus/share_plus/windows/CMakeLists.txt diff --git a/packages/share_plus/share_plus_windows/windows/include/share_plus_windows/share_plus_windows_plugin_c_api.h b/packages/share_plus/share_plus/windows/include/share_plus_windows/share_plus_windows_plugin_c_api.h similarity index 100% rename from packages/share_plus/share_plus_windows/windows/include/share_plus_windows/share_plus_windows_plugin_c_api.h rename to packages/share_plus/share_plus/windows/include/share_plus_windows/share_plus_windows_plugin_c_api.h diff --git a/packages/share_plus/share_plus_windows/windows/share_plus_windows_plugin.cpp b/packages/share_plus/share_plus/windows/share_plus_windows_plugin.cpp similarity index 100% rename from packages/share_plus/share_plus_windows/windows/share_plus_windows_plugin.cpp rename to packages/share_plus/share_plus/windows/share_plus_windows_plugin.cpp diff --git a/packages/share_plus/share_plus_windows/windows/share_plus_windows_plugin.h b/packages/share_plus/share_plus/windows/share_plus_windows_plugin.h similarity index 100% rename from packages/share_plus/share_plus_windows/windows/share_plus_windows_plugin.h rename to packages/share_plus/share_plus/windows/share_plus_windows_plugin.h diff --git a/packages/share_plus/share_plus_windows/windows/share_plus_windows_plugin_c_api.cpp b/packages/share_plus/share_plus/windows/share_plus_windows_plugin_c_api.cpp similarity index 100% rename from packages/share_plus/share_plus_windows/windows/share_plus_windows_plugin_c_api.cpp rename to packages/share_plus/share_plus/windows/share_plus_windows_plugin_c_api.cpp diff --git a/packages/share_plus/share_plus_windows/windows/vector.h b/packages/share_plus/share_plus/windows/vector.h similarity index 100% rename from packages/share_plus/share_plus_windows/windows/vector.h rename to packages/share_plus/share_plus/windows/vector.h diff --git a/packages/share_plus/share_plus_linux/.gitignore b/packages/share_plus/share_plus_linux/.gitignore deleted file mode 100644 index 88ce490e47..0000000000 --- a/packages/share_plus/share_plus_linux/.gitignore +++ /dev/null @@ -1,47 +0,0 @@ -.DS_Store -.atom/ -.idea/ -.vscode/ - -.packages -.pub/ -.dart_tool/ -pubspec.lock -flutter_export_environment.sh - -examples/all_plugins/pubspec.yaml - -Podfile -Podfile.lock -Pods/ -.symlinks/ -**/Flutter/App.framework/ -**/Flutter/ephemeral/ -**/Flutter/Flutter.framework/ -**/Flutter/Generated.xcconfig -**/Flutter/flutter_assets/ - -ServiceDefinitions.json -xcuserdata/ -**/DerivedData/ - -local.properties -keystore.properties -.gradle/ -gradlew -gradlew.bat -gradle-wrapper.jar -.flutter-plugins-dependencies -*.iml - -generated_plugin_registrant.dart -GeneratedPluginRegistrant.h -GeneratedPluginRegistrant.m -GeneratedPluginRegistrant.java -GeneratedPluginRegistrant.swift -build/ -.flutter-plugins - -.project -.classpath -.settings diff --git a/packages/share_plus/share_plus_linux/.metadata b/packages/share_plus/share_plus_linux/.metadata deleted file mode 100644 index c05ad03edc..0000000000 --- a/packages/share_plus/share_plus_linux/.metadata +++ /dev/null @@ -1,10 +0,0 @@ -# This file tracks properties of this Flutter project. -# Used by Flutter tool to assess capabilities and perform upgrades etc. -# -# This file should be version controlled and should not be manually edited. - -version: - revision: 9d7bdb5903bc7149b415bf268fa3c6413355e7ad - channel: master - -project_type: package diff --git a/packages/share_plus/share_plus_linux/CHANGELOG.md b/packages/share_plus/share_plus_linux/CHANGELOG.md deleted file mode 100644 index b290bcece5..0000000000 --- a/packages/share_plus/share_plus_linux/CHANGELOG.md +++ /dev/null @@ -1,35 +0,0 @@ -## 3.0.1 - - - **FIX**: Share.shareXFiles resulting in stack-overflow on Windows & Linux (#1186). - -## 3.0.0 - -- Version bump - -## 2.0.4 - -- Fixes: sharing in isolated sandboxes like Flatpak - -## 2.0.3 - -- Hotfix on 2.0.2, improved solution. - -## 2.0.2 - -- Fixes: share URL is constructed incorrectly #235 - -## 2.0.1 - -- Improve documentation - -## 2.0.0 - -- Migrated to null safety - -## 1.1.0 - -- Transfer to plus-plugins monorepo - -## 1.0.0 - -- Initial Linux support. diff --git a/packages/share_plus/share_plus_linux/LICENSE b/packages/share_plus/share_plus_linux/LICENSE deleted file mode 100644 index 484084f72d..0000000000 --- a/packages/share_plus/share_plus_linux/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2020 The Flutter Community Plus Plugin Authors - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/packages/share_plus/share_plus_linux/README.md b/packages/share_plus/share_plus_linux/README.md deleted file mode 100644 index ec7a901ef6..0000000000 --- a/packages/share_plus/share_plus_linux/README.md +++ /dev/null @@ -1,12 +0,0 @@ -# Share Plus Linux - -[![Flutter Community: share_plus_linux](https://fluttercommunity.dev/_github/header/share_plus_linux)](https://github.com/fluttercommunity/community) - -[![pub package](https://img.shields.io/pub/v/share_plus_linux.svg)](https://pub.dev/packages/share_plus_linux) - -The Linux implementation of [`share_plus`](https://pub.dev/packages/share_plus). - -## Usage - -This package is already included as part of the `share_plus` package dependency, and will -be included when using `share_plus` as normal. diff --git a/packages/share_plus/share_plus_linux/pubspec.yaml b/packages/share_plus/share_plus_linux/pubspec.yaml deleted file mode 100644 index 2f7d043889..0000000000 --- a/packages/share_plus/share_plus_linux/pubspec.yaml +++ /dev/null @@ -1,32 +0,0 @@ -name: share_plus_linux -description: Linux implementation of the share_plus plugin -version: 3.0.1 -homepage: https://plus.fluttercommunity.dev/ -repository: https://github.com/fluttercommunity/plus_plugins/tree/main/packages/ - -environment: - sdk: ">=2.12.0 <3.0.0" - flutter: ">=1.20.0" - -dependencies: - cross_file: ^0.3.3+2 - share_plus_platform_interface: ^3.0.2 - file: ^6.0.0 - flutter: - sdk: flutter - meta: ^1.3.0 - url_launcher: ^6.1.2 - -dev_dependencies: - flutter_test: - sdk: flutter - flutter_lints: ^2.0.1 - url_launcher_platform_interface: ^2.0.2 - -flutter: - plugin: - implements: share_plus - platforms: - linux: - dartPluginClass: ShareLinux - pluginClass: none diff --git a/packages/share_plus/share_plus_macos/.gitignore b/packages/share_plus/share_plus_macos/.gitignore deleted file mode 100644 index e9dc58d3d6..0000000000 --- a/packages/share_plus/share_plus_macos/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -.DS_Store -.dart_tool/ - -.packages -.pub/ - -build/ diff --git a/packages/share_plus/share_plus_macos/.metadata b/packages/share_plus/share_plus_macos/.metadata deleted file mode 100644 index d3466449fc..0000000000 --- a/packages/share_plus/share_plus_macos/.metadata +++ /dev/null @@ -1,10 +0,0 @@ -# This file tracks properties of this Flutter project. -# Used by Flutter tool to assess capabilities and perform upgrades etc. -# -# This file should be version controlled and should not be manually edited. - -version: - revision: 79b49b9e1057f90ebf797725233c6b311722de69 - channel: beta - -project_type: plugin diff --git a/packages/share_plus/share_plus_macos/CHANGELOG.md b/packages/share_plus/share_plus_macos/CHANGELOG.md deleted file mode 100644 index 4fdba95b01..0000000000 --- a/packages/share_plus/share_plus_macos/CHANGELOG.md +++ /dev/null @@ -1,20 +0,0 @@ -## 3.0.1 - -- Update lints -- Fix analyzer warnings - -## 3.0.0 - -- Add *WithResult methods to get feedback on user action - -## 2.0.2 - -- Obtain Flutter view from the registrar - -## 2.0.1 - -- Improve documentation - -## 2.0.0 - -- Initial null-safe macOS support diff --git a/packages/share_plus/share_plus_macos/LICENSE b/packages/share_plus/share_plus_macos/LICENSE deleted file mode 100644 index 176a661f7e..0000000000 --- a/packages/share_plus/share_plus_macos/LICENSE +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2017, the Flutter project authors. All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/packages/share_plus/share_plus_macos/README.md b/packages/share_plus/share_plus_macos/README.md deleted file mode 100644 index 7ec7b77e2b..0000000000 --- a/packages/share_plus/share_plus_macos/README.md +++ /dev/null @@ -1,12 +0,0 @@ -# Share Plus macOS - -[![Flutter Community: share_plus_macos](https://fluttercommunity.dev/_github/header/share_plus_macos)](https://github.com/fluttercommunity/community) - -[![pub package](https://img.shields.io/pub/v/share_plus_macos.svg)](https://pub.dev/packages/share_plus_macos) - -The macOS implementation of [`share_plus`](https://pub.dev/packages/share_plus). - -## Usage - -This package is already included as part of the `share_plus` package dependency, and will -be included when using `share_plus` as normal. diff --git a/packages/share_plus/share_plus_macos/macos/share_plus_macos.podspec b/packages/share_plus/share_plus_macos/macos/share_plus_macos.podspec deleted file mode 100644 index 126418706f..0000000000 --- a/packages/share_plus/share_plus_macos/macos/share_plus_macos.podspec +++ /dev/null @@ -1,22 +0,0 @@ -# -# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html. -# Run `pod lib lint share_plus_macos.podspec` to validate before publishing. -# -Pod::Spec.new do |s| - s.name = 'share_plus_macos' - s.version = '0.0.1' - s.summary = 'Share Plus for macOS' - s.description = <<-DESC -A Flutter plugin for sharing text and files. - DESC - s.homepage = 'https://github.com/fluttercommunity/plus_plugins/tree/main/packages/share_plus_macos' - s.license = { :file => '../LICENSE' } - s.author = { 'Flutter Community' => 'authors@fluttercommunity.dev' } - s.source = { :path => 'https://github.com/fluttercommunity/plus_plugins/tree/main/packages/share_plus_macos' } - s.source_files = 'Classes/**/*' - s.dependency 'FlutterMacOS' - - s.platform = :osx, '10.11' - s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' } - s.swift_version = '5.0' -end diff --git a/packages/share_plus/share_plus_macos/pubspec.yaml b/packages/share_plus/share_plus_macos/pubspec.yaml deleted file mode 100644 index 6fcfe981b5..0000000000 --- a/packages/share_plus/share_plus_macos/pubspec.yaml +++ /dev/null @@ -1,25 +0,0 @@ -name: share_plus_macos -description: MacOS implementation of the share_plus plugin -version: 3.0.1 -homepage: https://plus.fluttercommunity.dev/ -repository: https://github.com/fluttercommunity/plus_plugins/tree/main/packages/ - -environment: - sdk: ">=2.12.0 <3.0.0" - flutter: ">=1.20.0" - -dependencies: - share_plus_platform_interface: ^3.0.2 - flutter: - sdk: flutter - -dev_dependencies: - flutter_test: - sdk: flutter - flutter_lints: ^2.0.1 - -flutter: - plugin: - platforms: - macos: - pluginClass: SharePlusMacosPlugin diff --git a/packages/share_plus/share_plus_web/CHANGELOG.md b/packages/share_plus/share_plus_web/CHANGELOG.md deleted file mode 100644 index cc7dfbb07b..0000000000 --- a/packages/share_plus/share_plus_web/CHANGELOG.md +++ /dev/null @@ -1,39 +0,0 @@ -## 3.1.0 - -- Add `shareXFiles` implementations -- Deprecate `shareFiles*` implementations -- Enable `shareXFiles` implementations on Web - -## 3.0.1 - -- Update dependencies -- Fix analyzer warnings -- Update `urlLauncher` and replace deprecated `launch` calls - -## 3.0.0 - -- Bump dependencies - -## 2.0.4 - -- Hotfix on 2.0.3, improved solution. - -## 2.0.3 - -- Fix #235: share URL is constructed incorrectly - -## 2.0.2 - -- Fix #201: avoid call to "tomail:" when canceling "Share" - -## 2.0.1 - -- Improve documentation - -## 2.0.0 - -- Migrated to null safety - -## 0.1.0 - -- Initial open-source release. diff --git a/packages/share_plus/share_plus_web/LICENSE b/packages/share_plus/share_plus_web/LICENSE deleted file mode 100644 index c89293372c..0000000000 --- a/packages/share_plus/share_plus_web/LICENSE +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/packages/share_plus/share_plus_web/README.md b/packages/share_plus/share_plus_web/README.md deleted file mode 100644 index acfaba99b8..0000000000 --- a/packages/share_plus/share_plus_web/README.md +++ /dev/null @@ -1,12 +0,0 @@ -# Share Plus Web - -[![Flutter Community: share_plus_web](https://fluttercommunity.dev/_github/header/share_plus_web)](https://github.com/fluttercommunity/community) - -[![pub package](https://img.shields.io/pub/v/share_plus_web.svg)](https://pub.dev/packages/share_plus_web) - -The Web implementation of [`share_plus`](https://pub.dev/packages/share_plus). - -## Usage - -This package is already included as part of the `share_plus` package dependency, and will -be included when using `share_plus` as normal. diff --git a/packages/share_plus/share_plus_web/pubspec.yaml b/packages/share_plus/share_plus_web/pubspec.yaml deleted file mode 100644 index 133ad3c41c..0000000000 --- a/packages/share_plus/share_plus_web/pubspec.yaml +++ /dev/null @@ -1,32 +0,0 @@ -name: share_plus_web -description: Web platform implementation of share_plus -homepage: https://plus.fluttercommunity.dev/ -repository: https://github.com/fluttercommunity/plus_plugins/tree/main/packages/ -version: 3.1.0 - -flutter: - plugin: - platforms: - web: - pluginClass: SharePlusPlugin - fileName: share_plus_web.dart - -dependencies: - cross_file: ^0.3.3+2 - share_plus_platform_interface: ^3.0.2 - url_launcher: ^6.1.2 - flutter: - sdk: flutter - flutter_web_plugins: - sdk: flutter - meta: ^1.7.0 - mime: ^1.0.0 - -dev_dependencies: - flutter_test: - sdk: flutter - flutter_lints: ^2.0.1 - -environment: - sdk: ">=2.12.0 <3.0.0" - flutter: ">=1.20.0" From 758ac55f21c4a44faf109faa6f8bac39b04ef79b Mon Sep 17 00:00:00 2001 From: Joachim Nohl <43643339+nohli@users.noreply.github.com> Date: Thu, 13 Oct 2022 17:55:17 +0200 Subject: [PATCH 2/9] melos run format --- .../example/windows/runner/flutter_window.cpp | 8 +- .../example/windows/runner/flutter_window.h | 10 +- .../example/windows/runner/main.cpp | 3 +- .../example/windows/runner/resource.h | 10 +- .../example/windows/runner/utils.cpp | 13 +- .../example/windows/runner/utils.h | 4 +- .../example/windows/runner/win32_window.cpp | 110 +++++++------- .../example/windows/runner/win32_window.h | 21 ++- .../share_plus/example/lib/main.dart | 30 +++- .../share_plus/lib/src/share_plus_linux.dart | 6 +- .../share_plus/lib/src/share_plus_web.dart | 6 +- .../lib/src/share_plus_windows.dart | 6 +- .../test/share_plus_linux_test.dart | 3 +- .../test/share_plus_windows_test.dart | 3 +- .../share_plus_windows_plugin_c_api.h | 4 +- .../windows/share_plus_windows_plugin.cpp | 41 +++--- .../windows/share_plus_windows_plugin.h | 24 +-- .../share_plus/share_plus/windows/vector.h | 137 ++++++++---------- 18 files changed, 218 insertions(+), 221 deletions(-) diff --git a/packages/package_info_plus/package_info_plus/example/windows/runner/flutter_window.cpp b/packages/package_info_plus/package_info_plus/example/windows/runner/flutter_window.cpp index b43b9095ea..edfe54e14e 100644 --- a/packages/package_info_plus/package_info_plus/example/windows/runner/flutter_window.cpp +++ b/packages/package_info_plus/package_info_plus/example/windows/runner/flutter_window.cpp @@ -4,7 +4,7 @@ #include "flutter/generated_plugin_registrant.h" -FlutterWindow::FlutterWindow(const flutter::DartProject& project) +FlutterWindow::FlutterWindow(const flutter::DartProject &project) : project_(project) {} FlutterWindow::~FlutterWindow() {} @@ -52,9 +52,9 @@ FlutterWindow::MessageHandler(HWND hwnd, UINT const message, } switch (message) { - case WM_FONTCHANGE: - flutter_controller_->engine()->ReloadSystemFonts(); - break; + case WM_FONTCHANGE: + flutter_controller_->engine()->ReloadSystemFonts(); + break; } return Win32Window::MessageHandler(hwnd, message, wparam, lparam); diff --git a/packages/package_info_plus/package_info_plus/example/windows/runner/flutter_window.h b/packages/package_info_plus/package_info_plus/example/windows/runner/flutter_window.h index 6da0652f05..7fa026bf24 100644 --- a/packages/package_info_plus/package_info_plus/example/windows/runner/flutter_window.h +++ b/packages/package_info_plus/package_info_plus/example/windows/runner/flutter_window.h @@ -10,19 +10,19 @@ // A window that does nothing but host a Flutter view. class FlutterWindow : public Win32Window { - public: +public: // Creates a new FlutterWindow hosting a Flutter view running |project|. - explicit FlutterWindow(const flutter::DartProject& project); + explicit FlutterWindow(const flutter::DartProject &project); virtual ~FlutterWindow(); - protected: +protected: // Win32Window: bool OnCreate() override; void OnDestroy() override; LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept override; - private: +private: // The project to run. flutter::DartProject project_; @@ -30,4 +30,4 @@ class FlutterWindow : public Win32Window { std::unique_ptr flutter_controller_; }; -#endif // RUNNER_FLUTTER_WINDOW_H_ +#endif // RUNNER_FLUTTER_WINDOW_H_ diff --git a/packages/package_info_plus/package_info_plus/example/windows/runner/main.cpp b/packages/package_info_plus/package_info_plus/example/windows/runner/main.cpp index bcb57b0e2a..261f186935 100644 --- a/packages/package_info_plus/package_info_plus/example/windows/runner/main.cpp +++ b/packages/package_info_plus/package_info_plus/example/windows/runner/main.cpp @@ -19,8 +19,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, flutter::DartProject project(L"data"); - std::vector command_line_arguments = - GetCommandLineArguments(); + std::vector command_line_arguments = GetCommandLineArguments(); project.set_dart_entrypoint_arguments(std::move(command_line_arguments)); diff --git a/packages/package_info_plus/package_info_plus/example/windows/runner/resource.h b/packages/package_info_plus/package_info_plus/example/windows/runner/resource.h index 66a65d1e4a..d5d958dc42 100644 --- a/packages/package_info_plus/package_info_plus/example/windows/runner/resource.h +++ b/packages/package_info_plus/package_info_plus/example/windows/runner/resource.h @@ -2,15 +2,15 @@ // Microsoft Visual C++ generated include file. // Used by Runner.rc // -#define IDI_APP_ICON 101 +#define IDI_APP_ICON 101 // Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 102 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1001 -#define _APS_NEXT_SYMED_VALUE 101 +#define _APS_NEXT_RESOURCE_VALUE 102 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1001 +#define _APS_NEXT_SYMED_VALUE 101 #endif #endif diff --git a/packages/package_info_plus/package_info_plus/example/windows/runner/utils.cpp b/packages/package_info_plus/package_info_plus/example/windows/runner/utils.cpp index f5bf9fa0f5..739b61f203 100644 --- a/packages/package_info_plus/package_info_plus/example/windows/runner/utils.cpp +++ b/packages/package_info_plus/package_info_plus/example/windows/runner/utils.cpp @@ -24,7 +24,7 @@ void CreateAndAttachConsole() { std::vector GetCommandLineArguments() { // Convert the UTF-16 command line arguments to UTF-8 for the Engine to use. int argc; - wchar_t** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc); + wchar_t **argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc); if (argv == nullptr) { return std::vector(); } @@ -41,21 +41,20 @@ std::vector GetCommandLineArguments() { return command_line_arguments; } -std::string Utf8FromUtf16(const wchar_t* utf16_string) { +std::string Utf8FromUtf16(const wchar_t *utf16_string) { if (utf16_string == nullptr) { return std::string(); } - int target_length = ::WideCharToMultiByte( - CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, - -1, nullptr, 0, nullptr, nullptr); + int target_length = + ::WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, -1, + nullptr, 0, nullptr, nullptr); std::string utf8_string; if (target_length == 0 || target_length > utf8_string.max_size()) { return utf8_string; } utf8_string.resize(target_length); int converted_length = ::WideCharToMultiByte( - CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, - -1, utf8_string.data(), + CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, -1, utf8_string.data(), target_length, nullptr, nullptr); if (converted_length == 0) { return std::string(); diff --git a/packages/package_info_plus/package_info_plus/example/windows/runner/utils.h b/packages/package_info_plus/package_info_plus/example/windows/runner/utils.h index 3879d54755..ff43ce2ce5 100644 --- a/packages/package_info_plus/package_info_plus/example/windows/runner/utils.h +++ b/packages/package_info_plus/package_info_plus/example/windows/runner/utils.h @@ -10,10 +10,10 @@ void CreateAndAttachConsole(); // Takes a null-terminated wchar_t* encoded in UTF-16 and returns a std::string // encoded in UTF-8. Returns an empty std::string on failure. -std::string Utf8FromUtf16(const wchar_t* utf16_string); +std::string Utf8FromUtf16(const wchar_t *utf16_string); // Gets the command line arguments passed in as a std::vector, // encoded in UTF-8. Returns an empty std::vector on failure. std::vector GetCommandLineArguments(); -#endif // RUNNER_UTILS_H_ +#endif // RUNNER_UTILS_H_ diff --git a/packages/package_info_plus/package_info_plus/example/windows/runner/win32_window.cpp b/packages/package_info_plus/package_info_plus/example/windows/runner/win32_window.cpp index c10f08dc7d..90ff01e592 100644 --- a/packages/package_info_plus/package_info_plus/example/windows/runner/win32_window.cpp +++ b/packages/package_info_plus/package_info_plus/example/windows/runner/win32_window.cpp @@ -27,7 +27,7 @@ void EnableFullDpiSupportIfAvailable(HWND hwnd) { return; } auto enable_non_client_dpi_scaling = - reinterpret_cast( + reinterpret_cast( GetProcAddress(user32_module, "EnableNonClientDpiScaling")); if (enable_non_client_dpi_scaling != nullptr) { enable_non_client_dpi_scaling(hwnd); @@ -35,15 +35,15 @@ void EnableFullDpiSupportIfAvailable(HWND hwnd) { } } -} // namespace +} // namespace // Manages the Win32Window's window class registration. class WindowClassRegistrar { - public: +public: ~WindowClassRegistrar() = default; // Returns the singleton registar instance. - static WindowClassRegistrar* GetInstance() { + static WindowClassRegistrar *GetInstance() { if (!instance_) { instance_ = new WindowClassRegistrar(); } @@ -52,23 +52,23 @@ class WindowClassRegistrar { // Returns the name of the window class, registering the class if it hasn't // previously been registered. - const wchar_t* GetWindowClass(); + const wchar_t *GetWindowClass(); // Unregisters the window class. Should only be called if there are no // instances of the window. void UnregisterWindowClass(); - private: +private: WindowClassRegistrar() = default; - static WindowClassRegistrar* instance_; + static WindowClassRegistrar *instance_; bool class_registered_ = false; }; -WindowClassRegistrar* WindowClassRegistrar::instance_ = nullptr; +WindowClassRegistrar *WindowClassRegistrar::instance_ = nullptr; -const wchar_t* WindowClassRegistrar::GetWindowClass() { +const wchar_t *WindowClassRegistrar::GetWindowClass() { if (!class_registered_) { WNDCLASS window_class{}; window_class.hCursor = LoadCursor(nullptr, IDC_ARROW); @@ -93,21 +93,18 @@ void WindowClassRegistrar::UnregisterWindowClass() { class_registered_ = false; } -Win32Window::Win32Window() { - ++g_active_window_count; -} +Win32Window::Win32Window() { ++g_active_window_count; } Win32Window::~Win32Window() { --g_active_window_count; Destroy(); } -bool Win32Window::CreateAndShow(const std::wstring& title, - const Point& origin, - const Size& size) { +bool Win32Window::CreateAndShow(const std::wstring &title, const Point &origin, + const Size &size) { Destroy(); - const wchar_t* window_class = + const wchar_t *window_class = WindowClassRegistrar::GetInstance()->GetWindowClass(); const POINT target_point = {static_cast(origin.x), @@ -130,19 +127,18 @@ bool Win32Window::CreateAndShow(const std::wstring& title, } // static -LRESULT CALLBACK Win32Window::WndProc(HWND const window, - UINT const message, +LRESULT CALLBACK Win32Window::WndProc(HWND const window, UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept { if (message == WM_NCCREATE) { - auto window_struct = reinterpret_cast(lparam); + auto window_struct = reinterpret_cast(lparam); SetWindowLongPtr(window, GWLP_USERDATA, reinterpret_cast(window_struct->lpCreateParams)); - auto that = static_cast(window_struct->lpCreateParams); + auto that = static_cast(window_struct->lpCreateParams); EnableFullDpiSupportIfAvailable(window); that->window_handle_ = window; - } else if (Win32Window* that = GetThisFromHandle(window)) { + } else if (Win32Window *that = GetThisFromHandle(window)) { return that->MessageHandler(window, message, wparam, lparam); } @@ -150,44 +146,42 @@ LRESULT CALLBACK Win32Window::WndProc(HWND const window, } LRESULT -Win32Window::MessageHandler(HWND hwnd, - UINT const message, - WPARAM const wparam, +Win32Window::MessageHandler(HWND hwnd, UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept { switch (message) { - case WM_DESTROY: - window_handle_ = nullptr; - Destroy(); - if (quit_on_close_) { - PostQuitMessage(0); - } - return 0; - - case WM_DPICHANGED: { - auto newRectSize = reinterpret_cast(lparam); - LONG newWidth = newRectSize->right - newRectSize->left; - LONG newHeight = newRectSize->bottom - newRectSize->top; - - SetWindowPos(hwnd, nullptr, newRectSize->left, newRectSize->top, newWidth, - newHeight, SWP_NOZORDER | SWP_NOACTIVATE); - - return 0; + case WM_DESTROY: + window_handle_ = nullptr; + Destroy(); + if (quit_on_close_) { + PostQuitMessage(0); } - case WM_SIZE: { - RECT rect = GetClientArea(); - if (child_content_ != nullptr) { - // Size and position the child window. - MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left, - rect.bottom - rect.top, TRUE); - } - return 0; + return 0; + + case WM_DPICHANGED: { + auto newRectSize = reinterpret_cast(lparam); + LONG newWidth = newRectSize->right - newRectSize->left; + LONG newHeight = newRectSize->bottom - newRectSize->top; + + SetWindowPos(hwnd, nullptr, newRectSize->left, newRectSize->top, newWidth, + newHeight, SWP_NOZORDER | SWP_NOACTIVATE); + + return 0; + } + case WM_SIZE: { + RECT rect = GetClientArea(); + if (child_content_ != nullptr) { + // Size and position the child window. + MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left, + rect.bottom - rect.top, TRUE); } + return 0; + } - case WM_ACTIVATE: - if (child_content_ != nullptr) { - SetFocus(child_content_); - } - return 0; + case WM_ACTIVATE: + if (child_content_ != nullptr) { + SetFocus(child_content_); + } + return 0; } return DefWindowProc(window_handle_, message, wparam, lparam); @@ -205,8 +199,8 @@ void Win32Window::Destroy() { } } -Win32Window* Win32Window::GetThisFromHandle(HWND const window) noexcept { - return reinterpret_cast( +Win32Window *Win32Window::GetThisFromHandle(HWND const window) noexcept { + return reinterpret_cast( GetWindowLongPtr(window, GWLP_USERDATA)); } @@ -227,9 +221,7 @@ RECT Win32Window::GetClientArea() { return frame; } -HWND Win32Window::GetHandle() { - return window_handle_; -} +HWND Win32Window::GetHandle() { return window_handle_; } void Win32Window::SetQuitOnClose(bool quit_on_close) { quit_on_close_ = quit_on_close; diff --git a/packages/package_info_plus/package_info_plus/example/windows/runner/win32_window.h b/packages/package_info_plus/package_info_plus/example/windows/runner/win32_window.h index 17ba431125..7b518125bb 100644 --- a/packages/package_info_plus/package_info_plus/example/windows/runner/win32_window.h +++ b/packages/package_info_plus/package_info_plus/example/windows/runner/win32_window.h @@ -11,7 +11,7 @@ // inherited from by classes that wish to specialize with custom // rendering and input handling class Win32Window { - public: +public: struct Point { unsigned int x; unsigned int y; @@ -34,9 +34,8 @@ class Win32Window { // consistent size to will treat the width height passed in to this function // as logical pixels and scale to appropriate for the default monitor. Returns // true if the window was created successfully. - bool CreateAndShow(const std::wstring& title, - const Point& origin, - const Size& size); + bool CreateAndShow(const std::wstring &title, const Point &origin, + const Size &size); // Release OS resources associated with window. void Destroy(); @@ -54,12 +53,11 @@ class Win32Window { // Return a RECT representing the bounds of the current client area. RECT GetClientArea(); - protected: +protected: // Processes and route salient window messages for mouse handling, // size change and DPI. Delegates handling of these to member overloads that // inheriting classes can handle. - virtual LRESULT MessageHandler(HWND window, - UINT const message, + virtual LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept; @@ -70,7 +68,7 @@ class Win32Window { // Called when Destroy is called. virtual void OnDestroy(); - private: +private: friend class WindowClassRegistrar; // OS callback called by message pump. Handles the WM_NCCREATE message which @@ -78,13 +76,12 @@ class Win32Window { // non-client DPI scaling so that the non-client area automatically // responsponds to changes in DPI. All other messages are handled by // MessageHandler. - static LRESULT CALLBACK WndProc(HWND const window, - UINT const message, + static LRESULT CALLBACK WndProc(HWND const window, UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept; // Retrieves a class instance pointer for |window| - static Win32Window* GetThisFromHandle(HWND const window) noexcept; + static Win32Window *GetThisFromHandle(HWND const window) noexcept; bool quit_on_close_ = false; @@ -95,4 +92,4 @@ class Win32Window { HWND child_content_ = nullptr; }; -#endif // RUNNER_WIN32_WINDOW_H_ +#endif // RUNNER_WIN32_WINDOW_H_ diff --git a/packages/share_plus/share_plus/example/lib/main.dart b/packages/share_plus/share_plus/example/lib/main.dart index b226596556..c46eba0e3e 100644 --- a/packages/share_plus/share_plus/example/lib/main.dart +++ b/packages/share_plus/share_plus/example/lib/main.dart @@ -71,13 +71,16 @@ class DemoAppState extends State { title: const Text('Add image'), onTap: () async { // Using `package:image_picker` to get image from gallery. - if (Platform.isMacOS || Platform.isLinux || Platform.isWindows) { + if (Platform.isMacOS || + Platform.isLinux || + Platform.isWindows) { // Using `package:file_selector` on windows, macos & Linux, since `package:image_picker` is not supported. const XTypeGroup typeGroup = XTypeGroup( label: 'images', extensions: ['jpg', 'jpeg', 'png', 'gif'], ); - final file = await openFile(acceptedTypeGroups: [typeGroup]); + final file = await openFile( + acceptedTypeGroups: [typeGroup]); if (file != null) { setState(() { imagePaths.add(file.path); @@ -102,7 +105,9 @@ class DemoAppState extends State { Builder( builder: (BuildContext context) { return ElevatedButton( - onPressed: text.isEmpty && imagePaths.isEmpty ? null : () => _onShare(context), + onPressed: text.isEmpty && imagePaths.isEmpty + ? null + : () => _onShare(context), child: const Text('Share'), ); }, @@ -111,7 +116,9 @@ class DemoAppState extends State { Builder( builder: (BuildContext context) { return ElevatedButton( - onPressed: text.isEmpty && imagePaths.isEmpty ? null : () => _onShareWithResult(context), + onPressed: text.isEmpty && imagePaths.isEmpty + ? null + : () => _onShareWithResult(context), child: const Text('Share With Result'), ); }, @@ -146,9 +153,13 @@ class DemoAppState extends State { files.add(XFile(imagePaths[i], name: imageNames[i])); } await Share.shareXFiles(files, - text: text, subject: subject, sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size); + text: text, + subject: subject, + sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size); } else { - await Share.share(text, subject: subject, sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size); + await Share.share(text, + subject: subject, + sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size); } } @@ -162,10 +173,13 @@ class DemoAppState extends State { files.add(XFile(imagePaths[i], name: imageNames[i])); } result = await Share.shareXFiles(files, - text: text, subject: subject, sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size); + text: text, + subject: subject, + sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size); } else { result = await Share.shareWithResult(text, - subject: subject, sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size); + subject: subject, + sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size); } scaffoldMessenger.showSnackBar(SnackBar( content: Text("Share result: ${result.status}"), diff --git a/packages/share_plus/share_plus/lib/src/share_plus_linux.dart b/packages/share_plus/share_plus/lib/src/share_plus_linux.dart index a51f08a39a..6080fc81a7 100644 --- a/packages/share_plus/share_plus/lib/src/share_plus_linux.dart +++ b/packages/share_plus/share_plus/lib/src/share_plus_linux.dart @@ -30,8 +30,10 @@ class SharePlusLinuxPlugin extends SharePlatform { // see https://github.com/dart-lang/sdk/issues/43838#issuecomment-823551891 final uri = Uri( scheme: 'mailto', - query: - queryParameters.entries.map((e) => '${Uri.encodeComponent(e.key)}=${Uri.encodeComponent(e.value)}').join('&'), + query: queryParameters.entries + .map((e) => + '${Uri.encodeComponent(e.key)}=${Uri.encodeComponent(e.value)}') + .join('&'), ); await launchUrl(uri); diff --git a/packages/share_plus/share_plus/lib/src/share_plus_web.dart b/packages/share_plus/share_plus/lib/src/share_plus_web.dart index 552efe6a4b..956cd29d9d 100644 --- a/packages/share_plus/share_plus/lib/src/share_plus_web.dart +++ b/packages/share_plus/share_plus/lib/src/share_plus_web.dart @@ -41,7 +41,8 @@ class SharePlusWebPlugin extends SharePlatform { final uri = Uri( scheme: 'mailto', query: queryParameters.entries - .map((e) => '${Uri.encodeComponent(e.key)}=${Uri.encodeComponent(e.value)}') + .map((e) => + '${Uri.encodeComponent(e.key)}=${Uri.encodeComponent(e.value)}') .join('&'), ); @@ -116,7 +117,8 @@ class SharePlusWebPlugin extends SharePlatform { } static String _mimeTypeForPath(XFile file, Uint8List bytes) { - return lookupMimeType(file.name, headerBytes: bytes) ?? 'application/octet-stream'; + return lookupMimeType(file.name, headerBytes: bytes) ?? + 'application/octet-stream'; } } diff --git a/packages/share_plus/share_plus/lib/src/share_plus_windows.dart b/packages/share_plus/share_plus/lib/src/share_plus_windows.dart index 166dc0f4e3..9ee66de60e 100644 --- a/packages/share_plus/share_plus/lib/src/share_plus_windows.dart +++ b/packages/share_plus/share_plus/lib/src/share_plus_windows.dart @@ -34,8 +34,10 @@ class SharePlusWindowsPlugin extends SharePlatform { // see https://github.com/dart-lang/sdk/issues/43838#issuecomment-823551891 final uri = Uri( scheme: 'mailto', - query: - queryParameters.entries.map((e) => '${Uri.encodeComponent(e.key)}=${Uri.encodeComponent(e.value)}').join('&'), + query: queryParameters.entries + .map((e) => + '${Uri.encodeComponent(e.key)}=${Uri.encodeComponent(e.value)}') + .join('&'), ); if (await canLaunchUrl(uri)) { diff --git a/packages/share_plus/share_plus/test/share_plus_linux_test.dart b/packages/share_plus/share_plus/test/share_plus_linux_test.dart index 71024f6c02..b5b02ad073 100644 --- a/packages/share_plus/share_plus/test/share_plus_linux_test.dart +++ b/packages/share_plus/share_plus/test/share_plus_linux_test.dart @@ -33,7 +33,8 @@ void main() { mock.canLaunchMockValue = false; UrlLauncherPlatform.instance = mock; - expect(() async => await SharePlusLinuxPlugin().share('foo bar'), throwsException); + expect(() async => await SharePlusLinuxPlugin().share('foo bar'), + throwsException); }); } diff --git a/packages/share_plus/share_plus/test/share_plus_windows_test.dart b/packages/share_plus/share_plus/test/share_plus_windows_test.dart index eb07377b1a..b27469c31b 100644 --- a/packages/share_plus/share_plus/test/share_plus_windows_test.dart +++ b/packages/share_plus/share_plus/test/share_plus_windows_test.dart @@ -61,7 +61,8 @@ void main() { mock.canLaunchMockValue = false; UrlLauncherPlatform.instance = mock; - expect(() async => await SharePlusWindowsPlugin().share('foo bar'), throwsException); + expect(() async => await SharePlusWindowsPlugin().share('foo bar'), + throwsException); }, skip: VersionHelper.instance.isWindows10RS5OrGreater, ); diff --git a/packages/share_plus/share_plus/windows/include/share_plus_windows/share_plus_windows_plugin_c_api.h b/packages/share_plus/share_plus/windows/include/share_plus_windows/share_plus_windows_plugin_c_api.h index a5d43111eb..760ce9a727 100644 --- a/packages/share_plus/share_plus/windows/include/share_plus_windows/share_plus_windows_plugin_c_api.h +++ b/packages/share_plus/share_plus/windows/include/share_plus_windows/share_plus_windows_plugin_c_api.h @@ -17,7 +17,7 @@ FLUTTER_PLUGIN_EXPORT void SharePlusWindowsPluginCApiRegisterWithRegistrar( FlutterDesktopPluginRegistrarRef registrar); #if defined(__cplusplus) -} // extern "C" +} // extern "C" #endif -#endif // FLUTTER_PLUGIN_SHARE_PLUS_WINDOWS_PLUGIN_C_API_H_ +#endif // FLUTTER_PLUGIN_SHARE_PLUS_WINDOWS_PLUGIN_C_API_H_ diff --git a/packages/share_plus/share_plus/windows/share_plus_windows_plugin.cpp b/packages/share_plus/share_plus/windows/share_plus_windows_plugin.cpp index 08e4d37603..686cde4985 100644 --- a/packages/share_plus/share_plus/windows/share_plus_windows_plugin.cpp +++ b/packages/share_plus/share_plus/windows/share_plus_windows_plugin.cpp @@ -9,14 +9,14 @@ namespace share_plus_windows { void SharePlusWindowsPlugin::RegisterWithRegistrar( - flutter::PluginRegistrarWindows* registrar) { + flutter::PluginRegistrarWindows *registrar) { auto channel = std::make_unique>( registrar->messenger(), kSharePlusChannelName, &flutter::StandardMethodCodec::GetInstance()); auto plugin = std::make_unique(registrar); channel->SetMethodCallHandler( - [plugin_pointer = plugin.get()](const auto& call, auto result) { + [plugin_pointer = plugin.get()](const auto &call, auto result) { plugin_pointer->HandleMethodCall(call, std::move(result)); }); @@ -24,7 +24,7 @@ void SharePlusWindowsPlugin::RegisterWithRegistrar( } SharePlusWindowsPlugin::SharePlusWindowsPlugin( - flutter::PluginRegistrarWindows* registrar) + flutter::PluginRegistrarWindows *registrar) : registrar_(registrar) {} SharePlusWindowsPlugin::~SharePlusWindowsPlugin() { @@ -55,8 +55,7 @@ SharePlusWindowsPlugin::GetDataTransferManager() { } HRESULT SharePlusWindowsPlugin::GetStorageFileFromPath( - wchar_t* path, - WindowsStorage::IStorageFile** file) { + wchar_t *path, WindowsStorage::IStorageFile **file) { using Microsoft::WRL::Wrappers::HStringReference; WRL::ComPtr factory = nullptr; HRESULT hr = S_OK; @@ -68,7 +67,7 @@ HRESULT SharePlusWindowsPlugin::GetStorageFileFromPath( } if (SUCCEEDED(hr)) { WRL::ComPtr< - WindowsFoundation::IAsyncOperation> + WindowsFoundation::IAsyncOperation> async_operation; hr = factory->GetFileFromPathAsync(HStringReference(path).Get(), &async_operation); @@ -92,7 +91,7 @@ HRESULT SharePlusWindowsPlugin::GetStorageFileFromPath( } void SharePlusWindowsPlugin::HandleMethodCall( - const flutter::MethodCall& method_call, + const flutter::MethodCall &method_call, std::unique_ptr> result) { if (method_call.method_name().compare(kShare) == 0 || method_call.method_name().compare(kShareWithResult) == 0) { @@ -109,9 +108,9 @@ void SharePlusWindowsPlugin::HandleMethodCall( share_subject_ = *subject_value; } auto callback = WRL::Callback>( - [&](auto&&, DataTransfer::IDataRequestedEventArgs* e) { + DataTransfer::DataTransferManager *, + DataTransfer::DataRequestedEventArgs *>>( + [&](auto &&, DataTransfer::IDataRequestedEventArgs *e) { using Microsoft::WRL::Wrappers::HStringReference; WRL::ComPtr request; e->get_Request(&request); @@ -165,21 +164,21 @@ void SharePlusWindowsPlugin::HandleMethodCall( if (auto paths = std::get_if( &args[flutter::EncodableValue("paths")])) { paths_.clear(); - for (auto& path : *paths) { + for (auto &path : *paths) { paths_.emplace_back(std::get(path)); } } if (auto mime_types = std::get_if( &args[flutter::EncodableValue("mimeTypes")])) { mime_types_.clear(); - for (auto& mime_type : *mime_types) { + for (auto &mime_type : *mime_types) { mime_types_.emplace_back(std::get(mime_type)); } } auto callback = WRL::Callback>( - [&](auto&&, DataTransfer::IDataRequestedEventArgs* e) { + DataTransfer::DataTransferManager *, + DataTransfer::DataRequestedEventArgs *>>( + [&](auto &&, DataTransfer::IDataRequestedEventArgs *e) { using Microsoft::WRL::Wrappers::HStringReference; WRL::ComPtr request; e->get_Request(&request); @@ -220,15 +219,15 @@ void SharePlusWindowsPlugin::HandleMethodCall( data->SetText(HStringReference(text.c_str()).Get()); } // Add files to the data. - Vector storage_items; - for (const std::string& path : paths_) { + Vector storage_items; + for (const std::string &path : paths_) { auto str = Utf16FromUtf8(path); - wchar_t* ptr = const_cast(str.c_str()); - WindowsStorage::IStorageFile* file = nullptr; + wchar_t *ptr = const_cast(str.c_str()); + WindowsStorage::IStorageFile *file = nullptr; if (SUCCEEDED(GetStorageFileFromPath(ptr, &file)) && file != nullptr) { storage_items.Append( - reinterpret_cast(file)); + reinterpret_cast(file)); } } data->SetStorageItemsReadOnly(&storage_items); @@ -267,4 +266,4 @@ std::wstring SharePlusWindowsPlugin::Utf16FromUtf8(std::string string) { return result; } -} // namespace share_plus_windows +} // namespace share_plus_windows diff --git a/packages/share_plus/share_plus/windows/share_plus_windows_plugin.h b/packages/share_plus/share_plus/windows/share_plus_windows_plugin.h index b96f9b3b0c..83d201c829 100644 --- a/packages/share_plus/share_plus/windows/share_plus_windows_plugin.h +++ b/packages/share_plus/share_plus/windows/share_plus_windows_plugin.h @@ -27,17 +27,17 @@ namespace DataTransfer = ABI::Windows::ApplicationModel::DataTransfer; namespace share_plus_windows { class SharePlusWindowsPlugin : public flutter::Plugin { - public: - static void RegisterWithRegistrar(flutter::PluginRegistrarWindows* registrar); +public: + static void RegisterWithRegistrar(flutter::PluginRegistrarWindows *registrar); - SharePlusWindowsPlugin(flutter::PluginRegistrarWindows* registrar); + SharePlusWindowsPlugin(flutter::PluginRegistrarWindows *registrar); virtual ~SharePlusWindowsPlugin(); - SharePlusWindowsPlugin(const SharePlusWindowsPlugin&) = delete; - SharePlusWindowsPlugin& operator=(const SharePlusWindowsPlugin&) = delete; + SharePlusWindowsPlugin(const SharePlusWindowsPlugin &) = delete; + SharePlusWindowsPlugin &operator=(const SharePlusWindowsPlugin &) = delete; - private: +private: static constexpr auto kSharePlusChannelName = "dev.fluttercommunity.plus/share"; @@ -54,15 +54,15 @@ class SharePlusWindowsPlugin : public flutter::Plugin { WRL::ComPtr GetDataTransferManager(); void HandleMethodCall( - const flutter::MethodCall& method_call, + const flutter::MethodCall &method_call, std::unique_ptr> result); - static HRESULT GetStorageFileFromPath(wchar_t* path, - WindowsStorage::IStorageFile** file); + static HRESULT GetStorageFileFromPath(wchar_t *path, + WindowsStorage::IStorageFile **file); static std::wstring SharePlusWindowsPlugin::Utf16FromUtf8(std::string string); - flutter::PluginRegistrarWindows* registrar_ = nullptr; + flutter::PluginRegistrarWindows *registrar_ = nullptr; WRL::ComPtr data_transfer_manager_interop_ = nullptr; WRL::ComPtr data_transfer_manager_ = @@ -78,6 +78,6 @@ class SharePlusWindowsPlugin : public flutter::Plugin { std::vector mime_types_ = {}; }; -} // namespace share_plus_windows +} // namespace share_plus_windows -#endif // FLUTTER_PLUGIN_SHARE_PLUS_WINDOWS_PLUGIN_H_ +#endif // FLUTTER_PLUGIN_SHARE_PLUS_WINDOWS_PLUGIN_H_ diff --git a/packages/share_plus/share_plus/windows/vector.h b/packages/share_plus/share_plus/windows/vector.h index c33319b5f5..105e42c222 100644 --- a/packages/share_plus/share_plus/windows/vector.h +++ b/packages/share_plus/share_plus/windows/vector.h @@ -3,13 +3,13 @@ #pragma once -#include +#include "winstring.h" #include +#include #include #include #include #include -#include "winstring.h" #include #include @@ -35,10 +35,10 @@ using namespace Microsoft::WRL::Wrappers; class HResultException { HRESULT m_Hr; - protected: +protected: explicit HResultException(HRESULT hr) : m_Hr(hr) {} - public: +public: HRESULT GetHr() const { return m_Hr; } __declspec(noreturn) friend void ThrowHR(HRESULT); @@ -65,8 +65,8 @@ __declspec(noreturn) __declspec(noinline) inline void ThrowHR(HRESULT hr, ThrowHR(hr); } -__declspec(noreturn) __declspec( - noinline) inline void ThrowHR(HRESULT hr, wchar_t const* message) { +__declspec(noreturn) __declspec(noinline) inline void ThrowHR( + HRESULT hr, wchar_t const *message) { using ::Microsoft::WRL::Wrappers::HStringReference; ThrowHR(hr, HStringReference(message).Get()); @@ -87,13 +87,12 @@ inline void ThrowIfFailed(HRESULT hr) { // Throws if the given pointer is null. // template -inline void ThrowIfNullPointer(T* ptr, HRESULT hrToThrow) { +inline void ThrowIfNullPointer(T *ptr, HRESULT hrToThrow) { if (ptr == nullptr) ThrowHR(hrToThrow); } -template -inline void ThrowIfNegative(T value) { +template inline void ThrowIfNegative(T value) { if (value < 0) ThrowHR(E_INVALIDARG); } @@ -109,8 +108,7 @@ inline void ThrowIfZeroOrNegative(uint32_t n) { // expected to be used at the beginning of methods to validate pointer // parameters that are marked as [in]. // -template -inline void CheckInPointer(T* ptr) { +template inline void CheckInPointer(T *ptr) { ThrowIfNullPointer(ptr, E_INVALIDARG); } @@ -119,8 +117,7 @@ inline void CheckInPointer(T* ptr) { // it to null. This is expected to be used at the beginning of methods to // validate out pointer parameters that are marked as [out]. // -template -inline void CheckAndClearOutPointer(T** ptr) { +template inline void CheckAndClearOutPointer(T **ptr) { CheckInPointer(ptr); *ptr = nullptr; } @@ -148,17 +145,16 @@ inline void CheckMakeResult(bool result) { __declspec(noinline) inline HRESULT ThrownExceptionToHResult() { try { throw; - } catch (HResultException const& e) { + } catch (HResultException const &e) { return e.GetHr(); - } catch (std::bad_alloc const&) { + } catch (std::bad_alloc const &) { return E_OUTOFMEMORY; } catch (...) { return E_UNEXPECTED; } } -template -HRESULT ExceptionBoundary(CALLABLE&& fn) { +template HRESULT ExceptionBoundary(CALLABLE &&fn) { try { fn(); return S_OK; @@ -171,83 +167,78 @@ HRESULT ExceptionBoundary(CALLABLE&& fn) { // collection. This default implementation is for value types. The same template // is specialized with more interesting versions for reference counted pointer // types and strings. -template -struct ElementTraits { +template struct ElementTraits { typedef T ElementType; - static ElementType Wrap(T const& value) { return value; } + static ElementType Wrap(T const &value) { return value; } - static void Unwrap(ElementType const& value, _Out_ T* result) { + static void Unwrap(ElementType const &value, _Out_ T *result) { *result = value; } - static bool Equals(T const& value1, T const& value2) { + static bool Equals(T const &value1, T const &value2) { return value1 == value2; } - static void CopyTo(T const& in, ElementType* out) { *out = in; } + static void CopyTo(T const &in, ElementType *out) { *out = in; } }; // Specialized element traits for reference counted pointer types. -template -struct ElementTraits { +template struct ElementTraits { typedef Microsoft::WRL::ComPtr ElementType; - static ElementType Wrap(T* value) { return Microsoft::WRL::ComPtr(value); } + static ElementType Wrap(T *value) { return Microsoft::WRL::ComPtr(value); } - static void Unwrap(ElementType const& value, _Out_ T** result) { + static void Unwrap(ElementType const &value, _Out_ T **result) { ThrowIfFailed(value.CopyTo(result)); } - static bool Equals(Microsoft::WRL::ComPtr const& value1, T* value2) { + static bool Equals(Microsoft::WRL::ComPtr const &value1, T *value2) { return value1.Get() == value2; } - static void CopyTo(Microsoft::WRL::ComPtr const& in, ElementType* out) { + static void CopyTo(Microsoft::WRL::ComPtr const &in, ElementType *out) { in.CopyTo(out->GetAddressOf()); } }; // Specialized element traits for strings. -template <> -struct ElementTraits { +template <> struct ElementTraits { typedef HString ElementType; - static ElementType Wrap(HSTRING const& value) { + static ElementType Wrap(HSTRING const &value) { HString hstringValue; hstringValue.Set(value); return hstringValue; } - static void Unwrap(ElementType const& value, _Out_ HSTRING* result) { + static void Unwrap(ElementType const &value, _Out_ HSTRING *result) { value.CopyTo(result); } - static bool Equals(HString const& value1, HSTRING const& value2) { + static bool Equals(HString const &value1, HSTRING const &value2) { int compareResult; ThrowIfFailed( WindowsCompareStringOrdinal(value1.Get(), value2, &compareResult)); return compareResult == 0; } - static void CopyTo(HString const& in, ElementType* out) { + static void CopyTo(HString const &in, ElementType *out) { in.CopyTo(out->GetAddressOf()); } }; // Vector traits describe how the collection itself is implemented. // This default version just uses an STL vector. -template -struct DefaultVectorTraits : public ElementTraits { +template struct DefaultVectorTraits : public ElementTraits { typedef std::vector InternalVectorType; - static unsigned GetSize(InternalVectorType const& vector) { + static unsigned GetSize(InternalVectorType const &vector) { return (unsigned)vector.size(); }; - static void GetAt(InternalVectorType const& vector, - unsigned index, - ElementType* element) { + static void GetAt(InternalVectorType const &vector, unsigned index, + ElementType *element) { if (index >= vector.size()) ThrowHR(E_BOUNDS); @@ -255,34 +246,33 @@ struct DefaultVectorTraits : public ElementTraits { return; } - static void SetAt(InternalVectorType& vector, unsigned index, T const& item) { + static void SetAt(InternalVectorType &vector, unsigned index, T const &item) { if (index >= vector.size()) ThrowHR(E_BOUNDS); vector[index] = Wrap(item); } - static void InsertAt(InternalVectorType& vector, - unsigned index, - T const& item) { + static void InsertAt(InternalVectorType &vector, unsigned index, + T const &item) { if (index > vector.size()) ThrowHR(E_BOUNDS); vector.insert(vector.begin() + index, Wrap(item)); } - static void RemoveAt(InternalVectorType& vector, unsigned index) { + static void RemoveAt(InternalVectorType &vector, unsigned index) { if (index >= vector.size()) ThrowHR(E_BOUNDS); vector.erase(vector.begin() + index); } - static void Append(InternalVectorType& vector, T const& item) { + static void Append(InternalVectorType &vector, T const &item) { vector.push_back(Wrap(item)); } - static void Clear(InternalVectorType& vector) { vector.clear(); } + static void Clear(InternalVectorType &vector) { vector.clear(); } }; // Implements the WinRT IVector interface. @@ -293,7 +283,7 @@ class Vector : public Microsoft::WRL::RuntimeClass< ABI::Windows::Foundation::Collections::IIterable> { InspectableClass(IVector::z_get_rc_name_impl(), BaseTrust); - public: +public: // T_abi is often the same as T, but if T is a runtime class, T_abi will be // the corresponding interface. typedef typename ABI::Windows::Foundation::Internal::GetAbiType< @@ -302,22 +292,21 @@ class Vector : public Microsoft::WRL::RuntimeClass< // Specialize our traits class to use the ABI version of the type. typedef Traits Traits; - private: +private: // Fields. typename Traits::InternalVectorType mVector; bool isFixedSize; bool isChanged; - public: +public: // Constructs an empty vector. Vector() : isFixedSize(false), isChanged(false) {} // Constructs a vector of the specified size. template - Vector(bool isFixedSize, Args&&... args) - : mVector(std::forward(args)...), - isFixedSize(isFixedSize), + Vector(bool isFixedSize, Args &&...args) + : mVector(std::forward(args)...), isFixedSize(isFixedSize), isChanged(false) {} // Checks whether this vector is fixed or resizable. @@ -332,9 +321,9 @@ class Vector : public Microsoft::WRL::RuntimeClass< // Expose direct access to the internal STL collection. This lets C++ owners // bypass the ExceptionBoundary overhead of the public WinRT API surface. - typename Traits::InternalVectorType& InternalVector() { return mVector; } + typename Traits::InternalVectorType &InternalVector() { return mVector; } - virtual HRESULT STDMETHODCALLTYPE get_Size(_Out_ unsigned* size) { + virtual HRESULT STDMETHODCALLTYPE get_Size(_Out_ unsigned *size) { return ExceptionBoundary([&] { CheckInPointer(size); @@ -343,7 +332,7 @@ class Vector : public Microsoft::WRL::RuntimeClass< }; virtual HRESULT STDMETHODCALLTYPE GetAt(_In_opt_ unsigned index, - _Out_ T_abi* item) { + _Out_ T_abi *item) { return ExceptionBoundary([&] { CheckInPointer(item); ZeroMemory(item, sizeof(*item)); @@ -355,8 +344,8 @@ class Vector : public Microsoft::WRL::RuntimeClass< } virtual HRESULT STDMETHODCALLTYPE IndexOf(_In_opt_ T_abi value, - _Out_ unsigned* index, - _Out_ boolean* found) { + _Out_ unsigned *index, + _Out_ boolean *found) { return ExceptionBoundary([&] { CheckInPointer(index); CheckInPointer(found); @@ -439,7 +428,7 @@ class Vector : public Microsoft::WRL::RuntimeClass< } virtual HRESULT STDMETHODCALLTYPE ReplaceAll(_In_ unsigned count, - _In_reads_(count) T_abi* value) { + _In_reads_(count) T_abi *value) { return ExceptionBoundary([&] { CheckInPointer(value); @@ -464,7 +453,7 @@ class Vector : public Microsoft::WRL::RuntimeClass< virtual HRESULT STDMETHODCALLTYPE GetView( _Outptr_result_maybenull_ - ABI::Windows::Foundation::Collections::IVectorView** view) { + ABI::Windows::Foundation::Collections::IVectorView **view) { return ExceptionBoundary([&] { CheckAndClearOutPointer(view); @@ -477,7 +466,7 @@ class Vector : public Microsoft::WRL::RuntimeClass< virtual HRESULT STDMETHODCALLTYPE First( _Outptr_result_maybenull_ - ABI::Windows::Foundation::Collections::IIterator** first) { + ABI::Windows::Foundation::Collections::IIterator **first) { return ExceptionBoundary([&] { CheckAndClearOutPointer(first); @@ -499,29 +488,29 @@ class VectorView : public Microsoft::WRL::RuntimeClass< // Fields. Microsoft::WRL::ComPtr mVector; - public: +public: // Constructor wraps around an existing Vector. - VectorView(TVector* vector) : mVector(vector) {} + VectorView(TVector *vector) : mVector(vector) {} - virtual HRESULT STDMETHODCALLTYPE get_Size(_Out_ unsigned* size) { + virtual HRESULT STDMETHODCALLTYPE get_Size(_Out_ unsigned *size) { return mVector->get_Size(size); }; virtual HRESULT STDMETHODCALLTYPE GetAt(_In_opt_ unsigned index, - _Out_ typename TVector::T_abi* item) { + _Out_ typename TVector::T_abi *item) { return mVector->GetAt(index, item); } virtual HRESULT STDMETHODCALLTYPE IndexOf(_In_opt_ typename TVector::T_abi value, - _Out_ unsigned* index, - _Out_ boolean* found) { + _Out_ unsigned *index, + _Out_ boolean *found) { return mVector->IndexOf(value, index, found); } virtual HRESULT STDMETHODCALLTYPE First( _Outptr_result_maybenull_ - ABI::Windows::Foundation::Collections::IIterator** first) { + ABI::Windows::Foundation::Collections::IIterator **first) { return mVector->First(first); } }; @@ -537,16 +526,16 @@ class VectorIterator Microsoft::WRL::ComPtr mVector; unsigned mPosition; - public: +public: // Constructor wraps around an existing Vector. - VectorIterator(TVector* vector) : mVector(vector), mPosition(0) {} + VectorIterator(TVector *vector) : mVector(vector), mPosition(0) {} virtual HRESULT STDMETHODCALLTYPE - get_Current(_Out_ typename TVector::T_abi* current) { + get_Current(_Out_ typename TVector::T_abi *current) { return mVector->GetAt(mPosition, current); } - virtual HRESULT STDMETHODCALLTYPE get_HasCurrent(_Out_ boolean* hasCurrent) { + virtual HRESULT STDMETHODCALLTYPE get_HasCurrent(_Out_ boolean *hasCurrent) { return ExceptionBoundary([&] { CheckInPointer(hasCurrent); @@ -555,7 +544,7 @@ class VectorIterator }); } - virtual HRESULT STDMETHODCALLTYPE MoveNext(_Out_ boolean* hasCurrent) { + virtual HRESULT STDMETHODCALLTYPE MoveNext(_Out_ boolean *hasCurrent) { return ExceptionBoundary([&] { CheckInPointer(hasCurrent); From 07963071aad3e1d56bd1bb54307e037292862931 Mon Sep 17 00:00:00 2001 From: Joachim Nohl <43643339+nohli@users.noreply.github.com> Date: Thu, 13 Oct 2022 18:18:11 +0200 Subject: [PATCH 3/9] Fix filename --- packages/share_plus/share_plus/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/share_plus/share_plus/pubspec.yaml b/packages/share_plus/share_plus/pubspec.yaml index 1a6ec1c76f..5d8f298237 100644 --- a/packages/share_plus/share_plus/pubspec.yaml +++ b/packages/share_plus/share_plus/pubspec.yaml @@ -19,7 +19,7 @@ flutter: pluginClass: SharePlusMacosPlugin web: pluginClass: SharePlusWebPlugin - fileName: share_plus_web.dart + fileName: src/share_plus_web.dart windows: dartPluginClass: SharePlusWindowsPlugin pluginClass: SharePlusWindowsPluginCApi From 84e520dd2d8ce9e3b7e5ba0e24ff34c28fb09d91 Mon Sep 17 00:00:00 2001 From: Joachim Nohl <43643339+nohli@users.noreply.github.com> Date: Thu, 13 Oct 2022 18:22:44 +0200 Subject: [PATCH 4/9] Remove old windows folder --- .../share_plus_windows/.clang-format | 12 --- .../share_plus/share_plus_windows/.gitignore | 74 ------------------- .../share_plus/share_plus_windows/.metadata | 10 --- .../share_plus_windows/CHANGELOG.md | 40 ---------- .../share_plus/share_plus_windows/LICENSE | 21 ------ .../share_plus/share_plus_windows/README.md | 12 --- .../share_plus_windows/pubspec.yaml | 33 --------- 7 files changed, 202 deletions(-) delete mode 100644 packages/share_plus/share_plus_windows/.clang-format delete mode 100644 packages/share_plus/share_plus_windows/.gitignore delete mode 100644 packages/share_plus/share_plus_windows/.metadata delete mode 100644 packages/share_plus/share_plus_windows/CHANGELOG.md delete mode 100644 packages/share_plus/share_plus_windows/LICENSE delete mode 100644 packages/share_plus/share_plus_windows/README.md delete mode 100644 packages/share_plus/share_plus_windows/pubspec.yaml diff --git a/packages/share_plus/share_plus_windows/.clang-format b/packages/share_plus/share_plus_windows/.clang-format deleted file mode 100644 index 3c73f32a33..0000000000 --- a/packages/share_plus/share_plus_windows/.clang-format +++ /dev/null @@ -1,12 +0,0 @@ -# Defines the Chromium style for automatic reformatting. -# http://clang.llvm.org/docs/ClangFormatStyleOptions.html -BasedOnStyle: Chromium -# This defaults to 'Auto'. Explicitly set it for a while, so that -# 'vector >' in existing files gets formatted to -# 'vector>'. ('Auto' means that clang-format will only use -# 'int>>' if the file already contains at least one such instance.) -Standard: Cpp11 -SortIncludes: true ---- -Language: ObjC -ColumnLimit: 100 diff --git a/packages/share_plus/share_plus_windows/.gitignore b/packages/share_plus/share_plus_windows/.gitignore deleted file mode 100644 index 1985397a2c..0000000000 --- a/packages/share_plus/share_plus_windows/.gitignore +++ /dev/null @@ -1,74 +0,0 @@ -# Miscellaneous -*.class -*.log -*.pyc -*.swp -.DS_Store -.atom/ -.buildlog/ -.history -.svn/ - -# IntelliJ related -*.iml -*.ipr -*.iws -.idea/ - -# The .vscode folder contains launch configuration and tasks you configure in -# VS Code which you may wish to be included in version control, so this line -# is commented out by default. -#.vscode/ - -# Flutter/Dart/Pub related -**/doc/api/ -.dart_tool/ -.flutter-plugins -.flutter-plugins-dependencies -.packages -.pub-cache/ -.pub/ -build/ - -# Android related -**/android/**/gradle-wrapper.jar -**/android/.gradle -**/android/captures/ -**/android/gradlew -**/android/gradlew.bat -**/android/local.properties -**/android/**/GeneratedPluginRegistrant.java - -# iOS/XCode related -**/ios/**/*.mode1v3 -**/ios/**/*.mode2v3 -**/ios/**/*.moved-aside -**/ios/**/*.pbxuser -**/ios/**/*.perspectivev3 -**/ios/**/*sync/ -**/ios/**/.sconsign.dblite -**/ios/**/.tags* -**/ios/**/.vagrant/ -**/ios/**/DerivedData/ -**/ios/**/Icon? -**/ios/**/Pods/ -**/ios/**/.symlinks/ -**/ios/**/profile -**/ios/**/xcuserdata -**/ios/.generated/ -**/ios/Flutter/App.framework -**/ios/Flutter/Flutter.framework -**/ios/Flutter/Flutter.podspec -**/ios/Flutter/Generated.xcconfig -**/ios/Flutter/app.flx -**/ios/Flutter/app.zip -**/ios/Flutter/flutter_assets/ -**/ios/Flutter/flutter_export_environment.sh -**/ios/ServiceDefinitions.json -**/ios/Runner/GeneratedPluginRegistrant.* - -# Exceptions to above rules. -!**/ios/**/default.mode1v3 -!**/ios/**/default.mode2v3 -!**/ios/**/default.pbxuser -!**/ios/**/default.perspectivev3 diff --git a/packages/share_plus/share_plus_windows/.metadata b/packages/share_plus/share_plus_windows/.metadata deleted file mode 100644 index c05ad03edc..0000000000 --- a/packages/share_plus/share_plus_windows/.metadata +++ /dev/null @@ -1,10 +0,0 @@ -# This file tracks properties of this Flutter project. -# Used by Flutter tool to assess capabilities and perform upgrades etc. -# -# This file should be version controlled and should not be manually edited. - -version: - revision: 9d7bdb5903bc7149b415bf268fa3c6413355e7ad - channel: master - -project_type: package diff --git a/packages/share_plus/share_plus_windows/CHANGELOG.md b/packages/share_plus/share_plus_windows/CHANGELOG.md deleted file mode 100644 index cd4dd89e54..0000000000 --- a/packages/share_plus/share_plus_windows/CHANGELOG.md +++ /dev/null @@ -1,40 +0,0 @@ -## 4.0.0 - -> Note: This release has breaking changes. - - - **FIX**: Share.shareXFiles resulting in stack-overflow on Windows & Linux (#1186). - - **BREAKING** **FEAT**: Native share UI for Windows (#1158). - -## 3.0.1 - -- Update dependencies -- Fix analyzer warnings -- Update `urlLauncher` and replace deprecated `launch` calls - -## 3.0.0 - -- Bump dependencies - -## 2.0.3 - -- Hotfix on 2.0.2, improved solution. - -## 2.0.2 - -- Fixes: share URL is constructed incorrectly #235 - -## 2.0.1 - -- Improve documentation - -## 2.0.0 - -- Migrated to null safety - -## 0.1.0 - -- Transfer to plus-plugins monorepo - -## 0.0.1 - -- Initial Windows support. diff --git a/packages/share_plus/share_plus_windows/LICENSE b/packages/share_plus/share_plus_windows/LICENSE deleted file mode 100644 index 484084f72d..0000000000 --- a/packages/share_plus/share_plus_windows/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2020 The Flutter Community Plus Plugin Authors - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/packages/share_plus/share_plus_windows/README.md b/packages/share_plus/share_plus_windows/README.md deleted file mode 100644 index 9a8710f76b..0000000000 --- a/packages/share_plus/share_plus_windows/README.md +++ /dev/null @@ -1,12 +0,0 @@ -# Share Plus Windows - -[![Flutter Community: share_plus_windows](https://fluttercommunity.dev/_github/header/share_plus_windows)](https://github.com/fluttercommunity/community) - -[![pub package](https://img.shields.io/pub/v/share_plus_windows.svg)](https://pub.dev/packages/share_plus_windows) - -The Windows implementation of [`share_plus`](https://pub.dev/packages/share_plus). - -## Usage - -This package is already included as part of the `share_plus` package dependency, and will -be included when using `share_plus` as normal. diff --git a/packages/share_plus/share_plus_windows/pubspec.yaml b/packages/share_plus/share_plus_windows/pubspec.yaml deleted file mode 100644 index a148de70d7..0000000000 --- a/packages/share_plus/share_plus_windows/pubspec.yaml +++ /dev/null @@ -1,33 +0,0 @@ -name: share_plus_windows -description: Windows implementation of the share_plus plugin -version: 4.0.0 -homepage: https://plus.fluttercommunity.dev/ -repository: https://github.com/fluttercommunity/plus_plugins/tree/main/packages/ - -environment: - sdk: ">=2.12.0 <3.0.0" - flutter: ">=1.20.0" - -dependencies: - cross_file: ^0.3.3+2 - share_plus_platform_interface: ^3.0.2 - flutter: - sdk: flutter - meta: ^1.7.0 - url_launcher: ^6.1.2 - ffi: ^2.0.1 - win32: ^3.0.0 - -dev_dependencies: - flutter_test: - sdk: flutter - flutter_lints: ^2.0.1 - url_launcher_platform_interface: ^2.0.2 - -flutter: - plugin: - implements: share_plus - platforms: - windows: - dartPluginClass: ShareWindows - pluginClass: SharePlusWindowsPluginCApi From 950e02f2f195c2f14e5dbbf5741413d53ffd4f79 Mon Sep 17 00:00:00 2001 From: Joachim Nohl <43643339+nohli@users.noreply.github.com> Date: Thu, 13 Oct 2022 18:32:06 +0200 Subject: [PATCH 5/9] Add conditional export --- packages/share_plus/share_plus/lib/share_plus.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/share_plus/share_plus/lib/share_plus.dart b/packages/share_plus/share_plus/lib/share_plus.dart index ac8266ab4c..5359e2beb0 100644 --- a/packages/share_plus/share_plus/lib/share_plus.dart +++ b/packages/share_plus/share_plus/lib/share_plus.dart @@ -11,8 +11,8 @@ import 'package:share_plus_platform_interface/share_plus_platform_interface.dart export 'package:share_plus_platform_interface/share_plus_platform_interface.dart' show ShareResult, ShareResultStatus; -export 'src/share_plus_linux.dart'; -export 'src/share_plus_web.dart'; +export 'src/share_plus_linux.dart' + if (dart.library.html) 'src/share_plus_web.dart'; /// Plugin for summoning a platform share sheet. class Share { From 885a49f3c08195457c1cb58630e05622a20c6793 Mon Sep 17 00:00:00 2001 From: Joachim Nohl <43643339+nohli@users.noreply.github.com> Date: Thu, 13 Oct 2022 18:46:20 +0200 Subject: [PATCH 6/9] Add share_plus_windows.dart export --- packages/share_plus/share_plus/lib/share_plus.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/share_plus/share_plus/lib/share_plus.dart b/packages/share_plus/share_plus/lib/share_plus.dart index 5359e2beb0..52d667f27f 100644 --- a/packages/share_plus/share_plus/lib/share_plus.dart +++ b/packages/share_plus/share_plus/lib/share_plus.dart @@ -11,7 +11,8 @@ import 'package:share_plus_platform_interface/share_plus_platform_interface.dart export 'package:share_plus_platform_interface/share_plus_platform_interface.dart' show ShareResult, ShareResultStatus; -export 'src/share_plus_linux.dart' +export 'src/share_plus_linux.dart'; +export 'src/share_plus_windows.dart' if (dart.library.html) 'src/share_plus_web.dart'; /// Plugin for summoning a platform share sheet. From e7332f470ed9daa0f98cb6e80d14916fcf615cd9 Mon Sep 17 00:00:00 2001 From: Miguel Beltran Date: Fri, 14 Oct 2022 15:52:10 +0200 Subject: [PATCH 7/9] fix: remove duplicated dep --- packages/share_plus/share_plus/example/pubspec.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/share_plus/share_plus/example/pubspec.yaml b/packages/share_plus/share_plus/example/pubspec.yaml index 6e85b43321..4d029287dc 100644 --- a/packages/share_plus/share_plus/example/pubspec.yaml +++ b/packages/share_plus/share_plus/example/pubspec.yaml @@ -21,8 +21,6 @@ dev_dependencies: integration_test: sdk: flutter flutter_lints: ^2.0.1 - flutter_test: - sdk: flutter flutter: uses-material-design: true From 9b6a0d878f7386d4216ba8a087175c2a5b446559 Mon Sep 17 00:00:00 2001 From: Miguel Beltran Date: Fri, 14 Oct 2022 16:06:17 +0200 Subject: [PATCH 8/9] fix: windows build --- .../example/ios/Flutter/Flutter.podspec | 18 -- .../share_plus/windows/CMakeLists.txt | 12 +- .../share_plus_windows_plugin_c_api.h | 23 -- .../windows/share_plus_windows_plugin.cpp | 269 ------------------ .../share_plus_windows_plugin_c_api.cpp | 12 - 5 files changed, 6 insertions(+), 328 deletions(-) delete mode 100644 packages/share_plus/share_plus/example/ios/Flutter/Flutter.podspec delete mode 100644 packages/share_plus/share_plus/windows/include/share_plus_windows/share_plus_windows_plugin_c_api.h delete mode 100644 packages/share_plus/share_plus/windows/share_plus_windows_plugin.cpp delete mode 100644 packages/share_plus/share_plus/windows/share_plus_windows_plugin_c_api.cpp diff --git a/packages/share_plus/share_plus/example/ios/Flutter/Flutter.podspec b/packages/share_plus/share_plus/example/ios/Flutter/Flutter.podspec deleted file mode 100644 index 663d5b2985..0000000000 --- a/packages/share_plus/share_plus/example/ios/Flutter/Flutter.podspec +++ /dev/null @@ -1,18 +0,0 @@ -# -# NOTE: This podspec is NOT to be published. It is only used as a local source! -# This is a generated file; do not edit or check into version control. -# - -Pod::Spec.new do |s| - s.name = 'Flutter' - s.version = '1.0.0' - s.summary = 'High-performance, high-fidelity mobile apps.' - s.homepage = 'https://flutter.io' - s.license = { :type => 'MIT' } - s.author = { 'Flutter Dev Team' => 'flutter-dev@googlegroups.com' } - s.source = { :git => 'https://github.com/flutter/engine', :tag => s.version.to_s } - s.ios.deployment_target = '9.0' - # Framework linking is handled by Flutter tooling, not CocoaPods. - # Add a placeholder to satisfy `s.dependency 'Flutter'` plugin podspecs. - s.vendored_frameworks = 'path/to/nothing' -end diff --git a/packages/share_plus/share_plus/windows/CMakeLists.txt b/packages/share_plus/share_plus/windows/CMakeLists.txt index d218cc0e2d..de33928673 100644 --- a/packages/share_plus/share_plus/windows/CMakeLists.txt +++ b/packages/share_plus/share_plus/windows/CMakeLists.txt @@ -5,24 +5,24 @@ cmake_minimum_required(VERSION 3.14) # Project-level configuration. -set(PROJECT_NAME "share_plus_windows") +set(PROJECT_NAME "share_plus") project(${PROJECT_NAME} LANGUAGES CXX) # This value is used when generating builds using this plugin, so it must # not be changed -set(PLUGIN_NAME "share_plus_windows_plugin") +set(PLUGIN_NAME "share_plus_plugin") # Any new source files that you add to the plugin should be added here. list(APPEND PLUGIN_SOURCES - "share_plus_windows_plugin.cpp" + "share_plus_plugin.cpp" "share_plus_windows_plugin.h" ) # Define the plugin library target. Its name must not be changed (see comment # on PLUGIN_NAME above). add_library(${PLUGIN_NAME} SHARED - "include/share_plus_windows/share_plus_windows_plugin_c_api.h" - "share_plus_windows_plugin_c_api.cpp" + "include/share_plus/share_plus_windows_plugin_c_api.h" + "share_plus_plugin_c_api.cpp" ${PLUGIN_SOURCES} ) @@ -47,7 +47,7 @@ target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin) # List of absolute paths to libraries that should be bundled with the plugin. # This list could contain prebuilt libraries, or libraries created by an # external build triggered from this build file. -set(share_plus_windows_bundled_libraries +set(share_plus_bundled_libraries "" PARENT_SCOPE ) diff --git a/packages/share_plus/share_plus/windows/include/share_plus_windows/share_plus_windows_plugin_c_api.h b/packages/share_plus/share_plus/windows/include/share_plus_windows/share_plus_windows_plugin_c_api.h deleted file mode 100644 index 760ce9a727..0000000000 --- a/packages/share_plus/share_plus/windows/include/share_plus_windows/share_plus_windows_plugin_c_api.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef FLUTTER_PLUGIN_SHARE_PLUS_WINDOWS_PLUGIN_C_API_H_ -#define FLUTTER_PLUGIN_SHARE_PLUS_WINDOWS_PLUGIN_C_API_H_ - -#include - -#ifdef FLUTTER_PLUGIN_IMPL -#define FLUTTER_PLUGIN_EXPORT __declspec(dllexport) -#else -#define FLUTTER_PLUGIN_EXPORT __declspec(dllimport) -#endif - -#if defined(__cplusplus) -extern "C" { -#endif - -FLUTTER_PLUGIN_EXPORT void SharePlusWindowsPluginCApiRegisterWithRegistrar( - FlutterDesktopPluginRegistrarRef registrar); - -#if defined(__cplusplus) -} // extern "C" -#endif - -#endif // FLUTTER_PLUGIN_SHARE_PLUS_WINDOWS_PLUGIN_C_API_H_ diff --git a/packages/share_plus/share_plus/windows/share_plus_windows_plugin.cpp b/packages/share_plus/share_plus/windows/share_plus_windows_plugin.cpp deleted file mode 100644 index 686cde4985..0000000000 --- a/packages/share_plus/share_plus/windows/share_plus_windows_plugin.cpp +++ /dev/null @@ -1,269 +0,0 @@ -#include "share_plus_windows_plugin.h" - -#include -#include -#include - -#include "vector.h" - -namespace share_plus_windows { - -void SharePlusWindowsPlugin::RegisterWithRegistrar( - flutter::PluginRegistrarWindows *registrar) { - auto channel = - std::make_unique>( - registrar->messenger(), kSharePlusChannelName, - &flutter::StandardMethodCodec::GetInstance()); - auto plugin = std::make_unique(registrar); - channel->SetMethodCallHandler( - [plugin_pointer = plugin.get()](const auto &call, auto result) { - plugin_pointer->HandleMethodCall(call, std::move(result)); - }); - - registrar->AddPlugin(std::move(plugin)); -} - -SharePlusWindowsPlugin::SharePlusWindowsPlugin( - flutter::PluginRegistrarWindows *registrar) - : registrar_(registrar) {} - -SharePlusWindowsPlugin::~SharePlusWindowsPlugin() { - if (data_transfer_manager_ != nullptr) { - data_transfer_manager_->remove_DataRequested(data_transfer_manager_token_); - data_transfer_manager_.Reset(); - } - if (data_transfer_manager_interop_ != nullptr) { - data_transfer_manager_interop_.Reset(); - } -} - -HWND SharePlusWindowsPlugin::GetWindow() { - return ::GetAncestor(registrar_->GetView()->GetNativeWindow(), GA_ROOT); -} - -WRL::ComPtr -SharePlusWindowsPlugin::GetDataTransferManager() { - using Microsoft::WRL::Wrappers::HStringReference; - ::RoGetActivationFactory( - HStringReference( - RuntimeClass_Windows_ApplicationModel_DataTransfer_DataTransferManager) - .Get(), - IID_PPV_ARGS(&data_transfer_manager_interop_)); - data_transfer_manager_interop_->GetForWindow( - GetWindow(), IID_PPV_ARGS(&data_transfer_manager_)); - return data_transfer_manager_; -} - -HRESULT SharePlusWindowsPlugin::GetStorageFileFromPath( - wchar_t *path, WindowsStorage::IStorageFile **file) { - using Microsoft::WRL::Wrappers::HStringReference; - WRL::ComPtr factory = nullptr; - HRESULT hr = S_OK; - *file = nullptr; - if (!factory) { - hr = WindowsFoundation::GetActivationFactory( - HStringReference(RuntimeClass_Windows_Storage_StorageFile).Get(), - &factory); - } - if (SUCCEEDED(hr)) { - WRL::ComPtr< - WindowsFoundation::IAsyncOperation> - async_operation; - hr = factory->GetFileFromPathAsync(HStringReference(path).Get(), - &async_operation); - if (SUCCEEDED(hr)) { - WRL::ComPtr info; - hr = async_operation.As(&info); - if (SUCCEEDED(hr)) { - AsyncStatus status; - while (SUCCEEDED(hr = info->get_Status(&status)) && - status == AsyncStatus::Started) - SleepEx(0, TRUE); - if (FAILED(hr) || status != AsyncStatus::Completed) { - info->get_ErrorCode(&hr); - } else { - async_operation->GetResults(file); - } - } - } - } - return hr; -} - -void SharePlusWindowsPlugin::HandleMethodCall( - const flutter::MethodCall &method_call, - std::unique_ptr> result) { - if (method_call.method_name().compare(kShare) == 0 || - method_call.method_name().compare(kShareWithResult) == 0) { - auto is_result_requested = - method_call.method_name().compare(kShareWithResult) == 0; - auto data_transfer_manager = GetDataTransferManager(); - auto args = std::get(*method_call.arguments()); - if (auto text_value = - std::get_if(&args[flutter::EncodableValue("text")])) { - share_text_ = *text_value; - } - if (auto subject_value = std::get_if( - &args[flutter::EncodableValue("subject")])) { - share_subject_ = *subject_value; - } - auto callback = WRL::Callback>( - [&](auto &&, DataTransfer::IDataRequestedEventArgs *e) { - using Microsoft::WRL::Wrappers::HStringReference; - WRL::ComPtr request; - e->get_Request(&request); - WRL::ComPtr data; - request->get_Data(&data); - WRL::ComPtr properties; - data->get_Properties(&properties); - // The title is mandatory for Windows. - // Using |share_text_| as title. - auto text = Utf16FromUtf8(share_text_); - properties->put_Title(HStringReference(text.c_str()).Get()); - // If |share_subject_| is available, then set it as text since - // |share_text_| is already set as title. - if (share_subject_ && !share_subject_.value_or("").empty()) { - auto subject = Utf16FromUtf8(share_subject_.value_or("")); - properties->put_Description( - HStringReference(subject.c_str()).Get()); - data->SetText(HStringReference(subject.c_str()).Get()); - } - // If |share_subject_| is not available, then use |share_text_| as - // text aswell. - else { - data->SetText(HStringReference(text.c_str()).Get()); - } - return S_OK; - }); - data_transfer_manager->add_DataRequested(callback.Get(), - &data_transfer_manager_token_); - if (data_transfer_manager_interop_ != nullptr) { - data_transfer_manager_interop_->ShowShareUIForWindow(GetWindow()); - } - if (is_result_requested) { - result->Success(flutter::EncodableValue(kShareResultUnavailable)); - } else { - result->Success(flutter::EncodableValue()); - } - } else if (method_call.method_name().compare(kShareFiles) == 0 || - method_call.method_name().compare(kShareFilesWithResult) == 0) { - auto is_result_requested = - method_call.method_name().compare(kShareFilesWithResult) == 0; - auto data_transfer_manager = GetDataTransferManager(); - auto args = std::get(*method_call.arguments()); - if (auto text_value = - std::get_if(&args[flutter::EncodableValue("text")])) { - share_text_ = *text_value; - } - if (auto subject_value = std::get_if( - &args[flutter::EncodableValue("subject")])) { - share_subject_ = *subject_value; - } - if (auto paths = std::get_if( - &args[flutter::EncodableValue("paths")])) { - paths_.clear(); - for (auto &path : *paths) { - paths_.emplace_back(std::get(path)); - } - } - if (auto mime_types = std::get_if( - &args[flutter::EncodableValue("mimeTypes")])) { - mime_types_.clear(); - for (auto &mime_type : *mime_types) { - mime_types_.emplace_back(std::get(mime_type)); - } - } - auto callback = WRL::Callback>( - [&](auto &&, DataTransfer::IDataRequestedEventArgs *e) { - using Microsoft::WRL::Wrappers::HStringReference; - WRL::ComPtr request; - e->get_Request(&request); - WRL::ComPtr data; - request->get_Data(&data); - WRL::ComPtr properties; - data->get_Properties(&properties); - // The title is mandatory for Windows. - // Using |share_text_| as title if available. - if (!share_text_.empty()) { - auto text = Utf16FromUtf8(share_text_); - properties->put_Title(HStringReference(text.c_str()).Get()); - } - // Or use the file count string as title if there are multiple - // files & use the file name if a single file is shared. - // Same behavior may be seen in File Explorer. - else { - if (paths_.size() > 1) { - auto title = std::to_wstring(paths_.size()) + L" files"; - properties->put_Title(HStringReference(title.c_str()).Get()); - } else if (paths_.size() == 1) { - auto title = Utf16FromUtf8(paths_.front()); - properties->put_Title(HStringReference(title.c_str()).Get()); - } - } - // If |share_subject_| is available, then set it as text since - // |share_text_| is already set as title. - if (share_subject_ && !share_subject_.value_or("").empty()) { - auto subject = Utf16FromUtf8(share_subject_.value_or("")); - properties->put_Description( - HStringReference(subject.c_str()).Get()); - data->SetText(HStringReference(subject.c_str()).Get()); - } - // If |share_subject_| is not available, then use |share_text_| as - // text aswell. - else if (!share_text_.empty()) { - auto text = Utf16FromUtf8(share_text_); - data->SetText(HStringReference(text.c_str()).Get()); - } - // Add files to the data. - Vector storage_items; - for (const std::string &path : paths_) { - auto str = Utf16FromUtf8(path); - wchar_t *ptr = const_cast(str.c_str()); - WindowsStorage::IStorageFile *file = nullptr; - if (SUCCEEDED(GetStorageFileFromPath(ptr, &file)) && - file != nullptr) { - storage_items.Append( - reinterpret_cast(file)); - } - } - data->SetStorageItemsReadOnly(&storage_items); - return S_OK; - }); - data_transfer_manager->add_DataRequested(callback.Get(), - &data_transfer_manager_token_); - if (data_transfer_manager_interop_ != nullptr) { - data_transfer_manager_interop_->ShowShareUIForWindow(GetWindow()); - } - if (is_result_requested) { - result->Success(flutter::EncodableValue(kShareResultUnavailable)); - } else { - result->Success(flutter::EncodableValue()); - } - } else { - result->NotImplemented(); - } -} - -// Converts string encoded in UTF-8 to wstring. -// Returns an empty |std::wstring| on failure. -// Present as static helper method. -std::wstring SharePlusWindowsPlugin::Utf16FromUtf8(std::string string) { - int size_needed = - MultiByteToWideChar(CP_UTF8, 0, string.c_str(), -1, NULL, 0); - if (size_needed == 0) { - return std::wstring(); - } - std::wstring result(size_needed, 0); - int converted_length = MultiByteToWideChar(CP_UTF8, 0, string.c_str(), -1, - &result[0], size_needed); - if (converted_length == 0) { - return std::wstring(); - } - return result; -} - -} // namespace share_plus_windows diff --git a/packages/share_plus/share_plus/windows/share_plus_windows_plugin_c_api.cpp b/packages/share_plus/share_plus/windows/share_plus_windows_plugin_c_api.cpp deleted file mode 100644 index 8237a1b8fb..0000000000 --- a/packages/share_plus/share_plus/windows/share_plus_windows_plugin_c_api.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "include/share_plus_windows/share_plus_windows_plugin_c_api.h" - -#include - -#include "share_plus_windows_plugin.h" - -void SharePlusWindowsPluginCApiRegisterWithRegistrar( - FlutterDesktopPluginRegistrarRef registrar) { - share_plus_windows::SharePlusWindowsPlugin::RegisterWithRegistrar( - flutter::PluginRegistrarManager::GetInstance() - ->GetRegistrar(registrar)); -} From 77a553c4a36ad922e7ecf40d23f07235dd718d3c Mon Sep 17 00:00:00 2001 From: Miguel Beltran Date: Fri, 14 Oct 2022 16:12:54 +0200 Subject: [PATCH 9/9] fix: commit missing files --- .../share_plus_windows_plugin_c_api.h | 23 ++ .../share_plus/windows/share_plus_plugin.cpp | 269 ++++++++++++++++++ .../windows/share_plus_plugin_c_api.cpp | 12 + 3 files changed, 304 insertions(+) create mode 100644 packages/share_plus/share_plus/windows/include/share_plus/share_plus_windows_plugin_c_api.h create mode 100644 packages/share_plus/share_plus/windows/share_plus_plugin.cpp create mode 100644 packages/share_plus/share_plus/windows/share_plus_plugin_c_api.cpp diff --git a/packages/share_plus/share_plus/windows/include/share_plus/share_plus_windows_plugin_c_api.h b/packages/share_plus/share_plus/windows/include/share_plus/share_plus_windows_plugin_c_api.h new file mode 100644 index 0000000000..760ce9a727 --- /dev/null +++ b/packages/share_plus/share_plus/windows/include/share_plus/share_plus_windows_plugin_c_api.h @@ -0,0 +1,23 @@ +#ifndef FLUTTER_PLUGIN_SHARE_PLUS_WINDOWS_PLUGIN_C_API_H_ +#define FLUTTER_PLUGIN_SHARE_PLUS_WINDOWS_PLUGIN_C_API_H_ + +#include + +#ifdef FLUTTER_PLUGIN_IMPL +#define FLUTTER_PLUGIN_EXPORT __declspec(dllexport) +#else +#define FLUTTER_PLUGIN_EXPORT __declspec(dllimport) +#endif + +#if defined(__cplusplus) +extern "C" { +#endif + +FLUTTER_PLUGIN_EXPORT void SharePlusWindowsPluginCApiRegisterWithRegistrar( + FlutterDesktopPluginRegistrarRef registrar); + +#if defined(__cplusplus) +} // extern "C" +#endif + +#endif // FLUTTER_PLUGIN_SHARE_PLUS_WINDOWS_PLUGIN_C_API_H_ diff --git a/packages/share_plus/share_plus/windows/share_plus_plugin.cpp b/packages/share_plus/share_plus/windows/share_plus_plugin.cpp new file mode 100644 index 0000000000..686cde4985 --- /dev/null +++ b/packages/share_plus/share_plus/windows/share_plus_plugin.cpp @@ -0,0 +1,269 @@ +#include "share_plus_windows_plugin.h" + +#include +#include +#include + +#include "vector.h" + +namespace share_plus_windows { + +void SharePlusWindowsPlugin::RegisterWithRegistrar( + flutter::PluginRegistrarWindows *registrar) { + auto channel = + std::make_unique>( + registrar->messenger(), kSharePlusChannelName, + &flutter::StandardMethodCodec::GetInstance()); + auto plugin = std::make_unique(registrar); + channel->SetMethodCallHandler( + [plugin_pointer = plugin.get()](const auto &call, auto result) { + plugin_pointer->HandleMethodCall(call, std::move(result)); + }); + + registrar->AddPlugin(std::move(plugin)); +} + +SharePlusWindowsPlugin::SharePlusWindowsPlugin( + flutter::PluginRegistrarWindows *registrar) + : registrar_(registrar) {} + +SharePlusWindowsPlugin::~SharePlusWindowsPlugin() { + if (data_transfer_manager_ != nullptr) { + data_transfer_manager_->remove_DataRequested(data_transfer_manager_token_); + data_transfer_manager_.Reset(); + } + if (data_transfer_manager_interop_ != nullptr) { + data_transfer_manager_interop_.Reset(); + } +} + +HWND SharePlusWindowsPlugin::GetWindow() { + return ::GetAncestor(registrar_->GetView()->GetNativeWindow(), GA_ROOT); +} + +WRL::ComPtr +SharePlusWindowsPlugin::GetDataTransferManager() { + using Microsoft::WRL::Wrappers::HStringReference; + ::RoGetActivationFactory( + HStringReference( + RuntimeClass_Windows_ApplicationModel_DataTransfer_DataTransferManager) + .Get(), + IID_PPV_ARGS(&data_transfer_manager_interop_)); + data_transfer_manager_interop_->GetForWindow( + GetWindow(), IID_PPV_ARGS(&data_transfer_manager_)); + return data_transfer_manager_; +} + +HRESULT SharePlusWindowsPlugin::GetStorageFileFromPath( + wchar_t *path, WindowsStorage::IStorageFile **file) { + using Microsoft::WRL::Wrappers::HStringReference; + WRL::ComPtr factory = nullptr; + HRESULT hr = S_OK; + *file = nullptr; + if (!factory) { + hr = WindowsFoundation::GetActivationFactory( + HStringReference(RuntimeClass_Windows_Storage_StorageFile).Get(), + &factory); + } + if (SUCCEEDED(hr)) { + WRL::ComPtr< + WindowsFoundation::IAsyncOperation> + async_operation; + hr = factory->GetFileFromPathAsync(HStringReference(path).Get(), + &async_operation); + if (SUCCEEDED(hr)) { + WRL::ComPtr info; + hr = async_operation.As(&info); + if (SUCCEEDED(hr)) { + AsyncStatus status; + while (SUCCEEDED(hr = info->get_Status(&status)) && + status == AsyncStatus::Started) + SleepEx(0, TRUE); + if (FAILED(hr) || status != AsyncStatus::Completed) { + info->get_ErrorCode(&hr); + } else { + async_operation->GetResults(file); + } + } + } + } + return hr; +} + +void SharePlusWindowsPlugin::HandleMethodCall( + const flutter::MethodCall &method_call, + std::unique_ptr> result) { + if (method_call.method_name().compare(kShare) == 0 || + method_call.method_name().compare(kShareWithResult) == 0) { + auto is_result_requested = + method_call.method_name().compare(kShareWithResult) == 0; + auto data_transfer_manager = GetDataTransferManager(); + auto args = std::get(*method_call.arguments()); + if (auto text_value = + std::get_if(&args[flutter::EncodableValue("text")])) { + share_text_ = *text_value; + } + if (auto subject_value = std::get_if( + &args[flutter::EncodableValue("subject")])) { + share_subject_ = *subject_value; + } + auto callback = WRL::Callback>( + [&](auto &&, DataTransfer::IDataRequestedEventArgs *e) { + using Microsoft::WRL::Wrappers::HStringReference; + WRL::ComPtr request; + e->get_Request(&request); + WRL::ComPtr data; + request->get_Data(&data); + WRL::ComPtr properties; + data->get_Properties(&properties); + // The title is mandatory for Windows. + // Using |share_text_| as title. + auto text = Utf16FromUtf8(share_text_); + properties->put_Title(HStringReference(text.c_str()).Get()); + // If |share_subject_| is available, then set it as text since + // |share_text_| is already set as title. + if (share_subject_ && !share_subject_.value_or("").empty()) { + auto subject = Utf16FromUtf8(share_subject_.value_or("")); + properties->put_Description( + HStringReference(subject.c_str()).Get()); + data->SetText(HStringReference(subject.c_str()).Get()); + } + // If |share_subject_| is not available, then use |share_text_| as + // text aswell. + else { + data->SetText(HStringReference(text.c_str()).Get()); + } + return S_OK; + }); + data_transfer_manager->add_DataRequested(callback.Get(), + &data_transfer_manager_token_); + if (data_transfer_manager_interop_ != nullptr) { + data_transfer_manager_interop_->ShowShareUIForWindow(GetWindow()); + } + if (is_result_requested) { + result->Success(flutter::EncodableValue(kShareResultUnavailable)); + } else { + result->Success(flutter::EncodableValue()); + } + } else if (method_call.method_name().compare(kShareFiles) == 0 || + method_call.method_name().compare(kShareFilesWithResult) == 0) { + auto is_result_requested = + method_call.method_name().compare(kShareFilesWithResult) == 0; + auto data_transfer_manager = GetDataTransferManager(); + auto args = std::get(*method_call.arguments()); + if (auto text_value = + std::get_if(&args[flutter::EncodableValue("text")])) { + share_text_ = *text_value; + } + if (auto subject_value = std::get_if( + &args[flutter::EncodableValue("subject")])) { + share_subject_ = *subject_value; + } + if (auto paths = std::get_if( + &args[flutter::EncodableValue("paths")])) { + paths_.clear(); + for (auto &path : *paths) { + paths_.emplace_back(std::get(path)); + } + } + if (auto mime_types = std::get_if( + &args[flutter::EncodableValue("mimeTypes")])) { + mime_types_.clear(); + for (auto &mime_type : *mime_types) { + mime_types_.emplace_back(std::get(mime_type)); + } + } + auto callback = WRL::Callback>( + [&](auto &&, DataTransfer::IDataRequestedEventArgs *e) { + using Microsoft::WRL::Wrappers::HStringReference; + WRL::ComPtr request; + e->get_Request(&request); + WRL::ComPtr data; + request->get_Data(&data); + WRL::ComPtr properties; + data->get_Properties(&properties); + // The title is mandatory for Windows. + // Using |share_text_| as title if available. + if (!share_text_.empty()) { + auto text = Utf16FromUtf8(share_text_); + properties->put_Title(HStringReference(text.c_str()).Get()); + } + // Or use the file count string as title if there are multiple + // files & use the file name if a single file is shared. + // Same behavior may be seen in File Explorer. + else { + if (paths_.size() > 1) { + auto title = std::to_wstring(paths_.size()) + L" files"; + properties->put_Title(HStringReference(title.c_str()).Get()); + } else if (paths_.size() == 1) { + auto title = Utf16FromUtf8(paths_.front()); + properties->put_Title(HStringReference(title.c_str()).Get()); + } + } + // If |share_subject_| is available, then set it as text since + // |share_text_| is already set as title. + if (share_subject_ && !share_subject_.value_or("").empty()) { + auto subject = Utf16FromUtf8(share_subject_.value_or("")); + properties->put_Description( + HStringReference(subject.c_str()).Get()); + data->SetText(HStringReference(subject.c_str()).Get()); + } + // If |share_subject_| is not available, then use |share_text_| as + // text aswell. + else if (!share_text_.empty()) { + auto text = Utf16FromUtf8(share_text_); + data->SetText(HStringReference(text.c_str()).Get()); + } + // Add files to the data. + Vector storage_items; + for (const std::string &path : paths_) { + auto str = Utf16FromUtf8(path); + wchar_t *ptr = const_cast(str.c_str()); + WindowsStorage::IStorageFile *file = nullptr; + if (SUCCEEDED(GetStorageFileFromPath(ptr, &file)) && + file != nullptr) { + storage_items.Append( + reinterpret_cast(file)); + } + } + data->SetStorageItemsReadOnly(&storage_items); + return S_OK; + }); + data_transfer_manager->add_DataRequested(callback.Get(), + &data_transfer_manager_token_); + if (data_transfer_manager_interop_ != nullptr) { + data_transfer_manager_interop_->ShowShareUIForWindow(GetWindow()); + } + if (is_result_requested) { + result->Success(flutter::EncodableValue(kShareResultUnavailable)); + } else { + result->Success(flutter::EncodableValue()); + } + } else { + result->NotImplemented(); + } +} + +// Converts string encoded in UTF-8 to wstring. +// Returns an empty |std::wstring| on failure. +// Present as static helper method. +std::wstring SharePlusWindowsPlugin::Utf16FromUtf8(std::string string) { + int size_needed = + MultiByteToWideChar(CP_UTF8, 0, string.c_str(), -1, NULL, 0); + if (size_needed == 0) { + return std::wstring(); + } + std::wstring result(size_needed, 0); + int converted_length = MultiByteToWideChar(CP_UTF8, 0, string.c_str(), -1, + &result[0], size_needed); + if (converted_length == 0) { + return std::wstring(); + } + return result; +} + +} // namespace share_plus_windows diff --git a/packages/share_plus/share_plus/windows/share_plus_plugin_c_api.cpp b/packages/share_plus/share_plus/windows/share_plus_plugin_c_api.cpp new file mode 100644 index 0000000000..b33c00f915 --- /dev/null +++ b/packages/share_plus/share_plus/windows/share_plus_plugin_c_api.cpp @@ -0,0 +1,12 @@ +#include "include/share_plus/share_plus_windows_plugin_c_api.h" + +#include + +#include "share_plus_windows_plugin.h" + +void SharePlusWindowsPluginCApiRegisterWithRegistrar( + FlutterDesktopPluginRegistrarRef registrar) { + share_plus_windows::SharePlusWindowsPlugin::RegisterWithRegistrar( + flutter::PluginRegistrarManager::GetInstance() + ->GetRegistrar(registrar)); +}