Skip to content

Commit c194de2

Browse files
authored
Add url_launcher_windows (flutter#3015)
Adds a federated Windows implementation of url_launcher (not yet endorsed). Since this is the first C++ plugin, this also adds a .clang-format file to the repo root for formatting C++ plugins. Part of flutter/flutter#41721 (will need follow-up to endorse it in url_launcher)
1 parent 97429bd commit c194de2

19 files changed

+513
-0
lines changed

.clang-format

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
BasedOnStyle: Google
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.packages
2+
.flutter-plugins
3+
pubspec.lock
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled and should not be manually edited.
5+
6+
version:
7+
revision: 6d1c244b79f3a2747281f718297ce248bd5ad099
8+
channel: master
9+
10+
project_type: plugin
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 0.0.1
2+
3+
* Initial Windows implementation of `url_launcher`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Copyright 2019 The Chromium Authors. All rights reserved.
2+
3+
Redistribution and use in source and binary forms, with or without modification,
4+
are permitted provided that the following conditions are met:
5+
6+
* Redistributions of source code must retain the above copyright
7+
notice, this list of conditions and the following disclaimer.
8+
* Redistributions in binary form must reproduce the above
9+
copyright notice, this list of conditions and the following
10+
disclaimer in the documentation and/or other materials provided
11+
with the distribution.
12+
* Neither the name of Google Inc. nor the names of its
13+
contributors may be used to endorse or promote products derived
14+
from this software without specific prior written permission.
15+
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
23+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# url_launcher_windows
2+
3+
The Windows implementation of [`url_launcher`][1].
4+
5+
## Backward compatible 1.0.0 version is coming
6+
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
7+
url_launcher_windows directly, rather than as an implementation detail
8+
of `url_launcher`, please use `url_launcher_windows: '>=0.0.y+x <2.0.0'`
9+
as your dependency constraint to allow a smoother ecosystem migration.
10+
For more details see: https://github.com/flutter/flutter/wiki/Package-migration-to-1.0.0
11+
12+
## Usage
13+
14+
### Import the package
15+
16+
This package has not yet been endorsed. Once it is you only need to add
17+
`url_launcher` as a dependency in your `pubspec.yaml`, but for now you
18+
need to include both `url_launcher` and `url_launcher_windows`.
19+
20+
This is what the above means to your `pubspec.yaml`:
21+
22+
```yaml
23+
...
24+
dependencies:
25+
...
26+
url_launcher: ^5.5.3
27+
url_launcher_windows: ^0.0.1
28+
...
29+
```
30+
31+
[1]: ../url_launcher/url_launcher
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.buildlog/
9+
.history
10+
.svn/
11+
12+
# IntelliJ related
13+
*.iml
14+
*.ipr
15+
*.iws
16+
.idea/
17+
18+
# The .vscode folder contains launch configuration and tasks you configure in
19+
# VS Code which you may wish to be included in version control, so this line
20+
# is commented out by default.
21+
#.vscode/
22+
23+
# Flutter/Dart/Pub related
24+
**/doc/api/
25+
**/ios/Flutter/.last_build_id
26+
.dart_tool/
27+
.flutter-plugins
28+
.flutter-plugins-dependencies
29+
.packages
30+
.pub-cache/
31+
.pub/
32+
/build/
33+
34+
# Web related
35+
lib/generated_plugin_registrant.dart
36+
37+
# Symbolication related
38+
app.*.symbols
39+
40+
# Obfuscation related
41+
app.*.map.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled and should not be manually edited.
5+
6+
version:
7+
revision: 6d1c244b79f3a2747281f718297ce248bd5ad099
8+
channel: master
9+
10+
project_type: app
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# url_launcher_windows_example
2+
3+
Demonstrates the url_launcher_windows plugin.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// Copyright 2017 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+
// ignore_for_file: public_member_api_docs
6+
7+
import 'dart:async';
8+
import 'package:flutter/material.dart';
9+
import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart';
10+
11+
void main() {
12+
runApp(MyApp());
13+
}
14+
15+
class MyApp extends StatelessWidget {
16+
@override
17+
Widget build(BuildContext context) {
18+
return MaterialApp(
19+
title: 'URL Launcher',
20+
theme: ThemeData(
21+
primarySwatch: Colors.blue,
22+
),
23+
home: MyHomePage(title: 'URL Launcher'),
24+
);
25+
}
26+
}
27+
28+
class MyHomePage extends StatefulWidget {
29+
MyHomePage({Key key, this.title}) : super(key: key);
30+
final String title;
31+
32+
@override
33+
_MyHomePageState createState() => _MyHomePageState();
34+
}
35+
36+
class _MyHomePageState extends State<MyHomePage> {
37+
Future<void> _launched;
38+
39+
Future<void> _launchInBrowser(String url) async {
40+
if (await UrlLauncherPlatform.instance.canLaunch(url)) {
41+
await UrlLauncherPlatform.instance.launch(
42+
url,
43+
useSafariVC: false,
44+
useWebView: false,
45+
enableJavaScript: false,
46+
enableDomStorage: false,
47+
universalLinksOnly: false,
48+
headers: <String, String>{},
49+
);
50+
} else {
51+
throw 'Could not launch $url';
52+
}
53+
}
54+
55+
Widget _launchStatus(BuildContext context, AsyncSnapshot<void> snapshot) {
56+
if (snapshot.hasError) {
57+
return Text('Error: ${snapshot.error}');
58+
} else {
59+
return const Text('');
60+
}
61+
}
62+
63+
@override
64+
Widget build(BuildContext context) {
65+
const String toLaunch = 'https://www.cylog.org/headers/';
66+
return Scaffold(
67+
appBar: AppBar(
68+
title: Text(widget.title),
69+
),
70+
body: ListView(
71+
children: <Widget>[
72+
Column(
73+
mainAxisAlignment: MainAxisAlignment.center,
74+
children: <Widget>[
75+
const Padding(
76+
padding: EdgeInsets.all(16.0),
77+
child: Text(toLaunch),
78+
),
79+
RaisedButton(
80+
onPressed: () => setState(() {
81+
_launched = _launchInBrowser(toLaunch);
82+
}),
83+
child: const Text('Launch in browser'),
84+
),
85+
const Padding(padding: EdgeInsets.all(16.0)),
86+
FutureBuilder<void>(future: _launched, builder: _launchStatus),
87+
],
88+
),
89+
],
90+
),
91+
);
92+
}
93+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: url_launcher_example
2+
description: Demonstrates the Windows implementation of the url_launcher plugin.
3+
4+
dependencies:
5+
flutter:
6+
sdk: flutter
7+
url_launcher_platform_interface: any
8+
url_launcher_windows:
9+
path: ../
10+
11+
dev_dependencies:
12+
integration_test:
13+
path: ../../../integration_test
14+
flutter_driver:
15+
sdk: flutter
16+
pedantic: ^1.8.0
17+
18+
flutter:
19+
uses-material-design: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2019, the Chromium project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:flutter_test/flutter_test.dart';
6+
import 'package:integration_test/integration_test.dart';
7+
import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart';
8+
9+
void main() {
10+
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
11+
12+
test('canLaunch', () async {
13+
UrlLauncherPlatform launcher = UrlLauncherPlatform.instance;
14+
15+
expect(await launcher.canLaunch('randomstring'), false);
16+
17+
// Generally all devices should have some default browser.
18+
expect(await launcher.canLaunch('http://flutter.dev'), true);
19+
});
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2019, the Chromium project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'dart:async';
6+
import 'dart:convert';
7+
import 'dart:io';
8+
import 'package:flutter_driver/flutter_driver.dart';
9+
10+
Future<void> main() async {
11+
final FlutterDriver driver = await FlutterDriver.connect();
12+
final String data =
13+
await driver.requestData(null, timeout: const Duration(minutes: 1));
14+
await driver.close();
15+
final Map<String, dynamic> result = jsonDecode(data);
16+
exit(result['result'] == 'true' ? 0 : 1);
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// The url_launcher_platform_interface defaults to MethodChannelUrlLauncher
2+
// as its instance, which is all the Windows implementation needs. This file
3+
// is here to silence warnings when publishing to pub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: url_launcher_windows
2+
description: Windows implementation of the url_launcher plugin.
3+
# 0.0.y+z is compatible with 1.0.0, if you land a breaking change bump
4+
# the version to 2.0.0.
5+
# See more details: https://github.com/flutter/flutter/wiki/Package-migration-to-1.0.0
6+
version: 0.0.1
7+
homepage: https://github.com/flutter/plugins/tree/master/packages/url_launcher/url_launcher_windows
8+
9+
flutter:
10+
plugin:
11+
platforms:
12+
windows:
13+
pluginClass: UrlLauncherPlugin
14+
15+
environment:
16+
sdk: ">=2.1.0 <3.0.0"
17+
flutter: ">=1.12.8 <2.0.0"
18+
19+
dependencies:
20+
flutter:
21+
sdk: flutter
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
flutter/
2+
3+
# Visual Studio user-specific files.
4+
*.suo
5+
*.user
6+
*.userosscache
7+
*.sln.docstates
8+
9+
# Visual Studio build-related files.
10+
x64/
11+
x86/
12+
13+
# Visual Studio cache files
14+
# files ending in .cache can be ignored
15+
*.[Cc]ache
16+
# but keep track of directories ending in .cache
17+
!*.[Cc]ache/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
cmake_minimum_required(VERSION 3.10)
2+
set(PROJECT_NAME "url_launcher_windows")
3+
project(${PROJECT_NAME} LANGUAGES CXX)
4+
5+
set(PLUGIN_NAME "${PROJECT_NAME}_plugin")
6+
7+
add_library(${PLUGIN_NAME} SHARED
8+
"url_launcher_plugin.cpp"
9+
)
10+
apply_standard_settings(${PLUGIN_NAME})
11+
set_target_properties(${PLUGIN_NAME} PROPERTIES
12+
CXX_VISIBILITY_PRESET hidden)
13+
target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL)
14+
target_include_directories(${PLUGIN_NAME} INTERFACE
15+
"${CMAKE_CURRENT_SOURCE_DIR}/include")
16+
target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin)
17+
18+
# List of absolute paths to libraries that should be bundled with the plugin
19+
set(file_chooser_bundled_libraries
20+
""
21+
PARENT_SCOPE
22+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
#ifndef PACKAGES_URL_LAUNCHER_URL_LAUNCHER_WINDOWS_WINDOWS_INCLUDE_URL_LAUNCHER_WINDOWS_URL_LAUNCHER_PLUGIN_H_
5+
#define PACKAGES_URL_LAUNCHER_URL_LAUNCHER_WINDOWS_WINDOWS_INCLUDE_URL_LAUNCHER_WINDOWS_URL_LAUNCHER_PLUGIN_H_
6+
7+
#include <flutter_plugin_registrar.h>
8+
9+
#ifdef FLUTTER_PLUGIN_IMPL
10+
#define FLUTTER_PLUGIN_EXPORT __declspec(dllexport)
11+
#else
12+
#define FLUTTER_PLUGIN_EXPORT __declspec(dllimport)
13+
#endif
14+
15+
#if defined(__cplusplus)
16+
extern "C" {
17+
#endif
18+
19+
FLUTTER_PLUGIN_EXPORT void UrlLauncherPluginRegisterWithRegistrar(
20+
FlutterDesktopPluginRegistrarRef registrar);
21+
22+
#if defined(__cplusplus)
23+
} // extern "C"
24+
#endif
25+
26+
#endif // PACKAGES_URL_LAUNCHER_URL_LAUNCHER_WINDOWS_WINDOWS_INCLUDE_URL_LAUNCHER_WINDOWS_URL_LAUNCHER_PLUGIN_H_

0 commit comments

Comments
 (0)