Skip to content

Merge from google/flutter-desktop-embedding #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Dec 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
out/
.DS_Store
1 change: 1 addition & 0 deletions .gn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
buildconfig = "//build/BUILDCONFIG.gn"
22 changes: 22 additions & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

group("gn_all") {
deps = [
"//library:flutter_embedder",
"//plugins/color_panel:color_panel",
"//plugins/file_chooser:file_chooser",
"//plugins/menubar:menubar",
]
}
80 changes: 80 additions & 0 deletions Debugging.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Debugging Desktop Flutter Applications

While the current workflow for debugging on desktop is not ideal, it is
possible to do most things, including source-level debugging and hot reload.

Because this relies on workarounds for desktop not being a supported device,
Flutter changes may break the workflows described below. We hope to extend
the `flutter` tool to improve support, but in the meantime please file
bugs in this project if you encounter issues with these instructions.

## Getting the Observatory Port

For all of these approaches, you will need the Observatory port of the
desktop application. Usually, `flutter run` would handle this, but there's
currently no way to `flutter run` a desktop application, so you will need to
provide it manually.

There are two options:

1. **Find the port in the console.** After launching your application, check
the console output (your terminal in Linux,
[Console](https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/debugging_with_xcode/chapters/debugging_tools.html)
in Xcode, etc.) for a line like:
```
Observatory listening on http://127.0.0.1:49494/
```
The port in this case is `49494`. This will change on every run of the
application, so you'll need to repeat this every time you relaunch.

1. **Hard-code the port**. In your embedder code, add `--observatory-port=49494`
(substituting a port of your choice) to the list of arguments passed to the
engine. If you are using `example/`, or code based on it, look for the
line that adds `--dart-non-checked-mode` for an example of adding arguments.
(Be sure not to add the `observatory-port` argument inside the `#if`,
however.)

## Debugging

### Command Line

The `flutter attach` command can connect to a desktop Flutter application
and provide the same interactive command line that `flutter run` would provide.
In the directory of the Flutter portion of your application (e.g.,
`/example/flutter_app`) run:

```
$ flutter attach --device-id=flutter-tester --debug-port=49494
```

Use the port you obtained above in place of `49494`. The `device-id` is
necessary to bypass checks for an attached iOS or Android device.

### VS Code

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

```
{
"name": "Flutter Desktop Attach",
"request": "attach",
"deviceId": "flutter-tester",
"observatoryUri": "http://127.0.0.1:49494/",
"type": "dart"
}
```

You will likely want to hard-code your observatory port, otherwise you will
need to change `launch.json` every time you relaunch the app.

In addition to the Flutter debug commands, source-level debugging with pause,
continue, variable inspection, etc. should all work.


### IntelliJ

**TBD**. If you test IntelliJ and are able to attach successfully, please
contribute instructions!
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,20 @@ In addition, there is:
by the build systems, but in the future developer utilities providing
some functionality similar to the `flutter` tool may be added.

## Flutter Application Requirements
## Flutter Application

### Requirements

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

### Debugging

Debugging of the Flutter side of a desktop application is possible, but requires
[a modified workflow](Debugging.md).

## Feedback and Discussion

For bug reports and specific feature requests, you can file GitHub issues. For
Expand Down
32 changes: 32 additions & 0 deletions build/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

config("defaults") {
cflags = [
"-std=c++14",
"-Wall",
"-Werror",
"-pthread",
]
include_dirs = [
"//"
]
}

config("shared_library_defaults") {
cflags = [
"-shared",
"-fPIC",
]
}
42 changes: 42 additions & 0 deletions build/BUILDCONFIG.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set_default_toolchain("//third_party/chromium/build/toolchain:gcc")

set_defaults("executable") {
configs = [ "//build:defaults" ]
}
set_defaults("static_library") {
configs = [ "//build:defaults" ]
}
set_defaults("shared_library") {
configs = [ "//build:defaults", "//build:shared_library_defaults" ]
}
set_defaults("published_shared_library") {
configs = [ "//build:defaults", "//build:shared_library_defaults" ]
}

