Skip to content

Commit 5f258ab

Browse files
authored
Merge pull request #8 from google/master
Merge pull request from google/master
2 parents 2a37650 + 2106e63 commit 5f258ab

Some content is hidden

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

60 files changed

+576
-211
lines changed

.appveyor.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ image: Visual Studio 2017
1717
platform: x64
1818

1919
install:
20-
- ps: build\ci\install_flutter.ps1 $env:APPVEYOR_BUILD_FOLDER\..
20+
# None of the packaged channels are new enough for the current state
21+
# of FDE, so for now clone master instead.
22+
#- ps: build\ci\install_flutter.ps1 $env:APPVEYOR_BUILD_FOLDER\..
23+
- git clone -b master https://github.com/flutter/flutter.git %APPVEYOR_BUILD_FOLDER%\..\flutter
2124

2225
build_script:
23-
- msbuild "example\windows\Example Embedder.sln"
26+
- msbuild "example\windows_fde\Example Embedder.sln"

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ matrix:
2525
before_script:
2626
- export PATH=$PATH:$TRAVIS_BUILD_DIR/../flutter/bin:$TRAVIS_BUILD_DIR/bin
2727
script:
28-
- make -C example/linux
28+
- make -C example/linux_fde
2929

3030
- os: linux
3131
dist: xenial
@@ -39,11 +39,11 @@ matrix:
3939
before_script:
4040
- export PATH=$PATH:$TRAVIS_BUILD_DIR/bin
4141
script:
42-
- make -C example/linux USE_GN=1
42+
- make -C example/linux_fde USE_GN=1
4343

4444
- os: osx
4545
language: objective-c
46-
xcode_project: example/macos/ExampleEmbedder.xcodeproj
46+
xcode_project: example/macos_fde/ExampleEmbedder.xcodeproj
4747
xcode_scheme: ExampleEmbedder
4848
install:
4949
- build/ci/install_flutter $TRAVIS_BUILD_DIR/..

Debugging.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ There are two options:
4141
The `flutter attach` command can connect to a desktop Flutter application
4242
and provide the same interactive command line that `flutter run` would provide.
4343
In the directory of the Flutter portion of your application (e.g.,
44-
`/example/flutter_app`) run:
44+
`/example/` for this project's example application) run:
4545

