forked from lonnc/golang-nw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoc.go
97 lines (67 loc) · 2.86 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
Call a golang web application from node-webkit to get a native looking application.
Instructions
Go get golang-nw:
go get github.com/lonnc/golang-nw/cmd/golang-nw-pkg
Create an app:
See https://github.com/lonnc/golang-nw/blob/master/cmd/example/main.go
package main
import (
"fmt"
"github.com/lonnc/golang-nw"
"net/http"
)
func main() {
// Setup our handler
http.HandleFunc("/", hello)
// Create a link back to node-webkit using the environment variable
// populated by golang-nw's node-webkit code
nodeWebkit, err := nw.New()
if err != nil {
panic(err)
}
// Pick a random localhost port, start listening for http requests using default handler
// and send a message back to node-webkit to redirect
if err := nodeWebkit.ListenAndServe(nil); err != nil {
panic(err)
}
}
func hello(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello from golang.")
}
Build your app:
go install .\src\github.com\lonnc\golang-nw\cmd\example
Wrap it in node-webkit:
.\bin\golang-nw-pkg.exe -app=.\bin\example.exe -name="My Application" -bin="myapp.exe" -toolbar=false
Building: myapp.exe.nw
Downloading: https://s3.amazonaws.com/node-webkit/v0.8.4/node-webkit-v0.8.4-win-ia32.zip
Packaging: myapp.exe
You are now good to go:
.\myapp.exe
You may want to create your own build script so you can control window dimensions etc.
See http://godoc.org/github.com/lonnc/golang-nw/build and
https://github.com/lonnc/golang-nw/blob/master/cmd/golang-nw-pkg/pkg.go
Command line options:
$ ./bin/golang-nw-pkg -h
Usage of ./bin/golang-nw-pkg:
-app="myapp": Web application to be wrapped by node-webkit.
-arch="amd64": Target arch [386|amd64].
-bin="myapp": Destination file for combined application and node-webkit .nw file (will be placed in binDir directory).
-binDir=".": Destination directory for bin and dependencies.
-cacheDir=".": Directory to cache node-webkit download.
-frame=true: Set to false to make window frameless.
-fullscreen=false: Enable fullscreen mode.
-includesDir="": Directory containing additional files to bundle with the .nw file
-name="My Application": Application name.
-os="linux": Target os [linux|windows|darwin].
-toolbar=true: Enable toolbar.
-version="v0.9.2": node-webkit version.
Known issues:
1) libudev.so.0 - On ubuntu >=13.10 (and similar) libudev.so.0 has been removed.
tl;dr:
$ ./bin/golang-nw-pkg -app=./bin/example -name="My Application" -bin="myapp" -toolbar=false
$ sed -i -e 's/udev\.so\.0/udev.so.1/g' myapp
Node-webkit has various work arounds described at https://github.com/rogerwang/node-webkit/wiki/The-solution-of-lacking-libudev.so.0
2) Download of node-webkit appears to stall - It's a ~43MB download and can take longer than expected (it could do with some feedback).
*/
package nw