Skip to content

Commit e2585e5

Browse files
committed
update clipboard event push
1 parent 33bae61 commit e2585e5

File tree

5 files changed

+46
-12
lines changed

5 files changed

+46
-12
lines changed

src/App.vue

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,21 @@ watch(
692692
}
693693
);
694694
695+
// 数据刷新事件处理器
696+
const handleDataRefresh = async (event: Event) => {
697+
try {
698+
const customEvent = event as CustomEvent;
699+
if (customEvent.detail?.type === "snippets") {
700+
await initializeSnippets();
701+
}
702+
if (customEvent.detail?.type === "clipboard") {
703+
await initializeClipboard();
704+
}
705+
} catch (error) {
706+
console.error("Failed to refresh data:", error);
707+
}
708+
};
709+
695710
// 组件挂载时初始化数据
696711
onMounted(async () => {
697712
try {
@@ -706,6 +721,9 @@ onMounted(async () => {
706721
707722
// 检查并自动启动MCP服务器
708723
await checkAndStartMcpServer();
724+
725+
// 监听数据刷新事件
726+
window.addEventListener("seekcode:data-refresh", handleDataRefresh);
709727
} catch (error) {
710728
console.error("Failed to initialize app:", error);
711729
}
@@ -715,6 +733,8 @@ onMounted(async () => {
715733
onUnmounted(async () => {
716734
try {
717735
await stopClipboardMonitoring();
736+
// 移除数据刷新事件监听器
737+
window.removeEventListener("seekcode:data-refresh", handleDataRefresh);
718738
} catch (error) {
719739
console.error("Failed to cleanup:", error);
720740
}

src/components/DataManagement.vue

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -461,10 +461,6 @@ const performImport = async (file: File, target: HTMLInputElement) => {
461461
await snippetApi.delete(snippet.id);
462462
}
463463
}
464-
465-
toast.success(
466-
t("settings.clearedExistingSnippets", { count: existingCount })
467-
);
468464
}
469465
470466
// 导入新的代码片段,只使用必要的字段
@@ -482,6 +478,13 @@ const performImport = async (file: File, target: HTMLInputElement) => {
482478
// 重新加载数据统计
483479
await loadDataStatistics();
484480
481+
// 触发数据刷新事件,通知首页更新数据
482+
window.dispatchEvent(
483+
new CustomEvent("seekcode:data-refresh", {
484+
detail: { type: "snippets" },
485+
})
486+
);
487+
485488
// 显示成功通知
486489
if (clearExistingData.value) {
487490
toast.success(
@@ -533,13 +536,10 @@ const saveClipboardSettings = async () => {
533536
// 清空剪贴板数据
534537
const clearClipboardData = async () => {
535538
// 使用 Tauri 的确认对话框
536-
const confirmed = await confirm(
537-
"确定要清空所有剪贴板数据吗?此操作不可恢复。",
538-
{
539-
title: "清空剪贴板数据",
540-
kind: "warning",
541-
}
542-
);
539+
const confirmed = await confirm(t("settings.confirmClearClipboardData"), {
540+
title: t("settings.confirmClearClipboardDataTitle"),
541+
kind: "warning",
542+
});
543543
544544
// 如果用户取消,直接返回,不执行任何操作
545545
if (!confirmed) {
@@ -552,6 +552,14 @@ const clearClipboardData = async () => {
552552
// 清空剪贴板数据
553553
await clipboardApi.clear();
554554
toast.success(t("settings.clipboardDataCleared"));
555+
556+
// 触发数据刷新事件,通知首页更新剪贴板数据
557+
window.dispatchEvent(
558+
new CustomEvent("seekcode:data-refresh", {
559+
detail: { type: "clipboard" },
560+
})
561+
);
562+
555563
// 重新加载数据统计
556564
await loadDataStatistics();
557565
} catch (error) {

src/components/Toast.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const emit = defineEmits<{
7070
}>();
7171
7272
const visible = ref(false);
73-
let timer: NodeJS.Timeout | null = null;
73+
let timer: number | null = null;
7474
7575
const typeClasses = {
7676
success:

src/i18n/locales/en-US.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,9 @@ export default {
293293
clearClipboardDataFailed: "Failed to clear clipboard data",
294294
save: "Save",
295295
codeSnippetDataManagement: "Code Snippet Data Management",
296+
confirmClearClipboardData:
297+
"Are you sure you want to clear all clipboard data? This action cannot be undone.",
298+
confirmClearClipboardDataTitle: "Clear Clipboard Data",
296299
clipboardSettingsSaved: "Clipboard settings saved",
297300
saveClipboardSettingsFailed: "Failed to save clipboard settings",
298301
saveSettingsFailed: "Failed to save settings",

src/i18n/locales/zh-CN.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ export default {
215215
updateAvailable: "发现新版本",
216216

217217
// 数据管理
218+
data: "数据管理",
218219
exportData: "数据导出",
219220
exportDataDesc: "导出你的代码片段数据用于备份和迁移。",
220221
exportSnippets: "导出代码片段",
@@ -256,6 +257,8 @@ export default {
256257
clearClipboardDataFailed: "清空剪贴板数据失败",
257258
save: "保存",
258259
codeSnippetDataManagement: "代码片段数据管理",
260+
confirmClearClipboardData: "确定要清空所有剪贴板数据吗?此操作不可恢复。",
261+
confirmClearClipboardDataTitle: "清空剪贴板数据",
259262
clipboardSettingsSaved: "剪贴板设置已保存",
260263
saveClipboardSettingsFailed: "保存剪贴板设置失败",
261264
saveSettingsFailed: "保存设置失败",

0 commit comments

Comments
 (0)