4646
```
4747
$ flutter attach --device-id=flutter-tester --debug-port=49494
@@ -52,7 +52,7 @@ necessary to bypass checks for an attached iOS or Android device.
5252

5353
### VS Code
5454

55-
Open the Flutter portion of your application (e.g., `/example/flutter_app`).
55+
Open the Flutter portion of your application (e.g., `/example/`).
5656
Add a [launch
5757
configuration](https://code.visualstudio.com/docs/editor/debugging#_launch-configurations)
5858
like the following, substituting your Observatory port:

Flutter-Requirements.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,13 @@ on all platforms.
6262

6363
Symptoms of missing fonts can include text failing to display, console logging
6464
about failure to load fonts, or in some cases crashes.
65+
66+
## Plugins
67+
68+
If your project uses any plugins with platform components, they won't
69+
work, as the native side will be missing. Depending on how the Dart side of the
70+
plugin is written, they may fail gracefully, or may throw errors.
71+
72+
You may need to make the calls to those plugins conditional based on the host
73+
platform. Alternately, if you have the expertise, you could implement the native
74+
side of the plugin in your desktop project(s).

Quick-Start.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Quick Start
2+
3+
A common question for people discovering this project is: How do I easily add
4+
desktop support to my existing Flutter application?
5+
6+
The answer is that at this point, you don't. The project is still in early
7+
stages, and a lot of things are still in flux; if you don't already have
8+
experience doing desktop development on the platform(s) you want to add,
9+
this project is probably not ready for you to use it yet. The focus is currently
10+
on improving core functionality, not on ease of use. Neither the API surface nor
11+
the project structure are stable, and no attempt will be made to provide
12+
supported migration paths as things change.
13+
14+
However, if you want to try out an existing Flutter application running on the
15+
desktop even with those caveats, and don't have experience with desktop
16+
development, here are two approaches that might work for you.
17+
18+
With either approach, be sure to follow the [main README](README.md) and
19+
[library README](library/README.md) instructions on setting up prerequisites
20+
and adjusting your Flutter application.
21+
22+
## Replace the 'example' Flutter Code
23+
24+
Since `example/` is already configured to run on all the platforms this project
25+
supports, you can swap in your project's Dart code, `pubspec.yaml`, resources,
26+
etc., then follow the [normal directions](example/README.md) for building the
27+
example application on your platform.
28+
29+
This will be the easiest approach to keep working as the project changes, but
30+
requires that you essentially wrap your whole application in a
31+
flutter-desktop-embedding checkout.
32+
33+
## Copy the '\*\_fde' Directories
34+
35+
Starting from the example projects means you don't have to create projects from
36+
scratch, and since they are self-contained they can be added to an existing
37+
project without needing to move it. However, because the projects build
38+
the flutter-desktop-embedding libraries from source, they contain relative paths
39+
to the flutter-desktop-embedding projects and tools they depend on. You will
40+
need to update those paths in order for the projects to work. On Linux, the
41+
variables you will need to change are documented in the Makefile. On macOS and
42+
Windows, you will need some familiarity with Xcode and Visual Studio
43+
respectively to make the changes.
44+
45+
With this approach, you should expect breakage when you update the
46+
flutter-desktop-embedding reposity; when that happens you will need to look at
47+
what has changed in the example projects and update your copies accordingly, or
48+
start over with fresh copies and adjust the paths again.

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@ optional plugins to access other native platform functionality.
1111

1212
## How to Use This Code
1313

14+
_If you have an existing Flutter app and just want to get it running, see
15+
the [quick start](Quick-Start.md) page before continuing._
16+
1417
### Setting Up
1518

1619
The tooling and build infrastructure for this project requires that you have
1720
a Flutter tree in the same parent directory as the clone of this project:
1821

1922
```
2023
<parent dir>
21-
├─ flutter (from http://github.com/flutter/flutter)
24+
├─ flutter (from https://github.com/flutter/flutter)
2225
└─ flutter-desktop-embedding (from https://github.com/google/flutter-desktop-embedding)
2326
```
2427

build/ci/install_flutter

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
set -e
1818

19-
readonly CHANNEL="stable"
20-
readonly VERSION="1.0.0"
19+
readonly CHANNEL="dev"
20+
readonly VERSION="1.1.8"
2121

2222
if [[ "${TRAVIS_OS_NAME}" == "linux" ]]; then
2323
readonly FLUTTER_OS="linux"
File renamed without changes.
File renamed without changes.

example/README.md

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,52 @@
33
This application shows an example of how to use the embedding library on each
44
platform including build dependencies, resource bundling, and using plugins.
55

6+
In this example, the platform-specific code lives in `<platform>_fde`. For
7+
instance, the macOS project is in macos\_fde. This follows the pattern of
8+
the `android/` and `ios/` directories in a typical Flutter application (with
9+
`_fde` suffixes to avoid confusion or collisions if desktop support is added
10+
to Flutter itself). There's no requirement to use the same names in your
11+
project, or even to put them in the Flutter application directory.
12+
613
The example application is intended to be a starting point, rather than an
714
authoritative example. For instance, you might use a different build system,
8-
package resources differently, etc.
15+
package resources differently, etc. If you are are adding Flutter to an
16+
existing desktop application, you might instead put the Flutter application code
17+
inside your existing project structure.
918

1019
It also serves as a simple test environment for the plugins that are part of
1120
this project, and built-in event handling, so is a collection of unrelated
1221
functionality rather than a usable application.
1322

1423
## Building and Running the Example
1524

16-
Since the example is meant to show how the library would actually be used, it
17-
deliberately uses platform-specific build systems that are separate from the
18-
rest of the project's build system.
25+
There is currently no tool that abstracts the platform-specific builds the
26+
way `flutter build` or `flutter run` does for iOS and Android, so you will need
27+
to follow the platform-specific build instructions for your platform below.
1928

20-
The examples do build the library from source, so you will need to ensure you
29+
The examples build the library from source, so you will need to ensure you
2130
have all the dependencies for
2231
[building the library on your platform](../library/README.md) before continuing.
2332

2433
### Linux
2534

26-
Run `make` under `linux/`. The example binary and its resources will be
27-
in `out/`, and can be run from there:
35+
Run `make -C example/linux_fde/`. The example binary and its resources will be
36+
in `example/build/linux_fde`, and can be run from there:
37+
38+
```
39+
$ ./example/build/linux_fde/debug/flutter_embedder_example
40+
```
41+
42+
To build a version with Dart asserts disabled (and thus no DEBUG banner),
43+
run `make BUILD=release` instead, then launch it with:
2844

2945
```
30-
$ ./out/flutter_embedder_example
46+
$ ./example/build/linux_fde/release/flutter_embedder_example
3147
```
3248

3349
### macOS
3450

35-
Open the ExampleEmbedder Xcode project under `macos/`, and build and run the
51+
Open the ExampleEmbedder Xcode project under `macos_fde/`, and build and run the
3652
example application target.
3753

3854
#### Note
@@ -50,11 +66,11 @@ to a XIB in your own project:
5066

5167
### Windows
5268

53-
Open the `Example Embedder` Visual Studio solution file under `windows\` and
69+
Open the `Example Embedder` Visual Studio solution file under `windows_fde\` and
5470
build the GLFW Example project.
5571

5672
The resulting binary will be in `bin\x64\$(Configuration)\GLFW Example\`. It
57-
currently uses relative paths so must be run from the `windows\` directory:
73+
currently uses relative paths so must be run from the `windows_fde\` directory:
5874

5975
```
6076
> ".\bin\x64\$(Configuration)\GLFW Example\GLFW Example.exe"

example/analysis_options.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include: ../analysis_options.yaml

example/flutter_app/README.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

example/flutter_app/analysis_options.yaml

Lines changed: 0 additions & 1 deletion
This file was deleted.
File renamed without changes.

example/linux/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

example/linux/Makefile renamed to example/linux_fde/Makefile

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,30 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
# Example-specific variables.
16+
# To modify this Makefile for a different application, these are the values
17+
# that are mostly likely to need to be changed.
18+
19+
# The location of the flutter-desktop-embedding repository.
20+
FDE_ROOT=$(CURDIR)/../..
21+
# The C++ code for the embedder application.
22+
SOURCES=flutter_embedder_example.cc
23+
# Plugins to include (from the flutter-desktop-embedding plugins/ directory).
24+
PLUGIN_NAMES=color_panel file_chooser menubar
25+
26+
27+
# Default build type. For a release build, set BUILD=release.
28+
# Currently this only sets NDEBUG, which is used to control the flags passed
29+
# to the Flutter engine in the example shell, and not the complation settings
30+
# (e.g., optimization level) of the C++ code.
31+
BUILD:=debug
32+
1533
# Dependency locations
16-
PROJECT_ROOT=$(CURDIR)/../..
17-
FLUTTER_EMBEDDER_LIB_DIR=$(PROJECT_ROOT)/library/linux
18-
FLUTTER_APP_DIR=$(PROJECT_ROOT)/example/flutter_app
19-
PLUGINS_DIR=$(PROJECT_ROOT)/plugins
20-
TOOLS_DIR=$(PROJECT_ROOT)/tools
34+
FLUTTER_APP_DIR=$(CURDIR)/..
35+
FLUTTER_APP_BUILD_DIR=$(FLUTTER_APP_DIR)/build
36+
FLUTTER_EMBEDDER_LIB_DIR=$(FDE_ROOT)/library/linux
37+
PLUGINS_DIR=$(FDE_ROOT)/plugins
38+
TOOLS_DIR=$(FDE_ROOT)/tools
2139
FLUTTER_DIR=$(shell $(TOOLS_DIR)/flutter_location)
2240

2341
# Libraries
@@ -27,7 +45,6 @@ FLUTTER_EMBEDDER_LIB=$(FLUTTER_EMBEDDER_LIB_DIR)/lib$(FLUTTER_EMBEDDER_LIB_NAME)
2745
FLUTTER_ENGINE_LIB_NAME=flutter_engine
2846
FLUTTER_ENGINE_LIB=$(FLUTTER_EMBEDDER_LIB_DIR)/lib$(FLUTTER_ENGINE_LIB_NAME).so
2947

30-
PLUGIN_NAMES=color_panel file_chooser menubar
3148
PLUGIN_LIB_NAME_PREFIX=flutter_embedder_
3249
PLUGIN_LIBS=$(foreach plugin,$(PLUGIN_NAMES)\
3350
,$(PLUGINS_DIR)/$(plugin)/linux/lib$(PLUGIN_LIB_NAME_PREFIX)$(plugin).so)
@@ -37,7 +54,7 @@ ALL_LIBS=$(FLUTTER_EMBEDDER_LIB) $(FLUTTER_ENGINE_LIB) $(PLUGIN_LIBS)
3754
# Headers
3855
PLUGIN_DIRS=$(patsubst %,$(PLUGINS_DIR)/%/linux,$(PLUGIN_NAMES))
3956
LIBRARY_DIRS=$(FLUTTER_EMBEDDER_LIB_DIR) $(PLUGIN_DIRS)
40-
INCLUDE_DIRS=$(patsubst %,%/include,$(LIBRARY_DIRS)) $(PROJECT_ROOT)/library/include
57+
INCLUDE_DIRS=$(patsubst %,%/include,$(LIBRARY_DIRS)) $(FDE_ROOT)/library/include
4158

4259
# Tools
4360
BUILD_ASSETS_BIN=$(TOOLS_DIR)/build_flutter_assets
@@ -47,10 +64,10 @@ FLUTTER_BIN=$(FLUTTER_DIR)/bin/flutter
4764
ICU_DATA_NAME=icudtl.dat
4865
ICU_DATA_SOURCE=$(FLUTTER_DIR)/bin/cache/artifacts/engine/linux-x64/$(ICU_DATA_NAME)
4966
FLUTTER_ASSETS_NAME=flutter_assets
50-
FLUTTER_ASSETS_SOURCE=$(FLUTTER_APP_DIR)/build/$(FLUTTER_ASSETS_NAME)
67+
FLUTTER_ASSETS_SOURCE=$(FLUTTER_APP_BUILD_DIR)/$(FLUTTER_ASSETS_NAME)
5168

5269
# Output bundle structure and targets
53-
OUT_DIR=$(CURDIR)/out
70+
OUT_DIR=$(FLUTTER_APP_BUILD_DIR)/linux_fde/$(BUILD)
5471
OUT_DATA_DIR=$(OUT_DIR)/data
5572
OUT_LIB_DIR=$(OUT_DIR)/lib
5673

@@ -60,9 +77,7 @@ ALL_LIBS_OUT=$(foreach lib,$(ALL_LIBS),$(OUT_LIB_DIR)/$(notdir $(lib)))
6077

6178
# Overrides for the optional GN build.
6279
ifdef USE_GN
63-
GN_OUT_DIR=$(PROJECT_ROOT)/out
64-
# Use GN's out dir even though this isn't a GN build, to group build output.
65-
OUT_DIR=$(GN_OUT_DIR)/example
80+
GN_OUT_DIR=$(FDE_ROOT)/out
6681

6782
# The GN build places all libraries at the top level of the output directory.
6883
FLUTTER_EMBEDDER_LIB=$(GN_OUT_DIR)/lib$(FLUTTER_EMBEDDER_LIB_NAME).so
@@ -83,7 +98,9 @@ endif
8398

8499
# Build settings
85100
CXX=g++ -std=c++14
86-
CXXFLAGS=-Wall -Werror $(shell pkg-config --cflags jsoncpp glfw3)
101+
CXXFLAGS.release=-DNDEBUG
102+
CXXFLAGS=-Wall -Werror $(shell pkg-config --cflags jsoncpp glfw3) \
103+
$(CXXFLAGS.$(BUILD))
87104
CPPFLAGS=$(patsubst %,-I%,$(INCLUDE_DIRS))
88105
ifdef USE_GN
89106
CPPFLAGS+=-DUSE_FLATTENED_INCLUDES
@@ -95,8 +112,6 @@ LDFLAGS=-L$(OUT_LIB_DIR) \
95112
$(patsubst %,-l$(PLUGIN_LIB_NAME_PREFIX)%,$(PLUGIN_NAMES)) \
96113
-Wl,-rpath=\$$ORIGIN/lib
97114

98-
SOURCES=flutter_embedder_example.cc
99-
100115
# Targets
101116

102117
.PHONY: all

example/linux/flutter_embedder_example.cc renamed to example/linux_fde/flutter_embedder_example.cc

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
#include <menubar/menubar_plugin.h>
2525

2626
#ifdef USE_FLATTENED_INCLUDES
27-
#include <flutter_desktop_embedding/embedder.h>
27+
#include <flutter_desktop_embedding/flutter_window_controller.h>
2828
#else
29-
#include <flutter_desktop_embedding/glfw/embedder.h>
29+
#include <flutter_desktop_embedding/glfw/flutter_window_controller.h>
3030
#endif
3131

3232
namespace {
@@ -53,10 +53,6 @@ std::string GetExecutableDirectory() {
5353
} // namespace
5454

5555
int main(int argc, char **argv) {
56-
if (!flutter_desktop_embedding::FlutterInit()) {
57-
std::cerr << "Couldn't init GLFW" << std::endl;
58-
}
59-
6056
// Resources are located relative to the executable.
6157
std::string base_directory = GetExecutableDirectory();
6258
if (base_directory.empty()) {
@@ -71,26 +67,27 @@ int main(int argc, char **argv) {
7167
#ifdef NDEBUG
7268
arguments.push_back("--disable-dart-asserts");
7369
#endif
70+
71+
flutter_desktop_embedding::FlutterWindowController flutter_controller(
72+
icu_data_path);
73+
7474
// Start the engine.
75-
auto window = flutter_desktop_embedding::CreateFlutterWindow(
76-
640, 480, assets_path, icu_data_path, arguments);
77-
if (window == nullptr) {
78-
flutter_desktop_embedding::FlutterTerminate();
75+
if (!flutter_controller.CreateWindow(640, 480, assets_path, arguments)) {
7976
return EXIT_FAILURE;
8077
}
8178

8279
// Register any native plugins.
8380
plugins_menubar::MenubarPlugin::RegisterWithRegistrar(
84-
flutter_desktop_embedding::GetRegistrarForPlugin(
85-
window, "plugins_menubar::MenubarPlugin"));
81+
flutter_controller.GetRegistrarForPlugin(
82+
"plugins_menubar::MenubarPlugin"));
8683
plugins_color_panel::ColorPanelPlugin::RegisterWithRegistrar(
87-
flutter_desktop_embedding::GetRegistrarForPlugin(
88-
window, "plugins_color_panel::ColorPanelPlugin"));
84+
flutter_controller.GetRegistrarForPlugin(
85+
"plugins_color_panel::ColorPanelPlugin"));
8986
plugins_file_chooser::FileChooserPlugin::RegisterWithRegistrar(
90-
flutter_desktop_embedding::GetRegistrarForPlugin(
91-
window, "plugins_file_chooser::FileChooserPlugin"));
87+
flutter_controller.GetRegistrarForPlugin(
88+
"plugins_file_chooser::FileChooserPlugin"));
9289

93-
flutter_desktop_embedding::FlutterWindowLoop(window);
94-
glfwTerminate();
90+
// Run until the window is closed.
91+
flutter_controller.RunEventLoop();
9592
return EXIT_SUCCESS;
9693
}
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)