@yufengtadian/freedom-cli 1.13.2 → 1.13.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +40 -0
- package/README.md +44 -14
- package/lib/agents.js +182 -52
- package/lib/build.js +22 -7
- package/lib/cli.js +100 -7
- package/lib/shell.js +165 -61
- package/lib/toolchain.js +339 -0
- package/lib/utils.js +51 -0
- package/lib/verify.js +5 -4
- package/lib/webkit.js +45 -0
- package/package.json +2 -2
- package/shell/linux-x64/freedom-shell +0 -0
- package/shell/win-x64/freedom-shell.exe +0 -0
- package/skill/freedom/SKILL.md +3 -3
- package/templates/desktop/backend/desktop.mjs +16 -6
- package/templates/desktop/freedom.config.js +4 -1
- package/templates/go/go.mod +3 -0
- package/templates/go/pkg/freedom/anti_debug_linux.go +69 -0
- package/templates/go/pkg/freedom/anti_debug_other.go +5 -3
- package/templates/go/pkg/freedom/anti_debug_windows.go +136 -12
- package/templates/go/pkg/freedom/assets_embed.go +1 -0
- package/templates/go/pkg/freedom/backend_proc.go +5 -5
- package/templates/go/pkg/freedom/events_windows.go +5 -5
- package/templates/go/pkg/freedom/freedom.go +13 -2
- package/templates/go/pkg/freedom/msgwindow_windows.go +8 -8
- package/templates/go/pkg/freedom/resources.go +52 -1
- package/templates/go/pkg/freedom/security.go +57 -7
- package/templates/go/pkg/freedom/shutdown.go +55 -0
- package/templates/go/pkg/freedom/shutdown_windows.go +47 -0
- package/templates/go/pkg/freedom/store.go +3 -3
- package/templates/go/pkg/freedom/syscap_windows.go +33 -33
- package/templates/go/pkg/freedom/sysint_windows.go +2 -2
- package/templates/go/pkg/freedom/tray_windows.go +18 -18
- package/templates/go/pkg/freedom/updater.go +3 -3
- package/templates/go/third_party/webview_go/CHANGELOG.md +15 -0
- package/templates/go/third_party/webview_go/FREEDOM-PATCH.md +32 -0
- package/templates/go/third_party/webview_go/LICENSE +22 -0
- package/templates/go/third_party/webview_go/README.md +50 -0
- package/templates/go/third_party/webview_go/glue.c +36 -0
- package/templates/go/third_party/webview_go/go.mod +3 -0
- package/templates/go/third_party/webview_go/go.sum +0 -0
- package/templates/go/third_party/webview_go/libs/mswebview2/LICENSE +27 -0
- package/templates/go/third_party/webview_go/libs/mswebview2/include/WebView2.h +23568 -0
- package/templates/go/third_party/webview_go/libs/mswebview2/include/vendor.go +2 -0
- package/templates/go/third_party/webview_go/libs/mswebview2/vendor.go +2 -0
- package/templates/go/third_party/webview_go/libs/mswebview2/version.txt +1 -0
- package/templates/go/third_party/webview_go/libs/webview/LICENSE +22 -0
- package/templates/go/third_party/webview_go/libs/webview/include/vendor.go +2 -0
- package/templates/go/third_party/webview_go/libs/webview/include/webview.h +3598 -0
- package/templates/go/third_party/webview_go/libs/webview/vendor.go +2 -0
- package/templates/go/third_party/webview_go/libs/webview/version.txt +1 -0
- package/templates/go/third_party/webview_go/webkit2_40.go +21 -0
- package/templates/go/third_party/webview_go/webkit2_41.go +8 -0
- package/templates/go/third_party/webview_go/webview.cc +1 -0
- package/templates/go/third_party/webview_go/webview.go +332 -0
|
@@ -26,7 +26,7 @@ import (
|
|
|
26
26
|
var comInitDone atomic.Bool
|
|
27
27
|
|
|
28
28
|
var (
|
|
29
|
-
ole32
|
|
29
|
+
ole32 = syscall.NewLazyDLL("ole32.dll")
|
|
30
30
|
procCoCreateInstance = ole32.NewProc("CoCreateInstance")
|
|
31
31
|
procCoTaskMemFree = ole32.NewProc("CoTaskMemFree")
|
|
32
32
|
procCoInitializeEx = ole32.NewProc("CoInitializeEx")
|
|
@@ -102,6 +102,7 @@ func comVtable(ppv uintptr, index uint32) uintptr {
|
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
// comVtableImpl 是实际的 vtable 查找实现,通过单独函数隔离 vet 检查。
|
|
105
|
+
//
|
|
105
106
|
//go:noinline
|
|
106
107
|
func comVtableImpl(ppv uintptr, index uint32) uintptr {
|
|
107
108
|
// 读取 vtable 指针:COM 对象首 8 字节是指针数组。
|
|
@@ -146,10 +147,10 @@ var (
|
|
|
146
147
|
|
|
147
148
|
// ITaskbarList3 vtable 索引(0=QueryInterface,1=AddRef,2=Release)。
|
|
148
149
|
const (
|
|
149
|
-
tb3HrInit
|
|
150
|
-
tb3SetProgressValue
|
|
151
|
-
tb3SetProgressState
|
|
152
|
-
tb3SetOverlayIcon
|
|
150
|
+
tb3HrInit = 3
|
|
151
|
+
tb3SetProgressValue = 8
|
|
152
|
+
tb3SetProgressState = 9
|
|
153
|
+
tb3SetOverlayIcon = 17
|
|
153
154
|
)
|
|
154
155
|
|
|
155
156
|
// TBPFLAG 任务栏进度条状态。
|
|
@@ -170,7 +171,7 @@ func taskbarList3() uintptr {
|
|
|
170
171
|
hr, _, _ := procCoCreateInstance.Call(
|
|
171
172
|
uintptr(unsafe.Pointer(&clsidTaskbarList)),
|
|
172
173
|
0,
|
|
173
|
-
0x1 /*CLSCTX_INPROC_SERVER
|
|
174
|
+
0x1, /*CLSCTX_INPROC_SERVER*/
|
|
174
175
|
uintptr(unsafe.Pointer(&iidTaskbarList3)),
|
|
175
176
|
uintptr(unsafe.Pointer(&ppv)),
|
|
176
177
|
)
|
|
@@ -265,11 +266,11 @@ const (
|
|
|
265
266
|
dwmwaSystemBackdropType = 38
|
|
266
267
|
dwmwaBorderColor = 34
|
|
267
268
|
|
|
268
|
-
dwmsbtAuto
|
|
269
|
-
dwmsbtNone
|
|
270
|
-
dwmsbtMainWindow
|
|
271
|
-
dwmsbtTransientWin
|
|
272
|
-
dwmsbtTabbedWindow
|
|
269
|
+
dwmsbtAuto = 0
|
|
270
|
+
dwmsbtNone = 1
|
|
271
|
+
dwmsbtMainWindow = 2 // Mica
|
|
272
|
+
dwmsbtTransientWin = 3 // Acrylic
|
|
273
|
+
dwmsbtTabbedWindow = 4
|
|
273
274
|
|
|
274
275
|
dwmwcpDefault = 0
|
|
275
276
|
dwmwcpDoNotRound = 1
|
|
@@ -401,9 +402,9 @@ func hiconFromPNG(pngData []byte) uintptr {
|
|
|
401
402
|
}
|
|
402
403
|
|
|
403
404
|
type iconInfo struct {
|
|
404
|
-
fIcon
|
|
405
|
-
xHotspot, yHotspot
|
|
406
|
-
hbmMask, hbmColor
|
|
405
|
+
fIcon int32
|
|
406
|
+
xHotspot, yHotspot uint32
|
|
407
|
+
hbmMask, hbmColor uintptr
|
|
407
408
|
}
|
|
408
409
|
ii := iconInfo{fIcon: 1, hbmMask: hbmMask, hbmColor: hbmColor}
|
|
409
410
|
hicon, _, _ := procCreateIconIndirect.Call(uintptr(unsafe.Pointer(&ii)))
|
|
@@ -412,7 +413,6 @@ func hiconFromPNG(pngData []byte) uintptr {
|
|
|
412
413
|
return hicon
|
|
413
414
|
}
|
|
414
415
|
|
|
415
|
-
|
|
416
416
|
// syscallMessageBox 调用系统消息框。返回按钮标识(ok/yes/no/cancel)。
|
|
417
417
|
func syscallMessageBox(hwnd uintptr, title, message, buttons, icon string) (string, error) {
|
|
418
418
|
var flags uintptr
|
|
@@ -465,33 +465,33 @@ var procMessageBoxW = user32win.NewProc("MessageBoxW")
|
|
|
465
465
|
|
|
466
466
|
// IFileOpenDialog / IFileSaveDialog / IShellItem COM 常量。
|
|
467
467
|
var (
|
|
468
|
-
clsidFileOpenDialog
|
|
469
|
-
clsidFileSaveDialog
|
|
470
|
-
iidIFileOpenDialog
|
|
471
|
-
iidIFileSaveDialog
|
|
472
|
-
iidIShellItem
|
|
468
|
+
clsidFileOpenDialog = comGUIDFromString("{DC1C5A9C-E88A-4DDE-A5A1-60F82A20AEF7}")
|
|
469
|
+
clsidFileSaveDialog = comGUIDFromString("{C0B4E2F3-BA21-4773-8DBA-335EC946EB8B}")
|
|
470
|
+
iidIFileOpenDialog = comGUIDFromString("{D57C7288-D4AD-4768-BE02-9D969532D960}")
|
|
471
|
+
iidIFileSaveDialog = comGUIDFromString("{84BCCD23-5FDE-4CDB-AEA4-AF64B83D78AB}")
|
|
472
|
+
iidIShellItem = comGUIDFromString("{43826D1E-E718-42EE-BC55-A1E261C37BFE}")
|
|
473
473
|
)
|
|
474
474
|
|
|
475
475
|
// IFileDialog vtable 索引(IModalWindow: 0-3, IFileDialog: 4-20)。
|
|
476
476
|
const (
|
|
477
|
-
ifdSetFileTypes
|
|
477
|
+
ifdSetFileTypes = 4
|
|
478
478
|
ifdSetFileTypeIndex = 5
|
|
479
|
-
ifdSetOptions
|
|
480
|
-
ifdSetTitle
|
|
481
|
-
ifdSetFileName
|
|
482
|
-
ifdGetResult
|
|
483
|
-
ifdShow
|
|
479
|
+
ifdSetOptions = 9
|
|
480
|
+
ifdSetTitle = 17
|
|
481
|
+
ifdSetFileName = 15
|
|
482
|
+
ifdGetResult = 20
|
|
483
|
+
ifdShow = 3 // IModalWindow::Show
|
|
484
484
|
)
|
|
485
485
|
|
|
486
486
|
// IFOS 选项(IFileDialogOptions)。
|
|
487
487
|
const (
|
|
488
|
-
fosOverwritePrompt
|
|
489
|
-
fosStrictFileTypes
|
|
490
|
-
fosNoChangeDir
|
|
491
|
-
fosForceFileSystem
|
|
492
|
-
fosAllowMultiSelect
|
|
493
|
-
fosPathMustExist
|
|
494
|
-
fosFileMustExist
|
|
488
|
+
fosOverwritePrompt = 0x00000002
|
|
489
|
+
fosStrictFileTypes = 0x00000004
|
|
490
|
+
fosNoChangeDir = 0x00000008
|
|
491
|
+
fosForceFileSystem = 0x00000040
|
|
492
|
+
fosAllowMultiSelect = 0x00000200
|
|
493
|
+
fosPathMustExist = 0x00000800
|
|
494
|
+
fosFileMustExist = 0x00001000
|
|
495
495
|
fosDefaultNoMiniMode = 0x20000000
|
|
496
496
|
)
|
|
497
497
|
|
|
@@ -34,7 +34,7 @@ var (
|
|
|
34
34
|
"alt": modAlt, "option": modAlt,
|
|
35
35
|
"ctrl": modControl, "control": modControl,
|
|
36
36
|
"shift": modShift,
|
|
37
|
-
"win":
|
|
37
|
+
"win": modWin, "cmd": modWin, "meta": modWin, "super": modWin,
|
|
38
38
|
}
|
|
39
39
|
hotkeyVKs = map[string]uint32{}
|
|
40
40
|
)
|
|
@@ -230,7 +230,7 @@ const (
|
|
|
230
230
|
keyRead = 0x101
|
|
231
231
|
regSz = 1
|
|
232
232
|
|
|
233
|
-
runKeyPath
|
|
233
|
+
runKeyPath = `Software\Microsoft\Windows\CurrentVersion\Run`
|
|
234
234
|
classesBase = `Software\Classes`
|
|
235
235
|
)
|
|
236
236
|
|
|
@@ -39,12 +39,12 @@ const (
|
|
|
39
39
|
tpmRightButton = 0x00000002
|
|
40
40
|
tpmLeftAlign = 0x00000000
|
|
41
41
|
|
|
42
|
-
mfString
|
|
43
|
-
mfSeparator
|
|
44
|
-
mfChecked
|
|
45
|
-
mfGrayed
|
|
46
|
-
mfEnabled
|
|
47
|
-
mfPopup
|
|
42
|
+
mfString = 0x00000000
|
|
43
|
+
mfSeparator = 0x00000800
|
|
44
|
+
mfChecked = 0x00000008
|
|
45
|
+
mfGrayed = 0x00000001
|
|
46
|
+
mfEnabled = 0x00000000
|
|
47
|
+
mfPopup = 0x00000010
|
|
48
48
|
mfByPosition = 0x00000400
|
|
49
49
|
)
|
|
50
50
|
|
|
@@ -52,19 +52,19 @@ var (
|
|
|
52
52
|
shell32 = syscall.NewLazyDLL("shell32.dll")
|
|
53
53
|
procShellNotifyIconW = shell32.NewProc("Shell_NotifyIconW")
|
|
54
54
|
|
|
55
|
-
procRegisterClassExW
|
|
56
|
-
procCreateWindowExW
|
|
57
|
-
procDefWindowProcW
|
|
58
|
-
procCreatePopupMenu
|
|
59
|
-
procCreateMenu
|
|
60
|
-
procAppendMenuW
|
|
61
|
-
procInsertMenuW
|
|
62
|
-
procDestroyMenu
|
|
63
|
-
procTrackPopupMenu
|
|
64
|
-
procGetCursorPos
|
|
55
|
+
procRegisterClassExW = user32win.NewProc("RegisterClassExW")
|
|
56
|
+
procCreateWindowExW = user32win.NewProc("CreateWindowExW")
|
|
57
|
+
procDefWindowProcW = user32win.NewProc("DefWindowProcW")
|
|
58
|
+
procCreatePopupMenu = user32win.NewProc("CreatePopupMenu")
|
|
59
|
+
procCreateMenu = user32win.NewProc("CreateMenu")
|
|
60
|
+
procAppendMenuW = user32win.NewProc("AppendMenuW")
|
|
61
|
+
procInsertMenuW = user32win.NewProc("InsertMenuW")
|
|
62
|
+
procDestroyMenu = user32win.NewProc("DestroyMenu")
|
|
63
|
+
procTrackPopupMenu = user32win.NewProc("TrackPopupMenu")
|
|
64
|
+
procGetCursorPos = user32win.NewProc("GetCursorPos")
|
|
65
65
|
procSetForegroundWindow = user32win.NewProc("SetForegroundWindow")
|
|
66
|
-
procSetMenu
|
|
67
|
-
procDrawMenuBar
|
|
66
|
+
procSetMenu = user32win.NewProc("SetMenu")
|
|
67
|
+
procDrawMenuBar = user32win.NewProc("DrawMenuBar")
|
|
68
68
|
)
|
|
69
69
|
|
|
70
70
|
// ---- 结构 ----
|
|
@@ -178,9 +178,9 @@ func (a *App) CheckUpdate(ctx context.Context) (*UpdateInfo, error) {
|
|
|
178
178
|
if !updateURLAllowed(m.URL) {
|
|
179
179
|
return nil, fmt.Errorf("freedom: artifact URL scheme rejected: %q", m.URL)
|
|
180
180
|
}
|
|
181
|
-
cmp, err := compareVersions(
|
|
181
|
+
cmp, err := compareVersions(a.appVersion(), m.Version)
|
|
182
182
|
if err != nil {
|
|
183
|
-
return nil, fmt.Errorf("freedom: current version %q uncomparable: %w",
|
|
183
|
+
return nil, fmt.Errorf("freedom: current version %q uncomparable: %w", a.appVersion(), err)
|
|
184
184
|
}
|
|
185
185
|
a.upMu.Lock()
|
|
186
186
|
if cmp >= 0 {
|
|
@@ -333,7 +333,7 @@ func (a *App) updateCheckAsync() interface{} {
|
|
|
333
333
|
return
|
|
334
334
|
}
|
|
335
335
|
if info == nil {
|
|
336
|
-
a.Emit("update.upToDate", map[string]string{"current":
|
|
336
|
+
a.Emit("update.upToDate", map[string]string{"current": a.appVersion()})
|
|
337
337
|
return
|
|
338
338
|
}
|
|
339
339
|
a.Emit("update.available", info)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
### Migrating from v0.1.1 to v0.10.0
|
|
4
|
+
|
|
5
|
+
1. `Webview.Open()` has been removed. Use other webview APIs to create a window, open a link and run main UI loop.
|
|
6
|
+
2. `Webview.Debug()` and `webview.Debugf()` have been removed. Use your favorite logging library to debug webview apps.
|
|
7
|
+
3. `Webview.Settings` struct has been removed. Title, URL and size are controlled via other API setters and can be updated at any time, not only when webview is created.
|
|
8
|
+
4. `Webview.Loop()` has been removed. Use `Run()` instead.
|
|
9
|
+
5. `WebView.Run()`, `WebView.Terminate()`, `WebView.SetTitle()`, `WebView.Dispatch()` stayed the same.
|
|
10
|
+
6. `WebView.Exit()` has been renamed to `WebView.Destroy()`
|
|
11
|
+
7. `WebView.SetColor()` and `WebView.SetFullScreen()` have been removed. Use `Window()` to get native window handle and probably write some Cgo code to adjust native window to your taste.
|
|
12
|
+
8. `Webview.Dialog` has been removed. But it is likely to be brought back as a standalone module.
|
|
13
|
+
9. `WebView.Eval()` remained the same.
|
|
14
|
+
10. `WebView.InjectCSS()` has been removed. Use eval to inject style tag with CSS inside.
|
|
15
|
+
11. `WebView.Bind()` kept the name, but changed the semantics. Only functions can be bound. Not the structs, like in Lorca.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
From: https://github.com/webview/webview_go
|
|
2
|
+
Upstream commit: 6173450d4dd6 (v0.0.0-20240831120633)
|
|
3
|
+
License: MIT (see LICENSE)
|
|
4
|
+
|
|
5
|
+
Why this copy exists
|
|
6
|
+
------------------
|
|
7
|
+
Upstream hardcodes the CGO dependency name as `pkg-config: gtk+-3.0 webkit2gtk-4.0`.
|
|
8
|
+
Ubuntu 24.04 / Debian 13 removed the webkit2gtk-4.0 dev package (libsoup2 line) and ship
|
|
9
|
+
the API-compatible webkit2gtk-4.1 instead, so `go build` fails there with
|
|
10
|
+
"Package webkit2gtk-4.0 was not found".
|
|
11
|
+
|
|
12
|
+
What was changed (the only two deltas)
|
|
13
|
+
--------------------------------------
|
|
14
|
+
1. webview.go: dropped the hardcoded linux `pkg-config:` line (comment marks the spot).
|
|
15
|
+
2. webkit2_40.go / webkit2_41.go: the same directive, split by mutually exclusive build
|
|
16
|
+
tags. Default stays 4.0 (unchanged behaviour on old distros and in CI artifacts);
|
|
17
|
+
`-tags webkit2_41` selects 4.1.
|
|
18
|
+
|
|
19
|
+
Nothing else was touched: examples/ and webview_test.go were deleted, no code change.
|
|
20
|
+
|
|
21
|
+
Who flips the tag
|
|
22
|
+
-----------------
|
|
23
|
+
- repo/dev + CI: build.sh sources tools/webkit-env.sh (appends -tags=webkit2_41 to GOFLAGS)
|
|
24
|
+
- npm CLI: freedom-cli/lib/webkit.js (applyWebkitTags), used by `freedom shell build`
|
|
25
|
+
Detection is by pkg-config availability, so no user-facing flag is needed.
|
|
26
|
+
|
|
27
|
+
To refresh from upstream: copy the new tree over this directory, re-apply the two deltas
|
|
28
|
+
above, delete examples/ and webview_test.go, then re-sync the identical copy under
|
|
29
|
+
freedom-cli/templates/go/third_party/webview_go/ (it is what `freedom shell build` compiles).
|
|
30
|
+
|
|
31
|
+
webkitgtk-6.0 is NOT bridgeable this way (different C API: WebKitNetworkSession,
|
|
32
|
+
permission handlers); it needs an upstream port.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 Serge Zaitsev
|
|
4
|
+
Copyright (c) 2020 webview
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# webview_go
|
|
2
|
+
|
|
3
|
+
[](https://godoc.org/github.com/webview/webview_go)
|
|
4
|
+
[](https://goreportcard.com/report/github.com/webview/webview_go)
|
|
5
|
+
|
|
6
|
+
Go language binding for the [webview library][webview].
|
|
7
|
+
|
|
8
|
+
> [!NOTE]
|
|
9
|
+
> Versions <= 0.1.1 are available in the [old repository][webview].
|
|
10
|
+
|
|
11
|
+
### Getting Started
|
|
12
|
+
|
|
13
|
+
See [Go package documentation][go-docs] for the Go API documentation, or simply read the source code.
|
|
14
|
+
|
|
15
|
+
Start with creating a new directory structure for your project.
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
mkdir my-project && cd my-project
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Create a new Go module.
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
go mod init example.com/app
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Save one of the example programs into your project directory.
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
curl -sSLo main.go "https://raw.githubusercontent.com/webview/webview_go/master/examples/basic/main.go"
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Install dependencies.
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
go get github.com/webview/webview_go
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Build the example. On Windows, add `-ldflags="-H windowsgui"` to the command line.
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
go build
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Notes
|
|
46
|
+
|
|
47
|
+
Calling `Eval()` or `Dispatch()` before `Run()` does not work because the webview instance has only been configured and not yet started.
|
|
48
|
+
|
|
49
|
+
[go-docs]: https://pkg.go.dev/github.com/webview/webview_go
|
|
50
|
+
[webview]: https://github.com/webview/webview
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#include "webview.h"
|
|
2
|
+
|
|
3
|
+
#include <stdlib.h>
|
|
4
|
+
#include <stdint.h>
|
|
5
|
+
|
|
6
|
+
struct binding_context {
|
|
7
|
+
webview_t w;
|
|
8
|
+
uintptr_t index;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
void _webviewDispatchGoCallback(void *);
|
|
12
|
+
void _webviewBindingGoCallback(webview_t, char *, char *, uintptr_t);
|
|
13
|
+
|
|
14
|
+
static void _webview_dispatch_cb(webview_t w, void *arg) {
|
|
15
|
+
_webviewDispatchGoCallback(arg);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
static void _webview_binding_cb(const char *id, const char *req, void *arg) {
|
|
19
|
+
struct binding_context *ctx = (struct binding_context *) arg;
|
|
20
|
+
_webviewBindingGoCallback(ctx->w, (char *)id, (char *)req, ctx->index);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
void CgoWebViewDispatch(webview_t w, uintptr_t arg) {
|
|
24
|
+
webview_dispatch(w, _webview_dispatch_cb, (void *)arg);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
void CgoWebViewBind(webview_t w, const char *name, uintptr_t index) {
|
|
28
|
+
struct binding_context *ctx = calloc(1, sizeof(struct binding_context));
|
|
29
|
+
ctx->w = w;
|
|
30
|
+
ctx->index = index;
|
|
31
|
+
webview_bind(w, name, _webview_binding_cb, (void *)ctx);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
void CgoWebViewUnbind(webview_t w, const char *name) {
|
|
35
|
+
webview_unbind(w, name);
|
|
36
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Copyright (C) Microsoft Corporation. All rights reserved.
|
|
2
|
+
|
|
3
|
+
Redistribution and use in source and binary forms, with or without
|
|
4
|
+
modification, are permitted provided that the following conditions are
|
|
5
|
+
met:
|
|
6
|
+
|
|
7
|
+
* Redistributions of source code must retain the above copyright
|
|
8
|
+
notice, this list of conditions and the following disclaimer.
|
|
9
|
+
* Redistributions in binary form must reproduce the above
|
|
10
|
+
copyright notice, this list of conditions and the following disclaimer
|
|
11
|
+
in the documentation and/or other materials provided with the
|
|
12
|
+
distribution.
|
|
13
|
+
* The name of Microsoft Corporation, or the names of its contributors
|
|
14
|
+
may not be used to endorse or promote products derived from this
|
|
15
|
+
software without specific prior written permission.
|
|
16
|
+
|
|
17
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
18
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
19
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
20
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
21
|
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
22
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
23
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
24
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
25
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
26
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
27
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|