@ytchuan/flowlink 1.0.3 → 1.0.5
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 +6 -1
- package/bin/flowlink.js +31 -8
- package/main.js +10 -0
- package/package.json +3 -1
- package/scripts/postinstall.js +44 -0
package/README.md
CHANGED
|
@@ -19,6 +19,7 @@ app/
|
|
|
19
19
|
├── scripts/ # 发布辅助脚本
|
|
20
20
|
│ ├── copy-ui.js # 发布前复制渲染层产物到包内
|
|
21
21
|
│ ├── manifest-electron.js # 切换 electron 依赖位置(保留兼容)
|
|
22
|
+
│ ├── postinstall.js # 安装后校验/补装 Electron 二进制(国内镜像)
|
|
22
23
|
│ └── release.js # 发布脚本(处理 electron 依赖 + 调用 npm publish)
|
|
23
24
|
├── docs/ # 设计文档与 Agent 说明
|
|
24
25
|
└── package.json # 依赖与 electron-builder 打包配置
|
|
@@ -37,7 +38,11 @@ npm install -g @ytchuan/flowlink
|
|
|
37
38
|
flowlink
|
|
38
39
|
```
|
|
39
40
|
|
|
40
|
-
|
|
41
|
+
## 首次安装会下载 Electron(~150MB)。已内置国内镜像(npmmirror),无需额外配置;
|
|
42
|
+
### 如仍下载失败,可手动设置镜像后重装:
|
|
43
|
+
```bash
|
|
44
|
+
npm config set electron_mirror https://npmmirror.com/mirrors/electron/
|
|
45
|
+
```
|
|
41
46
|
|
|
42
47
|
## 版本更新
|
|
43
48
|
|
package/bin/flowlink.js
CHANGED
|
@@ -3,22 +3,45 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* FlowLink CLI 入口
|
|
5
5
|
* npm install -g @ytchuan/flowlink 后,用户直接执行 flowlink 即可启动
|
|
6
|
+
*
|
|
7
|
+
* 用法:
|
|
8
|
+
* flowlink # 后台运行(推荐)
|
|
9
|
+
* flowlink --foreground # 前台运行(调试用,终端显示日志)
|
|
6
10
|
*/
|
|
7
11
|
const { spawn } = require('child_process')
|
|
8
12
|
const path = require('path')
|
|
9
13
|
|
|
14
|
+
// 兜底:Electron 二进制缺失时会触发运行时按需下载(@electron/get),
|
|
15
|
+
// 默认源是 GitHub Releases,国内容易失败。未显式配置镜像时默认走国内镜像。
|
|
16
|
+
if (!process.env.ELECTRON_MIRROR && !process.env.npm_config_electron_mirror) {
|
|
17
|
+
process.env.ELECTRON_MIRROR = 'https://npmmirror.com/mirrors/electron/'
|
|
18
|
+
}
|
|
19
|
+
|
|
10
20
|
// 定位 electron 可执行文件
|
|
11
21
|
const electronPath = require('electron')
|
|
12
22
|
|
|
13
23
|
// 应用根目录(bin 的上一级)
|
|
14
24
|
const appDir = path.join(__dirname, '..')
|
|
15
25
|
|
|
16
|
-
//
|
|
17
|
-
const
|
|
18
|
-
stdio: 'inherit',
|
|
19
|
-
env: process.env,
|
|
20
|
-
})
|
|
26
|
+
// 检查是否前台模式(调试用)
|
|
27
|
+
const isForeground = process.argv.includes('--foreground') || process.argv.includes('-f')
|
|
21
28
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
29
|
+
if (isForeground) {
|
|
30
|
+
// 前台模式:继承终端,显示日志,Ctrl+C 退出
|
|
31
|
+
const child = spawn(electronPath, [appDir], {
|
|
32
|
+
stdio: 'inherit',
|
|
33
|
+
env: process.env,
|
|
34
|
+
})
|
|
35
|
+
child.on('close', (code) => {
|
|
36
|
+
process.exitCode = code
|
|
37
|
+
})
|
|
38
|
+
} else {
|
|
39
|
+
// 后台模式:分离进程,立即返回终端控制权给用户
|
|
40
|
+
const child = spawn(electronPath, [appDir], {
|
|
41
|
+
detached: true,
|
|
42
|
+
stdio: 'ignore',
|
|
43
|
+
env: process.env,
|
|
44
|
+
})
|
|
45
|
+
child.unref() // 允许父进程退出,不等待子进程
|
|
46
|
+
console.log('FlowLink 已在后台启动')
|
|
47
|
+
}
|
package/main.js
CHANGED
|
@@ -248,6 +248,16 @@ function registerIpcHandlers() {
|
|
|
248
248
|
// ---- App 生命周期 ----
|
|
249
249
|
app.whenReady().then(() => {
|
|
250
250
|
registerIpcHandlers()
|
|
251
|
+
|
|
252
|
+
// macOS: 设置 Dock 图标(非打包模式下默认显示 Electron 图标)
|
|
253
|
+
if (process.platform === 'darwin' && app.dock) {
|
|
254
|
+
const { nativeImage } = require('electron')
|
|
255
|
+
const dockIcon = nativeImage.createFromPath(path.join(__dirname, 'assets', 'logo512.png'))
|
|
256
|
+
if (!dockIcon.isEmpty()) {
|
|
257
|
+
app.dock.setIcon(dockIcon)
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
251
261
|
createWindow()
|
|
252
262
|
|
|
253
263
|
// 调度服务不随软件启动,由主页"启动服务"按钮触发(scheduler:start)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ytchuan/flowlink",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "FlowLink 桌面客户端 - AI 服务调度与管理",
|
|
5
5
|
"main": "main.js",
|
|
6
6
|
"bin": {
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"app-ui/dist/",
|
|
15
15
|
"assets/",
|
|
16
16
|
"resources/",
|
|
17
|
+
"scripts/postinstall.js",
|
|
17
18
|
".npmrc"
|
|
18
19
|
],
|
|
19
20
|
"engines": {
|
|
@@ -31,6 +32,7 @@
|
|
|
31
32
|
"build:mac": "npm run build:ui && electron-builder --mac",
|
|
32
33
|
"build:mac:zip": "npm run build:ui && electron-builder --mac zip",
|
|
33
34
|
"prepack": "npm run build:ui && node scripts/copy-ui.js",
|
|
35
|
+
"postinstall": "node scripts/postinstall.js",
|
|
34
36
|
"release": "node scripts/release.js",
|
|
35
37
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
36
38
|
},
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 安装兜底脚本(postinstall)
|
|
5
|
+
*
|
|
6
|
+
* electron 包自带的 postinstall 负责下载二进制,但在网络异常/跳过脚本等情况下
|
|
7
|
+
* 可能下载失败,导致用户首次运行 `flowlink` 时触发运行时按需下载(默认走 GitHub,
|
|
8
|
+
* 国内大概率失败)。此脚本在包安装完成后校验二进制是否完整,缺失则用国内镜像补装。
|
|
9
|
+
*/
|
|
10
|
+
const fs = require('fs')
|
|
11
|
+
const path = require('path')
|
|
12
|
+
const { execFileSync } = require('child_process')
|
|
13
|
+
|
|
14
|
+
const MIRROR = 'https://npmmirror.com/mirrors/electron/'
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
// 定位全局/本地安装的 electron 包目录
|
|
18
|
+
const electronDir = path.dirname(require.resolve('electron/package.json'))
|
|
19
|
+
const pathTxt = path.join(electronDir, 'path.txt')
|
|
20
|
+
|
|
21
|
+
// 二进制已完整则跳过(path.txt 内容为 dist 内的相对路径)
|
|
22
|
+
if (fs.existsSync(pathTxt)) {
|
|
23
|
+
const relPath = fs.readFileSync(pathTxt, 'utf8').trim()
|
|
24
|
+
if (fs.existsSync(path.join(electronDir, 'dist', relPath))) {
|
|
25
|
+
process.exit(0)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// 未显式配置镜像时默认走国内镜像
|
|
30
|
+
const env = { ...process.env }
|
|
31
|
+
if (!env.ELECTRON_MIRROR && !env.npm_config_electron_mirror) {
|
|
32
|
+
env.ELECTRON_MIRROR = MIRROR
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
console.log('[flowlink] Electron 二进制缺失,正在通过镜像补装...')
|
|
36
|
+
execFileSync(process.execPath, [path.join(electronDir, 'install.js')], {
|
|
37
|
+
stdio: 'inherit',
|
|
38
|
+
env,
|
|
39
|
+
cwd: electronDir,
|
|
40
|
+
})
|
|
41
|
+
} catch (err) {
|
|
42
|
+
// 补装失败不阻塞安装流程;首次运行 `flowlink` 时会再次尝试(同样走镜像)
|
|
43
|
+
console.warn('[flowlink] Electron 二进制补装失败,首次运行时将自动重试:', err.message)
|
|
44
|
+
}
|