Skip to content

Commit cc6383d

Browse files
committed
v0.6.0 新版本检测支持,部分已知问题修复
1 parent f2d2893 commit cc6383d

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

changelog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## v0.6.0
1+
## v0.6.0 新版本检测支持,部分已知问题修复
22

33
- 新增:启动新版本检测,支持新版本检测开关
44
- 新增:用户接口请求支持异常捕获配置 catchException

electron/mapi/file/index.ts

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import fs from "node:fs";
44
import {StrUtil, TimeUtil} from "../../lib/util";
55
import Apps from "../app";
66
import {Readable} from "node:stream";
7-
import {isWin} from "../../lib/env";
87

98
const nodePath = path
109

@@ -351,6 +350,47 @@ const copy = async (pathOld: string, pathNew: string, option?: { isFullPath?: bo
351350
fs.copyFileSync(fullPathOld, fullPathNew)
352351
}
353352

353+
const hubCreate = async (ext: string = 'bin') => {
354+
return path.join(
355+
'hub',
356+
TimeUtil.replacePattern('{year}'),
357+
TimeUtil.replacePattern('{month}'),
358+
TimeUtil.replacePattern('{day}'),
359+
TimeUtil.replacePattern('{hour}'),
360+
[
361+
TimeUtil.replacePattern('{minute}'),
362+
TimeUtil.replacePattern('{second}'),
363+
StrUtil.randomString(10),
364+
].join('_') + `.${ext}`
365+
)
366+
}
367+
368+
const hubSave = async (file: string, option?: {
369+
isFullPath?: boolean,
370+
returnFullPath?: boolean,
371+
}) => {
372+
option = Object.assign({
373+
isFullPath: false,
374+
returnFullPath: false,
375+
}, option)
376+
let fp = file
377+
if (!option.isFullPath) {
378+
fp = await fullPath(file)
379+
}
380+
if (!fs.existsSync(fp)) {
381+
throw `FileNotFound ${fp}`
382+
}
383+
const fileExt = ext(fp)
384+
const hubFile = await hubCreate(fileExt)
385+
await copy(fp, path.join(root(), hubFile), {
386+
isFullPath: true,
387+
})
388+
if (option.returnFullPath) {
389+
return path.join(root(), hubFile)
390+
}
391+
return hubFile
392+
}
393+
354394
const tempRoot = async () => {
355395
await waitAppEnvReady()
356396
const tempDir = path.join(AppEnv.userData, 'temp')
@@ -590,6 +630,7 @@ export const FileIndex = {
590630
appendText,
591631
download,
592632
ext,
633+
hubSave,
593634
}
594635

595636
export default FileIndex

0 commit comments

Comments
 (0)