Skip to content

Commit 3296390

Browse files
Harry TerkelsenPark Sung Min
Harry Terkelsen
authored and
Park Sung Min
committed
Add web url launcher (flutter#2119)
* Move url_launcher to url_launcher/url_launcher Add url_launcher_web package Test plugins even if they don't have a pubspec in the top-level folder Bump up the pubspec version for new homepage URL Add dummy podspec file for iOS Remove unused import Format test Update check_publish.sh script * UPdate check_publish for federated plugins. * Follow correct semver when bumping version * Add some tests for `launch` * Check if directory exists for CI
1 parent 1cdbbfb commit 3296390

File tree

71 files changed

+215
-11
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+215
-11
lines changed

packages/url_launcher/CHANGELOG.md renamed to packages/url_launcher/url_launcher/CHANGELOG.md

Lines changed: 4 additions & 0 deletions

packages/url_launcher/pubspec.yaml renamed to packages/url_launcher/url_launcher/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ name: url_launcher
22
description: Flutter plugin for launching a URL on Android and iOS. Supports
33
web, phone, SMS, and email schemes.
44
author: Flutter Team <[email protected]>
5-
homepage: https://github.com/flutter/plugins/tree/master/packages/url_launcher
6-
version: 5.1.4
5+
homepage: https://github.com/flutter/plugins/tree/master/packages/url_launcher/url_launcher
6+
version: 5.1.5
77

88
flutter:
99
plugin:
Lines changed: 3 additions & 0 deletions
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2019 The Chromium Authors. All rights reserved.
2+
//
3+
// Redistribution and use in source and binary forms, with or without
4+
// modification, are permitted provided that the following conditions are
5+
// met:
6+
//
7+
// * Redistributions of source code must retain the above copyright
8+
// notice, this list of conditions and the following disclaimer.
9+
// * Redistributions in binary form must reproduce the above
10+
// copyright notice, this list of conditions and the following disclaimer
11+
// in the documentation and/or other materials provided with the
12+
// distribution.
13+
// * Neither the name of Google Inc. nor the names of its
14+
// contributors may be used to endorse or promote products derived from
15+
// this software without specific prior written permission.
16+
//
17+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Lines changed: 24 additions & 0 deletions
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#
2+
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
3+
#
4+
Pod::Spec.new do |s|
5+
s.name = 'url_launcher_web'
6+
s.version = '0.0.1'
7+
s.summary = 'No-op implementation of url_launcher_web web plugin to avoid build issues on iOS'
8+
s.description = <<-DESC
9+
temp fake url_launcher_web plugin
10+
DESC
11+
s.homepage = 'https://github.com/flutter/plugins/tree/master/packages/url_launcher/url_launcher_web'
12+
s.license = { :file => '../LICENSE' }
13+
s.author = { 'Flutter Team' => '[email protected]' }
14+
s.source = { :path => '.' }
15+
s.source_files = 'Classes/**/*'
16+
s.public_header_files = 'Classes/**/*.h'
17+
s.dependency 'Flutter'
18+
19+
s.ios.deployment_target = '8.0'
20+
end
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import 'dart:async';
2+
import 'dart:html' as html;
3+
4+
import 'package:flutter/services.dart';
5+
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
6+
import 'package:meta/meta.dart';
7+
8+
class UrlLauncherPlugin {
9+
static void registerWith(Registrar registrar) {
10+
final MethodChannel channel = MethodChannel(
11+
'plugins.flutter.io/url_launcher',
12+
const StandardMethodCodec(),
13+
registrar.messenger);
14+
final UrlLauncherPlugin instance = UrlLauncherPlugin();
15+
channel.setMethodCallHandler(instance.handleMethodCall);
16+
}
17+
18+
Future<dynamic> handleMethodCall(MethodCall call) async {
19+
switch (call.method) {
20+
case 'canLaunch':
21+
final String url = call.arguments['url'];
22+
return _canLaunch(url);
23+
case 'launch':
24+
final String url = call.arguments['url'];
25+
return _launch(url);
26+
default:
27+
throw PlatformException(
28+
code: 'Unimplemented',
29+
details: "The url_launcher plugin for web doesn't implement "
30+
"the method '${call.method}'");
31+
}
32+
}
33+
34+
bool _canLaunch(String url) {
35+
final Uri parsedUrl = Uri.tryParse(url);
36+
if (parsedUrl == null) return false;
37+
38+
return parsedUrl.isScheme('http') || parsedUrl.isScheme('https');
39+
}
40+
41+
bool _launch(String url) {
42+
return openNewWindow(url) != null;
43+
}
44+
45+
@visibleForTesting
46+
html.WindowBase openNewWindow(String url) {
47+
return html.window.open(url, '');
48+
}
49+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: url_launcher_web
2+
description: Web platform implementation of url_launcher
3+
author: Flutter Team <[email protected]>
4+
homepage: https://github.com/flutter/plugins/tree/master/packages/url_launcher/url_launcher_web
5+
version: 0.0.1
6+
7+
flutter:
8+
plugin:
9+
platforms:
10+
web:
11+
pluginClass: UrlLauncherPlugin
12+
fileName: url_launcher_web.dart
13+
14+
dependencies:
15+
flutter:
16+
sdk: flutter
17+
flutter_web_plugins:
18+
sdk: flutter
19+
meta: ^1.1.7
20+
21+
dev_dependencies:
22+
flutter_test:
23+
sdk: flutter
24+
url_launcher:
25+
path: ../url_launcher
26+
27+
environment:
28+
sdk: ">=2.0.0-dev.28.0 <3.0.0"
29+
flutter: ">=1.5.0 <2.0.0"
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2019 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
@TestOn('chrome') // Uses web-only Flutter SDK
6+
7+
import 'dart:html' as html;
8+
9+
import 'package:flutter_test/flutter_test.dart';
10+
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
11+
import 'package:url_launcher/url_launcher.dart';
12+
import 'package:url_launcher_web/url_launcher_web.dart';
13+
14+
void main() {
15+
group('URL Launcher for Web', () {
16+
setUp(() {
17+
TestWidgetsFlutterBinding.ensureInitialized();
18+
webPluginRegistry.registerMessageHandler();
19+
final Registrar registrar =
20+
webPluginRegistry.registrarFor(UrlLauncherPlugin);
21+
UrlLauncherPlugin.registerWith(registrar);
22+
});
23+
24+
test('can launch "http" URLs', () {
25+
expect(canLaunch('http://google.com'), completion(isTrue));
26+
});
27+
28+
test('can launch "https" URLs', () {
29+
expect(canLaunch('https://google.com'), completion(isTrue));
30+
});
31+
32+
test('cannot launch "tel" URLs', () {
33+
expect(canLaunch('tel:5551234567'), completion(isFalse));
34+
});
35+
36+
test('launching a URL returns true', () {
37+
expect(launch('https://www.google.com'), completion(isTrue));
38+
});
39+
40+
test('the window that is launched is a new window', () {
41+
final UrlLauncherPlugin urlLauncherPlugin = UrlLauncherPlugin();
42+
final html.WindowBase newWindow =
43+
urlLauncherPlugin.openNewWindow('https://www.google.com');
44+
expect(newWindow, isNotNull);
45+
expect(newWindow, isNot(equals(html.window)));
46+
expect(newWindow.opener, equals(html.window));
47+
});
48+
});
49+
}

script/check_publish.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ source "$SCRIPT_DIR/common.sh"
1212

1313
function check_publish() {
1414
local failures=()
15-
for package_name in "$@"; do
16-
local dir="$REPO_DIR/packages/$package_name"
15+
for dir in $(pub global run flutter_plugin_tools list --plugins="$1"); do
16+
local package_name=$(basename "$dir")
1717
echo "Checking that $package_name can be published."
1818
if [[ $(cd "$dir" && cat pubspec.yaml | grep -E "^publish_to: none") ]]; then
1919
echo "Package $package_name is marked as unpublishable. Skipping."
@@ -33,9 +33,9 @@ function check_publish() {
3333
return "${#failures[@]}"
3434
}
3535

36-
# Sets CHANGED_PACKAGE_LIST
36+
# Sets CHANGED_PACKAGE_LIST and CHANGED_PACKAGES
3737
check_changed_packages
3838

3939
if [[ "${#CHANGED_PACKAGE_LIST[@]}" != 0 ]]; then
40-
check_publish "${CHANGED_PACKAGE_LIST[@]}"
41-
fi
40+
check_publish "${CHANGED_PACKAGES}"
41+
fi

script/common.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,12 @@ function check_changed_packages() {
2323
return 1
2424
fi
2525

26-
# Filter out any packages that don't have a pubspec.yaml: they have probably
27-
# been deleted in this PR. Also filter out `location_background` since it
28-
# should be removed soon.
2926
CHANGED_PACKAGES=""
3027
CHANGED_PACKAGE_LIST=()
28+
29+
# Filter out packages that have been deleted.
3130
for package in "${packages[@]}"; do
32-
if [ -f "$REPO_DIR/packages/$package/pubspec.yaml" ] && [ $package != "location_background" ]; then
31+
if [ -d "$REPO_DIR/packages/$package" ]; then
3332
CHANGED_PACKAGES="${CHANGED_PACKAGES},$package"
3433
CHANGED_PACKAGE_LIST=("${CHANGED_PACKAGE_LIST[@]}" "$package")
3534
fi

0 commit comments

Comments
 (0)