This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Add web url launcher #2119
Merged
harryterkelsen
merged 5 commits into
flutter:master
from
harryterkelsen:add-web-url-launcher
Oct 2, 2019
Merged
Add web url launcher #2119
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7a7186f
Move url_launcher to url_launcher/url_launcher
harryterkelsen 53938a8
UPdate check_publish for federated plugins.
harryterkelsen 5b48d74
Follow correct semver when bumping version
harryterkelsen 2d9a6a8
Add some tests for `launch`
harryterkelsen d5fee1e
Check if directory exists for CI
harryterkelsen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
packages/url_launcher/CHANGELOG.md → ...es/url_launcher/url_launcher/CHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # 0.0.1 | ||
|
|
||
| - Initial open-source release. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // Copyright 2019 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # url_launcher_web | ||
|
|
||
| The web implementation of [`url_launcher`][1]. | ||
|
|
||
| ## Usage | ||
|
|
||
| To use this plugin in your Flutter Web app, simply add it as a dependency in | ||
| your pubspec using a `git` dependency. This is only temporary: in the future | ||
| we hope to make this package an "endorsed" implementation of `url_launcher`, | ||
| so that it is automatically included in your Flutter Web app when you depend | ||
| on `package:url_launcher`. | ||
|
|
||
| ```yaml | ||
| dependencies: | ||
| url_launcher: ^5.1.4 | ||
| url_launcher_web: | ||
| git: git@github.com:flutter/plugins.git | ||
| path: packages/url_launcher/url_launcher_web | ||
| ``` | ||
|
|
||
| Once you have the `url_launcher_web` dependency in your pubspec, you should | ||
| be able to use `package:url_launcher` as normal. | ||
|
|
||
| [1]: ../url_launcher |
20 changes: 20 additions & 0 deletions
20
packages/url_launcher/url_launcher_web/ios/url_launcher_web.podspec
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # | ||
| # To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html | ||
| # | ||
| Pod::Spec.new do |s| | ||
| s.name = 'url_launcher_web' | ||
| s.version = '0.0.1' | ||
| s.summary = 'No-op implementation of url_launcher_web web plugin to avoid build issues on iOS' | ||
| s.description = <<-DESC | ||
| temp fake url_launcher_web plugin | ||
| DESC | ||
| s.homepage = 'https://github.com/flutter/plugins/tree/master/packages/url_launcher/url_launcher_web' | ||
| s.license = { :file => '../LICENSE' } | ||
| s.author = { 'Flutter Team' => 'flutter-dev@googlegroups.com' } | ||
| s.source = { :path => '.' } | ||
| s.source_files = 'Classes/**/*' | ||
| s.public_header_files = 'Classes/**/*.h' | ||
| s.dependency 'Flutter' | ||
|
|
||
| s.ios.deployment_target = '8.0' | ||
| end |
49 changes: 49 additions & 0 deletions
49
packages/url_launcher/url_launcher_web/lib/url_launcher_web.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import 'dart:async'; | ||
| import 'dart:html' as html; | ||
|
|
||
| import 'package:flutter/services.dart'; | ||
| import 'package:flutter_web_plugins/flutter_web_plugins.dart'; | ||
| import 'package:meta/meta.dart'; | ||
|
|
||
| class UrlLauncherPlugin { | ||
| static void registerWith(Registrar registrar) { | ||
| final MethodChannel channel = MethodChannel( | ||
| 'plugins.flutter.io/url_launcher', | ||
| const StandardMethodCodec(), | ||
| registrar.messenger); | ||
| final UrlLauncherPlugin instance = UrlLauncherPlugin(); | ||
| channel.setMethodCallHandler(instance.handleMethodCall); | ||
| } | ||
|
|
||
| Future<dynamic> handleMethodCall(MethodCall call) async { | ||
| switch (call.method) { | ||
| case 'canLaunch': | ||
| final String url = call.arguments['url']; | ||
| return _canLaunch(url); | ||
| case 'launch': | ||
| final String url = call.arguments['url']; | ||
| return _launch(url); | ||
| default: | ||
| throw PlatformException( | ||
| code: 'Unimplemented', | ||
| details: "The url_launcher plugin for web doesn't implement " | ||
| "the method '${call.method}'"); | ||
| } | ||
| } | ||
|
|
||
| bool _canLaunch(String url) { | ||
| final Uri parsedUrl = Uri.tryParse(url); | ||
| if (parsedUrl == null) return false; | ||
|
|
||
| return parsedUrl.isScheme('http') || parsedUrl.isScheme('https'); | ||
| } | ||
|
|
||
| bool _launch(String url) { | ||
| return openNewWindow(url) != null; | ||
| } | ||
|
|
||
| @visibleForTesting | ||
| html.WindowBase openNewWindow(String url) { | ||
| return html.window.open(url, ''); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| name: url_launcher_web | ||
| description: Web platform implementation of url_launcher | ||
| author: Flutter Team <flutter-dev@googlegroups.com> | ||
| homepage: https://github.com/flutter/plugins/tree/master/packages/url_launcher/url_launcher_web | ||
| version: 0.0.1 | ||
|
|
||
| flutter: | ||
| plugin: | ||
| platforms: | ||
| web: | ||
| pluginClass: UrlLauncherPlugin | ||
| fileName: url_launcher_web.dart | ||
|
|
||
| dependencies: | ||
| flutter: | ||
| sdk: flutter | ||
| flutter_web_plugins: | ||
| sdk: flutter | ||
| meta: ^1.1.7 | ||
|
|
||
| dev_dependencies: | ||
| flutter_test: | ||
| sdk: flutter | ||
| url_launcher: | ||
| path: ../url_launcher | ||
|
|
||
| environment: | ||
| sdk: ">=2.0.0-dev.28.0 <3.0.0" | ||
| flutter: ">=1.5.0 <2.0.0" |
49 changes: 49 additions & 0 deletions
49
packages/url_launcher/url_launcher_web/test/url_launcher_web_test.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| // Copyright 2019 The Chromium Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| @TestOn('chrome') // Uses web-only Flutter SDK | ||
|
|
||
| import 'dart:html' as html; | ||
|
|
||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:flutter_web_plugins/flutter_web_plugins.dart'; | ||
| import 'package:url_launcher/url_launcher.dart'; | ||
| import 'package:url_launcher_web/url_launcher_web.dart'; | ||
|
|
||
| void main() { | ||
| group('URL Launcher for Web', () { | ||
| setUp(() { | ||
| TestWidgetsFlutterBinding.ensureInitialized(); | ||
| webPluginRegistry.registerMessageHandler(); | ||
| final Registrar registrar = | ||
| webPluginRegistry.registrarFor(UrlLauncherPlugin); | ||
| UrlLauncherPlugin.registerWith(registrar); | ||
| }); | ||
|
|
||
| test('can launch "http" URLs', () { | ||
| expect(canLaunch('http://google.com'), completion(isTrue)); | ||
| }); | ||
|
|
||
| test('can launch "https" URLs', () { | ||
| expect(canLaunch('https://google.com'), completion(isTrue)); | ||
| }); | ||
|
|
||
| test('cannot launch "tel" URLs', () { | ||
| expect(canLaunch('tel:5551234567'), completion(isFalse)); | ||
| }); | ||
|
|
||
| test('launching a URL returns true', () { | ||
| expect(launch('https://www.google.com'), completion(isTrue)); | ||
| }); | ||
|
|
||
| test('the window that is launched is a new window', () { | ||
| final UrlLauncherPlugin urlLauncherPlugin = UrlLauncherPlugin(); | ||
| final html.WindowBase newWindow = | ||
| urlLauncherPlugin.openNewWindow('https://www.google.com'); | ||
| expect(newWindow, isNotNull); | ||
| expect(newWindow, isNot(equals(html.window))); | ||
| expect(newWindow.opener, equals(html.window)); | ||
| }); | ||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,8 +12,8 @@ source "$SCRIPT_DIR/common.sh" | |
|
|
||
| function check_publish() { | ||
| local failures=() | ||
| for package_name in "$@"; do | ||
| local dir="$REPO_DIR/packages/$package_name" | ||
| for dir in $(pub global run flutter_plugin_tools list --plugins="$1"); do | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems wrong to only look at the first argument (prior to this change it would check the packages for all arguments)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That was because previously, |
||
| local package_name=$(basename "$dir") | ||
| echo "Checking that $package_name can be published." | ||
| if [[ $(cd "$dir" && cat pubspec.yaml | grep -E "^publish_to: none") ]]; then | ||
| echo "Package $package_name is marked as unpublishable. Skipping." | ||
|
|
@@ -33,9 +33,9 @@ function check_publish() { | |
| return "${#failures[@]}" | ||
| } | ||
|
|
||
| # Sets CHANGED_PACKAGE_LIST | ||
| # Sets CHANGED_PACKAGE_LIST and CHANGED_PACKAGES | ||
| check_changed_packages | ||
|
|
||
| if [[ "${#CHANGED_PACKAGE_LIST[@]}" != 0 ]]; then | ||
| check_publish "${CHANGED_PACKAGE_LIST[@]}" | ||
| fi | ||
| check_publish "${CHANGED_PACKAGES}" | ||
| fi | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a way to test launch ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would require a lot of extra code. Rather than running the test using
flutter test --platform chromewe would have to spin up our own instance of Chrome, somehow build the JS getting the Flutter Web SDK from somewhere, calllaunch, and determine that a new tab was opened with the correct API.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added some basic tests for
launch