@yufengtadian/freedom-cli 1.12.12 → 1.12.14
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 +17 -3
- package/bin/freedom.js +8 -3
- package/lib/build.js +64 -13
- package/lib/cli.js +129 -82
- package/lib/config.js +0 -7
- package/lib/shell.js +170 -33
- package/lib/theme.js +105 -0
- package/lib/tui.js +27 -3
- package/lib/update.js +109 -0
- package/lib/utils.js +14 -1
- package/package.json +1 -1
- package/shell/darwin-arm64/freedom-shell +0 -0
- package/shell/linux-x64/freedom-shell +0 -0
- package/shell/win-x64/freedom-shell.exe +0 -0
- package/templates/go/main.go +2 -1
- package/templates/go/pkg/freedom/assets/freedom.js +10 -4
- package/templates/go/pkg/freedom/backend_proc.go +7 -4
- package/templates/go/pkg/freedom/center_windows.go +44 -5
- package/templates/go/pkg/freedom/configfile.go +12 -5
- package/templates/go/pkg/freedom/freedom.go +303 -273
- package/templates/go/pkg/freedom/window_other.go +6 -2
- package/templates/go/webview_go/libs/webview/include/webview.h +31 -0
- package/templates/go/webview_go/webview.go +32 -6
- package/templates/project/src/main.js +12 -5
- package/templates/go/build_out.txt +0 -0
- package/templates/go/err.txt +0 -2
- package/templates/go/err10.txt +0 -0
- package/templates/go/err11.txt +0 -0
- package/templates/go/err2.txt +0 -0
- package/templates/go/err3.txt +0 -0
- package/templates/go/err4.txt +0 -1
- package/templates/go/err5.txt +0 -0
- package/templates/go/err6.txt +0 -0
- package/templates/go/err7.txt +0 -0
- package/templates/go/err8.txt +0 -0
- package/templates/go/err9.txt +0 -0
- package/templates/go/go.mod.bak_gbk +0 -11
- package/templates/go/tidy.txt +0 -0
- package/templates/go/vet_out.txt +0 -0
|
@@ -8,18 +8,36 @@ import (
|
|
|
8
8
|
)
|
|
9
9
|
|
|
10
10
|
var (
|
|
11
|
-
user32
|
|
12
|
-
getSystemMetrics
|
|
13
|
-
moveWindow
|
|
11
|
+
user32 = syscall.NewLazyDLL("user32.dll")
|
|
12
|
+
getSystemMetrics = user32.NewProc("GetSystemMetrics")
|
|
13
|
+
moveWindow = user32.NewProc("MoveWindow")
|
|
14
|
+
monitorFromWindow = user32.NewProc("MonitorFromWindow")
|
|
15
|
+
getMonitorInfo = user32.NewProc("GetMonitorInfoW")
|
|
14
16
|
)
|
|
15
17
|
|
|
16
18
|
const (
|
|
17
|
-
smCxScreen
|
|
18
|
-
smCyScreen
|
|
19
|
+
smCxScreen = 16
|
|
20
|
+
smCyScreen = 17
|
|
21
|
+
monitorDefaultToNear = 2 // MONITOR_DEFAULTTONEAREST
|
|
19
22
|
)
|
|
20
23
|
|
|
24
|
+
type rect struct {
|
|
25
|
+
left, top, right, bottom int32
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// monitorInfo 对应 Win32 MONITORINFO(cbSize 置 0 时用 struct 大小填充,
|
|
29
|
+
// 32 位下与 64 位下布局一致,字段对齐与 cbSize 校验兼容)。
|
|
30
|
+
type monitorInfo struct {
|
|
31
|
+
cbSize uint32
|
|
32
|
+
rcMonitor rect
|
|
33
|
+
rcWork rect
|
|
34
|
+
dwFlags uint32
|
|
35
|
+
}
|
|
36
|
+
|
|
21
37
|
// applyCenter 在 Windows 上把窗口置于屏幕中央(需在 SetSize 之后调用)。
|
|
22
38
|
// webview_go 未提供 SetPosition,这里通过原生 HWND + MoveWindow 定位。
|
|
39
|
+
// 优先居中到窗口当前所在监视器的工作区(rcWork):多屏副屏(负坐标 /
|
|
40
|
+
// 不同分辨率 / 任务栏遮挡)下也能正确居中;API 失败时回退主屏全屏居中。
|
|
23
41
|
func (a *App) applyCenter() {
|
|
24
42
|
if !a.cfg.Center || a.view == nil {
|
|
25
43
|
return
|
|
@@ -28,6 +46,27 @@ func (a *App) applyCenter() {
|
|
|
28
46
|
if hwnd == 0 {
|
|
29
47
|
return
|
|
30
48
|
}
|
|
49
|
+
mon, _, _ := monitorFromWindow.Call(hwnd, monitorDefaultToNear)
|
|
50
|
+
if mon != 0 {
|
|
51
|
+
var mi monitorInfo
|
|
52
|
+
mi.cbSize = uint32(unsafe.Sizeof(mi))
|
|
53
|
+
if r1, _, _ := getMonitorInfo.Call(mon, uintptr(unsafe.Pointer(&mi))); r1 != 0 {
|
|
54
|
+
work := mi.rcWork
|
|
55
|
+
sw := work.right - work.left
|
|
56
|
+
sh := work.bottom - work.top
|
|
57
|
+
x := work.left + (sw-int32(a.cfg.Width))/2
|
|
58
|
+
y := work.top + (sh-int32(a.cfg.Height))/2
|
|
59
|
+
if x < 0 {
|
|
60
|
+
x = 0
|
|
61
|
+
}
|
|
62
|
+
if y < 0 {
|
|
63
|
+
y = 0
|
|
64
|
+
}
|
|
65
|
+
moveWindow.Call(hwnd, uintptr(x), uintptr(y), uintptr(a.cfg.Width), uintptr(a.cfg.Height), 1)
|
|
66
|
+
return
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// 回退:主屏全屏尺寸居中(原实现)
|
|
31
70
|
sw, _, _ := getSystemMetrics.Call(smCxScreen)
|
|
32
71
|
sh, _, _ := getSystemMetrics.Call(smCyScreen)
|
|
33
72
|
x := int(sw/2) - a.cfg.Width/2
|
|
@@ -12,6 +12,8 @@ package freedom
|
|
|
12
12
|
|
|
13
13
|
import (
|
|
14
14
|
"encoding/json"
|
|
15
|
+
"errors"
|
|
16
|
+
"fmt"
|
|
15
17
|
"os"
|
|
16
18
|
"path/filepath"
|
|
17
19
|
)
|
|
@@ -47,19 +49,24 @@ func resourcesDir() (string, error) {
|
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
// loadRuntimeConfig 读取 exe 同目录 resources/config.json,将命中的字段覆盖到应用配置。
|
|
50
|
-
//
|
|
52
|
+
// 文件不存在时视为未配置(返回 nil,保持编译期/默认配置不变);
|
|
53
|
+
// 文件存在但读取/解析失败时返回具体错误,由调用方打印告警,避免用户手改配置出错时无感知。
|
|
51
54
|
func (a *App) loadRuntimeConfig() error {
|
|
52
55
|
dir, err := resourcesDir()
|
|
53
56
|
if err != nil {
|
|
54
|
-
return
|
|
57
|
+
return err
|
|
55
58
|
}
|
|
56
|
-
|
|
59
|
+
cfgPath := filepath.Join(dir, "config.json")
|
|
60
|
+
data, err := os.ReadFile(cfgPath)
|
|
57
61
|
if err != nil {
|
|
58
|
-
|
|
62
|
+
if errors.Is(err, os.ErrNotExist) {
|
|
63
|
+
return nil // 未配置:正常回退默认
|
|
64
|
+
}
|
|
65
|
+
return fmt.Errorf("read %s: %w", cfgPath, err)
|
|
59
66
|
}
|
|
60
67
|
var rc runtimeConfigFile
|
|
61
68
|
if err := json.Unmarshal(data, &rc); err != nil {
|
|
62
|
-
return
|
|
69
|
+
return fmt.Errorf("parse %s: %w", cfgPath, err)
|
|
63
70
|
}
|
|
64
71
|
if rc.Title != "" {
|
|
65
72
|
a.cfg.Title = rc.Title
|