Skip to content

Commit d6a94e9

Browse files
authored
Merge pull request #1 from google/master
Merge from google/flutter-desktop-embedding
2 parents 4990b13 + 157ab9b commit d6a94e9

File tree

82 files changed

+2097
-263
lines changed

Some content is hidden

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

82 files changed

+2097
-263
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
out/
12
.DS_Store

.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
buildconfig = "//build/BUILDCONFIG.gn"

BUILD.gn

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
group("gn_all") {
16+
deps = [
17+
"//library:flutter_embedder",
18+
"//plugins/color_panel:color_panel",
19+
"//plugins/file_chooser:file_chooser",
20+
"//plugins/menubar:menubar",
21+
]
22+
}

Debugging.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Debugging Desktop Flutter Applications
2+
3+
While the current workflow for debugging on desktop is not ideal, it is
4+
possible to do most things, including source-level debugging and hot reload.
5+
6+
Because this relies on workarounds for desktop not being a supported device,
7+
Flutter changes may break the workflows described below. We hope to extend
8+
the `flutter` tool to improve support, but in the meantime please file
9+
bugs in this project if you encounter issues with these instructions.
10+
11+
## Getting the Observatory Port
12+
13+
For all of these approaches, you will need the Observatory port of the
14+
desktop application. Usually, `flutter run` would handle this, but there's
15+
currently no way to `flutter run` a desktop application, so you will need to
16+
provide it manually.
17+
18+
There are two options:
19+
20+
1. **Find the port in the console.** After launching your application, check
21+
the console output (your terminal in Linux,
22+
[Console](https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/debugging_with_xcode/chapters/debugging_tools.html)
23+
in Xcode, etc.) for a line like:
24+
```
25+
Observatory listening on http://127.0.0.1:49494/
26+
```
27+
The port in this case is `49494`. This will change on every run of the
28+
application, so you'll need to repeat this every time you relaunch.
29+
30+
1. **Hard-code the port**. In your embedder code, add `--observatory-port=49494`
31+
(substituting a port of your choice) to the list of arguments passed to the
32+
engine. If you are using `example/`, or code based on it, look for the
33+
line that adds `--dart-non-checked-mode` for an example of adding arguments.
34+
(Be sure not to add the `observatory-port` argument inside the `#if`,
35+
however.)
36+
37+
## Debugging
38+
39+
### Command Line
40+
41+
The `flutter attach` command can connect to a desktop Flutter application
42+
and provide the same interactive command line that `flutter run` would provide.
43+
In the directory of the Flutter portion of your application (e.g.,
44+
`/example/flutter_app`) run:
45+
46+
```
47+
$ flutter attach --device-id=flutter-tester --debug-port=49494
48+
```
49+
50+
Use the port you obtained above in place of `49494`. The `device-id` is
51+
necessary to bypass checks for an attached iOS or Android device.
52+
53+
### VS Code
54+
55+
Open the Flutter portion of your application (e.g., `/example/flutter_app`).
56+
Add a [launch
57+
configuration](https://code.visualstudio.com/docs/editor/debugging#_launch-configurations)
58+
like the following, substituting your Observatory port:
59+
60+
```
61+
{
62+
"name": "Flutter Desktop Attach",
63+
"request": "attach",
64+
"deviceId": "flutter-tester",
65+
"observatoryUri": "http://127.0.0.1:49494/",
66+
"type": "dart"
67+
}
68+
```
69+
70+
You will likely want to hard-code your observatory port, otherwise you will
71+
need to change `launch.json` every time you relaunch the app.
72+
73+
In addition to the Flutter debug commands, source-level debugging with pause,
74+
continue, variable inspection, etc. should all work.
75+
76+
77+
### IntelliJ
78+
79+
**TBD**. If you test IntelliJ and are able to attach successfully, please
80+
contribute instructions!

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,20 @@ In addition, there is:
4646
by the build systems, but in the future developer utilities providing
4747
some functionality similar to the `flutter` tool may be added.
4848

49-
## Flutter Application Requirements
49+
## Flutter Application
50+
51+
### Requirements
5052

5153
Since desktop is not a supported platform for Flutter, be sure to read the
5254
[Flutter application requirements document](Flutter-Requirements.md) for
5355
important information about how to set up your Flutter application for use
5456
with this library.
5557

58+
### Debugging
59+
60+
Debugging of the Flutter side of a desktop application is possible, but requires
61+
[a modified workflow](Debugging.md).
62+
5663
## Feedback and Discussion
5764

5865
For bug reports and specific feature requests, you can file GitHub issues. For

build/BUILD.gn

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
config("defaults") {
16+
cflags = [
17+
"-std=c++14",
18+
"-Wall",
19+
"-Werror",
20+
"-pthread",
21+
]
22+
include_dirs = [
23+
"//"
24+
]
25+
}
26+
27+
config("shared_library_defaults") {
28+
cflags = [
29+
"-shared",
30+
"-fPIC",
31+
]
32+
}

build/BUILDCONFIG.gn

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
set_default_toolchain("//third_party/chromium/build/toolchain:gcc")
16+
17+
set_defaults("executable") {
18+
configs = [ "//build:defaults" ]
19+
}
20+
set_defaults("static_library") {
21+
configs = [ "//build:defaults" ]
22+
}
23+
set_defaults("shared_library") {
24+
configs = [ "//build:defaults", "//build:shared_library_defaults" ]
25+
}
26+
set_defaults("published_shared_library") {
27+
configs = [ "//build:defaults", "//build:shared_library_defaults" ]
28+
}
29+
30+
if (host_os == "linux") {
31+
is_linux = true
32+
is_mac = false
33+
is_win = false
34+
} else if (host_os == "mac") {
35+
is_linux = false
36+
is_mac = true
37+
is_win = false
38+
} else if (host_os == "win") {
39+
is_linux = false
40+
is_mac = false
41+
is_win = true
42+
}

build/flutter.gni

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
declare_args() {
16+
# The path to the Flutter tree to use for any Flutter operations or assets.
17+
# If empty, assumes a directory called 'flutter' that is a sibling of this
18+
# repository (like tools/flutter_location; this duplication avoids shelling
19+
# out).
20+
flutter_tree_path = rebase_path("../../flutter")
21+
}

build/linux/config/BUILD.gn

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import("//third_party/chromium/build/config/linux/pkg_config.gni")
16+
17+
pkg_config("gtk3") {
18+
packages = [ "gtk+-3.0" ]
19+
}
20+
21+
pkg_config("epoxy") {
22+
packages = [ "epoxy" ]
23+
}
24+
25+
pkg_config("x11") {
26+
packages = [ "x11" ]
27+
}
28+
29+
pkg_config("jsoncpp") {
30+
packages = [ "jsoncpp" ]
31+
}

build/packaging.gni

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Puts the public headers of the invoker in public_header_subdir
16+
# under the top-level include/ directory in the build output.
17+
#
18+
# This is intended to make consuming public headers of all the libraries built
19+
# by GN easy for outside build systems on Linux, by requiring only a single
20+
# include directory.
21+
if (is_linux) {
22+
template("copy_includes") {
23+
copy(target_name) {
24+
assert(defined(invoker.sources),
25+
"|sources| must be provided for copy_includes.")
26+
forward_variables_from(invoker, [ "deps", "sources", "subdir" ])
27+
output_dir = "$root_out_dir/include"
28+
if (defined(subdir)) {
29+
output_dir = "$output_dir/$subdir"
30+
}
31+
outputs = [ "$output_dir/{{source_file_part}}"]
32+
}
33+
}
34+
}
35+
36+
# An abstraction for a shared library with associated headers that is intended
37+
# to be consumed from the build output.
38+
#
39+
# On Linux, this performs a copy_includes in addition to building the library.
40+
template("published_shared_library") {
41+
template_target_name = target_name
42+
43+
if (is_linux) {
44+
copy_includes("_publish_${template_target_name}_headers") {
45+
sources = invoker.public
46+
subdir = invoker.public_header_subdir
47+
}
48+
49+
shared_library(template_target_name) {
50+
forward_variables_from(invoker, "*")
51+
assert(defined(public),
52+
"|public| must be provided for published_shared_library.")
53+
54+
if (!defined(deps)) {
55+
deps = []
56+
}
57+
deps += [ ":_publish_${template_target_name}_headers" ]
58+
}
59+
}
60+
}

example/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ functionality rather than a usable application.
1313

1414
## Building and Running the Example
1515

16-
Since the exmaple is meant to show how the library would actually be used, it
16+
Since the example is meant to show how the library would actually be used, it
1717
deliberately uses platform-specific build systems that are separate from the
1818
rest of the project's build system.
1919

@@ -54,7 +54,7 @@ Open the `Example Embedder` Visual Studio solution file under `windows\` and
5454
build the GLFW Example project.
5555

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

5959
```
6060
> ".\bin\x64\$(Configuration)\GLFW Example\GLFW Example.exe"

example/flutter_app/lib/main.dart

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ class _MyHomePage extends StatelessWidget {
150150
if (!colorPanel.showing) {
151151
colorPanel.show((color) {
152152
_AppState.of(context).setPrimaryColor(color);
153-
});
153+
// Setting the primary color to a non-opaque color raises an exception.
154+
}, showAlpha: false);
154155
}
155156
}
156157

@@ -212,9 +213,9 @@ class FileChooserTestWidget extends StatelessWidget {
212213
onPressed: () {
213214
file_chooser.showSavePanel((result, paths) {
214215
Scaffold.of(context).showSnackBar(SnackBar(
215-
content: Text(_resultTextForFileChooserOperation(
216-
_FileChooserType.save, result, paths)),
217-
));
216+
content: Text(_resultTextForFileChooserOperation(
217+
_FileChooserType.save, result, paths)),
218+
));
218219
}, suggestedFileName: 'save_test.txt');
219220
},
220221
),
@@ -223,9 +224,9 @@ class FileChooserTestWidget extends StatelessWidget {
223224
onPressed: () {
224225
file_chooser.showOpenPanel((result, paths) {
225226
Scaffold.of(context).showSnackBar(SnackBar(
226-
content: Text(_resultTextForFileChooserOperation(
227-
_FileChooserType.open, result, paths)),
228-
));
227+
content: Text(_resultTextForFileChooserOperation(
228+
_FileChooserType.open, result, paths)),
229+
));
229230
}, allowsMultipleSelection: true);
230231
},
231232
),

0 commit comments

Comments
 (0)