Skip to content

Commit 9b74c38

Browse files
stuartmorgan-gEgor
authored andcommitted
[url_launcher] Endorse url_launcher_linux (flutter#2863)
Adds an endorsement for url_launcher_linux, so that Linux is supported automatically. Part of flutter/flutter#41721
1 parent 39c45f6 commit 9b74c38

File tree

15 files changed

+327
-8
lines changed

15 files changed

+327
-8
lines changed

packages/url_launcher/url_launcher/CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 5.5.0
2+
3+
* Support Linux by default.
4+
15
## 5.4.11
26

37
* Add documentation in README suggesting how to properly encode urls with special characters.
@@ -46,7 +50,7 @@
4650

4751
## 5.4.0
4852

49-
* Support macos by default.
53+
* Support macOS by default.
5054

5155
## 5.3.0
5256

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
cmake_minimum_required(VERSION 3.10)
2+
project(runner LANGUAGES CXX)
3+
4+
set(BINARY_NAME "example")
5+
6+
cmake_policy(SET CMP0063 NEW)
7+
8+
set(CMAKE_INSTALL_RPATH "$ORIGIN/lib")
9+
10+
# Configure build options.
11+
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
12+
set(CMAKE_BUILD_TYPE "Debug" CACHE
13+
STRING "Flutter build mode" FORCE)
14+
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
15+
"Debug" "Profile" "Release")
16+
endif()
17+
18+
# Compilation settings that should be applied to most targets.
19+
function(APPLY_STANDARD_SETTINGS TARGET)
20+
target_compile_features(${TARGET} PUBLIC cxx_std_14)
21+
target_compile_options(${TARGET} PRIVATE -Wall -Werror)
22+
target_compile_options(${TARGET} PRIVATE "$<$<NOT:$<CONFIG:Debug>>:-O3>")
23+
target_compile_definitions(${TARGET} PRIVATE "$<$<NOT:$<CONFIG:Debug>>:NDEBUG>")
24+
endfunction()
25+
26+
set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")
27+
28+
# Flutter library and tool build rules.
29+
add_subdirectory(${FLUTTER_MANAGED_DIR})
30+
31+
# System-level dependencies.
32+
find_package(PkgConfig REQUIRED)
33+
pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)
34+
35+
# Application build
36+
add_executable(${BINARY_NAME}
37+
"main.cc"
38+
"my_application.cc"
39+
"${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
40+
)
41+
apply_standard_settings(${BINARY_NAME})
42+
target_link_libraries(${BINARY_NAME} PRIVATE flutter)
43+
target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK)
44+
add_dependencies(${BINARY_NAME} flutter_assemble)
45+
46+
# Generated plugin build rules, which manage building the plugins and adding
47+
# them to the application.
48+
include(flutter/generated_plugins.cmake)
49+
50+
51+
# === Installation ===
52+
# By default, "installing" just makes a relocatable bundle in the build
53+
# directory.
54+
set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle")
55+
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
56+
set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE)
57+
endif()
58+
59+
# Start with a clean build bundle directory every time.
60+
install(CODE "
61+
file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\")
62+
" COMPONENT Runtime)
63+
64+
set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data")
65+
set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib")
66+
67+
install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}"
68+
COMPONENT Runtime)
69+
70+
install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
71+
COMPONENT Runtime)
72+
73+
install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
74+
COMPONENT Runtime)
75+
76+
if(PLUGIN_BUNDLED_LIBRARIES)
77+
install(FILES "${PLUGIN_BUNDLED_LIBRARIES}"
78+
DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
79+
COMPONENT Runtime)
80+
endif()
81+
82+
# Fully re-copy the assets directory on each build to avoid having stale files
83+
# from a previous install.
84+
set(FLUTTER_ASSET_DIR_NAME "flutter_assets")
85+
install(CODE "
86+
file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\")
87+
" COMPONENT Runtime)
88+
install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}"
89+
DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime)
90+
91+
# Install the AOT library on non-Debug builds only.
92+
if(NOT CMAKE_BUILD_TYPE MATCHES "Debug")
93+
install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
94+
COMPONENT Runtime)
95+
endif()
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
cmake_minimum_required(VERSION 3.10)
2+
3+
set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral")
4+
5+
# Configuration provided via flutter tool.
6+
include(${EPHEMERAL_DIR}/generated_config.cmake)
7+
8+
# TODO: Move the rest of this into files in ephemeral. See
9+
# https://github.com/flutter/flutter/issues/57146.
10+
11+
# Serves the same purpose as list(TRANSFORM ... PREPEND ...),
12+
# which isn't available in 3.10.
13+
function(list_prepend LIST_NAME PREFIX)
14+
set(NEW_LIST "")
15+
foreach(element ${${LIST_NAME}})
16+
list(APPEND NEW_LIST "${PREFIX}${element}")
17+
endforeach(element)
18+
set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE)
19+
endfunction()
20+
21+
# === Flutter Library ===
22+
# System-level dependencies.
23+
find_package(PkgConfig REQUIRED)
24+
pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)
25+
pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0)
26+
pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0)
27+
28+
set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so")
29+
30+
# Published to parent scope for install step.
31+
set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE)
32+
set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE)
33+
set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE)
34+
set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE)
35+
36+
list(APPEND FLUTTER_LIBRARY_HEADERS
37+
"fl_basic_message_channel.h"
38+
"fl_binary_codec.h"
39+
"fl_binary_messenger.h"
40+
"fl_dart_project.h"
41+
"fl_engine.h"
42+
"fl_json_message_codec.h"
43+
"fl_json_method_codec.h"
44+
"fl_message_codec.h"
45+
"fl_method_call.h"
46+
"fl_method_channel.h"
47+
"fl_method_codec.h"
48+
"fl_method_response.h"
49+
"fl_plugin_registrar.h"
50+
"fl_plugin_registry.h"
51+
"fl_standard_message_codec.h"
52+
"fl_standard_method_codec.h"
53+
"fl_string_codec.h"
54+
"fl_value.h"
55+
"fl_view.h"
56+
"flutter_linux.h"
57+
)
58+
list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/")
59+
add_library(flutter INTERFACE)
60+
target_include_directories(flutter INTERFACE
61+
"${EPHEMERAL_DIR}"
62+
)
63+
target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}")
64+
target_link_libraries(flutter INTERFACE
65+
PkgConfig::GTK
66+
PkgConfig::GLIB
67+
PkgConfig::GIO
68+
)
69+
add_dependencies(flutter flutter_assemble)
70+
71+
# === Flutter tool backend ===
72+
# _phony_ is a non-existent file to force this command to run every time,
73+
# since currently there's no way to get a full input/output list from the
74+
# flutter tool.
75+
add_custom_command(
76+
OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS}
77+
${CMAKE_CURRENT_BINARY_DIR}/_phony_
78+
COMMAND ${CMAKE_COMMAND} -E env
79+
${FLUTTER_TOOL_ENVIRONMENT}
80+
"${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh"
81+
linux-x64 ${CMAKE_BUILD_TYPE}
82+
)
83+
add_custom_target(flutter_assemble DEPENDS
84+
"${FLUTTER_LIBRARY}"
85+
${FLUTTER_LIBRARY_HEADERS}
86+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// Generated file. Do not edit.
3+
//
4+
5+
#include "generated_plugin_registrant.h"
6+
7+
#include <url_launcher_linux/url_launcher_plugin.h>
8+
9+
void fl_register_plugins(FlPluginRegistry* registry) {
10+
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
11+
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
12+
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// Generated file. Do not edit.
3+
//
4+
5+
#ifndef GENERATED_PLUGIN_REGISTRANT_
6+
#define GENERATED_PLUGIN_REGISTRANT_
7+
8+
#include <flutter_linux/flutter_linux.h>
9+
10+
// Registers Flutter plugins.
11+
void fl_register_plugins(FlPluginRegistry* registry);
12+
13+
#endif // GENERATED_PLUGIN_REGISTRANT_
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#
2+
# Generated file, do not edit.
3+
#
4+
5+
list(APPEND FLUTTER_PLUGIN_LIST
6+
url_launcher_linux
7+
)
8+
9+
set(PLUGIN_BUNDLED_LIBRARIES)
10+
11+
foreach(plugin ${FLUTTER_PLUGIN_LIST})
12+
add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/linux plugins/${plugin})
13+
target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin)
14+
list(APPEND PLUGIN_BUNDLED_LIBRARIES $<TARGET_FILE:${plugin}_plugin>)
15+
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
16+
endforeach(plugin)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "my_application.h"
2+
3+
int main(int argc, char** argv) {
4+
g_autoptr(MyApplication) app = my_application_new();
5+
return g_application_run(G_APPLICATION(app), argc, argv);
6+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include "my_application.h"
2+
3+
#include <flutter_linux/flutter_linux.h>
4+
5+
#include "flutter/generated_plugin_registrant.h"
6+
7+
struct _MyApplication {
8+
GtkApplication parent_instance;
9+
};
10+
11+
G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION)
12+
13+
// Implements GApplication::activate.
14+
static void my_application_activate(GApplication* application) {
15+
GtkWindow* window =
16+
GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application)));
17+
GtkHeaderBar *header_bar = GTK_HEADER_BAR(gtk_header_bar_new());
18+
gtk_widget_show(GTK_WIDGET(header_bar));
19+
gtk_header_bar_set_title(header_bar, "example");
20+
gtk_header_bar_set_show_close_button(header_bar, TRUE);
21+
gtk_window_set_titlebar(window, GTK_WIDGET(header_bar));
22+
gtk_window_set_default_size(window, 1280, 720);
23+
gtk_widget_show(GTK_WIDGET(window));
24+
25+
g_autoptr(FlDartProject) project = fl_dart_project_new();
26+
27+
FlView* view = fl_view_new(project);
28+
gtk_widget_show(GTK_WIDGET(view));
29+
gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view));
30+
31+
fl_register_plugins(FL_PLUGIN_REGISTRY(view));
32+
33+
gtk_widget_grab_focus(GTK_WIDGET(view));
34+
}
35+
36+
static void my_application_class_init(MyApplicationClass* klass) {
37+
G_APPLICATION_CLASS(klass)->activate = my_application_activate;
38+
}
39+
40+
static void my_application_init(MyApplication* self) {}
41+
42+
MyApplication* my_application_new() {
43+
return MY_APPLICATION(g_object_new(my_application_get_type(), nullptr));
44+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef FLUTTER_MY_APPLICATION_H_
2+
#define FLUTTER_MY_APPLICATION_H_
3+
4+
#include <gtk/gtk.h>
5+
6+
G_DECLARE_FINAL_TYPE(MyApplication, my_application, MY, APPLICATION,
7+
GtkApplication)
8+
9+
/**
10+
* my_application_new:
11+
*
12+
* Creates a new Flutter-based application.
13+
*
14+
* Returns: a new #MyApplication.
15+
*/
16+
MyApplication* my_application_new();
17+
18+
#endif // FLUTTER_MY_APPLICATION_H_

packages/url_launcher/url_launcher/example/test_driver/url_launcher_e2e.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'dart:io' show Platform;
6+
7+
import 'package:flutter/foundation.dart' show kIsWeb;
58
import 'package:flutter_test/flutter_test.dart';
69
import 'package:e2e/e2e.dart';
710
import 'package:url_launcher/url_launcher.dart';
@@ -15,8 +18,10 @@ void main() {
1518
// Generally all devices should have some default browser.
1619
expect(await canLaunch('http://flutter.dev'), true);
1720

18-
// Generally all devices should have some default SMS app.
19-
expect(await canLaunch('sms:5555555555'), true);
21+
// SMS handling is available by default on most platforms.
22+
if (kIsWeb || !Platform.isLinux) {
23+
expect(await canLaunch('sms:5555555555'), true);
24+
}
2025

2126
// tel: and mailto: links may not be openable on every device. iOS
2227
// simulators notably can't open these link types.

packages/url_launcher/url_launcher/pubspec.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: url_launcher
22
description: Flutter plugin for launching a URL on Android and iOS. Supports
33
web, phone, SMS, and email schemes.
44
homepage: https://github.com/flutter/plugins/tree/master/packages/url_launcher/url_launcher
5-
version: 5.4.11
5+
version: 5.5.0
66

77
flutter:
88
plugin:
@@ -14,6 +14,8 @@ flutter:
1414
pluginClass: FLTURLLauncherPlugin
1515
web:
1616
default_package: url_launcher_web
17+
linux:
18+
default_package: url_laucher_linux
1719
macos:
1820
default_package: url_laucher_macos
1921

@@ -27,6 +29,7 @@ dependencies:
2729
# TODO(amirh): Revisit this (either update this part in the design or the pub tool).
2830
# https://github.com/flutter/flutter/issues/46264
2931
url_launcher_web: ^0.1.0+1
32+
url_launcher_linux: ^0.0.1
3033
url_launcher_macos: ^0.0.1
3134

3235
dev_dependencies:
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1+
# 0.0.1+1
2+
* README update for endorsement by url_launcher.
3+
14
# 0.0.1
25
* The initial implementation of url_launcher for Linux

packages/url_launcher/url_launcher_linux/README.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,22 @@ The Linux implementation of [`url_launcher`][1].
66

77
### Import the package
88

9-
This package is an unendorsed Linux implementation of `url_launcher`.
9+
This package has been endorsed, meaning that you only need to add `url_launcher`
10+
as a dependency in your `pubspec.yaml`. It will be automatically included in your app
11+
when you depend on `package:url_launcher`.
1012

11-
In order to use this now, you'll need to depend on `url_launcher_linux`.
12-
When this package is endorsed it will be automatically used by the `url_launcher` package and you can switch to that API.
13+
This is what the above means to your `pubspec.yaml`:
14+
15+
```yaml
16+
...
17+
dependencies:
18+
...
19+
url_launcher: ^5.5.0
20+
...
21+
```
22+
23+
If you wish to use the Linux package only, you can add `url_launcher_linux` as a
24+
dependency:
1325

1426
```yaml
1527
...

0 commit comments

Comments
 (0)