-
-
Notifications
You must be signed in to change notification settings - Fork 164
/
Copy pathmain.go
52 lines (40 loc) · 1.36 KB
/
main.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
package main
import (
"embed"
"fmt"
"io/fs"
"github.com/progrium/darwinkit/macos"
"github.com/progrium/darwinkit/macos/appkit"
"github.com/progrium/darwinkit/macos/foundation"
"github.com/progrium/darwinkit/macos/webkit"
"github.com/progrium/darwinkit/objc"
)
//go:embed assets
var assetsFS embed.FS
func main() {
macos.RunApp(launched)
}
func launched(app appkit.Application, delegate *appkit.ApplicationDelegate) {
w := appkit.NewWindowWithSize(600, 400)
objc.Retain(&w)
w.SetTitle("Test FS WebView")
_fs, _ := fs.Sub(assetsFS, "assets")
configuration := webkit.NewWebViewConfiguration()
gofsHandler := &webkit.FileSystemURLSchemeHandler{FS: _fs}
configuration.SetURLSchemeHandlerForURLScheme(gofsHandler, "gofs")
view := webkit.NewWebViewWithFrameConfiguration(foundation.Rect{}, configuration)
webkit.AddScriptMessageHandlerWithReply(view, "greet", func(message objc.Object) (objc.Object, error) {
param := message.Description()
fmt.Println("greet handled")
return foundation.NewStringWithString("hello: " + param).Object, nil
})
w.SetContentView(view)
w.MakeKeyAndOrderFront(nil)
w.Center()
webkit.LoadURL(view, "gofs:/index.html")
delegate.SetApplicationShouldTerminateAfterLastWindowClosed(func(appkit.Application) bool {
return true
})
app.SetActivationPolicy(appkit.ApplicationActivationPolicyRegular)
app.ActivateIgnoringOtherApps(true)
}