From adc01f288695e62ff2e8844f5acea5d8a318411a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Palma?= Date: Thu, 25 Jun 2020 16:43:53 +0100 Subject: [PATCH 1/4] Adds tel --- packages/url_launcher/url_launcher/pubspec.yaml | 6 +++++- .../url_launcher/url_launcher_web/lib/url_launcher_web.dart | 3 ++- .../url_launcher_web/test/url_launcher_web_test.dart | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/url_launcher/url_launcher/pubspec.yaml b/packages/url_launcher/url_launcher/pubspec.yaml index 08ac3f9f8b80..525006022c26 100644 --- a/packages/url_launcher/url_launcher/pubspec.yaml +++ b/packages/url_launcher/url_launcher/pubspec.yaml @@ -26,7 +26,11 @@ dependencies: # validation, so we set a ^ constraint. # TODO(amirh): Revisit this (either update this part in the design or the pub tool). # https://github.com/flutter/flutter/issues/46264 - url_launcher_web: ^0.1.0+1 + url_launcher_web: + git: + url: https://github.com/Vanethos/plugins + ref: feature/add-tel-url + path: packages/url_launcher/url_launcher_web url_launcher_macos: ^0.0.1 dev_dependencies: diff --git a/packages/url_launcher/url_launcher_web/lib/url_launcher_web.dart b/packages/url_launcher/url_launcher_web/lib/url_launcher_web.dart index e55ceb2269bc..07bc851cd880 100644 --- a/packages/url_launcher/url_launcher_web/lib/url_launcher_web.dart +++ b/packages/url_launcher/url_launcher_web/lib/url_launcher_web.dart @@ -8,6 +8,7 @@ import 'package:url_launcher_platform_interface/url_launcher_platform_interface. import 'package:platform_detect/platform_detect.dart' show browser; const _mailtoScheme = 'mailto'; +const _phoneScheme = 'tel'; /// The web implementation of [UrlLauncherPlatform]. /// @@ -16,7 +17,7 @@ class UrlLauncherPlugin extends UrlLauncherPlatform { html.Window _window; // The set of schemes that can be handled by the plugin - static final _supportedSchemes = {'http', 'https', _mailtoScheme}; + static final _supportedSchemes = {'http', 'https', _mailtoScheme, _phoneScheme}; /// A constructor that allows tests to override the window object used by the plugin. UrlLauncherPlugin({@visibleForTesting html.Window window}) diff --git a/packages/url_launcher/url_launcher_web/test/url_launcher_web_test.dart b/packages/url_launcher/url_launcher_web/test/url_launcher_web_test.dart index 4cf92062e10f..7d50b7ff72b7 100644 --- a/packages/url_launcher/url_launcher_web/test/url_launcher_web_test.dart +++ b/packages/url_launcher/url_launcher_web/test/url_launcher_web_test.dart @@ -36,8 +36,8 @@ void main() { plugin.canLaunch('mailto:name@mydomain.com'), completion(isTrue)); }); - test('"tel" URLs -> false', () { - expect(plugin.canLaunch('tel:5551234567'), completion(isFalse)); + test('"tel" URLs -> true', () { + expect(plugin.canLaunch('tel:5551234567'), completion(isTrue)); }); }); From f890c46f0c55c276869b2db9c7ba0b76ef7a997a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonc=CC=A7alo=20Palma?= Date: Sun, 28 Jun 2020 17:10:37 +0100 Subject: [PATCH 2/4] Requested Changes --- packages/url_launcher/url_launcher/pubspec.yaml | 6 +----- .../url_launcher/url_launcher_web/CHANGELOG.md | 4 ++++ .../url_launcher_web/lib/url_launcher_web.dart | 17 ++++++++++++----- .../url_launcher/url_launcher_web/pubspec.yaml | 2 +- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/packages/url_launcher/url_launcher/pubspec.yaml b/packages/url_launcher/url_launcher/pubspec.yaml index 525006022c26..08ac3f9f8b80 100644 --- a/packages/url_launcher/url_launcher/pubspec.yaml +++ b/packages/url_launcher/url_launcher/pubspec.yaml @@ -26,11 +26,7 @@ dependencies: # validation, so we set a ^ constraint. # TODO(amirh): Revisit this (either update this part in the design or the pub tool). # https://github.com/flutter/flutter/issues/46264 - url_launcher_web: - git: - url: https://github.com/Vanethos/plugins - ref: feature/add-tel-url - path: packages/url_launcher/url_launcher_web + url_launcher_web: ^0.1.0+1 url_launcher_macos: ^0.0.1 dev_dependencies: diff --git a/packages/url_launcher/url_launcher_web/CHANGELOG.md b/packages/url_launcher/url_launcher_web/CHANGELOG.md index df1b2c97b744..25d32cbdb879 100644 --- a/packages/url_launcher/url_launcher_web/CHANGELOG.md +++ b/packages/url_launcher/url_launcher_web/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.1.2 + +- Adds "tel" support + # 0.1.1+6 - Open "mailto" urls with target set as "\_top" on Safari browsers. diff --git a/packages/url_launcher/url_launcher_web/lib/url_launcher_web.dart b/packages/url_launcher/url_launcher_web/lib/url_launcher_web.dart index 07bc851cd880..b61cdccbc65a 100644 --- a/packages/url_launcher/url_launcher_web/lib/url_launcher_web.dart +++ b/packages/url_launcher/url_launcher_web/lib/url_launcher_web.dart @@ -7,8 +7,10 @@ import 'package:url_launcher_platform_interface/url_launcher_platform_interface. import 'package:platform_detect/platform_detect.dart' show browser; -const _mailtoScheme = 'mailto'; -const _phoneScheme = 'tel'; +const _safariTargetTopSchemes = { + 'mailto', + 'tel', +}; /// The web implementation of [UrlLauncherPlatform]. /// @@ -17,7 +19,10 @@ class UrlLauncherPlugin extends UrlLauncherPlatform { html.Window _window; // The set of schemes that can be handled by the plugin - static final _supportedSchemes = {'http', 'https', _mailtoScheme, _phoneScheme}; + static final _supportedSchemes = { + 'http', + 'https', + }.union(_safariTargetTopSchemes); /// A constructor that allows tests to override the window object used by the plugin. UrlLauncherPlugin({@visibleForTesting html.Window window}) @@ -30,7 +35,8 @@ class UrlLauncherPlugin extends UrlLauncherPlatform { String _getUrlScheme(String url) => Uri.tryParse(url)?.scheme; - bool _isMailtoScheme(String url) => _getUrlScheme(url) == _mailtoScheme; + bool _isSafariTargetTopScheme(String url) => + _safariTargetTopSchemes.contains(_getUrlScheme(url)); /// Opens the given [url] in a new window. /// @@ -39,7 +45,8 @@ class UrlLauncherPlugin extends UrlLauncherPlatform { html.WindowBase openNewWindow(String url) { // We need to open mailto urls on the _top window context on safari browsers. // See https://github.com/flutter/flutter/issues/51461 for reference. - final target = browser.isSafari && _isMailtoScheme(url) ? '_top' : ''; + final target = + browser.isSafari && _isSafariTargetTopScheme(url) ? '_top' : ''; return _window.open(url, target); } diff --git a/packages/url_launcher/url_launcher_web/pubspec.yaml b/packages/url_launcher/url_launcher_web/pubspec.yaml index 207f2dc15424..9a5beac00b94 100644 --- a/packages/url_launcher/url_launcher_web/pubspec.yaml +++ b/packages/url_launcher/url_launcher_web/pubspec.yaml @@ -4,7 +4,7 @@ homepage: https://github.com/flutter/plugins/tree/master/packages/url_launcher/u # 0.1.y+z is compatible with 1.0.0, if you land a breaking change bump # the version to 2.0.0. # See more details: https://github.com/flutter/flutter/wiki/Package-migration-to-1.0.0 -version: 0.1.1+6 +version: 0.1.2 flutter: plugin: From ff197be44ac3aaf662cd9f9e3312bfae29b48c25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonc=CC=A7alo=20Palma?= Date: Mon, 29 Jun 2020 23:20:36 +0100 Subject: [PATCH 3/4] Adds "sms" support Adds tests for "tel" and sms --- .../url_launcher_web/CHANGELOG.md | 2 +- .../lib/url_launcher_web.dart | 3 +- .../test/url_launcher_web_test.dart | 60 +++++++++++++++++++ 3 files changed, 63 insertions(+), 2 deletions(-) diff --git a/packages/url_launcher/url_launcher_web/CHANGELOG.md b/packages/url_launcher/url_launcher_web/CHANGELOG.md index 25d32cbdb879..e9f7bde63fda 100644 --- a/packages/url_launcher/url_launcher_web/CHANGELOG.md +++ b/packages/url_launcher/url_launcher_web/CHANGELOG.md @@ -1,6 +1,6 @@ # 0.1.2 -- Adds "tel" support +- Adds "tel" and "sms" support # 0.1.1+6 diff --git a/packages/url_launcher/url_launcher_web/lib/url_launcher_web.dart b/packages/url_launcher/url_launcher_web/lib/url_launcher_web.dart index b61cdccbc65a..1bac4d524122 100644 --- a/packages/url_launcher/url_launcher_web/lib/url_launcher_web.dart +++ b/packages/url_launcher/url_launcher_web/lib/url_launcher_web.dart @@ -10,6 +10,7 @@ import 'package:platform_detect/platform_detect.dart' show browser; const _safariTargetTopSchemes = { 'mailto', 'tel', + 'sms', }; /// The web implementation of [UrlLauncherPlatform]. @@ -43,7 +44,7 @@ class UrlLauncherPlugin extends UrlLauncherPlatform { /// Returns the newly created window. @visibleForTesting html.WindowBase openNewWindow(String url) { - // We need to open mailto urls on the _top window context on safari browsers. + // We need to open mailto, tel and sms urls on the _top window context on safari browsers. // See https://github.com/flutter/flutter/issues/51461 for reference. final target = browser.isSafari && _isSafariTargetTopScheme(url) ? '_top' : ''; diff --git a/packages/url_launcher/url_launcher_web/test/url_launcher_web_test.dart b/packages/url_launcher/url_launcher_web/test/url_launcher_web_test.dart index 7d50b7ff72b7..cb15140d4eb1 100644 --- a/packages/url_launcher/url_launcher_web/test/url_launcher_web_test.dart +++ b/packages/url_launcher/url_launcher_web/test/url_launcher_web_test.dart @@ -39,6 +39,10 @@ void main() { test('"tel" URLs -> true', () { expect(plugin.canLaunch('tel:5551234567'), completion(isTrue)); }); + + test('"sms" URLs -> true', () { + expect(plugin.canLaunch('sms:+19725551212?body=hello%20there'), completion(isTrue)); + }); }); group('launch', () { @@ -48,6 +52,10 @@ void main() { .thenReturn(MockWindow()); when(mockWindow.open('mailto:name@mydomain.com', '')) .thenReturn(MockWindow()); + when(mockWindow.open('tel:5551234567', '')) + .thenReturn(MockWindow()); + when(mockWindow.open('sms:+19725551212?body=hello%20there', '')) + .thenReturn(MockWindow()); }); test('launching a URL returns true', () { @@ -77,6 +85,34 @@ void main() { ), completion(isTrue)); }); + + test('launching a "tel" returns true', () { + expect( + plugin.launch( + 'tel:5551234567', + useSafariVC: null, + useWebView: null, + universalLinksOnly: null, + enableDomStorage: null, + enableJavaScript: null, + headers: null, + ), + completion(isTrue)); + }); + + test('launching a "sms" returns true', () { + expect( + plugin.launch( + 'sms:+19725551212?body=hello%20there', + useSafariVC: null, + useWebView: null, + universalLinksOnly: null, + enableDomStorage: null, + enableJavaScript: null, + headers: null, + ), + completion(isTrue)); + }); }); group('openNewWindow', () { @@ -98,6 +134,18 @@ void main() { verify(mockWindow.open('mailto:name@mydomain.com', '')); }); + test('tel urls should be launched on a new window', () { + plugin.openNewWindow('tel:5551234567'); + + verify(mockWindow.open('tel:5551234567', '')); + }); + + test('sms urls should be launched on a new window', () { + plugin.openNewWindow('sms:+19725551212?body=hello%20there'); + + verify(mockWindow.open('sms:+19725551212?body=hello%20there', '')); + }); + group('Safari', () { setUp(() { platform.configurePlatformForTesting(browser: platform.safari); @@ -120,6 +168,18 @@ void main() { verify(mockWindow.open('mailto:name@mydomain.com', '_top')); }); + + test('tel urls should be launched on the same window', () { + plugin.openNewWindow('tel:5551234567'); + + verify(mockWindow.open('tel:5551234567', '_top')); + }); + + test('sms urls should be launched on the same window', () { + plugin.openNewWindow('sms:+19725551212?body=hello%20there'); + + verify(mockWindow.open('sms:+19725551212?body=hello%20there', '_top')); + }); }); }); }); From 7cd6c8036d8f27b006db6072c662b68d7ee1650d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonc=CC=A7alo=20Palma?= Date: Tue, 30 Jun 2020 10:23:13 +0100 Subject: [PATCH 4/4] Applied dart fmt -w . --- .../url_launcher_web/test/url_launcher_web_test.dart | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/url_launcher/url_launcher_web/test/url_launcher_web_test.dart b/packages/url_launcher/url_launcher_web/test/url_launcher_web_test.dart index cb15140d4eb1..b7e107d892cf 100644 --- a/packages/url_launcher/url_launcher_web/test/url_launcher_web_test.dart +++ b/packages/url_launcher/url_launcher_web/test/url_launcher_web_test.dart @@ -41,7 +41,8 @@ void main() { }); test('"sms" URLs -> true', () { - expect(plugin.canLaunch('sms:+19725551212?body=hello%20there'), completion(isTrue)); + expect(plugin.canLaunch('sms:+19725551212?body=hello%20there'), + completion(isTrue)); }); }); @@ -52,8 +53,7 @@ void main() { .thenReturn(MockWindow()); when(mockWindow.open('mailto:name@mydomain.com', '')) .thenReturn(MockWindow()); - when(mockWindow.open('tel:5551234567', '')) - .thenReturn(MockWindow()); + when(mockWindow.open('tel:5551234567', '')).thenReturn(MockWindow()); when(mockWindow.open('sms:+19725551212?body=hello%20there', '')) .thenReturn(MockWindow()); }); @@ -178,7 +178,8 @@ void main() { test('sms urls should be launched on the same window', () { plugin.openNewWindow('sms:+19725551212?body=hello%20there'); - verify(mockWindow.open('sms:+19725551212?body=hello%20there', '_top')); + verify( + mockWindow.open('sms:+19725551212?body=hello%20there', '_top')); }); }); });