forked from mmatey/cef2go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_linux.go
executable file
·92 lines (76 loc) · 2.42 KB
/
main_linux.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
// Copyright (c) 2014 The cef2go authors. All rights reserved.
// License: BSD 3-clause.
// Website: https://github.com/CzarekTomczak/cef2go
package main
//#include <string.h>
import "C"
import (
"fmt"
"github.com/josiah2009/cef2go/cef"
"github.com/op/go-logging"
"os"
"time"
"unsafe"
)
const browserWidth = 1280
const browserHeight = 720
type OffscreenRenderHandler struct {
}
func (this *OffscreenRenderHandler) GetRootScreenRect(rect *cef.CefRect) int {
rect.SetDimensions(0, 0, browserWidth, browserHeight)
return 1
}
func (this *OffscreenRenderHandler) GetViewRect(rect *cef.CefRect) int {
rect.SetDimensions(0, 0, browserWidth, browserHeight)
return 1
}
func (this *OffscreenRenderHandler) GetScreenPoint(x, y int, screenX, screenY *int) int {
return 0
}
func (this *OffscreenRenderHandler) GetScreenInfo(info *cef.CefScreenInfo) int {
return 0
}
func (this *OffscreenRenderHandler) OnPopupShow(show int) {
}
func (this *OffscreenRenderHandler) OnPopupSize(size *cef.CefRect) {
}
func (this *OffscreenRenderHandler) OnPaint(paintType cef.CefPaintElementType, dirtyRectsCount int, dirtyRects unsafe.Pointer, buffer unsafe.Pointer, width, height int) {
}
func (this *OffscreenRenderHandler) OnCursorChange(cursor cef.CefCursorHandle, ctype cef.CefCursorType, custom_cursor_info cef.CefCursorInfo) {
}
func (this *OffscreenRenderHandler) OnScrollOffsetChanged(x, y float64) {
}
func main() {
cwd, _ := os.Getwd()
logging.SetLevel(logging.DEBUG, "cef")
var releasePath = os.Getenv("RELEASE_PATH")
if releasePath == "" {
releasePath = cwd
}
// CEF subprocesses.
cef.ExecuteProcess(nil, os.Args)
// CEF initialize.
settings := cef.Settings{}
settings.SingleProcess = 0
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
init := cef.Initialize(settings)
fmt.Printf("Initialized: %d", init)
cef.XlibRegisterHandlers()
time.Sleep(2500 * time.Millisecond)
// Create browser.
browserSettings := &cef.BrowserSettings{}
url := "file://" + cwd + "/Release/example.html"
go func() {
browser := cef.CreateBrowser(browserSettings, url, true)
browser.RenderHandler = &OffscreenRenderHandler{}
}()
// CEF loop and shutdown.
cef.RunMessageLoop()
cef.Shutdown()
os.Exit(1)
}