-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Add url_launcher_windows #3015
Add url_launcher_windows #3015
Changes from all commits
cde2a2f
c82d936
511e13e
5b0e203
a8e1cce
cd1549a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| BasedOnStyle: Google |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| .packages | ||
| .flutter-plugins | ||
| pubspec.lock |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # 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: 6d1c244b79f3a2747281f718297ce248bd5ad099 | ||
| channel: master | ||
|
|
||
| project_type: plugin |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ## 0.0.1 | ||
|
|
||
| * Initial Windows implementation of `url_launcher`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| 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. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # url_launcher_windows | ||
|
|
||
| The Windows implementation of [`url_launcher`][1]. | ||
|
|
||
| ## Backward compatible 1.0.0 version is coming | ||
| The plugin has reached a stable API, we guarantee that version `1.0.0` will be backward compatible with `0.0.y+z`. If you use | ||
| url_launcher_windows directly, rather than as an implementation detail | ||
| of `url_launcher`, please use `url_launcher_windows: '>=0.0.y+x <2.0.0'` | ||
| as your dependency constraint to allow a smoother ecosystem migration. | ||
| For more details see: https://github.com/flutter/flutter/wiki/Package-migration-to-1.0.0 | ||
|
|
||
| ## Usage | ||
|
|
||
| ### Import the package | ||
|
|
||
| This package has not yet been endorsed. Once it is you only need to add | ||
| `url_launcher` as a dependency in your `pubspec.yaml`, but for now you | ||
| need to include both `url_launcher` and `url_launcher_windows`. | ||
|
|
||
| This is what the above means to your `pubspec.yaml`: | ||
|
|
||
| ```yaml | ||
| ... | ||
| dependencies: | ||
| ... | ||
| url_launcher: ^5.5.3 | ||
| url_launcher_windows: ^0.0.1 | ||
| ... | ||
| ``` | ||
|
|
||
| [1]: ../url_launcher/url_launcher | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # 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/ | ||
| **/ios/Flutter/.last_build_id | ||
| .dart_tool/ | ||
| .flutter-plugins | ||
| .flutter-plugins-dependencies | ||
| .packages | ||
| .pub-cache/ | ||
| .pub/ | ||
| /build/ | ||
|
|
||
| # Web related | ||
| lib/generated_plugin_registrant.dart | ||
|
|
||
| # Symbolication related | ||
| app.*.symbols | ||
|
|
||
| # Obfuscation related | ||
| app.*.map.json |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # 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: 6d1c244b79f3a2747281f718297ce248bd5ad099 | ||
| channel: master | ||
|
|
||
| project_type: app |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # url_launcher_windows_example | ||
|
|
||
| Demonstrates the url_launcher_windows plugin. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| // Copyright 2017 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. | ||
|
|
||
| // ignore_for_file: public_member_api_docs | ||
|
|
||
| import 'dart:async'; | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart'; | ||
|
|
||
| void main() { | ||
| runApp(MyApp()); | ||
| } | ||
|
|
||
| class MyApp extends StatelessWidget { | ||
| @override | ||
| Widget build(BuildContext context) { | ||
| return MaterialApp( | ||
| title: 'URL Launcher', | ||
| theme: ThemeData( | ||
| primarySwatch: Colors.blue, | ||
| ), | ||
| home: MyHomePage(title: 'URL Launcher'), | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| class MyHomePage extends StatefulWidget { | ||
| MyHomePage({Key key, this.title}) : super(key: key); | ||
| final String title; | ||
|
|
||
| @override | ||
| _MyHomePageState createState() => _MyHomePageState(); | ||
| } | ||
|
|
||
| class _MyHomePageState extends State<MyHomePage> { | ||
| Future<void> _launched; | ||
|
|
||
| Future<void> _launchInBrowser(String url) async { | ||
| if (await UrlLauncherPlatform.instance.canLaunch(url)) { | ||
|
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. Not for this PR but still - This saddens me, I really want us to come up with a way to share relevant pieces of the example app and e2e tests (and not have an example app thats using the platform interface). I'm planning to be focusing on these issues in the coming weeks.
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. Per my recent comments is Discord, I think using the platform interface rather than the app-facing plugin is a better way to write the driver tests; maybe we can continue the discussion there. The role of the example app in a federated implementation is questionable though; it's only going to be an example in the (rare?) cases where there is extra API in the platform implementation. Having it replicate things that are in the main example—which is what people should look at in almost every case—isn't really useful as an example. But it is useful to have a self-contained build when working on the implementation. |
||
| await UrlLauncherPlatform.instance.launch( | ||
| url, | ||
| useSafariVC: false, | ||
| useWebView: false, | ||
| enableJavaScript: false, | ||
| enableDomStorage: false, | ||
| universalLinksOnly: false, | ||
| headers: <String, String>{}, | ||
| ); | ||
| } else { | ||
| throw 'Could not launch $url'; | ||
| } | ||
| } | ||
|
|
||
| Widget _launchStatus(BuildContext context, AsyncSnapshot<void> snapshot) { | ||
| if (snapshot.hasError) { | ||
| return Text('Error: ${snapshot.error}'); | ||
| } else { | ||
| return const Text(''); | ||
| } | ||
| } | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| const String toLaunch = 'https://www.cylog.org/headers/'; | ||
| return Scaffold( | ||
| appBar: AppBar( | ||
| title: Text(widget.title), | ||
| ), | ||
| body: ListView( | ||
| children: <Widget>[ | ||
| Column( | ||
| mainAxisAlignment: MainAxisAlignment.center, | ||
| children: <Widget>[ | ||
| const Padding( | ||
| padding: EdgeInsets.all(16.0), | ||
| child: Text(toLaunch), | ||
| ), | ||
| RaisedButton( | ||
| onPressed: () => setState(() { | ||
| _launched = _launchInBrowser(toLaunch); | ||
| }), | ||
| child: const Text('Launch in browser'), | ||
| ), | ||
| const Padding(padding: EdgeInsets.all(16.0)), | ||
| FutureBuilder<void>(future: _launched, builder: _launchStatus), | ||
| ], | ||
| ), | ||
| ], | ||
| ), | ||
| ); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| name: url_launcher_example | ||
| description: Demonstrates the Windows implementation of the url_launcher plugin. | ||
|
|
||
| dependencies: | ||
| flutter: | ||
| sdk: flutter | ||
| url_launcher_platform_interface: any | ||
| url_launcher_windows: | ||
| path: ../ | ||
|
|
||
| dev_dependencies: | ||
| integration_test: | ||
| path: ../../../integration_test | ||
| flutter_driver: | ||
| sdk: flutter | ||
| pedantic: ^1.8.0 | ||
|
|
||
| flutter: | ||
| uses-material-design: true |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // Copyright 2019, the Chromium project authors. Please see the AUTHORS file | ||
| // for details. All rights reserved. Use of this source code is governed by a | ||
| // BSD-style license that can be found in the LICENSE file. | ||
|
|
||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:integration_test/integration_test.dart'; | ||
| import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart'; | ||
|
|
||
| void main() { | ||
| IntegrationTestWidgetsFlutterBinding.ensureInitialized(); | ||
|
|
||
| test('canLaunch', () async { | ||
| UrlLauncherPlatform launcher = UrlLauncherPlatform.instance; | ||
|
|
||
| expect(await launcher.canLaunch('randomstring'), false); | ||
|
|
||
| // Generally all devices should have some default browser. | ||
| expect(await launcher.canLaunch('http://flutter.dev'), true); | ||
| }); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // Copyright 2019, the Chromium project authors. Please see the AUTHORS file | ||
| // for details. All rights reserved. Use of this source code is governed by a | ||
| // BSD-style license that can be found in the LICENSE file. | ||
|
|
||
| import 'dart:async'; | ||
| import 'dart:convert'; | ||
| import 'dart:io'; | ||
| import 'package:flutter_driver/flutter_driver.dart'; | ||
|
|
||
| Future<void> main() async { | ||
| final FlutterDriver driver = await FlutterDriver.connect(); | ||
| final String data = | ||
| await driver.requestData(null, timeout: const Duration(minutes: 1)); | ||
| await driver.close(); | ||
| final Map<String, dynamic> result = jsonDecode(data); | ||
| exit(result['result'] == 'true' ? 0 : 1); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| // The url_launcher_platform_interface defaults to MethodChannelUrlLauncher | ||
| // as its instance, which is all the Windows implementation needs. This file | ||
| // is here to silence warnings when publishing to pub. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| name: url_launcher_windows | ||
| description: Windows implementation of the url_launcher plugin. | ||
| # 0.0.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.0.1 | ||
| homepage: https://github.com/flutter/plugins/tree/master/packages/url_launcher/url_launcher_windows | ||
|
|
||
| flutter: | ||
| plugin: | ||
| platforms: | ||
| windows: | ||
| pluginClass: UrlLauncherPlugin | ||
|
|
||
| environment: | ||
| sdk: ">=2.1.0 <3.0.0" | ||
| flutter: ">=1.12.8 <2.0.0" | ||
|
|
||
| dependencies: | ||
| flutter: | ||
| sdk: flutter |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| flutter/ | ||
|
|
||
| # Visual Studio user-specific files. | ||
| *.suo | ||
| *.user | ||
| *.userosscache | ||
| *.sln.docstates | ||
|
|
||
| # Visual Studio build-related files. | ||
| x64/ | ||
| x86/ | ||
|
|
||
| # Visual Studio cache files | ||
| # files ending in .cache can be ignored | ||
| *.[Cc]ache | ||
| # but keep track of directories ending in .cache | ||
| !*.[Cc]ache/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| cmake_minimum_required(VERSION 3.10) | ||
| set(PROJECT_NAME "url_launcher_windows") | ||
| project(${PROJECT_NAME} LANGUAGES CXX) | ||
|
|
||
| set(PLUGIN_NAME "${PROJECT_NAME}_plugin") | ||
|
|
||
| add_library(${PLUGIN_NAME} SHARED | ||
| "url_launcher_plugin.cpp" | ||
| ) | ||
| apply_standard_settings(${PLUGIN_NAME}) | ||
| set_target_properties(${PLUGIN_NAME} PROPERTIES | ||
| CXX_VISIBILITY_PRESET hidden) | ||
| target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL) | ||
| target_include_directories(${PLUGIN_NAME} INTERFACE | ||
| "${CMAKE_CURRENT_SOURCE_DIR}/include") | ||
| target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin) | ||
|
|
||
| # List of absolute paths to libraries that should be bundled with the plugin | ||
| set(file_chooser_bundled_libraries | ||
| "" | ||
| PARENT_SCOPE | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // 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. | ||
| #ifndef PACKAGES_URL_LAUNCHER_URL_LAUNCHER_WINDOWS_WINDOWS_INCLUDE_URL_LAUNCHER_WINDOWS_URL_LAUNCHER_PLUGIN_H_ | ||
| #define PACKAGES_URL_LAUNCHER_URL_LAUNCHER_WINDOWS_WINDOWS_INCLUDE_URL_LAUNCHER_WINDOWS_URL_LAUNCHER_PLUGIN_H_ | ||
|
|
||
| #include <flutter_plugin_registrar.h> | ||
|
|
||
| #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 UrlLauncherPluginRegisterWithRegistrar( | ||
| FlutterDesktopPluginRegistrarRef registrar); | ||
|
|
||
| #if defined(__cplusplus) | ||
| } // extern "C" | ||
| #endif | ||
|
|
||
| #endif // PACKAGES_URL_LAUNCHER_URL_LAUNCHER_WINDOWS_WINDOWS_INCLUDE_URL_LAUNCHER_WINDOWS_URL_LAUNCHER_PLUGIN_H_ |
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.
can I ask why we're recommending this instead of putting the right version of the plugin as a dependency of url_launcher?
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.
answering my own question, I assume we're doing this as a temporary message until Windows hits alpha.
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.
To endorse a federated plugin (i.e., make it a dependency of the main plugin), the plugin already has to be published. So our flow for a new federated implementation is:
This README covers steps 3 through 5, where this plugin exists in the wild as a published plugin but isn't endorsed. In step 6, the foo_windows readme gets updated to say that it's included automatically by foo. (Then that gets published as a minor, README-only change to foo_windows).
It's cumbersome, but the alternative (putting everything in one PR) wouldn't pass CI because the build of the main plugin would fail due to the federated implementation not having been published.