if (host_os == "linux") {
is_linux = true
is_mac = false
is_win = false
} else if (host_os == "mac") {
is_linux = false
is_mac = true
is_win = false
} else if (host_os == "win") {
is_linux = false
is_mac = false
is_win = true
}
21 changes: 21 additions & 0 deletions build/flutter.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

declare_args() {
# The path to the Flutter tree to use for any Flutter operations or assets.
# If empty, assumes a directory called 'flutter' that is a sibling of this
# repository (like tools/flutter_location; this duplication avoids shelling
# out).
flutter_tree_path = rebase_path("../../flutter")
}
31 changes: 31 additions & 0 deletions build/linux/config/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import("//third_party/chromium/build/config/linux/pkg_config.gni")

pkg_config("gtk3") {
packages = [ "gtk+-3.0" ]
}

pkg_config("epoxy") {
packages = [ "epoxy" ]
}

pkg_config("x11") {
packages = [ "x11" ]
}

pkg_config("jsoncpp") {
packages = [ "jsoncpp" ]
}
60 changes: 60 additions & 0 deletions build/packaging.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Puts the public headers of the invoker in public_header_subdir
# under the top-level include/ directory in the build output.
#
# This is intended to make consuming public headers of all the libraries built
# by GN easy for outside build systems on Linux, by requiring only a single
# include directory.
if (is_linux) {
template("copy_includes") {
copy(target_name) {
assert(defined(invoker.sources),
"|sources| must be provided for copy_includes.")
forward_variables_from(invoker, [ "deps", "sources", "subdir" ])
output_dir = "$root_out_dir/include"
if (defined(subdir)) {
output_dir = "$output_dir/$subdir"
}
outputs = [ "$output_dir/{{source_file_part}}"]
}
}
}

# An abstraction for a shared library with associated headers that is intended
# to be consumed from the build output.
#
# On Linux, this performs a copy_includes in addition to building the library.
template("published_shared_library") {
template_target_name = target_name

if (is_linux) {
copy_includes("_publish_${template_target_name}_headers") {
sources = invoker.public
subdir = invoker.public_header_subdir
}

shared_library(template_target_name) {
forward_variables_from(invoker, "*")
assert(defined(public),
"|public| must be provided for published_shared_library.")

if (!defined(deps)) {
deps = []
}
deps += [ ":_publish_${template_target_name}_headers" ]
}
}
}
4 changes: 2 additions & 2 deletions example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ functionality rather than a usable application.

## Building and Running the Example

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

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

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

```
> ".\bin\x64\$(Configuration)\GLFW Example\GLFW Example.exe"
Expand Down
15 changes: 8 additions & 7 deletions example/flutter_app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ class _MyHomePage extends StatelessWidget {
if (!colorPanel.showing) {
colorPanel.show((color) {
_AppState.of(context).setPrimaryColor(color);
});
// Setting the primary color to a non-opaque color raises an exception.
}, showAlpha: false);
}
}

Expand Down Expand Up @@ -212,9 +213,9 @@ class FileChooserTestWidget extends StatelessWidget {
onPressed: () {
file_chooser.showSavePanel((result, paths) {
Scaffold.of(context).showSnackBar(SnackBar(
content: Text(_resultTextForFileChooserOperation(
_FileChooserType.save, result, paths)),
));
content: Text(_resultTextForFileChooserOperation(
_FileChooserType.save, result, paths)),
));
}, suggestedFileName: 'save_test.txt');
},
),
Expand All @@ -223,9 +224,9 @@ class FileChooserTestWidget extends StatelessWidget {
onPressed: () {
file_chooser.showOpenPanel((result, paths) {
Scaffold.of(context).showSnackBar(SnackBar(
content: Text(_resultTextForFileChooserOperation(
_FileChooserType.open, result, paths)),
));
content: Text(_resultTextForFileChooserOperation(
_FileChooserType.open, result, paths)),
));
}, allowsMultipleSelection: true);
},
),
Expand Down
Loading