forked from raintean/blink
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pool.go
48 lines (43 loc) · 914 Bytes
/
pool.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
package blink
//#include "wke.h"
import "C"
import (
"github.com/lxn/win"
"sync"
)
var windowMap = make(map[C.wkeWebView]*WebView)
var handleMap = make(map[win.HWND]*WebView)
var locker sync.RWMutex
func addViewToPool(view *WebView) {
locker.Lock()
windowMap[view.window] = view
handleMap[view.handle] = view
locker.Unlock()
//如果webview destroy的话,从池中清除
view.On("destroy", func(v *WebView) {
locker.Lock()
delete(windowMap, v.window)
delete(handleMap, v.handle)
locker.Unlock()
})
}
func getWebViewByWindow(window C.wkeWebView) *WebView {
locker.RLock()
if view, exist := windowMap[window]; exist {
locker.RUnlock()
return view
} else {
locker.RUnlock()
return nil
}
}
func getWebViewByHandle(handle win.HWND) *WebView {
locker.RLock()
if view, exist := handleMap[handle]; exist {
locker.RUnlock()
return view
} else {
locker.RUnlock()
return nil
}
}