Skip to content

Plugin Support #20

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 9 commits into from
Nov 4, 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
80 changes: 63 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ for desktop
This project doesn't compete with
[this](https://github.com/google/flutter-desktop-embedding) awesome one.
The purpose of this project is to support the
[Flutter](https://github.com/flutter/flutter) framework on Windows, macOS, and
[Flutter](https://github.com/flutter/flutter) framework on Windows, MacOS, and
Linux using a **SINGLE** code base.

[**GLFW**](https://github.com/go-gl/glfw) fits the job because it
Expand Down Expand Up @@ -58,11 +58,11 @@ cd ../..
# Download the share library (CORRESPONDING to the Flutter's version shown above)
wget https://storage.googleapis.com/flutter_infra/flutter/af42b6dc95bd9f719e43c4e9f29a00640f0f0bba/linux-x64/linux-x64-embedder -O .build/temp.zip

# Move the share library
unzip .build/temp.zip -x flutter_embedder.h && mv libflutter_engine.so flutter/library/linux/
# Extract the share library
unzip .build/temp.zip -x flutter_embedder.h

# REQUIRED: When using `go build` or `go run main.go`, the go library need to know where to look for the share library
export CGO_LDFLAGS="-L${PWD}/flutter/library/linux"
export CGO_LDFLAGS="-L${PWD}"

# If you `go build`, the share library must stay in the same path, relative to the go binary

Expand Down Expand Up @@ -118,6 +118,48 @@ go run main.go

</details>

<details>
<summary> :package: :apple: MacOS</summary>
<h4>From binaries</h4>
Check out the <a href="https://github.com/Drakirus/go-flutter-desktop-embedder/releases">Release</a> page for prebuilt versions.

<h4>From source</h4>

Go read first: [go-gl/glfw](https://github.com/go-gl/glfw/)


```bash
# Clone
git clone https://github.com/Drakirus/go-flutter-desktop-embedder.git
cd go-flutter-desktop-embedder

# Build the flutter simpleDemo project
cd example/simpleDemo/
cd flutter_project/demo/
flutter build bundle
cd ../..

# Download the share library (CORRESPONDING to the Flutter's version shown above)
wget https://storage.googleapis.com/flutter_infra/flutter/af42b6dc95bd9f719e43c4e9f29a00640f0f0bba/darwin-x64/FlutterEmbedder.framework.zip -O .build/temp.zip

# Move the share library
unzip .build/temp.zip -d .build && unzip .build/FlutterEmbedder.framework.zip -d .build/FlutterEmbedder.framework
mv .build/FlutterEmbedder.framework .

# REQUIRED: When using `go build` or `go run main.go`, the go library need to know where to look for the share library
export CGO_LDFLAGS="-F${PWD} -Wl,-rpath,@executable_path"

# If you `go build`, the share library must stay in the same path, relative to the go binary

# Get the libraries
go get -u -v github.com/Drakirus/go-flutter-desktop-embedder

# Make sure the path in "main.go" to the `icudtl.dat` is correct.
# Build the example project
go build
```

</details>


## Flutter Demos Projects
Expand All @@ -128,17 +170,21 @@ The examples are available [here](./example/)

- [x] Linux :penguin:
- [x] Windows :checkered_flag:
- [ ] MacOS :apple:
- [x] Text input
- [ ] Plugins
- [x] MacOS :apple:
- [x] Importable go library
- [x] Clipboard (through shortcuts)
- [ ] Clipboard (through the click)
- [x] Keyboard shortcuts
- [x] <kbd>ctrl-c</kbd> <kbd>ctrl-v</kbd> <kbd>ctrl-x</kbd> <kbd>ctrl-a</kbd>
- [x] <kbd>Home</kbd> <kbd>End</kbd> <kbd>shift-Home</kbd> <kbd>shift-End</kbd>
- [x] <kbd>Left</kbd> <kbd>ctrl-Left</kbd> <kbd>ctrl-shift-Left</kbd>
- [x] <kbd>Right</kbd> <kbd>ctrl-Right</kbd> <kbd>ctrl-shift-Right</kbd>
- [x] <kbd>Backspace</kbd> <kbd>ctrl-Backspace</kbd> <kbd>Delete</kbd>
- [ ] <kbd>ctrl-Delete</kbd>
- [ ] Key events
- [ ] Plugins [Medium article on how the the Flutter's messaging works](https://medium.com/flutter-io/flutter-platform-channels-ce7f540a104e)
- [x] JSON MethodChannel
- [ ] StandardMethodCodec, ...
- [ ] System plugins [Platform channels used by the Flutter system](https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/services/system_channels.dart)
- [x] Window Title
- [x] Text input
- [x] Clipboard (through shortcuts)
- [ ] Clipboard (through the click)
- [x] Keyboard shortcuts
- [x] <kbd>ctrl-c</kbd> <kbd>ctrl-v</kbd> <kbd>ctrl-x</kbd> <kbd>ctrl-a</kbd>
- [x] <kbd>Home</kbd> <kbd>End</kbd> <kbd>shift-Home</kbd> <kbd>shift-End</kbd>
- [x] <kbd>Left</kbd> <kbd>ctrl-Left</kbd> <kbd>ctrl-shift-Left</kbd>
- [x] <kbd>Right</kbd> <kbd>ctrl-Right</kbd> <kbd>ctrl-shift-Right</kbd>
- [x] <kbd>Backspace</kbd> <kbd>ctrl-Backspace</kbd> <kbd>Delete</kbd>
- [ ] <kbd>ctrl-Delete</kbd>
- [ ] Key events
3 changes: 2 additions & 1 deletion example/simpleDemo/.build/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
temp.zip
*
!.gitignore
2 changes: 0 additions & 2 deletions example/simpleDemo/flutter/library/linux/.gitignore

This file was deleted.

24 changes: 23 additions & 1 deletion example/simpleDemo/flutter_project/demo/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart'
show debugDefaultTargetPlatformOverride;

import 'package:flutter/services.dart';
import 'dart:async';

void main() {
// Desktop platforms aren't a valid platform.
debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia;
Expand Down Expand Up @@ -31,11 +34,26 @@ class MyHomePage extends StatefulWidget {
final String title;

@override
_MyHomePageState createState() => new _MyHomePageState();
_MyHomePageState createState() {
return new _MyHomePageState();
}
}

class _MyHomePageState extends State<MyHomePage> {


static MethodChannel _channel = new MethodChannel('plugin_demo', new JSONMethodCodec());
Future GetVersion() async {
var res = await _channel.invokeMethod('getNumber');
print(res);
setState(() {
_counter = res;
});
}


int _counter = 0;
bool _ok = false;

void _incrementCounter() {
setState(() {
Expand All @@ -45,6 +63,10 @@ class _MyHomePageState extends State<MyHomePage> {

@override
Widget build(BuildContext context) {
if (!_ok) {
GetVersion();
_ok = true;
}
return new Scaffold(
appBar: new AppBar(
title: new Text(widget.title),
Expand Down
18 changes: 9 additions & 9 deletions example/simpleDemo/flutter_project/demo/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
name: analyzer
url: "https://pub.dartlang.org"
source: hosted
version: "0.32.5"
version: "0.33.0"
args:
dependency: transitive
description:
Expand Down Expand Up @@ -63,7 +63,7 @@ packages:
name: csslib
url: "https://pub.dartlang.org"
source: hosted
version: "0.14.5"
version: "0.14.6"
cupertino_icons:
dependency: "direct main"
description:
Expand All @@ -87,7 +87,7 @@ packages:
name: front_end
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.4+1"
version: "0.1.6"
glob:
dependency: transitive
description:
Expand All @@ -108,7 +108,7 @@ packages:
name: http
url: "https://pub.dartlang.org"
source: hosted
version: "0.11.3+17"
version: "0.12.0"
http_multi_server:
dependency: transitive
description:
Expand Down Expand Up @@ -150,7 +150,7 @@ packages:
name: kernel
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.4+1"
version: "0.3.6"
logging:
dependency: transitive
description:
Expand Down Expand Up @@ -206,7 +206,7 @@ packages:
name: package_resolver
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.4"
version: "1.0.6"
path:
dependency: transitive
description:
Expand Down Expand Up @@ -288,7 +288,7 @@ packages:
name: source_maps
url: "https://pub.dartlang.org"
source: hosted
version: "0.10.7"
version: "0.10.8"
source_span:
dependency: transitive
description:
Expand Down Expand Up @@ -330,7 +330,7 @@ packages:
name: test
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "1.3.4"
typed_data:
dependency: transitive
description:
Expand Down Expand Up @@ -381,4 +381,4 @@ packages:
source: hosted
version: "2.1.15"
sdks:
dart: ">=2.0.0-dev.68.0 <3.0.0"
dart: ">=2.0.0 <3.0.0"
41 changes: 39 additions & 2 deletions example/simpleDemo/main.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package main

import (
"bufio"
"image"
_ "image/png"
"log"
"os"
"path"
"runtime"

gutter "github.com/Drakirus/go-flutter-desktop-embedder"
"github.com/Drakirus/go-flutter-desktop-embedder/flutter"

"github.com/go-gl/glfw/v3.2/glfw"
)
Expand All @@ -16,10 +20,18 @@ func main() {
err error
)

_, currentFilePath, _, _ := runtime.Caller(0)
dir := path.Dir(currentFilePath)

options := []gutter.Option{
gutter.OptionAssetPath("flutter_project/demo/build/flutter_assets"),
gutter.OptionAssetPath(dir + "/flutter_project/demo/build/flutter_assets"),
gutter.OptionICUDataPath("/opt/flutter/bin/cache/artifacts/engine/linux-x64/icudtl.dat"),
gutter.OptionWindowInitializer(setIcon),
gutter.OptionWindowDimension(800, 600),
gutter.OptionWindowInitializer(setIcon),
gutter.OptionPixelRatio(1.2),
gutter.OptionVMArguments([]string{"--dart-non-checked-mode", "--observatory-port=50300"}),
gutter.OptionAddPluginReceiver(ownPlugin, "plugin_demo"),
}

if err = gutter.Run(options...); err != nil {
Expand All @@ -29,7 +41,9 @@ func main() {
}

func setIcon(window *glfw.Window) error {
imgFile, err := os.Open("assets/icon.png")
_, currentFilePath, _, _ := runtime.Caller(0)
dir := path.Dir(currentFilePath)
imgFile, err := os.Open(dir + "/assets/icon.png")
if err != nil {
return err
}
Expand All @@ -40,3 +54,26 @@ func setIcon(window *glfw.Window) error {
window.SetIcon([]image.Image{img})
return nil
}

// Plugin that read the stdin and send the number to the dart side
func ownPlugin(
platMessage flutter.PlatformMessage,
flutterEngine *flutter.EngineOpenGL,
window *glfw.Window,
) bool {
if platMessage.Message.Method != "getNumber" {
log.Printf("Unhandled platform method: %#v from channel %#v\n",
platMessage.Message.Method, platMessage.Channel)
return false
}

go func() {
reader := bufio.NewReader(os.Stdin)
print("Reading (A number): ")
s, _ := reader.ReadString('\n')
flutterEngine.SendPlatformMessageResponse(platMessage, []byte("[ "+s+" ]"))
}()

return true

}
3 changes: 2 additions & 1 deletion example/stocks/.build/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
temp.zip
*
!.gitignore
6 changes: 5 additions & 1 deletion example/stocks/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ func main() {

options := []gutter.Option{
gutter.OptionAssetPath("flutter_project/stocks/build/flutter_assets"),
gutter.OptionICUDataPath("/opt/flutter/bin/cache/artifacts/engine/linux-x64/icudtl.dat"),
gutter.OptionICUDataPath("/opt/flutter/bin/cache/artifacts/engine/linux-x64/icudtl.dat"), // Linux (arch)
// gutter.OptionICUDataPath("./FlutterEmbedder.framework/Resources/icudtl.dat"), // OSX
gutter.OptionWindowDimension(800, 600),
gutter.OptionWindowInitializer(setIcon),
gutter.OptionPixelRatio(1.2),
gutter.OptionVMArguments([]string{"--dart-non-checked-mode", "--observatory-port=50300"}),
}

if err = gutter.Run(options...); err != nil {
Expand Down
7 changes: 6 additions & 1 deletion flutter/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ package flutter
// Linux Build Tags
// ----------------
#cgo linux CFLAGS: -I${SRCDIR}/library
#cgo linux LDFLAGS: -lflutter_engine -Wl,-rpath,$ORIGIN/flutter/library/linux
#cgo linux LDFLAGS: -lflutter_engine -Wl,-rpath,$ORIGIN

// Windows Build Tags
// ----------------
#cgo windows CFLAGS: -I${SRCDIR}/library
#cgo windows LDFLAGS: -lflutter_engine

// Darwin Build Tags
// ----------------
#cgo darwin CFLAGS: -I${SRCDIR}/library
#cgo darwin LDFLAGS: -framework FlutterEmbedder

*/
import "C"

Expand Down
Loading