@yufengtadian/freedom-cli 1.10.12 → 1.12.0
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 +43 -11
- package/lib/build.js +76 -14
- package/lib/cli.js +21 -2
- package/lib/config.js +4 -2
- package/lib/shell.js +73 -3
- package/lib/tui.js +5 -2
- package/package.json +14 -4
- package/shell/win-x64/freedom-shell.exe +0 -0
- package/templates/go/gen_config.go +1 -1
- package/templates/go/pkg/freedom/window_windows.go +19 -2
- package/templates/project/freedom.config.js +10 -3
- package/shell/darwin-arm64/freedom-shell +0 -0
- package/shell/darwin-x64/freedom-shell +0 -0
- package/shell/linux-arm64/freedom-shell +0 -0
- package/shell/linux-x64/freedom-shell +0 -0
package/README.md
CHANGED
|
@@ -2,23 +2,40 @@
|
|
|
2
2
|
AIGC:
|
|
3
3
|
Label: "1"
|
|
4
4
|
ContentProducer: 001191440300708461136T1XGW3
|
|
5
|
-
ProduceID:
|
|
6
|
-
ReservedCode1:
|
|
5
|
+
ProduceID: 84e692d233baf4c4ebb909c06f044dd3_2d74bd4d9c4911f184de525400f8a581
|
|
6
|
+
ReservedCode1: xo2+Pdj5CsKT7YjGd4Rry/qknv3mVecOBHAw6HqFk7EuALvKYsLlY/JCDoqw3oHEfX+sRjzs+lLZfypsJxbkr73mtQrkuHrqQIZ8f4A7vIr7hTO5V+aMiCz29hrSmbNXeI0q5SXfE/orzUoL63JrdZc1HpZGj82RLwzxXZA/d59gHWK/oYb4EXzirS8=
|
|
7
7
|
ContentPropagator: 001191440300708461136T1XGW3
|
|
8
|
-
PropagateID:
|
|
9
|
-
ReservedCode2:
|
|
8
|
+
PropagateID: 84e692d233baf4c4ebb909c06f044dd3_2d74bd4d9c4911f184de525400f8a581
|
|
9
|
+
ReservedCode2: xo2+Pdj5CsKT7YjGd4Rry/qknv3mVecOBHAw6HqFk7EuALvKYsLlY/JCDoqw3oHEfX+sRjzs+lLZfypsJxbkr73mtQrkuHrqQIZ8f4A7vIr7hTO5V+aMiCz29hrSmbNXeI0q5SXfE/orzUoL63JrdZc1HpZGj82RLwzxXZA/d59gHWK/oYb4EXzirS8=
|
|
10
10
|
---
|
|
11
11
|
|
|
12
|
+
|
|
13
|
+
|
|
12
14
|
# freedom-cli
|
|
13
15
|
|
|
14
|
-
Freedom 桌面壳打包工具:把你的 Web 前端一键打包成跨平台桌面应用(v1.
|
|
16
|
+
Freedom 桌面壳打包工具:把你的 Web 前端一键打包成跨平台桌面应用(v1.12.0)。
|
|
15
17
|
|
|
16
18
|
基于自研 Freedom WebView 壳层(对标 Wails / Tauri):前端完全自由、后端可任意语言、渲染复用系统 WebView(Windows WebView2 / macOS WKWebView / Linux WebKitGTK),产物为单个可执行文件 + resources 目录,前端页面内存加载,不占本地端口。
|
|
17
19
|
|
|
20
|
+
**v1.12.0 核心升级**:标题栏默认改为完全无边框(`frameless`)——标题栏不存在,关闭 / 最大化 / 最小化按钮由前端自绘融入 UI(模板已内置自绘标题栏示例),不再依赖 Windows 原生按钮。`freedom titlebar` 仍可随时切回 `native` / `hidden`。
|
|
21
|
+
|
|
22
|
+
**v1.12.x 修复与加固**:
|
|
23
|
+
- 修复 close 按钮缺陷:窗口关闭改走 `PostMessage(WM_CLOSE)`(原 `CloseWindow` 语义为最小化,导致点关闭只最小化);
|
|
24
|
+
- 壳二进制平台校验:构建前校验壳文件头(PE / Mach-O / ELF),杜绝"Windows 壳冒充 mac/linux 壳"的假壳被静默分发;
|
|
25
|
+
- `freedom shell download` 默认版本改为动态跟随包版本(`releaseTag()` 不再硬编码 v1.1.10),并新增 `.github/workflows/build-shell.yml` 三平台 CI 构建与 Release 资产上传;
|
|
26
|
+
- 壳进程启用 DPI 感知,高 DPI 屏幕下窗口坐标 / 渲染 / 鼠标自动化定位一致,内容更清晰;
|
|
27
|
+
- `freedom config set` 兼容双引号配置写法;依赖变更检测改用 `package-lock.json` 作基准。
|
|
28
|
+
|
|
29
|
+
**v1.11.0 核心升级**:支持自定义应用图标 + 默认隐藏 Windows 原生标题栏。配置 `freedom.config.js` 的 `icon`(Windows 用 `.ico`,macOS 用 `.icns`),`freedom build` 时自动把图标注入到 exe 的 PE 资源(RT_ICON / RT_GROUP_ICON)或 `.app/Contents/Resources`,无需任何资源编译器;`freedom icon <path>` 可一键设置。标题栏默认值由 `native` 调整为 `hidden`——保留 Windows 原生最小化 / 最大化 / 关闭按钮,隐藏标题栏视觉(DWM 扩展实现),默认不再占用窗口顶部空间。
|
|
30
|
+
|
|
18
31
|
**v1.10.12 核心升级**:macOS 产物升级为标准 .app 应用包,直接产出 `.app.zip`(mac 用户解压即得 `.app`,拖入 /Applications 即可使用);在 macOS 上执行 `freedom dmg` 可再用系统 hdiutil 生成 `.dmg`。全程仍不依赖 Go 工具链。
|
|
19
32
|
|
|
20
33
|
**v1.1.11 核心升级**:不再依赖 Go 工具链。壳层以预编译二进制随 npm 包分发(`shell/<platform>/`),`freedom build` 直接复制壳 + 写入前端与配置即可出包,Windows / macOS / Linux 三平台一次全出,任意前后端语言自由组合。
|
|
21
34
|
|
|
35
|
+
**v1.11.0 新特性**:
|
|
36
|
+
- 自定义应用图标:`icon` 配置 + `freedom icon <path>` 命令,Windows 构建时用 rcedit 注入 `.ico` 到 exe 资源(支持多尺寸,资源管理器 / 任务栏 / 快捷方式统一显示),macOS 构建时把 `.icns` 放入 `.app` 并写入 Info.plist;
|
|
37
|
+
- 标题栏默认改为 `hidden`:默认隐藏标题栏视觉,仅保留 Windows 原生最小化 / 最大化 / 关闭按钮;仍可用 `freedom titlebar` 随时切回 `native` / `frameless`。
|
|
38
|
+
|
|
22
39
|
**v1.10.12 新特性**:
|
|
23
40
|
- macOS 产物打包为标准 `.app` bundle + `.app.zip`:壳复制进 `Contents/MacOS/`,resources 与前端/后端随包,解压即用,无需任何语言运行时;
|
|
24
41
|
- `freedom dmg`:在 macOS 上用系统 hdiutil 把 `.app` 打成 `.dmg`(Windows / Linux 上运行会给出指引);
|
|
@@ -48,10 +65,13 @@ npm install
|
|
|
48
65
|
# 2. 交互式终端界面(方向键 + 回车选择,q 返回)
|
|
49
66
|
freedom tui
|
|
50
67
|
|
|
51
|
-
# 3.
|
|
52
|
-
freedom titlebar native #
|
|
68
|
+
# 3. 调整标题栏(可选,随时可改;默认 frameless:标题栏不存在,关闭/最大化/最小化按钮由前端自绘融入 UI)
|
|
69
|
+
freedom titlebar native # 保留系统原生标题栏
|
|
53
70
|
freedom titlebar hidden # 隐藏标题栏视觉,仅保留 Windows 原生最小化/最大化/关闭按钮
|
|
54
|
-
freedom titlebar frameless #
|
|
71
|
+
freedom titlebar frameless # 完全无边框,标题栏不存在,三按钮由前端自绘(默认,模板已内置示例)
|
|
72
|
+
|
|
73
|
+
# 3.5 设置应用图标(可选;Windows 用 .ico,macOS 用 .icns)
|
|
74
|
+
freedom icon icon.ico
|
|
55
75
|
|
|
56
76
|
# 4. 打包
|
|
57
77
|
freedom build # 默认当前平台
|
|
@@ -82,6 +102,10 @@ mac 用户解压 `.app.zip` 即得 `.app`,拖入 `/Applications` 即可直接
|
|
|
82
102
|
|
|
83
103
|
**三平台打包**:壳层二进制随包分发,无需本机安装 Go 或交叉编译工具链。首次构建某平台时若本地缺少对应壳二进制,CLI 自动从 GitHub Releases 下载(`freedom shell download <platform>` 可手动补齐);仅当你想用本机 Go 工具链亲自编译壳时才需要 `freedom shell build`(只产出本机平台)。多平台分发为并行执行,全平台打包耗时大幅缩短。
|
|
84
104
|
|
|
105
|
+
**壳二进制平台校验**:`freedom build` 在分发前会读取壳二进制文件头,校验其确为目标平台的真实格式(Windows PE / macOS Mach-O / Linux ELF)。若某平台壳缺失或格式不匹配(例如误用其它平台的二进制顶替),会**明确报错并给出修复指引**,绝不静默产出无法运行的假产物。
|
|
106
|
+
|
|
107
|
+
**预编译壳的来源与 CI**:`webview_go` 依赖各系统自带 WebView 框架,**无法交叉编译**,三平台壳必须在对应平台本机编译。仓库已提供 `.github/workflows/build-shell.yml`:在 win / mac(Intel / Apple Silicon)/ linux runner 上分别编译真实壳并上传到 GitHub Release,供 `freedom shell download` 拉取。发布新版本时:先 `npm publish`,再创建同名 GitHub Release,手动触发 `build-shell` workflow(或直接发 Release 自动触发)即自动补齐各平台壳资产。
|
|
108
|
+
|
|
85
109
|
产物目录可在 `freedom.config.js` 的 `outDir` 中调整:默认 `'dist'`,设为 `'.'` 则直接输出到项目根目录(dist 的上级),设为任意相对 / 绝对路径亦可。输出到项目根目录时会自动跳过 `index.html` 副本,避免覆盖项目源文件。
|
|
86
110
|
|
|
87
111
|
```bash
|
|
@@ -93,9 +117,9 @@ freedom config set outDir dist # 恢复默认 dist/
|
|
|
93
117
|
|
|
94
118
|
| 模式 | 说明 |
|
|
95
119
|
| --- | --- |
|
|
96
|
-
| `native` |
|
|
120
|
+
| `native` | 保留系统原生标题栏 |
|
|
97
121
|
| `hidden` | 隐藏标题栏视觉,仅保留 Windows 原生最小化 / 最大化 / 关闭按钮(DWM 扩展实现) |
|
|
98
|
-
| `frameless` |
|
|
122
|
+
| `frameless` | 完全无边框,标题栏不存在,客户区铺满窗口,关闭 / 最大化 / 最小化按钮由前端自绘(默认,模板已内置示例) |
|
|
99
123
|
|
|
100
124
|
`hidden` / `frameless` 模式下,前端可通过注入的 `window.freedom.window` API 控制窗口(`minimize` / `maximize` / `toggleMaximize` / `close` / `isMaximized` / `isFrameless`),模板已内置自绘标题栏示例。
|
|
101
125
|
|
|
@@ -110,12 +134,18 @@ export default {
|
|
|
110
134
|
minHeight: 300,
|
|
111
135
|
center: true, // 启动居中
|
|
112
136
|
debug: false, // 开发者工具
|
|
113
|
-
titlebar: '
|
|
137
|
+
titlebar: 'frameless', // frameless(默认,标题栏不存在,三按钮由前端自绘)| native | hidden
|
|
138
|
+
icon: undefined, // 应用图标:Windows 用 .ico(推荐多尺寸),macOS 用 .icns
|
|
114
139
|
outDir: 'dist', // 产物目录:'dist'(默认)| '.'(项目根目录)| 任意路径
|
|
115
140
|
// backend: { command: 'node', args: ['backend/main.mjs'] }, // 任意语言后端进程
|
|
116
141
|
};
|
|
117
142
|
```
|
|
118
143
|
|
|
144
|
+
**图标说明**:
|
|
145
|
+
- Windows:`.ico` 在构建时由 rcedit 注入 exe 资源(无需 VC 资源编译器),资源管理器 / 任务栏 / 快捷方式统一显示自定义图标;推荐含 16 / 32 / 48 / 256 多尺寸;
|
|
146
|
+
- macOS:`.icns` 在构建时放入 `.app/Contents/Resources` 并写入 Info.plist 的 `CFBundleIconFile`;
|
|
147
|
+
- 未配置时使用壳默认图标。`freedom icon <path>` 可直接写入该配置。
|
|
148
|
+
|
|
119
149
|
## 前端
|
|
120
150
|
|
|
121
151
|
前端是标准 Vite 项目,`vite build` 时通过 `vite-plugin-singlefile` 内联为单个 HTML。壳层注入全局对象 `window.freedom`:
|
|
@@ -140,6 +170,7 @@ freedom tui # 交互式终端界面
|
|
|
140
170
|
freedom init <目录> [--force]
|
|
141
171
|
freedom build [--platform win-x64|mac-arm64|linux-x64|all] [--no-cache]
|
|
142
172
|
freedom titlebar <native|hidden|frameless>
|
|
173
|
+
freedom icon <path> # 设置应用图标(Windows 用 .ico,macOS 用 .icns)
|
|
143
174
|
freedom config [get|set]
|
|
144
175
|
freedom shell list|download <platform>|build <platform>
|
|
145
176
|
freedom dmg [--platform <plat>] # 在 macOS 上把 .app 打包为 .dmg
|
|
@@ -170,3 +201,4 @@ export default {
|
|
|
170
201
|
|
|
171
202
|
MIT
|
|
172
203
|
*(内容由AI生成,仅供参考)*
|
|
204
|
+
*(内容由AI生成,仅供参考)*
|
package/lib/build.js
CHANGED
|
@@ -33,7 +33,7 @@ const {
|
|
|
33
33
|
nativePlatform,
|
|
34
34
|
localShellPath,
|
|
35
35
|
} = require('./utils');
|
|
36
|
-
const { hasShell, downloadShell } = require('./shell');
|
|
36
|
+
const { hasShell, downloadShell, validateLocalShell } = require('./shell');
|
|
37
37
|
|
|
38
38
|
function run(cmd, args, opts = {}) {
|
|
39
39
|
// Windows 下 npm 是 .cmd 批处理,必须经 shell 执行
|
|
@@ -104,13 +104,17 @@ async function build(projectDir, opts = {}) {
|
|
|
104
104
|
const backendDir = path.join(dir, cfg.backendDir || 'backend');
|
|
105
105
|
const hasBackend = !!(cfg.backend && fs.existsSync(backendDir));
|
|
106
106
|
|
|
107
|
-
// 3)
|
|
107
|
+
// 3) 应用图标:cfg.icon(相对项目根或绝对路径)。Windows 注入 .ico 到 exe 资源,
|
|
108
|
+
// macOS 把 .icns 放入 .app/Contents/Resources 并在 Info.plist 声明。
|
|
109
|
+
const icon = resolveIcon(dir, cfg.icon);
|
|
110
|
+
|
|
111
|
+
// 4) 逐平台分发(多平台并行,显著缩短全平台打包耗时)
|
|
108
112
|
// 单平台直接输出到 outDir;多平台各自放到 outDir/<plat>/ 子目录,避免互相覆盖
|
|
109
113
|
const multi = platforms.length > 1;
|
|
110
114
|
const results = await Promise.all(
|
|
111
115
|
platforms.map(async (plat) => {
|
|
112
116
|
const targetDir = multi ? path.join(outDirPath, plat) : outDirPath;
|
|
113
|
-
const outFile = await emitPlatform({ plat, name, version, targetDir, html, configJSON, backendDir, hasBackend, autoDownload });
|
|
117
|
+
const outFile = await emitPlatform({ plat, name, version, targetDir, html, configJSON, backendDir, hasBackend, autoDownload, icon });
|
|
114
118
|
return { plat, outFile };
|
|
115
119
|
})
|
|
116
120
|
);
|
|
@@ -118,7 +122,7 @@ async function build(projectDir, opts = {}) {
|
|
|
118
122
|
return { results };
|
|
119
123
|
}
|
|
120
124
|
|
|
121
|
-
async function emitPlatform({ plat, name, version, targetDir, html, configJSON, backendDir, hasBackend, autoDownload }) {
|
|
125
|
+
async function emitPlatform({ plat, name, version, targetDir, html, configJSON, backendDir, hasBackend, autoDownload, icon }) {
|
|
122
126
|
// 取预编译壳二进制
|
|
123
127
|
const shell = localShellPath(plat);
|
|
124
128
|
if (!fs.existsSync(shell)) {
|
|
@@ -130,6 +134,12 @@ async function emitPlatform({ plat, name, version, targetDir, html, configJSON,
|
|
|
130
134
|
}
|
|
131
135
|
process.stdout.write(`[freedom] 本地无 ${plat} 壳,尝试自动下载...\n`);
|
|
132
136
|
await downloadShell(plat);
|
|
137
|
+
} else {
|
|
138
|
+
// 壳格式校验:防止 mac/linux 平台误用 Windows 假壳被静默分发(历史缺陷:shell/<darwin-*>/<linux-*> 曾误填 Windows PE 副本)。
|
|
139
|
+
const formatIssue = validateLocalShell(plat);
|
|
140
|
+
if (formatIssue) {
|
|
141
|
+
throw new Error(formatIssue);
|
|
142
|
+
}
|
|
133
143
|
}
|
|
134
144
|
|
|
135
145
|
await fsp.mkdir(targetDir, { recursive: true });
|
|
@@ -142,6 +152,11 @@ async function emitPlatform({ plat, name, version, targetDir, html, configJSON,
|
|
|
142
152
|
await fsp.chmod(outFile, 0o755);
|
|
143
153
|
}
|
|
144
154
|
|
|
155
|
+
// 自定义 exe 图标(仅 Windows PE 支持嵌入 .ico 资源;mac 用 .icns 走 .app 分支)
|
|
156
|
+
if (isWinPlat(plat) && icon) {
|
|
157
|
+
await applyWindowsIcon(outFile, icon);
|
|
158
|
+
}
|
|
159
|
+
|
|
145
160
|
// 写 resources:页面 + 配置 + 后端
|
|
146
161
|
const resDir = path.join(targetDir, 'resources');
|
|
147
162
|
await fsp.mkdir(resDir, { recursive: true });
|
|
@@ -154,7 +169,7 @@ async function emitPlatform({ plat, name, version, targetDir, html, configJSON,
|
|
|
154
169
|
// macOS:额外生成 .app bundle + .app.zip(供 mac 用户解压即用)
|
|
155
170
|
// 壳加载 exe 同目录 resources/,故把 resources 放进 Contents/MacOS/ 即可运行,无需改壳。
|
|
156
171
|
if (isMacPlat(plat)) {
|
|
157
|
-
const appZip = createMacApp({ targetDir, name, plat, exeName, resDir, version });
|
|
172
|
+
const appZip = createMacApp({ targetDir, name, plat, exeName, resDir, version, icon });
|
|
158
173
|
process.stdout.write(
|
|
159
174
|
`[freedom] macOS 产物已打包为 .app.zip:${path.relative(process.cwd(), appZip)}\n`
|
|
160
175
|
);
|
|
@@ -163,8 +178,40 @@ async function emitPlatform({ plat, name, version, targetDir, html, configJSON,
|
|
|
163
178
|
return outFile;
|
|
164
179
|
}
|
|
165
180
|
|
|
181
|
+
// 把 .ico 图标注入到 Windows exe 的 PE 资源(RT_ICON + RT_GROUP_ICON)。
|
|
182
|
+
// 依赖 rcedit(随 npm 包分发的预编译 rcedit-x64.exe,无需 Go/资源编译器)。
|
|
183
|
+
async function applyWindowsIcon(exePath, iconPath) {
|
|
184
|
+
const ext = path.extname(iconPath).toLowerCase();
|
|
185
|
+
if (ext !== '.ico') {
|
|
186
|
+
process.stdout.write(
|
|
187
|
+
`[freedom] 提示:Windows exe 图标需 .ico 格式,已跳过(${iconPath})。\n`
|
|
188
|
+
);
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
if (process.platform !== 'win32') {
|
|
192
|
+
process.stdout.write(
|
|
193
|
+
'[freedom] 提示:exe 图标注入需在 Windows 本机执行,已跳过。\n'
|
|
194
|
+
);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
const rcedit = require('rcedit'); // 惰性加载,避免未配置 icon 时增加启动开销
|
|
198
|
+
await rcedit(exePath, { icon: iconPath });
|
|
199
|
+
process.stdout.write(`[freedom] 已注入 exe 图标:${iconPath}\n`);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// 解析 cfg.icon:相对项目根或绝对路径 -> 绝对路径;未配置返回 null。
|
|
203
|
+
// 不校验格式,格式由各平台注入逻辑决定(win 需 .ico / mac 需 .icns)。
|
|
204
|
+
function resolveIcon(dir, icon) {
|
|
205
|
+
if (!icon) return null;
|
|
206
|
+
const p = path.isAbsolute(icon) ? icon : path.resolve(dir, icon);
|
|
207
|
+
if (!fs.existsSync(p)) {
|
|
208
|
+
throw new Error(`未找到图标文件:${icon}(已尝试 ${p})。请检查 freedom.config.js 的 icon 配置。`);
|
|
209
|
+
}
|
|
210
|
+
return p;
|
|
211
|
+
}
|
|
212
|
+
|
|
166
213
|
// 把已分发的裸产物升级为标准 .app bundle,并压缩为 .app.zip
|
|
167
|
-
function createMacApp({ targetDir, name, plat, exeName, resDir, version }) {
|
|
214
|
+
function createMacApp({ targetDir, name, plat, exeName, resDir, version, icon }) {
|
|
168
215
|
const appDir = path.join(targetDir, `${name}.app`);
|
|
169
216
|
const contents = path.join(appDir, 'Contents');
|
|
170
217
|
const macos = path.join(contents, 'MacOS');
|
|
@@ -182,8 +229,19 @@ function createMacApp({ targetDir, name, plat, exeName, resDir, version }) {
|
|
|
182
229
|
copyDir(resDir, appRes);
|
|
183
230
|
}
|
|
184
231
|
|
|
232
|
+
// 自定义 .app 图标:icon 为 .icns 时放入 Resources/ 并在 Info.plist 声明
|
|
233
|
+
let icnsName = null;
|
|
234
|
+
if (icon && path.extname(icon).toLowerCase() === '.icns') {
|
|
235
|
+
icnsName = 'icon.icns';
|
|
236
|
+
fs.copyFileSync(icon, path.join(contents, 'Resources', icnsName));
|
|
237
|
+
} else if (icon) {
|
|
238
|
+
process.stdout.write(
|
|
239
|
+
`[freedom] 提示:macOS .app 图标需 .icns 格式,已跳过(${icon})。\n`
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
|
|
185
243
|
// Info.plist
|
|
186
|
-
fs.writeFileSync(path.join(contents, 'Info.plist'), renderInfoPlist(name, version), 'utf8');
|
|
244
|
+
fs.writeFileSync(path.join(contents, 'Info.plist'), renderInfoPlist(name, version, icnsName), 'utf8');
|
|
187
245
|
|
|
188
246
|
// .app.zip:解压即得 .app,拖入 /Applications 即可使用
|
|
189
247
|
const zipPath = path.join(targetDir, `${name}-${plat}.app.zip`);
|
|
@@ -191,9 +249,12 @@ function createMacApp({ targetDir, name, plat, exeName, resDir, version }) {
|
|
|
191
249
|
return zipPath;
|
|
192
250
|
}
|
|
193
251
|
|
|
194
|
-
function renderInfoPlist(name, version) {
|
|
252
|
+
function renderInfoPlist(name, version, icnsName) {
|
|
195
253
|
const safe = String(name).replace(/&/g, '&');
|
|
196
254
|
const bundleId = `com.freedom.app.${String(name).toLowerCase().replace(/[^a-z0-9.-]/g, '-')}`;
|
|
255
|
+
const iconEntry = icnsName
|
|
256
|
+
? ` <key>CFBundleIconFile</key>\n <string>${icnsName}</string>\n`
|
|
257
|
+
: '';
|
|
197
258
|
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
198
259
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
199
260
|
<plist version="1.0">
|
|
@@ -202,7 +263,7 @@ function renderInfoPlist(name, version) {
|
|
|
202
263
|
<string>${safe}</string>
|
|
203
264
|
<key>CFBundleDisplayName</key>
|
|
204
265
|
<string>${safe}</string>
|
|
205
|
-
<key>CFBundleExecutable</key>
|
|
266
|
+
${iconEntry} <key>CFBundleExecutable</key>
|
|
206
267
|
<string>${safe}</string>
|
|
207
268
|
<key>CFBundleIdentifier</key>
|
|
208
269
|
<string>${bundleId}</string>
|
|
@@ -256,7 +317,7 @@ function renderConfigJSON(cfg, name) {
|
|
|
256
317
|
const obj = {
|
|
257
318
|
name,
|
|
258
319
|
title: cfg.title || cfg.name || name,
|
|
259
|
-
titlebar: cfg.titlebar || '
|
|
320
|
+
titlebar: cfg.titlebar || 'frameless',
|
|
260
321
|
width: intVal(cfg.width, 1024),
|
|
261
322
|
height: intVal(cfg.height, 720),
|
|
262
323
|
minWidth: intVal(cfg.minWidth, 400),
|
|
@@ -334,18 +395,19 @@ function writeViteCacheMarker(dir) {
|
|
|
334
395
|
}
|
|
335
396
|
|
|
336
397
|
function ensureNodeModules(dir) {
|
|
337
|
-
//
|
|
398
|
+
// 依赖变更检测:package.json 比 package-lock.json 新,说明依赖声明有更新,自动重装。
|
|
399
|
+
// 以 package-lock.json(npm install 后必然生成)为基准,比旧版依赖 node_modules/.package-lock.json 更可靠。
|
|
338
400
|
const pkgFile = path.join(dir, 'package.json');
|
|
401
|
+
const lockFile = path.join(dir, 'package-lock.json');
|
|
339
402
|
const nmDir = path.join(dir, 'node_modules');
|
|
340
|
-
const marker = path.join(nmDir, '.package-lock.json');
|
|
341
403
|
if (!fs.existsSync(nmDir)) {
|
|
342
404
|
const res = run('npm', ['install'], { cwd: dir, stdio: 'inherit' });
|
|
343
405
|
if (res.status !== 0) throw new Error('npm install 失败。');
|
|
344
406
|
return;
|
|
345
407
|
}
|
|
346
|
-
if (fs.existsSync(pkgFile) && fs.existsSync(
|
|
408
|
+
if (fs.existsSync(pkgFile) && fs.existsSync(lockFile)) {
|
|
347
409
|
const pkgMtime = fs.statSync(pkgFile).mtimeMs;
|
|
348
|
-
const lockMtime = fs.statSync(
|
|
410
|
+
const lockMtime = fs.statSync(lockFile).mtimeMs;
|
|
349
411
|
if (pkgMtime > lockMtime + 1000) {
|
|
350
412
|
process.stdout.write('[freedom] package.json 已更新,重新安装依赖...\n');
|
|
351
413
|
const res = run('npm', ['install'], { cwd: dir, stdio: 'inherit' });
|
package/lib/cli.js
CHANGED
|
@@ -21,6 +21,7 @@ freedom - Freedom 桌面壳打包工具 v${VERSION}
|
|
|
21
21
|
--no-cache 忽略前端构建缓存,强制重新打包
|
|
22
22
|
freedom titlebar <native|hidden|frameless>
|
|
23
23
|
一键切换标题栏策略
|
|
24
|
+
freedom icon <path> 设置应用图标(Windows 需 .ico,macOS 需 .icns)
|
|
24
25
|
freedom shell list 列出本地已就绪的预编译壳
|
|
25
26
|
freedom shell download <plat> 从 GitHub Releases 下载预编译壳(无需 Go)
|
|
26
27
|
freedom shell build <plat> 本地用 Go 编译壳(可选,壳已预编译一般无需)
|
|
@@ -41,9 +42,13 @@ macOS 产物说明:
|
|
|
41
42
|
在 macOS 上执行 freedom dmg 用系统 hdiutil 生成。
|
|
42
43
|
|
|
43
44
|
标题栏策略说明:
|
|
44
|
-
native
|
|
45
|
+
native 保留系统原生标题栏
|
|
45
46
|
hidden 隐藏标题栏视觉,仅保留 Windows 原生最小化/最大化/关闭按钮
|
|
46
|
-
frameless
|
|
47
|
+
frameless 完全无边框,标题栏不存在,关闭/最大化/最小化按钮由前端自绘(默认,模板已内置示例)
|
|
48
|
+
|
|
49
|
+
图标说明:
|
|
50
|
+
Windows exe 图标:在 freedom.config.js 配置 icon(.ico 路径),构建时自动注入;
|
|
51
|
+
macOS .app 图标:icon 配置 .icns 路径即可;未配置则使用壳默认图标。
|
|
47
52
|
`.trim();
|
|
48
53
|
}
|
|
49
54
|
|
|
@@ -112,6 +117,20 @@ async function run(argv) {
|
|
|
112
117
|
return 0;
|
|
113
118
|
}
|
|
114
119
|
|
|
120
|
+
case 'icon': {
|
|
121
|
+
const iconPath = rest[0];
|
|
122
|
+
if (!iconPath) {
|
|
123
|
+
console.error('[freedom] 用法:freedom icon <path>');
|
|
124
|
+
console.error(' 示例:freedom icon icon.ico (Windows exe 图标,.ico 格式)');
|
|
125
|
+
console.error(' freedom icon icon.icns (macOS .app 图标,.icns 格式)');
|
|
126
|
+
return 1;
|
|
127
|
+
}
|
|
128
|
+
setConfig(process.cwd(), 'icon', iconPath);
|
|
129
|
+
console.log(`[freedom] icon 已设置为:${iconPath}`);
|
|
130
|
+
console.log(' 运行 freedom build 重新打包生效。');
|
|
131
|
+
return 0;
|
|
132
|
+
}
|
|
133
|
+
|
|
115
134
|
case 'config': {
|
|
116
135
|
const sub = rest[0];
|
|
117
136
|
if (sub === 'get') {
|
package/lib/config.js
CHANGED
|
@@ -13,7 +13,8 @@ const KNOWN_KEYS = {
|
|
|
13
13
|
minHeight: 300,
|
|
14
14
|
center: true,
|
|
15
15
|
debug: false,
|
|
16
|
-
titlebar: '
|
|
16
|
+
titlebar: 'frameless',
|
|
17
|
+
icon: undefined,
|
|
17
18
|
outDir: 'dist',
|
|
18
19
|
};
|
|
19
20
|
|
|
@@ -32,7 +33,8 @@ function setConfig(dir, key, value) {
|
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
|
|
36
|
+
// 同时兼容单引号与双引号字符串写法(模板统一单引号,用户手写可能用双引号)。
|
|
37
|
+
const regex = new RegExp(`(${key}\\s*:\\s*)(\"[^\"]*\"|'[^']*'|\\d+|true|false|undefined|null)`, 'g');
|
|
36
38
|
if (!regex.test(text)) {
|
|
37
39
|
throw new Error(`配置项 ${key} 未在 freedom.config.js 中找到,请手动添加。`);
|
|
38
40
|
}
|
package/lib/shell.js
CHANGED
|
@@ -27,15 +27,75 @@ const {
|
|
|
27
27
|
// GitHub Releases 下载源(可用环境变量覆盖)。
|
|
28
28
|
// 资产命名约定:freedom-shell-<plat>(单文件二进制,不压缩)。
|
|
29
29
|
function releaseRepo() {
|
|
30
|
-
return process.env.FREEDOM_SHELL_REPO || '
|
|
30
|
+
return process.env.FREEDOM_SHELL_REPO || 'YUfeng12TA/freedom';
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// 远程壳下载的默认版本:与当前包版本保持一致。
|
|
34
|
+
// 通过环境变量 FREEDOM_SHELL_TAG 可强制覆盖;默认动态读取 package.json 的 version,
|
|
35
|
+
// 避免与包版本漂移(历史曾硬编码 v1.1.10 导致下载到旧壳)。
|
|
36
|
+
function pkgVersion() {
|
|
37
|
+
try {
|
|
38
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf8'));
|
|
39
|
+
return typeof pkg.version === 'string' && pkg.version ? pkg.version : '1.1.10';
|
|
40
|
+
} catch (e) {
|
|
41
|
+
return '1.1.10';
|
|
42
|
+
}
|
|
31
43
|
}
|
|
32
44
|
function releaseTag() {
|
|
33
|
-
return process.env.FREEDOM_SHELL_TAG ||
|
|
45
|
+
return process.env.FREEDOM_SHELL_TAG || `v${pkgVersion()}`;
|
|
34
46
|
}
|
|
35
47
|
function releaseUrl(plat) {
|
|
36
48
|
return `https://github.com/${releaseRepo()}/releases/download/${releaseTag()}/freedom-shell-${plat}`;
|
|
37
49
|
}
|
|
38
50
|
|
|
51
|
+
// ---- 壳二进制平台格式校验 ----
|
|
52
|
+
// 读取二进制文件头判断真实平台格式,防止"用 Windows 壳冒充 mac/linux 壳"这类假壳
|
|
53
|
+
// 被静默分发(历史缺陷:shell/<darwin-*>/<linux-*> 曾误填 Windows PE 副本)。
|
|
54
|
+
function detectShellFormat(buf) {
|
|
55
|
+
if (!buf || buf.length < 4) return 'unknown';
|
|
56
|
+
// Windows PE:MZ
|
|
57
|
+
if (buf[0] === 0x4d && buf[1] === 0x5a) return 'win';
|
|
58
|
+
// Mach-O 64 位:CF FA ED FE(32 位为 CE FA ED FE,本项目仅 64 位)
|
|
59
|
+
if (buf[0] === 0xcf && buf[1] === 0xfa && buf[2] === 0xed && buf[3] === 0xfe) return 'mac';
|
|
60
|
+
// ELF:7F 45 4C 46
|
|
61
|
+
if (buf[0] === 0x7f && buf[1] === 0x45 && buf[2] === 0x4c && buf[3] === 0x46) return 'linux';
|
|
62
|
+
return 'unknown';
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// 平台 key -> 期望的二进制格式族
|
|
66
|
+
function expectedFormat(plat) {
|
|
67
|
+
if (plat.startsWith('win')) return 'win';
|
|
68
|
+
if (plat.startsWith('darwin')) return 'mac';
|
|
69
|
+
if (plat.startsWith('linux')) return 'linux';
|
|
70
|
+
return 'unknown';
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// 校验本地壳二进制是否为目标平台的真实格式;不匹配返回错误说明,不抛错(供调用方决策)。
|
|
74
|
+
function validateLocalShell(plat) {
|
|
75
|
+
const p = localShellPath(plat);
|
|
76
|
+
if (!fs.existsSync(p)) {
|
|
77
|
+
return null; // 壳不存在:不校验,由调用方决定下载/编译
|
|
78
|
+
}
|
|
79
|
+
let buf;
|
|
80
|
+
try {
|
|
81
|
+
buf = fs.readFileSync(p);
|
|
82
|
+
} catch (e) {
|
|
83
|
+
return `无法读取壳二进制 ${p}:${e.message}`;
|
|
84
|
+
}
|
|
85
|
+
const fmt = detectShellFormat(buf);
|
|
86
|
+
const want = expectedFormat(plat);
|
|
87
|
+
if (fmt === 'unknown') {
|
|
88
|
+
return `壳二进制 ${p} 不是可识别的 PE/Mach-O/ELF 格式(detect=${fmt})。`;
|
|
89
|
+
}
|
|
90
|
+
if (fmt !== want) {
|
|
91
|
+
return `壳二进制 ${p} 格式与目标平台 ${plat} 不匹配:期望 ${want},实际 ${fmt}。` +
|
|
92
|
+
`这是假壳(历史缺陷曾把 Windows 壳复制到 mac/linux 平台)。` +
|
|
93
|
+
`请运行 freedom shell build ${plat} 在 ${plat} 本机编译真实壳,` +
|
|
94
|
+
`或 freedom shell download ${plat} 拉取 CI 预编译产物。`;
|
|
95
|
+
}
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
|
|
39
99
|
// 列出本地已就绪的壳平台
|
|
40
100
|
function listLocal() {
|
|
41
101
|
const dir = shellDir();
|
|
@@ -136,4 +196,14 @@ function nativePlatformKey() {
|
|
|
136
196
|
return `${plat}-${arch}`;
|
|
137
197
|
}
|
|
138
198
|
|
|
139
|
-
module.exports = {
|
|
199
|
+
module.exports = {
|
|
200
|
+
listLocal,
|
|
201
|
+
hasShell,
|
|
202
|
+
downloadShell,
|
|
203
|
+
buildShell,
|
|
204
|
+
releaseRepo,
|
|
205
|
+
releaseTag,
|
|
206
|
+
detectShellFormat,
|
|
207
|
+
expectedFormat,
|
|
208
|
+
validateLocalShell,
|
|
209
|
+
};
|
package/lib/tui.js
CHANGED
|
@@ -8,7 +8,9 @@ const readline = require('readline');
|
|
|
8
8
|
const { init } = require('./init');
|
|
9
9
|
const { build } = require('./build');
|
|
10
10
|
const { setConfig, showConfig } = require('./config');
|
|
11
|
-
const { tutorialFile, hasConfig, ALL_PLATFORMS } = require('./utils');
|
|
11
|
+
const { tutorialFile, hasConfig, ALL_PLATFORMS, packageRoot } = require('./utils');
|
|
12
|
+
|
|
13
|
+
const TUI_VERSION = require(path.join(packageRoot(), 'package.json')).version;
|
|
12
14
|
|
|
13
15
|
// ---------------- ANSI ----------------
|
|
14
16
|
const ESC = '\x1b';
|
|
@@ -75,7 +77,7 @@ class TUI {
|
|
|
75
77
|
const pad = (s) => ` ${s}`;
|
|
76
78
|
const lines = [
|
|
77
79
|
'',
|
|
78
|
-
` ${C.fgCyan}${C.bold}▚ F R E E D O M T U I ${C.fgGray}
|
|
80
|
+
` ${C.fgCyan}${C.bold}▚ F R E E D O M T U I ${C.fgGray}v${TUI_VERSION}${C.reset}`,
|
|
79
81
|
'',
|
|
80
82
|
top,
|
|
81
83
|
pad(titleMid),
|
|
@@ -191,6 +193,7 @@ const CONFIG_KEYS = [
|
|
|
191
193
|
['center', '启动居中(true/false)'],
|
|
192
194
|
['debug', '开发者工具(true/false)'],
|
|
193
195
|
['titlebar', '标题栏:native | hidden | frameless'],
|
|
196
|
+
['icon', '应用图标:.ico(Windows)/ .icns(macOS)路径'],
|
|
194
197
|
['outDir', '产物目录:dist(默认)| .(项目根)| 任意路径'],
|
|
195
198
|
['backend', '任意语言后端进程(JSON)'],
|
|
196
199
|
];
|
package/package.json
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
{
|
|
2
2
|
"name": "@yufengtadian/freedom-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0",
|
|
4
4
|
"description": "Freedom WebView desktop shell packaging tool - no Go toolchain required, one command packs three-platform desktop apps",
|
|
5
|
-
"keywords": [
|
|
5
|
+
"keywords": [
|
|
6
|
+
"desktop",
|
|
7
|
+
"webview",
|
|
8
|
+
"electron-alternative",
|
|
9
|
+
"wails",
|
|
10
|
+
"tauri",
|
|
11
|
+
"frontend",
|
|
12
|
+
"cross-platform"
|
|
13
|
+
],
|
|
6
14
|
"license": "MIT",
|
|
7
15
|
"publishConfig": {
|
|
8
16
|
"access": "public"
|
|
@@ -24,6 +32,8 @@
|
|
|
24
32
|
},
|
|
25
33
|
"engines": {
|
|
26
34
|
"node": ">=18"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"rcedit": "^4.0.1"
|
|
27
38
|
}
|
|
28
39
|
}
|
|
29
|
-
|
|
Binary file
|
|
@@ -8,6 +8,20 @@ import (
|
|
|
8
8
|
"unsafe"
|
|
9
9
|
)
|
|
10
10
|
|
|
11
|
+
// 进程级 DPI 感知:让窗口坐标 / WebView 渲染统一按物理像素工作。
|
|
12
|
+
// 若不设置,高 DPI 系统(如 125%/150% 缩放)下 GetWindowRect 返回逻辑坐标,
|
|
13
|
+
// 与物理像素的鼠标坐标错位(UI 自动化难定位),且 WebView 内容渲染模糊。
|
|
14
|
+
// 必须在窗口创建前生效,故放在 init()。
|
|
15
|
+
func init() {
|
|
16
|
+
shcore := syscall.NewLazyDLL("shcore.dll")
|
|
17
|
+
procSetProcessDpiAwareness := shcore.NewProc("SetProcessDpiAwareness")
|
|
18
|
+
r, _, _ := procSetProcessDpiAwareness.Call(2) // PER_MONITOR_DPI_AWARE
|
|
19
|
+
if r != 0 {
|
|
20
|
+
// 回退到 user32 的旧版 API(Win 8 以下 / 调用失败时)
|
|
21
|
+
user32win.NewProc("SetProcessDPIAware").Call()
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
11
25
|
// Windows 平台原生窗口操作(user32 / dwmapi)。
|
|
12
26
|
// 供标题栏策略(applyTitleBar)与前端 window.freedom.window.* 控制使用。
|
|
13
27
|
|
|
@@ -17,10 +31,10 @@ var (
|
|
|
17
31
|
procGetWindowLongPtr = user32win.NewProc("GetWindowLongPtrW")
|
|
18
32
|
procSetWindowLongPtr = user32win.NewProc("SetWindowLongPtrW")
|
|
19
33
|
procShowWindow = user32win.NewProc("ShowWindow")
|
|
20
|
-
procCloseWindow = user32win.NewProc("CloseWindow")
|
|
21
34
|
procIsZoomed = user32win.NewProc("IsZoomed")
|
|
22
35
|
procSetWindowPos = user32win.NewProc("SetWindowPos")
|
|
23
36
|
procSetWindowText = user32win.NewProc("SetWindowTextW")
|
|
37
|
+
procPostMessage = user32win.NewProc("PostMessageW")
|
|
24
38
|
|
|
25
39
|
dwmapi = syscall.NewLazyDLL("dwmapi.dll")
|
|
26
40
|
procDwmExtendFrameIntoArea = dwmapi.NewProc("DwmExtendFrameIntoClientArea")
|
|
@@ -31,6 +45,7 @@ const (
|
|
|
31
45
|
wsSysMenu = 0x00080000
|
|
32
46
|
wsThickFrame = 0x00040000
|
|
33
47
|
|
|
48
|
+
wmClose = 0x0010 // WM_CLOSE:请求窗口正常关闭(触发 GoWnd 的关闭回调)
|
|
34
49
|
swHide = 0
|
|
35
50
|
swShow = 5
|
|
36
51
|
swMinimize = 6
|
|
@@ -89,7 +104,9 @@ func windowControl(hwnd uintptr, action string, mode TitleBarMode) (interface{},
|
|
|
89
104
|
}
|
|
90
105
|
return nil, nil
|
|
91
106
|
case "close":
|
|
92
|
-
|
|
107
|
+
// 发送 WM_CLOSE 请求正常关闭(触发 GoWnd 关闭回调,释放 WebView 资源)。
|
|
108
|
+
// 注意:不能使用 user32.CloseWindow —— 该 API 语义是最小化窗口。
|
|
109
|
+
procPostMessage.Call(hwnd, wmClose, 0, 0)
|
|
93
110
|
return nil, nil
|
|
94
111
|
case "isMaximized":
|
|
95
112
|
return isZoomed(hwnd), nil
|
|
@@ -19,11 +19,18 @@ export default {
|
|
|
19
19
|
debug: false,
|
|
20
20
|
|
|
21
21
|
// 标题栏策略,在终端随时可改,三选一:
|
|
22
|
-
// 'native' -
|
|
22
|
+
// 'native' - 保留系统原生标题栏
|
|
23
23
|
// 'hidden' - 隐藏标题栏视觉,仅保留 Windows 原生最小化 / 最大化 / 关闭按钮
|
|
24
|
-
// 'frameless' -
|
|
24
|
+
// 'frameless' - 完全无边框,标题栏不存在,关闭 / 最大化 / 最小化按钮由前端自绘(模板已内置示例,默认)
|
|
25
25
|
// 终端命令:freedom titlebar <native|hidden|frameless>
|
|
26
|
-
titlebar: '
|
|
26
|
+
titlebar: 'frameless',
|
|
27
|
+
|
|
28
|
+
// 应用图标(可执行文件 / .app 的图标):
|
|
29
|
+
// Windows 需 .ico(推荐含 16/32/48/256 多尺寸),构建时注入 exe 资源;
|
|
30
|
+
// macOS 需 .icns,构建时放入 .app/Contents/Resources 并写入 Info.plist。
|
|
31
|
+
// 值为相对项目根目录的路径或绝对路径,未配置则使用壳默认图标。
|
|
32
|
+
// 终端命令:freedom icon <path>(Windows 主用)
|
|
33
|
+
icon: undefined,
|
|
27
34
|
|
|
28
35
|
// 产物输出目录(相对项目根目录或绝对路径):
|
|
29
36
|
// 'dist' - 输出到 dist/ 子目录(默认)
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|