From 26ed90f01953d40f17fbf8ec2f33646319429606 Mon Sep 17 00:00:00 2001 From: SirusCodes Date: Tue, 1 Nov 2022 23:09:36 +0530 Subject: [PATCH 1/7] fix(share_plus): revert to the older contruct for linux --- .../share_plus/share_plus/lib/src/share_plus_linux.dart | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) 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 a0f8531942..2ff4ffc780 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 @@ -40,11 +40,7 @@ class SharePlusLinuxPlugin extends SharePlatform { .join('&'), ); - if (await urlLauncher.canLaunch(uri.toString())) { - await urlLauncher.launchUrl(uri.toString(), const LaunchOptions()); - } else { - throw Exception('Unable to share on web'); - } + await urlLauncher.launchUrl(uri.toString(), const LaunchOptions()); } /// Share files. From 90b6cfb8baa4cba7828eac10ea60c3526e5f0d41 Mon Sep 17 00:00:00 2001 From: SirusCodes Date: Tue, 1 Nov 2022 23:36:11 +0530 Subject: [PATCH 2/7] feat(share_plus): remove `canLaunch` check for win and web --- packages/share_plus/share_plus/lib/src/share_plus_web.dart | 6 +----- .../share_plus/share_plus/lib/src/share_plus_windows.dart | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) 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 f1bad19f94..41e30efd59 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 @@ -50,11 +50,7 @@ class SharePlusWebPlugin extends SharePlatform { .join('&'), ); - if (await urlLauncher.canLaunch(uri.toString())) { - await urlLauncher.launchUrl(uri.toString(), const LaunchOptions()); - } else { - throw Exception('Unable to share on web'); - } + await urlLauncher.launchUrl(uri.toString(), const LaunchOptions()); } } 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 bc850b9252..c292710588 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 @@ -44,11 +44,7 @@ class SharePlusWindowsPlugin extends SharePlatform { .join('&'), ); - if (await urlLauncher.canLaunch(uri.toString())) { - await urlLauncher.launchUrl(uri.toString(), const LaunchOptions()); - } else { - throw Exception('Unable to share on windows'); - } + await urlLauncher.launchUrl(uri.toString(), const LaunchOptions()); } /// Share files. From bfa14da2d18f29edad1a709f6a603468234e1bbe Mon Sep 17 00:00:00 2001 From: Miguel Beltran Date: Wed, 2 Nov 2022 07:29:01 +0100 Subject: [PATCH 3/7] handle launchUrl result and throw if fail --- .../share_plus/share_plus/lib/src/share_plus_linux.dart | 9 +++++++-- .../share_plus/share_plus/lib/src/share_plus_web.dart | 8 +++++++- .../share_plus/lib/src/share_plus_windows.dart | 9 ++++++++- 3 files changed, 22 insertions(+), 4 deletions(-) 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 2ff4ffc780..90cda537f2 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 @@ -19,7 +19,6 @@ class SharePlusLinuxPlugin extends SharePlatform { } /// Share text. - /// Throws a [PlatformException] if `mailto:` scheme cannot be handled. @override Future share( String text, { @@ -40,7 +39,13 @@ class SharePlusLinuxPlugin extends SharePlatform { .join('&'), ); - await urlLauncher.launchUrl(uri.toString(), const LaunchOptions()); + final launchResult = await urlLauncher.launchUrl( + uri.toString(), + const LaunchOptions(), + ); + if (!launchResult) { + throw Exception('Failed to launch mailto: URI'); + } } /// Share files. 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 41e30efd59..a90af064f8 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 @@ -50,7 +50,13 @@ class SharePlusWebPlugin extends SharePlatform { .join('&'), ); - await urlLauncher.launchUrl(uri.toString(), const LaunchOptions()); + final launchResult = await urlLauncher.launchUrl( + uri.toString(), + const LaunchOptions(), + ); + if (!launchResult) { + throw Exception('Failed to launch mailto: URI'); + } } } 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 c292710588..e673d85965 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 @@ -3,6 +3,7 @@ library share_plus_windows; import 'dart:ui'; +import 'package:flutter/services.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_platform_interface/url_launcher_platform_interface.dart'; @@ -44,7 +45,13 @@ class SharePlusWindowsPlugin extends SharePlatform { .join('&'), ); - await urlLauncher.launchUrl(uri.toString(), const LaunchOptions()); + final launchResult = await urlLauncher.launchUrl( + uri.toString(), + const LaunchOptions(), + ); + if (!launchResult) { + throw Exception('Failed to launch mailto: URI'); + } } /// Share files. From de129d19b1a41f6baec5925de9f210807aad345a Mon Sep 17 00:00:00 2001 From: Miguel Beltran Date: Wed, 2 Nov 2022 07:34:28 +0100 Subject: [PATCH 4/7] fix test mock --- .../test/share_plus_linux_test.dart | 33 ++----------------- .../test/share_plus_windows_test.dart | 30 ++--------------- .../share_plus/test/url_launcher_mock.dart | 30 +++++++++++++++++ 3 files changed, 34 insertions(+), 59 deletions(-) create mode 100644 packages/share_plus/share_plus/test/url_launcher_mock.dart 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 e0800edccd..f879a7c817 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 @@ -4,6 +4,8 @@ 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'; +import 'url_launcher_mock.dart'; + void main() { test('registered instance', () { SharePlusLinuxPlugin.registerWith(); @@ -34,34 +36,3 @@ void main() { throwsException); }); } - -class MockUrlLauncherPlatform extends UrlLauncherPlatform { - String? url; - bool canLaunchMockValue = true; - - @override - LinkDelegate? get linkDelegate => throw UnimplementedError(); - - @override - Future canLaunch(String url) async { - return canLaunchMockValue; - } - - @override - Future launch( - String url, { - required bool useSafariVC, - required bool useWebView, - required bool enableJavaScript, - required bool enableDomStorage, - required bool universalLinksOnly, - required Map headers, - String? webOnlyWindowName, - }) async { - this.url = url; - if (!canLaunchMockValue) { - throw Exception(); - } - return true; - } -} 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 0f77ee6181..9208982c8c 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 @@ -6,6 +6,8 @@ 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'; +import 'url_launcher_mock.dart'; + void main() { test( 'registered instance', @@ -64,31 +66,3 @@ void main() { skip: VersionHelper.instance.isWindows10RS5OrGreater, ); } - -class MockUrlLauncherPlatform extends UrlLauncherPlatform { - String? url; - bool canLaunchMockValue = true; - - @override - LinkDelegate? get linkDelegate => throw UnimplementedError(); - - @override - Future canLaunch(String url) async { - return canLaunchMockValue; - } - - @override - Future launch( - String url, { - required bool useSafariVC, - required bool useWebView, - required bool enableJavaScript, - required bool enableDomStorage, - required bool universalLinksOnly, - required Map headers, - String? webOnlyWindowName, - }) async { - this.url = url; - return true; - } -} diff --git a/packages/share_plus/share_plus/test/url_launcher_mock.dart b/packages/share_plus/share_plus/test/url_launcher_mock.dart new file mode 100644 index 0000000000..a3c23a1d29 --- /dev/null +++ b/packages/share_plus/share_plus/test/url_launcher_mock.dart @@ -0,0 +1,30 @@ +import 'package:url_launcher_platform_interface/link.dart'; +import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart'; + +class MockUrlLauncherPlatform extends UrlLauncherPlatform { + String? url; + bool canLaunchMockValue = true; + + @override + LinkDelegate? get linkDelegate => throw UnimplementedError(); + + @override + Future canLaunch(String url) async { + return canLaunchMockValue; + } + + @override + Future launch( + String url, { + required bool useSafariVC, + required bool useWebView, + required bool enableJavaScript, + required bool enableDomStorage, + required bool universalLinksOnly, + required Map headers, + String? webOnlyWindowName, + }) async { + this.url = url; + return canLaunchMockValue; + } +} From 8d3c20773ec505be11f2b1a6c47daed2bba040da Mon Sep 17 00:00:00 2001 From: Miguel Beltran Date: Wed, 2 Nov 2022 07:41:34 +0100 Subject: [PATCH 5/7] code formatting --- .../share_plus/test/url_launcher_mock.dart | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/share_plus/share_plus/test/url_launcher_mock.dart b/packages/share_plus/share_plus/test/url_launcher_mock.dart index a3c23a1d29..76b8026ef2 100644 --- a/packages/share_plus/share_plus/test/url_launcher_mock.dart +++ b/packages/share_plus/share_plus/test/url_launcher_mock.dart @@ -15,15 +15,15 @@ class MockUrlLauncherPlatform extends UrlLauncherPlatform { @override Future launch( - String url, { - required bool useSafariVC, - required bool useWebView, - required bool enableJavaScript, - required bool enableDomStorage, - required bool universalLinksOnly, - required Map headers, - String? webOnlyWindowName, - }) async { + String url, { + required bool useSafariVC, + required bool useWebView, + required bool enableJavaScript, + required bool enableDomStorage, + required bool universalLinksOnly, + required Map headers, + String? webOnlyWindowName, + }) async { this.url = url; return canLaunchMockValue; } From c4427dd6ca1fd511ceb18530fa0296b7de56f4ff Mon Sep 17 00:00:00 2001 From: SirusCodes Date: Thu, 3 Nov 2022 00:48:29 +0530 Subject: [PATCH 6/7] chores(share_plus): remove redundant import --- packages/share_plus/share_plus/lib/src/share_plus_windows.dart | 1 - 1 file changed, 1 deletion(-) 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 e673d85965..d18a26054e 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 @@ -3,7 +3,6 @@ library share_plus_windows; import 'dart:ui'; -import 'package:flutter/services.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_platform_interface/url_launcher_platform_interface.dart'; From 88ab02c178bafdd8cb64bce3755d397c8f4711ee Mon Sep 17 00:00:00 2001 From: Miguel Beltran Date: Mon, 7 Nov 2022 10:02:24 +0100 Subject: [PATCH 7/7] improved exception message --- packages/share_plus/share_plus/lib/src/share_plus_linux.dart | 2 +- packages/share_plus/share_plus/lib/src/share_plus_web.dart | 2 +- packages/share_plus/share_plus/lib/src/share_plus_windows.dart | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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 90cda537f2..f1cd13b7a7 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 @@ -44,7 +44,7 @@ class SharePlusLinuxPlugin extends SharePlatform { const LaunchOptions(), ); if (!launchResult) { - throw Exception('Failed to launch mailto: URI'); + throw Exception('Failed to launch $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 a90af064f8..562f318831 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 @@ -55,7 +55,7 @@ class SharePlusWebPlugin extends SharePlatform { const LaunchOptions(), ); if (!launchResult) { - throw Exception('Failed to launch mailto: URI'); + throw Exception('Failed to launch $uri'); } } } 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 d18a26054e..05f49880cb 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 @@ -49,7 +49,7 @@ class SharePlusWindowsPlugin extends SharePlatform { const LaunchOptions(), ); if (!launchResult) { - throw Exception('Failed to launch mailto: URI'); + throw Exception('Failed to launch $uri'); } }