forked from cztomczak/cef2go
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain_linux.go
More file actions
58 lines (53 loc) · 1.64 KB
/
main_linux.go
File metadata and controls
58 lines (53 loc) · 1.64 KB
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
// Copyright (c) 2014 The cef2go authors. All rights reserved.
// License: BSD 3-clause.
// Website: https://github.com/CzarekTomczak/cef2go
package main
import "C"
import (
"fmt"
"github.com/op/go-logging"
"github.com/paperlesspost/cef2go/cef"
"os"
)
func main() {
//quit := make(chan int)
cwd, _ := os.Getwd()
logging.SetLevel(logging.DEBUG, "cef")
var releasePath = os.Getenv("RELEASE_PATH")
if releasePath == "" {
releasePath = cwd
}
// you need to register to the callback before we fork processes
cef.RegisterV8Callback("sup", cef.V8Callback(func(args []*cef.V8Value) {
arg0 := args[0].ToInt32()
arg1 := args[1].ToFloat32()
arg2 := args[2].ToBool()
arg3 := args[3].ToString()
fmt.Printf("Calling V8Callback args: %d %f %v %s\n", arg0, arg1, arg2, arg3)
fmt.Printf("Exiting\n")
cef.QuitMessageLoop()
os.Exit(0)
}))
// CEF subprocesses.
cef.ExecuteProcess(nil)
// CEF initialize.
settings := cef.Settings{}
settings.ResourcesDirPath = releasePath
settings.LocalesDirPath = releasePath + "/locales"
settings.CachePath = cwd + "/webcache" // Set to empty to disable
settings.LogSeverity = cef.LOGSEVERITY_INFO // LOGSEVERITY_VERBOSE
settings.LogFile = cwd + "/debug.log"
settings.RemoteDebuggingPort = 7000
cef.Initialize(settings)
// Create browser.
browserSettings := &cef.BrowserSettings{}
url := "file://" + cwd + "/Release/example.html"
go func() {
browser := cef.CreateBrowser(browserSettings, url, true)
browser.ExecuteJavaScript("console.log('we outchea'); cef2go.callback('sup', 10, 13.10, true, 'something');", "sup.js", 1)
}()
// CEF loop and shutdown.
cef.RunMessageLoop()
cef.Shutdown()
os.Exit(1)
}