@yufengtadian/freedom-cli 1.12.1 → 1.12.13
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/README.md +31 -14
- package/bin/freedom.js +5 -1
- package/lib/build.js +49 -8
- package/lib/cli.js +107 -80
- package/lib/config.js +108 -31
- package/lib/shell.js +73 -20
- package/lib/theme.js +105 -0
- package/lib/tui.js +21 -3
- package/lib/update.js +109 -0
- package/lib/utils.js +14 -1
- package/package.json +1 -1
- package/shell/win-x64/freedom-shell.exe +0 -0
- package/templates/go/go.mod +6 -0
- package/templates/go/go.sum +2 -2
- package/templates/go/pkg/freedom/assets/freedom.js +6 -0
- package/templates/go/pkg/freedom/assets/index.html +1 -1
- package/templates/go/pkg/freedom/backend_proc.go +4 -4
- package/templates/go/pkg/freedom/configfile.go +12 -7
- package/templates/go/pkg/freedom/freedom.go +27 -11
- package/templates/go/pkg/freedom/window_other.go +64 -12
- package/templates/go/pkg/freedom/window_windows.go +244 -29
- package/templates/go/webview_go/.github/workflows/ci.yaml +62 -0
- package/templates/go/webview_go/CHANGELOG.md +15 -0
- package/templates/go/webview_go/LICENSE +22 -0
- package/templates/go/webview_go/README.md +50 -0
- package/templates/go/webview_go/examples/basic/main.go +12 -0
- package/templates/go/webview_go/examples/bind/main.go +38 -0
- package/templates/go/webview_go/glue.c +36 -0
- package/templates/go/webview_go/go.mod +3 -0
- package/templates/go/webview_go/go.sum +0 -0
- package/templates/go/webview_go/libs/mswebview2/LICENSE +27 -0
- package/templates/go/webview_go/libs/mswebview2/include/WebView2.h +23568 -0
- package/templates/go/webview_go/libs/mswebview2/include/vendor.go +2 -0
- package/templates/go/webview_go/libs/mswebview2/vendor.go +2 -0
- package/templates/go/webview_go/libs/mswebview2/version.txt +1 -0
- package/templates/go/webview_go/libs/webview/LICENSE +22 -0
- package/templates/go/webview_go/libs/webview/include/vendor.go +2 -0
- package/templates/go/webview_go/libs/webview/include/webview.h +3871 -0
- package/templates/go/webview_go/libs/webview/vendor.go +2 -0
- package/templates/go/webview_go/libs/webview/version.txt +1 -0
- package/templates/go/webview_go/webview.cc +1 -0
- package/templates/go/webview_go/webview.go +379 -0
- package/templates/go/webview_go/webview_test.go +50 -0
- package/templates/project/freedom.config.js +5 -5
- package/templates/project/index.html +45 -5
- package/templates/project/src/main.js +149 -8
- package/tutorial/tutorial.html +4 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
fb6b17d826041411e6346cd9a785a5ceba7987c4
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#include "webview.h"
|
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
package webview
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
#cgo CFLAGS: -I${SRCDIR}/libs/webview/include
|
|
5
|
+
#cgo CXXFLAGS: -I${SRCDIR}/libs/webview/include -DWEBVIEW_STATIC
|
|
6
|
+
|
|
7
|
+
#cgo linux openbsd freebsd netbsd CXXFLAGS: -DWEBVIEW_GTK -std=c++11
|
|
8
|
+
#cgo linux openbsd freebsd netbsd LDFLAGS: -ldl
|
|
9
|
+
#cgo linux openbsd freebsd netbsd pkg-config: gtk+-3.0 webkit2gtk-4.0
|
|
10
|
+
|
|
11
|
+
#cgo darwin CXXFLAGS: -DWEBVIEW_COCOA -std=c++11
|
|
12
|
+
#cgo darwin LDFLAGS: -framework WebKit -ldl
|
|
13
|
+
|
|
14
|
+
#cgo windows CXXFLAGS: -DWEBVIEW_EDGE -std=c++14 -I${SRCDIR}/libs/mswebview2/include
|
|
15
|
+
#cgo windows LDFLAGS: -static -ladvapi32 -lole32 -lshell32 -lshlwapi -luser32 -lversion
|
|
16
|
+
|
|
17
|
+
#include "webview.h"
|
|
18
|
+
|
|
19
|
+
#include <stdlib.h>
|
|
20
|
+
#include <stdint.h>
|
|
21
|
+
|
|
22
|
+
void CgoWebViewDispatch(webview_t w, uintptr_t arg);
|
|
23
|
+
void CgoWebViewBind(webview_t w, const char *name, uintptr_t index);
|
|
24
|
+
void CgoWebViewUnbind(webview_t w, const char *name);
|
|
25
|
+
*/
|
|
26
|
+
import "C"
|
|
27
|
+
import (
|
|
28
|
+
_ "github.com/webview/webview_go/libs/mswebview2"
|
|
29
|
+
_ "github.com/webview/webview_go/libs/mswebview2/include"
|
|
30
|
+
_ "github.com/webview/webview_go/libs/webview"
|
|
31
|
+
_ "github.com/webview/webview_go/libs/webview/include"
|
|
32
|
+
"encoding/json"
|
|
33
|
+
"errors"
|
|
34
|
+
"reflect"
|
|
35
|
+
"runtime"
|
|
36
|
+
"sync"
|
|
37
|
+
"unsafe"
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
func init() {
|
|
41
|
+
// Ensure that main.main is called from the main thread
|
|
42
|
+
runtime.LockOSThread()
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Hints are used to configure window sizing and resizing
|
|
46
|
+
type Hint int
|
|
47
|
+
|
|
48
|
+
// WindowAction 是原生窗口控制动作(前端自绘标题栏三按钮使用)。
|
|
49
|
+
type WindowAction int
|
|
50
|
+
|
|
51
|
+
const (
|
|
52
|
+
// WindowMinimize 最小化窗口
|
|
53
|
+
WindowMinimize WindowAction = iota
|
|
54
|
+
// WindowMaximize 最大化窗口
|
|
55
|
+
WindowMaximize
|
|
56
|
+
// WindowUnmaximize 取消最大化
|
|
57
|
+
WindowUnmaximize
|
|
58
|
+
// WindowRestore 还原窗口(取消最大化并恢复到前台)
|
|
59
|
+
WindowRestore
|
|
60
|
+
// WindowClose 关闭窗口
|
|
61
|
+
WindowClose
|
|
62
|
+
// WindowToggleMaximize 在最大化/还原间切换
|
|
63
|
+
WindowToggleMaximize
|
|
64
|
+
// WindowIsMaximized 查询窗口是否最大化
|
|
65
|
+
WindowIsMaximized
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
const (
|
|
69
|
+
// Width and height are default size
|
|
70
|
+
HintNone = C.WEBVIEW_HINT_NONE
|
|
71
|
+
|
|
72
|
+
// Window size can not be changed by a user
|
|
73
|
+
HintFixed = C.WEBVIEW_HINT_FIXED
|
|
74
|
+
|
|
75
|
+
// Width and height are minimum bounds
|
|
76
|
+
HintMin = C.WEBVIEW_HINT_MIN
|
|
77
|
+
|
|
78
|
+
// Width and height are maximum bounds
|
|
79
|
+
HintMax = C.WEBVIEW_HINT_MAX
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
type WebView interface {
|
|
83
|
+
|
|
84
|
+
// Run runs the main loop until it's terminated. After this function exits -
|
|
85
|
+
// you must destroy the webview.
|
|
86
|
+
Run()
|
|
87
|
+
|
|
88
|
+
// Terminate stops the main loop. It is safe to call this function from
|
|
89
|
+
// a background thread.
|
|
90
|
+
Terminate()
|
|
91
|
+
|
|
92
|
+
// Dispatch posts a function to be executed on the main thread. You normally
|
|
93
|
+
// do not need to call this function, unless you want to tweak the native
|
|
94
|
+
// window.
|
|
95
|
+
Dispatch(f func())
|
|
96
|
+
|
|
97
|
+
// Destroy destroys a webview and closes the native window.
|
|
98
|
+
Destroy()
|
|
99
|
+
|
|
100
|
+
// Window returns a native window handle pointer. When using GTK backend the
|
|
101
|
+
// pointer is GtkWindow pointer, when using Cocoa backend the pointer is
|
|
102
|
+
// NSWindow pointer, when using Win32 backend the pointer is HWND pointer.
|
|
103
|
+
Window() unsafe.Pointer
|
|
104
|
+
|
|
105
|
+
// SetTitle updates the title of the native window. Must be called from the UI
|
|
106
|
+
// thread.
|
|
107
|
+
SetTitle(title string)
|
|
108
|
+
|
|
109
|
+
// SetDecorated controls whether the native window shows its system title
|
|
110
|
+
// bar decoration. frameless mode should call SetDecorated(false) so the
|
|
111
|
+
// front-end can draw its own min/max/close buttons. Must be called from
|
|
112
|
+
// the UI thread. On Windows this is a no-op (handled by the freedom shell
|
|
113
|
+
// layer via WS_CAPTION / WM_NCHITTEST).
|
|
114
|
+
SetDecorated(decorated bool)
|
|
115
|
+
|
|
116
|
+
// WindowControl 执行原生窗口控制动作(最小化/最大化/还原/关闭/查询)。
|
|
117
|
+
// 返回 0 表示成功,-1 表示平台不支持;WindowIsMaximized 返回 1/0。
|
|
118
|
+
// 供前端自绘标题栏三按钮调用。Windows 上由 freedom 壳层处理,此处返回 -1。
|
|
119
|
+
WindowControl(action WindowAction) int
|
|
120
|
+
|
|
121
|
+
// BeginMoveDrag 发起无边框窗口的原生拖动(macOS/Linux)。
|
|
122
|
+
// Windows 由 freedom 壳层用 WM_NCLBUTTONDOWN 处理,此处返回 -1。
|
|
123
|
+
BeginMoveDrag() int
|
|
124
|
+
|
|
125
|
+
// SetSize updates native window size. See Hint constants.
|
|
126
|
+
SetSize(w int, h int, hint Hint)
|
|
127
|
+
|
|
128
|
+
// Navigate navigates webview to the given URL. URL may be a properly encoded data.
|
|
129
|
+
// URI. Examples:
|
|
130
|
+
// w.Navigate("https://github.com/webview/webview")
|
|
131
|
+
// w.Navigate("data:text/html,%3Ch1%3EHello%3C%2Fh1%3E")
|
|
132
|
+
// w.Navigate("data:text/html;base64,PGgxPkhlbGxvPC9oMT4=")
|
|
133
|
+
Navigate(url string)
|
|
134
|
+
|
|
135
|
+
// SetHtml sets the webview HTML directly.
|
|
136
|
+
// Example: w.SetHtml(w, "<h1>Hello</h1>");
|
|
137
|
+
SetHtml(html string)
|
|
138
|
+
|
|
139
|
+
// Init injects JavaScript code at the initialization of the new page. Every
|
|
140
|
+
// time the webview will open a the new page - this initialization code will
|
|
141
|
+
// be executed. It is guaranteed that code is executed before window.onload.
|
|
142
|
+
Init(js string)
|
|
143
|
+
|
|
144
|
+
// Eval evaluates arbitrary JavaScript code. Evaluation happens asynchronously,
|
|
145
|
+
// also the result of the expression is ignored. Use RPC bindings if you want
|
|
146
|
+
// to receive notifications about the results of the evaluation.
|
|
147
|
+
Eval(js string)
|
|
148
|
+
|
|
149
|
+
// Bind binds a callback function so that it will appear under the given name
|
|
150
|
+
// as a global JavaScript function. Internally it uses webview_init().
|
|
151
|
+
// Callback receives a request string and a user-provided argument pointer.
|
|
152
|
+
// Request string is a JSON array of all the arguments passed to the
|
|
153
|
+
// JavaScript function.
|
|
154
|
+
//
|
|
155
|
+
// f must be a function
|
|
156
|
+
// f must return either value and error or just error
|
|
157
|
+
Bind(name string, f interface{}) error
|
|
158
|
+
|
|
159
|
+
// Removes a callback that was previously set by Bind.
|
|
160
|
+
Unbind(name string) error
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
type webview struct {
|
|
164
|
+
w C.webview_t
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
var (
|
|
168
|
+
m sync.Mutex
|
|
169
|
+
index uintptr
|
|
170
|
+
dispatch = map[uintptr]func(){}
|
|
171
|
+
bindings = map[uintptr]func(id, req string) (interface{}, error){}
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
func boolToInt(b bool) C.int {
|
|
175
|
+
if b {
|
|
176
|
+
return 1
|
|
177
|
+
}
|
|
178
|
+
return 0
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// New calls NewWindow to create a new window and a new webview instance. If debug
|
|
182
|
+
// is non-zero - developer tools will be enabled (if the platform supports them).
|
|
183
|
+
func New(debug bool) WebView { return NewWindow(debug, nil) }
|
|
184
|
+
|
|
185
|
+
// NewWindow creates a new webview instance. If debug is non-zero - developer
|
|
186
|
+
// tools will be enabled (if the platform supports them). Window parameter can be
|
|
187
|
+
// a pointer to the native window handle. If it's non-null - then child WebView is
|
|
188
|
+
// embedded into the given parent window. Otherwise a new window is created.
|
|
189
|
+
// Depending on the platform, a GtkWindow, NSWindow or HWND pointer can be passed
|
|
190
|
+
// here.
|
|
191
|
+
func NewWindow(debug bool, window unsafe.Pointer) WebView {
|
|
192
|
+
w := &webview{}
|
|
193
|
+
w.w = C.webview_create(boolToInt(debug), window)
|
|
194
|
+
return w
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
func (w *webview) Destroy() {
|
|
198
|
+
C.webview_destroy(w.w)
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
func (w *webview) Run() {
|
|
202
|
+
C.webview_run(w.w)
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
func (w *webview) Terminate() {
|
|
206
|
+
C.webview_terminate(w.w)
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
func (w *webview) Window() unsafe.Pointer {
|
|
210
|
+
return C.webview_get_window(w.w)
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
func (w *webview) Navigate(url string) {
|
|
214
|
+
s := C.CString(url)
|
|
215
|
+
defer C.free(unsafe.Pointer(s))
|
|
216
|
+
C.webview_navigate(w.w, s)
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
func (w *webview) SetHtml(html string) {
|
|
220
|
+
s := C.CString(html)
|
|
221
|
+
defer C.free(unsafe.Pointer(s))
|
|
222
|
+
C.webview_set_html(w.w, s)
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
func (w *webview) SetTitle(title string) {
|
|
226
|
+
s := C.CString(title)
|
|
227
|
+
defer C.free(unsafe.Pointer(s))
|
|
228
|
+
C.webview_set_title(w.w, s)
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
func (w *webview) SetDecorated(decorated bool) {
|
|
232
|
+
C.webview_set_decorated(w.w, boolToInt(decorated))
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
func (w *webview) WindowControl(action WindowAction) int {
|
|
236
|
+
return int(C.webview_window_control(w.w, C.webview_window_action_t(action)))
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
func (w *webview) BeginMoveDrag() int {
|
|
240
|
+
return int(C.webview_window_begin_move_drag(w.w))
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
func (w *webview) SetSize(width int, height int, hint Hint) {
|
|
244
|
+
C.webview_set_size(w.w, C.int(width), C.int(height), C.webview_hint_t(hint))
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
func (w *webview) Init(js string) {
|
|
248
|
+
s := C.CString(js)
|
|
249
|
+
defer C.free(unsafe.Pointer(s))
|
|
250
|
+
C.webview_init(w.w, s)
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
func (w *webview) Eval(js string) {
|
|
254
|
+
s := C.CString(js)
|
|
255
|
+
defer C.free(unsafe.Pointer(s))
|
|
256
|
+
C.webview_eval(w.w, s)
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
func (w *webview) Dispatch(f func()) {
|
|
260
|
+
m.Lock()
|
|
261
|
+
for ; dispatch[index] != nil; index++ {
|
|
262
|
+
}
|
|
263
|
+
dispatch[index] = f
|
|
264
|
+
m.Unlock()
|
|
265
|
+
C.CgoWebViewDispatch(w.w, C.uintptr_t(index))
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
//export _webviewDispatchGoCallback
|
|
269
|
+
func _webviewDispatchGoCallback(index unsafe.Pointer) {
|
|
270
|
+
m.Lock()
|
|
271
|
+
f := dispatch[uintptr(index)]
|
|
272
|
+
delete(dispatch, uintptr(index))
|
|
273
|
+
m.Unlock()
|
|
274
|
+
f()
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
//export _webviewBindingGoCallback
|
|
278
|
+
func _webviewBindingGoCallback(w C.webview_t, id *C.char, req *C.char, index uintptr) {
|
|
279
|
+
m.Lock()
|
|
280
|
+
f := bindings[uintptr(index)]
|
|
281
|
+
m.Unlock()
|
|
282
|
+
jsString := func(v interface{}) string { b, _ := json.Marshal(v); return string(b) }
|
|
283
|
+
status, result := 0, ""
|
|
284
|
+
if res, err := f(C.GoString(id), C.GoString(req)); err != nil {
|
|
285
|
+
status = -1
|
|
286
|
+
result = jsString(err.Error())
|
|
287
|
+
} else if b, err := json.Marshal(res); err != nil {
|
|
288
|
+
status = -1
|
|
289
|
+
result = jsString(err.Error())
|
|
290
|
+
} else {
|
|
291
|
+
status = 0
|
|
292
|
+
result = string(b)
|
|
293
|
+
}
|
|
294
|
+
s := C.CString(result)
|
|
295
|
+
defer C.free(unsafe.Pointer(s))
|
|
296
|
+
C.webview_return(w, id, C.int(status), s)
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
func (w *webview) Bind(name string, f interface{}) error {
|
|
300
|
+
v := reflect.ValueOf(f)
|
|
301
|
+
// f must be a function
|
|
302
|
+
if v.Kind() != reflect.Func {
|
|
303
|
+
return errors.New("only functions can be bound")
|
|
304
|
+
}
|
|
305
|
+
// f must return either value and error or just error
|
|
306
|
+
if n := v.Type().NumOut(); n > 2 {
|
|
307
|
+
return errors.New("function may only return a value or a value+error")
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
binding := func(id, req string) (interface{}, error) {
|
|
311
|
+
raw := []json.RawMessage{}
|
|
312
|
+
if err := json.Unmarshal([]byte(req), &raw); err != nil {
|
|
313
|
+
return nil, err
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
isVariadic := v.Type().IsVariadic()
|
|
317
|
+
numIn := v.Type().NumIn()
|
|
318
|
+
if (isVariadic && len(raw) < numIn-1) || (!isVariadic && len(raw) != numIn) {
|
|
319
|
+
return nil, errors.New("function arguments mismatch")
|
|
320
|
+
}
|
|
321
|
+
args := []reflect.Value{}
|
|
322
|
+
for i := range raw {
|
|
323
|
+
var arg reflect.Value
|
|
324
|
+
if isVariadic && i >= numIn-1 {
|
|
325
|
+
arg = reflect.New(v.Type().In(numIn - 1).Elem())
|
|
326
|
+
} else {
|
|
327
|
+
arg = reflect.New(v.Type().In(i))
|
|
328
|
+
}
|
|
329
|
+
if err := json.Unmarshal(raw[i], arg.Interface()); err != nil {
|
|
330
|
+
return nil, err
|
|
331
|
+
}
|
|
332
|
+
args = append(args, arg.Elem())
|
|
333
|
+
}
|
|
334
|
+
errorType := reflect.TypeOf((*error)(nil)).Elem()
|
|
335
|
+
res := v.Call(args)
|
|
336
|
+
switch len(res) {
|
|
337
|
+
case 0:
|
|
338
|
+
// No results from the function, just return nil
|
|
339
|
+
return nil, nil
|
|
340
|
+
case 1:
|
|
341
|
+
// One result may be a value, or an error
|
|
342
|
+
if res[0].Type().Implements(errorType) {
|
|
343
|
+
if res[0].Interface() != nil {
|
|
344
|
+
return nil, res[0].Interface().(error)
|
|
345
|
+
}
|
|
346
|
+
return nil, nil
|
|
347
|
+
}
|
|
348
|
+
return res[0].Interface(), nil
|
|
349
|
+
case 2:
|
|
350
|
+
// Two results: first one is value, second is error
|
|
351
|
+
if !res[1].Type().Implements(errorType) {
|
|
352
|
+
return nil, errors.New("second return value must be an error")
|
|
353
|
+
}
|
|
354
|
+
if res[1].Interface() == nil {
|
|
355
|
+
return res[0].Interface(), nil
|
|
356
|
+
}
|
|
357
|
+
return res[0].Interface(), res[1].Interface().(error)
|
|
358
|
+
default:
|
|
359
|
+
return nil, errors.New("unexpected number of return values")
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
m.Lock()
|
|
364
|
+
for ; bindings[index] != nil; index++ {
|
|
365
|
+
}
|
|
366
|
+
bindings[index] = binding
|
|
367
|
+
m.Unlock()
|
|
368
|
+
cname := C.CString(name)
|
|
369
|
+
defer C.free(unsafe.Pointer(cname))
|
|
370
|
+
C.CgoWebViewBind(w.w, cname, C.uintptr_t(index))
|
|
371
|
+
return nil
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
func (w *webview) Unbind(name string) error {
|
|
375
|
+
cname := C.CString(name)
|
|
376
|
+
defer C.free(unsafe.Pointer(cname))
|
|
377
|
+
C.CgoWebViewUnbind(w.w, cname)
|
|
378
|
+
return nil
|
|
379
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
package webview
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"flag"
|
|
5
|
+
"log"
|
|
6
|
+
"os"
|
|
7
|
+
"testing"
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
func Example() {
|
|
11
|
+
w := New(true)
|
|
12
|
+
defer w.Destroy()
|
|
13
|
+
w.SetTitle("Hello")
|
|
14
|
+
w.Bind("noop", func() string {
|
|
15
|
+
log.Println("hello")
|
|
16
|
+
return "hello"
|
|
17
|
+
})
|
|
18
|
+
w.Bind("add", func(a, b int) int {
|
|
19
|
+
return a + b
|
|
20
|
+
})
|
|
21
|
+
w.Bind("quit", func() {
|
|
22
|
+
w.Terminate()
|
|
23
|
+
})
|
|
24
|
+
w.SetHtml(`<!doctype html>
|
|
25
|
+
<html>
|
|
26
|
+
<body>hello</body>
|
|
27
|
+
<script>
|
|
28
|
+
window.onload = function() {
|
|
29
|
+
document.body.innerText = ` + "`hello, ${navigator.userAgent}`" + `;
|
|
30
|
+
noop().then(function(res) {
|
|
31
|
+
console.log('noop res', res);
|
|
32
|
+
add(1, 2).then(function(res) {
|
|
33
|
+
console.log('add res', res);
|
|
34
|
+
quit();
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
</script>
|
|
39
|
+
</html>
|
|
40
|
+
)`)
|
|
41
|
+
w.Run()
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
func TestMain(m *testing.M) {
|
|
45
|
+
flag.Parse()
|
|
46
|
+
if testing.Verbose() {
|
|
47
|
+
Example()
|
|
48
|
+
}
|
|
49
|
+
os.Exit(m.Run())
|
|
50
|
+
}
|
|
@@ -18,11 +18,11 @@ export default {
|
|
|
18
18
|
// 是否开启 WebView 开发者工具。
|
|
19
19
|
debug: false,
|
|
20
20
|
|
|
21
|
-
//
|
|
22
|
-
// 'native' -
|
|
23
|
-
// '
|
|
24
|
-
//
|
|
25
|
-
// 终端命令:freedom titlebar <native|
|
|
21
|
+
// 标题栏策略,在终端随时可改,二选一:
|
|
22
|
+
// 'native' - 保留系统原生标题栏,标题栏图标与 exe 图标一致
|
|
23
|
+
// 'frameless' - 完全无边框,标题栏与 Windows 原生最小化 / 最大化 / 关闭按钮均不存在,
|
|
24
|
+
// 关闭 / 最大化 / 最小化按钮由前端自绘(模板已内置示例,默认)
|
|
25
|
+
// 终端命令:freedom titlebar <native|frameless>
|
|
26
26
|
titlebar: 'frameless',
|
|
27
27
|
|
|
28
28
|
// 应用图标(可执行文件 / .app 的图标):
|
|
@@ -24,12 +24,21 @@
|
|
|
24
24
|
flex: 0 0 38px;
|
|
25
25
|
align-items: center;
|
|
26
26
|
justify-content: space-between;
|
|
27
|
-
padding-left:
|
|
27
|
+
padding-left: 12px;
|
|
28
28
|
background: rgba(17, 24, 39, .92);
|
|
29
29
|
border-bottom: 1px solid rgba(156, 163, 175, .15);
|
|
30
|
-
|
|
30
|
+
/* 拖动改为 JS 实现(startDrag),以便保留双击最大化 / 右键菜单事件 */
|
|
31
|
+
-webkit-user-select: none;
|
|
32
|
+
}
|
|
33
|
+
.titlebar-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
|
|
34
|
+
.tb-icon {
|
|
35
|
+
width: 16px; height: 16px; flex: 0 0 16px;
|
|
36
|
+
object-fit: contain; display: none;
|
|
37
|
+
}
|
|
38
|
+
.titlebar .tb-title {
|
|
39
|
+
font-size: 13px; color: #9ca3af;
|
|
40
|
+
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
|
|
31
41
|
}
|
|
32
|
-
.titlebar .tb-title { font-size: 13px; color: #9ca3af; }
|
|
33
42
|
.tb-btns { display: flex; height: 100%; -webkit-app-region: no-drag; }
|
|
34
43
|
.tb-btn {
|
|
35
44
|
width: 46px; height: 100%;
|
|
@@ -42,6 +51,25 @@
|
|
|
42
51
|
.tb-btn.close:hover { background: #e81123; color: #fff; }
|
|
43
52
|
body.freedom-frameless .titlebar { display: flex; }
|
|
44
53
|
|
|
54
|
+
/* 标题栏右键菜单 */
|
|
55
|
+
.tb-menu {
|
|
56
|
+
position: fixed; z-index: 9999;
|
|
57
|
+
min-width: 160px; padding: 4px;
|
|
58
|
+
background: rgba(30, 41, 59, .98);
|
|
59
|
+
border: 1px solid rgba(156, 163, 175, .25);
|
|
60
|
+
border-radius: 8px;
|
|
61
|
+
box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
|
|
62
|
+
display: none;
|
|
63
|
+
}
|
|
64
|
+
.tb-menu-item {
|
|
65
|
+
display: flex; align-items: center;
|
|
66
|
+
padding: 6px 12px; font-size: 13px; color: #e5e7eb;
|
|
67
|
+
border-radius: 5px; cursor: default;
|
|
68
|
+
}
|
|
69
|
+
.tb-menu-item:hover { background: rgba(99, 102, 241, .35); }
|
|
70
|
+
.tb-menu-item.danger:hover { background: #e81123; }
|
|
71
|
+
.tb-menu-divider { height: 1px; margin: 4px 6px; background: rgba(156, 163, 175, .2); }
|
|
72
|
+
|
|
45
73
|
main {
|
|
46
74
|
flex: 1;
|
|
47
75
|
display: flex; flex-direction: column;
|
|
@@ -61,8 +89,11 @@
|
|
|
61
89
|
</style>
|
|
62
90
|
</head>
|
|
63
91
|
<body>
|
|
64
|
-
<div class="titlebar">
|
|
65
|
-
<div class="
|
|
92
|
+
<div class="titlebar" id="titlebar">
|
|
93
|
+
<div class="titlebar-left">
|
|
94
|
+
<img class="tb-icon" id="tbIcon" alt="" draggable="false">
|
|
95
|
+
<div class="tb-title" id="tbTitle">Freedom App</div>
|
|
96
|
+
</div>
|
|
66
97
|
<div class="tb-btns">
|
|
67
98
|
<button class="tb-btn" id="tbMin"></button>
|
|
68
99
|
<button class="tb-btn" id="tbMax"></button>
|
|
@@ -70,6 +101,15 @@
|
|
|
70
101
|
</div>
|
|
71
102
|
</div>
|
|
72
103
|
|
|
104
|
+
<!-- 标题栏右键菜单 -->
|
|
105
|
+
<div class="tb-menu" id="tbMenu">
|
|
106
|
+
<div class="tb-menu-item" data-action="restore">还原</div>
|
|
107
|
+
<div class="tb-menu-item" data-action="minimize">最小化</div>
|
|
108
|
+
<div class="tb-menu-item" data-action="maximize">最大化</div>
|
|
109
|
+
<div class="tb-menu-divider"></div>
|
|
110
|
+
<div class="tb-menu-item danger" data-action="close">关闭</div>
|
|
111
|
+
</div>
|
|
112
|
+
|
|
73
113
|
<main>
|
|
74
114
|
<h1>Freedom App</h1>
|
|
75
115
|
<div class="desc">你的桌面应用已就绪。</div>
|