-
Notifications
You must be signed in to change notification settings - Fork 3
/
window.go
84 lines (69 loc) · 1.57 KB
/
window.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
package goui
/*
#include <stdlib.h>
#include "window.h"
*/
import "C"
import (
"os"
"path"
"runtime"
"unsafe"
)
const defaultDir = "ui"
const defaultIndex = "index.html"
func BoolToCInt(b bool) (i C.int) {
if b {
i = 1
}
return
}
func convertSettings(settings Settings) C.WindowSettings {
//dir := path.Dir(settings.Url)
if settings.UIDir == "" {
settings.UIDir = defaultDir
}
if settings.Index == "" {
settings.Index = defaultIndex
}
if settings.Url == "" {
settings.Url = path.Join(settings.UIDir, settings.Index)
if runtime.GOOS == "linux" {
wd, _ := os.Getwd()
settings.Url = path.Join("file://", wd, settings.Url)
} else if runtime.GOOS == "android" {
settings.Url = path.Join("file:///android_asset/", settings.Url)
}
}
// windows needs WebDir and Index
// macOS and iOS need Url
return C.WindowSettings{C.CString(settings.Title),
C.CString(settings.UIDir),
//C.CString(abs),
C.CString(settings.Index),
C.CString(settings.Url),
C.int(settings.Left),
C.int(settings.Top),
C.int(settings.Width),
C.int(settings.Height),
BoolToCInt(settings.Resizable),
BoolToCInt(settings.Debug),
}
}
func create(settings Settings, menuDefs []MenuDef) {
//C.Create((*C.WindowSettings)(unsafe.Pointer(settings)))
cs := convertSettings(settings)
cMenuDefs, count := convertMenuDefs(menuDefs)
cCreate(cs, cMenuDefs, count)
}
func activate() {
}
func invokeJS(js string, fromMainThread bool) {
cJs := C.CString(js)
Log("invoke:", js)
defer C.free(unsafe.Pointer(cJs))
cInvokeJS(cJs, BoolToCInt(fromMainThread))
}
func exit() {
cExit()
}