@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.
Files changed (39) hide show
  1. package/README.md +17 -3
  2. package/bin/freedom.js +8 -3
  3. package/lib/build.js +64 -13
  4. package/lib/cli.js +129 -82
  5. package/lib/config.js +0 -7
  6. package/lib/shell.js +170 -33
  7. package/lib/theme.js +105 -0
  8. package/lib/tui.js +27 -3
  9. package/lib/update.js +109 -0
  10. package/lib/utils.js +14 -1
  11. package/package.json +1 -1
  12. package/shell/darwin-arm64/freedom-shell +0 -0
  13. package/shell/linux-x64/freedom-shell +0 -0
  14. package/shell/win-x64/freedom-shell.exe +0 -0
  15. package/templates/go/main.go +2 -1
  16. package/templates/go/pkg/freedom/assets/freedom.js +10 -4
  17. package/templates/go/pkg/freedom/backend_proc.go +7 -4
  18. package/templates/go/pkg/freedom/center_windows.go +44 -5
  19. package/templates/go/pkg/freedom/configfile.go +12 -5
  20. package/templates/go/pkg/freedom/freedom.go +303 -273
  21. package/templates/go/pkg/freedom/window_other.go +6 -2
  22. package/templates/go/webview_go/libs/webview/include/webview.h +31 -0
  23. package/templates/go/webview_go/webview.go +32 -6
  24. package/templates/project/src/main.js +12 -5
  25. package/templates/go/build_out.txt +0 -0
  26. package/templates/go/err.txt +0 -2
  27. package/templates/go/err10.txt +0 -0
  28. package/templates/go/err11.txt +0 -0
  29. package/templates/go/err2.txt +0 -0
  30. package/templates/go/err3.txt +0 -0
  31. package/templates/go/err4.txt +0 -1
  32. package/templates/go/err5.txt +0 -0
  33. package/templates/go/err6.txt +0 -0
  34. package/templates/go/err7.txt +0 -0
  35. package/templates/go/err8.txt +0 -0
  36. package/templates/go/err9.txt +0 -0
  37. package/templates/go/go.mod.bak_gbk +0 -11
  38. package/templates/go/tidy.txt +0 -0
  39. package/templates/go/vet_out.txt +0 -0
@@ -8,18 +8,36 @@ import (
8
8
  )
9
9
 
10
10
  var (
11
- user32 = syscall.NewLazyDLL("user32.dll")
12
- getSystemMetrics = user32.NewProc("GetSystemMetrics")
13
- moveWindow = user32.NewProc("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 = 16
18
- smCyScreen = 17
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
- // 文件不存在或内容非法时静默回退(返回 nil),保持编译期/默认配置不变。
52
+ // 文件不存在时视为未配置(返回 nil,保持编译期/默认配置不变);
53
+ // 文件存在但读取/解析失败时返回具体错误,由调用方打印告警,避免用户手改配置出错时无感知。
51
54
  func (a *App) loadRuntimeConfig() error {
52
55
  dir, err := resourcesDir()
53
56
  if err != nil {
54
- return nil
57
+ return err
55
58
  }
56
- data, err := os.ReadFile(filepath.Join(dir, "config.json"))
59
+ cfgPath := filepath.Join(dir, "config.json")
60
+ data, err := os.ReadFile(cfgPath)
57
61
  if err != nil {
58
- return nil
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 nil
69
+ return fmt.Errorf("parse %s: %w", cfgPath, err)
63
70
  }
64
71
  if rc.Title != "" {
65
72
  a.cfg.Title = rc.Title