Skip to content

Commit dde6575

Browse files
authored
ui: disable confirmation for fresh pull (#206)
1 parent 8a02f50 commit dde6575

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

src/cmd/post-list/open-post-in-vscode.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export async function openPostInVscode(postId: number, forceUpdateLocalPostFile
4444
await openPostFile(mappedPostFilePath)
4545
return Uri.file(mappedPostFilePath)
4646
}
47+
4748
// 本地文件已经被删除了, 确保重新生成博文与本地文件的关联
4849
if (mappedPostFilePath !== undefined && !isFileExist) {
4950
await PostFileMapManager.updateOrCreate(postId, '')

src/cmd/post-list/post-pull.ts

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,34 @@ import { fsUtil } from '@/infra/fs/fsUtil'
1212

1313
export async function postPull(input: Post | PostTreeItem | Uri | undefined | null, showConfirm = true, mute = false) {
1414
const ctxList: CmdCtx[] = []
15+
let isFreshPull = false
1516
input = input instanceof PostTreeItem ? input.post : input
1617
if (parsePostInput(input) && input.id > 0) {
17-
await handlePostInput(input, ctxList)
18+
const post = input
19+
const path = PostFileMapManager.getFilePath(post.id)
20+
if (path === undefined || !(await fsUtil.exists(path))) {
21+
isFreshPull = true
22+
const uri = await buildLocalPostFileUri(post, false)
23+
await workspace.fs.writeFile(uri, Buffer.from(post.postBody))
24+
await PostFileMapManager.updateOrCreate(post.id, uri.path)
25+
await handlePostInput(input, ctxList, uri.path)
26+
} else {
27+
isFreshPull = !(await fsUtil.exists(path))
28+
await handlePostInput(input, ctxList, path)
29+
}
1830
} else {
1931
const uri = parseUriInput(input)
2032
if (uri !== undefined) handleUriInput(uri, ctxList)
2133
}
2234

2335
const fileName = resolveFileNames(ctxList)
2436

25-
if (showConfirm && MarkdownCfg.isShowConfirmMsgWhenPullPost()) {
37+
if (showConfirm && !isFreshPull && MarkdownCfg.isShowConfirmMsgWhenPullPost()) {
2638
const answer = await Alert.warn(
2739
'确认要拉取远程博文吗?',
2840
{
2941
modal: true,
30-
detail: `本地文件 ${fileName} 将被覆盖(可通过设置关闭对话框)`,
42+
detail: `本地文件${fileName}将被覆盖(可通过设置关闭对话框)`,
3143
},
3244
'确认'
3345
)
@@ -38,7 +50,10 @@ export async function postPull(input: Post | PostTreeItem | Uri | undefined | nu
3850

3951
await update(ctxList)
4052

41-
if (!mute) void Alert.info(`本地文件 ${resolveFileNames(ctxList)} 已更新`)
53+
if (!mute) {
54+
if (isFreshPull) await Alert.info(`博文已下载至本地:${resolveFileNames(ctxList)}`)
55+
else await Alert.info(`本地文件已更新: ${resolveFileNames(ctxList)}`)
56+
}
4257
}
4358

4459
type InputType = Post | Uri | undefined | null
@@ -49,16 +64,7 @@ type CmdCtx = {
4964

5065
const parsePostInput = (input: InputType): input is Post => input instanceof Post
5166

52-
async function handlePostInput(post: Post, contexts: CmdCtx[]) {
53-
const path = PostFileMapManager.getFilePath(post.id)
54-
// 本地没有博文或关联到的文件不存在
55-
if (path === undefined || !(await fsUtil.exists(path))) {
56-
const uri = await buildLocalPostFileUri(post, false)
57-
await workspace.fs.writeFile(uri, Buffer.from(post.postBody))
58-
await PostFileMapManager.updateOrCreate(post.id, uri.path)
59-
return
60-
}
61-
67+
async function handlePostInput(post: Post, contexts: CmdCtx[], path: string) {
6268
await revealPostListItem(post)
6369
contexts.push({ postId: post.id, fileUri: Uri.file(path) })
6470
}
@@ -91,5 +97,5 @@ async function update(contexts: CmdCtx[]) {
9197

9298
function resolveFileNames(ctxList: CmdCtx[]) {
9399
const arr = ctxList.map(x => path.basename(x.fileUri.fsPath))
94-
return `"${arr.join('", ')}`
100+
return `${arr.join(', ')}`
95101
}

0 commit comments

Comments
 (0)