From c53617340f1a5d98e4f864929271a1d032e5c636 Mon Sep 17 00:00:00 2001 From: laggage Date: Tue, 21 Mar 2023 12:54:53 +0800 Subject: [PATCH] ui(create-blog-export): acquire confirm before create --- src/commands/blog-export/create.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/commands/blog-export/create.ts b/src/commands/blog-export/create.ts index 59394d1e..b113ae6e 100644 --- a/src/commands/blog-export/create.ts +++ b/src/commands/blog-export/create.ts @@ -2,6 +2,7 @@ import { CommandHandler } from '@/commands/command-handler'; import { AlertService } from '@/services/alert.service'; import { BlogExportApi } from '@/services/blog-export.api'; import { BlogExportProvider } from '@/tree-view-providers/blog-export-provider'; +import { MessageItem, window } from 'vscode'; export class CreateBlogExportCommandHandler extends CommandHandler { static readonly commandName = 'vscode-cnb.blog-export.create'; @@ -13,6 +14,8 @@ export class CreateBlogExportCommandHandler extends CommandHandler { } async handle(): Promise { + if (!(await this.confirm())) return; + if ( (await this.blogExportApi.create().catch((e: unknown) => { AlertService.httpError(typeof e === 'object' && e ? e : {}, { message: '创建博客备份失败' }); @@ -21,4 +24,14 @@ export class CreateBlogExportCommandHandler extends CommandHandler { ) await BlogExportProvider.optionalInstance?.refreshRecords(); } + + private async confirm(): Promise { + const items: MessageItem[] = [{ title: '确定', isCloseAffordance: false }]; + const result = await window.showInformationMessage( + '确定要创建备份吗?', + { modal: true, detail: '普通用户一天可以创建一次备份' }, + ...items + ); + return result != null; + } }