Added data migration service

This commit is contained in:
2025-06-06 23:49:05 +08:00
parent 3e20f47b8e
commit 31addd5a20
25 changed files with 1915 additions and 425 deletions

View File

@@ -62,6 +62,23 @@ export class Menu {
}
}
export class WebviewWindow {
/** Creates a new WebviewWindow instance. */
constructor($$source: Partial<WebviewWindow> = {}) {
Object.assign(this, $$source);
}
/**
* Creates a new WebviewWindow instance from a string or object.
*/
static createFrom($$source: any = {}): WebviewWindow {
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
return new WebviewWindow($$parsedSource as Partial<WebviewWindow>);
}
}
// Private type creation functions
const $$createType0 = Menu.createFrom;
const $$createType1 = $Create.Nullable($$createType0);

View File

@@ -5,6 +5,42 @@
// @ts-ignore: Unused imports
import {Create as $Create} from "@wailsio/runtime";
/**
* A Duration represents the elapsed time between two instants
* as an int64 nanosecond count. The representation limits the
* largest representable duration to approximately 290 years.
*/
export enum Duration {
/**
* The Go zero value for the underlying type of the enum.
*/
$zero = 0,
minDuration = -9223372036854775808,
maxDuration = 9223372036854775807,
/**
* Common durations. There is no definition for units of Day or larger
* to avoid confusion across daylight savings time zone transitions.
*
* To count the number of units in a [Duration], divide:
*
* second := time.Second
* fmt.Print(int64(second/time.Millisecond)) // prints 1000
*
* To convert an integer number of units to a Duration, multiply:
*
* seconds := 10
* fmt.Print(time.Duration(seconds)*time.Second) // prints 10s
*/
Nanosecond = 1,
Microsecond = 1000,
Millisecond = 1000000,
Second = 1000000000,
Minute = 60000000000,
Hour = 3600000000000,
};
/**
* A Time represents an instant in time with nanosecond precision.
*

View File

@@ -348,20 +348,9 @@ export class GeneralConfig {
"alwaysOnTop": boolean;
/**
* 默认数据存储路径
* 数据存储路径
*/
"defaultDataPath": string;
/**
* 数据存储路径配置
* 是否使用自定义数据路径
*/
"useCustomDataPath": boolean;
/**
* 自定义数据存储路径
*/
"customDataPath": string;
"dataPath": string;
/**
* 全局热键设置
@@ -379,14 +368,8 @@ export class GeneralConfig {
if (!("alwaysOnTop" in $$source)) {
this["alwaysOnTop"] = false;
}
if (!("defaultDataPath" in $$source)) {
this["defaultDataPath"] = "";
}
if (!("useCustomDataPath" in $$source)) {
this["useCustomDataPath"] = false;
}
if (!("customDataPath" in $$source)) {
this["customDataPath"] = "";
if (!("dataPath" in $$source)) {
this["dataPath"] = "";
}
if (!("enableGlobalHotkey" in $$source)) {
this["enableGlobalHotkey"] = false;
@@ -402,10 +385,10 @@ export class GeneralConfig {
* Creates a new GeneralConfig instance from a string or object.
*/
static createFrom($$source: any = {}): GeneralConfig {
const $$createField5_0 = $$createType7;
const $$createField3_0 = $$createType7;
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
if ("globalHotkey" in $$parsedSource) {
$$parsedSource["globalHotkey"] = $$createField5_0($$parsedSource["globalHotkey"]);
$$parsedSource["globalHotkey"] = $$createField3_0($$parsedSource["globalHotkey"]);
}
return new GeneralConfig($$parsedSource as Partial<GeneralConfig>);
}

View File

@@ -50,6 +50,14 @@ export function Set(key: string, value: any): Promise<void> & { cancel(): void }
return $resultPromise;
}
/**
* SetDataPathChangeCallback 设置数据路径配置变更回调
*/
export function SetDataPathChangeCallback(callback: any): Promise<void> & { cancel(): void } {
let $resultPromise = $Call.ByID(393017412, callback) as any;
return $resultPromise;
}
/**
* SetHotkeyChangeCallback 设置热键配置变更回调
*/

View File

@@ -10,6 +10,10 @@
// @ts-ignore: Unused imports
import {Call as $Call, Create as $Create} from "@wailsio/runtime";
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore: Unused imports
import * as application$0 from "../../../github.com/wailsapp/wails/v3/pkg/application/models.js";
/**
* SelectDirectory 打开目录选择对话框
*/
@@ -17,3 +21,11 @@ export function SelectDirectory(): Promise<string> & { cancel(): void } {
let $resultPromise = $Call.ByID(2249533621) as any;
return $resultPromise;
}
/**
* SetWindow 设置绑定的窗口
*/
export function SetWindow(window: application$0.WebviewWindow | null): Promise<void> & { cancel(): void } {
let $resultPromise = $Call.ByID(968177170, window) as any;
return $resultPromise;
}

View File

@@ -15,7 +15,7 @@ import {Call as $Call, Create as $Create} from "@wailsio/runtime";
import * as models$0 from "../models/models.js";
/**
* ForceSave 强制保存当前文档
* ForceSave 强制保存
*/
export function ForceSave(): Promise<void> & { cancel(): void } {
let $resultPromise = $Call.ByID(2767091023) as any;
@@ -23,7 +23,7 @@ export function ForceSave(): Promise<void> & { cancel(): void } {
}
/**
* GetActiveDocument 获取当前活动文档
* GetActiveDocument 获取活动文档
*/
export function GetActiveDocument(): Promise<models$0.Document | null> & { cancel(): void } {
let $resultPromise = $Call.ByID(1785823398) as any;
@@ -35,15 +35,7 @@ export function GetActiveDocument(): Promise<models$0.Document | null> & { cance
}
/**
* GetActiveDocumentContent 获取当前活动文档内容
*/
export function GetActiveDocumentContent(): Promise<string> & { cancel(): void } {
let $resultPromise = $Call.ByID(922617063) as any;
return $resultPromise;
}
/**
* Initialize 初始化文档服务
* Initialize 初始化服务
*/
export function Initialize(): Promise<void> & { cancel(): void } {
let $resultPromise = $Call.ByID(3418008221) as any;
@@ -51,15 +43,23 @@ export function Initialize(): Promise<void> & { cancel(): void } {
}
/**
* SaveDocumentSync 同步保存文档内容
* OnDataPathChanged 处理数据路径变更
*/
export function SaveDocumentSync(content: string): Promise<void> & { cancel(): void } {
let $resultPromise = $Call.ByID(3770207288, content) as any;
export function OnDataPathChanged(oldPath: string, newPath: string): Promise<void> & { cancel(): void } {
let $resultPromise = $Call.ByID(269349439, oldPath, newPath) as any;
return $resultPromise;
}
/**
* ServiceShutdown 服务关闭
* ReloadDocument 重新加载文档
*/
export function ReloadDocument(): Promise<void> & { cancel(): void } {
let $resultPromise = $Call.ByID(3093415283) as any;
return $resultPromise;
}
/**
* ServiceShutdown 关闭服务
*/
export function ServiceShutdown(): Promise<void> & { cancel(): void } {
let $resultPromise = $Call.ByID(638578044) as any;
@@ -67,7 +67,7 @@ export function ServiceShutdown(): Promise<void> & { cancel(): void } {
}
/**
* UpdateActiveDocumentContent 更新当前活动文档内容
* UpdateActiveDocumentContent 更新文档内容
*/
export function UpdateActiveDocumentContent(content: string): Promise<void> & { cancel(): void } {
let $resultPromise = $Call.ByID(1486276638, content) as any;

View File

@@ -5,12 +5,14 @@ import * as ConfigService from "./configservice.js";
import * as DialogService from "./dialogservice.js";
import * as DocumentService from "./documentservice.js";
import * as HotkeyService from "./hotkeyservice.js";
import * as MigrationService from "./migrationservice.js";
import * as SystemService from "./systemservice.js";
export {
ConfigService,
DialogService,
DocumentService,
HotkeyService,
MigrationService,
SystemService
};

View File

@@ -0,0 +1,62 @@
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT
/**
* MigrationService 迁移服务
* @module
*/
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore: Unused imports
import {Call as $Call, Create as $Create} from "@wailsio/runtime";
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore: Unused imports
import * as $models from "./models.js";
/**
* CancelMigration 取消迁移
*/
export function CancelMigration(): Promise<void> & { cancel(): void } {
let $resultPromise = $Call.ByID(1813274502) as any;
return $resultPromise;
}
/**
* GetProgress 获取当前进度
*/
export function GetProgress(): Promise<$models.MigrationProgress> & { cancel(): void } {
let $resultPromise = $Call.ByID(3413264131) as any;
let $typingPromise = $resultPromise.then(($result: any) => {
return $$createType0($result);
}) as any;
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
return $typingPromise;
}
/**
* MigrateDirectory 迁移目录
*/
export function MigrateDirectory(srcPath: string, dstPath: string): Promise<void> & { cancel(): void } {
let $resultPromise = $Call.ByID(311970580, srcPath, dstPath) as any;
return $resultPromise;
}
/**
* ServiceShutdown 服务关闭
*/
export function ServiceShutdown(): Promise<void> & { cancel(): void } {
let $resultPromise = $Call.ByID(3472042605) as any;
return $resultPromise;
}
/**
* SetProgressCallback 设置进度回调
*/
export function SetProgressCallback(callback: $models.MigrationProgressCallback): Promise<void> & { cancel(): void } {
let $resultPromise = $Call.ByID(75752256, callback) as any;
return $resultPromise;
}
// Private type creation functions
const $$createType0 = $models.MigrationProgress.createFrom;

View File

@@ -5,6 +5,10 @@
// @ts-ignore: Unused imports
import {Create as $Create} from "@wailsio/runtime";
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore: Unused imports
import * as time$0 from "../../../time/models.js";
/**
* MemoryStats 内存统计信息
*/
@@ -71,3 +75,152 @@ export class MemoryStats {
return new MemoryStats($$parsedSource as Partial<MemoryStats>);
}
}
/**
* MigrationProgress 迁移进度信息
*/
export class MigrationProgress {
/**
* 迁移状态
*/
"status": MigrationStatus;
/**
* 当前处理的文件
*/
"currentFile": string;
/**
* 已处理文件数
*/
"processedFiles": number;
/**
* 总文件数
*/
"totalFiles": number;
/**
* 已处理字节数
*/
"processedBytes": number;
/**
* 总字节数
*/
"totalBytes": number;
/**
* 进度百分比 (0-100)
*/
"progress": number;
/**
* 状态消息
*/
"message": string;
/**
* 错误信息
*/
"error"?: string;
/**
* 开始时间
*/
"startTime": time$0.Time;
/**
* 估计剩余时间
*/
"estimatedTime": time$0.Duration;
/** Creates a new MigrationProgress instance. */
constructor($$source: Partial<MigrationProgress> = {}) {
if (!("status" in $$source)) {
this["status"] = ("" as MigrationStatus);
}
if (!("currentFile" in $$source)) {
this["currentFile"] = "";
}
if (!("processedFiles" in $$source)) {
this["processedFiles"] = 0;
}
if (!("totalFiles" in $$source)) {
this["totalFiles"] = 0;
}
if (!("processedBytes" in $$source)) {
this["processedBytes"] = 0;
}
if (!("totalBytes" in $$source)) {
this["totalBytes"] = 0;
}
if (!("progress" in $$source)) {
this["progress"] = 0;
}
if (!("message" in $$source)) {
this["message"] = "";
}
if (!("startTime" in $$source)) {
this["startTime"] = null;
}
if (!("estimatedTime" in $$source)) {
this["estimatedTime"] = (0 as time$0.Duration);
}
Object.assign(this, $$source);
}
/**
* Creates a new MigrationProgress instance from a string or object.
*/
static createFrom($$source: any = {}): MigrationProgress {
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
return new MigrationProgress($$parsedSource as Partial<MigrationProgress>);
}
}
/**
* MigrationProgressCallback 进度回调函数类型
*/
export type MigrationProgressCallback = any;
/**
* MigrationStatus 迁移状态
*/
export enum MigrationStatus {
/**
* The Go zero value for the underlying type of the enum.
*/
$zero = "",
/**
* 空闲状态
*/
MigrationStatusIdle = "idle",
/**
* 准备中
*/
MigrationStatusPreparing = "preparing",
/**
* 迁移中
*/
MigrationStatusMigrating = "migrating",
/**
* 完成
*/
MigrationStatusCompleted = "completed",
/**
* 失败
*/
MigrationStatusFailed = "failed",
/**
* 取消
*/
MigrationStatusCancelled = "cancelled",
};

View File

@@ -9,6 +9,7 @@ export {}
declare module 'vue' {
export interface GlobalComponents {
MemoryMonitor: typeof import('./src/components/monitor/MemoryMonitor.vue')['default']
MigrationProgress: typeof import('./src/components/migration/MigrationProgress.vue')['default']
RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView']
Toolbar: typeof import('./src/components/toolbar/Toolbar.vue')['default']

View File

@@ -0,0 +1,540 @@
<template>
<div v-if="visible" class="migration-overlay">
<div class="migration-modal">
<div class="migration-header">
<h3>{{ t('migration.title') }}</h3>
<div class="migration-status" :class="status">
{{ getStatusText() }}
</div>
</div>
<div class="migration-content">
<div class="progress-container">
<div class="progress-bar">
<div
class="progress-fill"
:style="{ width: `${progress.progress || 0}%` }"
:class="status"
></div>
</div>
<div class="progress-text">
{{ Math.round(progress.progress || 0) }}%
</div>
</div>
<div class="migration-details">
<div v-if="progress.message" class="message">
{{ progress.message }}
</div>
<div v-if="progress.currentFile" class="current-file">
<span class="label">{{ t('migration.currentFile') }}:</span>
<span class="file-name">{{ progress.currentFile }}</span>
</div>
<div class="stats" v-if="progress.totalFiles > 0">
<div class="stat-item">
<span class="label">{{ t('migration.files') }}:</span>
<span class="value">{{ progress.processedFiles }} / {{ progress.totalFiles }}</span>
</div>
<div class="stat-item" v-if="progress.totalBytes > 0">
<span class="label">{{ t('migration.size') }}:</span>
<span class="value">{{ formatBytes(progress.processedBytes) }} / {{ formatBytes(progress.totalBytes) }}</span>
</div>
<div class="stat-item" v-if="progress.estimatedTime && status === 'migrating'">
<span class="label">{{ t('migration.timeRemaining') }}:</span>
<span class="value">{{ formatDuration(progress.estimatedTime) }}</span>
</div>
</div>
<div v-if="progress.error" class="error-message">
<span class="error-icon"></span>
{{ progress.error }}
</div>
</div>
</div>
<div class="migration-actions">
<button
v-if="status === 'completed'"
@click="handleComplete"
class="action-button success"
>
{{ t('migration.complete') }}
</button>
<button
v-if="status === 'failed'"
@click="handleRetry"
class="action-button retry"
>
{{ t('migration.retry') }}
</button>
<button
v-if="status === 'failed'"
@click="handleClose"
class="action-button secondary"
>
{{ t('migration.close') }}
</button>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { computed, ref, watch, onMounted, onUnmounted } from 'vue';
import { useI18n } from 'vue-i18n';
import { MigrationService } from '../../../bindings/voidraft/internal/services';
interface MigrationProgress {
status: string;
currentFile: string;
processedFiles: number;
totalFiles: number;
processedBytes: number;
totalBytes: number;
progress: number;
message: string;
error?: string;
startTime: string;
estimatedTime: number;
}
interface Props {
visible: boolean;
}
interface Emits {
(e: 'complete'): void;
(e: 'close'): void;
(e: 'retry'): void;
}
const props = defineProps<Props>();
const emit = defineEmits<Emits>();
const { t } = useI18n();
// 迁移进度状态
const progress = ref<MigrationProgress>({
status: 'idle',
currentFile: '',
processedFiles: 0,
totalFiles: 0,
processedBytes: 0,
totalBytes: 0,
progress: 0,
message: '',
startTime: '',
estimatedTime: 0
});
const status = computed(() => progress.value.status);
// 定时器用于轮询进度
let progressTimer: number | null = null;
// 轮询迁移进度
const pollProgress = async () => {
try {
const currentProgress = await MigrationService.GetProgress();
progress.value = currentProgress;
// 如果迁移完成或失败,停止轮询
if (currentProgress.status === 'completed' || currentProgress.status === 'failed' || currentProgress.status === 'cancelled') {
stopPolling();
}
} catch (error) {
console.error('Failed to get migration progress:', error);
}
};
// 开始轮询
const startPolling = () => {
if (progressTimer) return;
// 立即获取一次进度
pollProgress();
// 每500ms轮询一次
progressTimer = window.setInterval(pollProgress, 500);
};
// 停止轮询
const stopPolling = () => {
if (progressTimer) {
clearInterval(progressTimer);
progressTimer = null;
}
};
// 监听可见性变化
watch(() => props.visible, (visible) => {
if (visible) {
startPolling();
} else {
stopPolling();
}
});
// 组件挂载时开始轮询(如果可见)
onMounted(() => {
if (props.visible) {
startPolling();
}
});
// 组件卸载时停止轮询
onUnmounted(() => {
stopPolling();
});
// 获取状态文本
const getStatusText = () => {
switch (status.value) {
case 'preparing':
return t('migration.preparing');
case 'migrating':
return t('migration.migrating');
case 'completed':
return t('migration.completed');
case 'failed':
return t('migration.failed');
case 'cancelled':
return t('migration.cancelled');
default:
return t('migration.idle');
}
};
// 格式化字节数
const formatBytes = (bytes: number): string => {
if (bytes === 0) return '0 B';
const k = 1024;
const sizes = ['B', 'KB', 'MB', 'GB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(1))} ${sizes[i]}`;
};
// 格式化持续时间
const formatDuration = (nanoseconds: number): string => {
const seconds = Math.floor(nanoseconds / 1000000000);
if (seconds < 60) {
return `${seconds}`;
} else if (seconds < 3600) {
const minutes = Math.floor(seconds / 60);
return `${minutes}分钟`;
} else {
const hours = Math.floor(seconds / 3600);
const minutes = Math.floor((seconds % 3600) / 60);
return `${hours}小时${minutes}分钟`;
}
};
// 处理完成
const handleComplete = () => {
emit('complete');
};
// 处理重试
const handleRetry = () => {
emit('retry');
};
// 处理关闭
const handleClose = () => {
emit('close');
};
</script>
<style scoped lang="scss">
.migration-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.7);
display: flex;
align-items: center;
justify-content: center;
z-index: 9999;
backdrop-filter: blur(4px);
}
.migration-modal {
background-color: #2a2a2a;
border-radius: 8px;
border: 1px solid #444444;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
width: 90%;
max-width: 500px;
max-height: 80vh;
overflow: hidden;
animation: modalSlideIn 0.3s ease-out;
}
@keyframes modalSlideIn {
from {
opacity: 0;
transform: translateY(-20px) scale(0.95);
}
to {
opacity: 1;
transform: translateY(0) scale(1);
}
}
.migration-header {
padding: 20px 24px 16px;
border-bottom: 1px solid #444444;
h3 {
margin: 0 0 8px 0;
color: #e0e0e0;
font-size: 18px;
font-weight: 600;
}
.migration-status {
font-size: 14px;
font-weight: 500;
padding: 4px 8px;
border-radius: 4px;
display: inline-block;
&.preparing {
color: #ffc107;
background-color: rgba(255, 193, 7, 0.1);
}
&.migrating {
color: #17a2b8;
background-color: rgba(23, 162, 184, 0.1);
}
&.completed {
color: #28a745;
background-color: rgba(40, 167, 69, 0.1);
}
&.failed {
color: #dc3545;
background-color: rgba(220, 53, 69, 0.1);
}
&.cancelled {
color: #6c757d;
background-color: rgba(108, 117, 125, 0.1);
}
}
}
.migration-content {
padding: 20px 24px;
max-height: 60vh;
overflow-y: auto;
}
.progress-container {
margin-bottom: 20px;
.progress-bar {
width: 100%;
height: 8px;
background-color: #444444;
border-radius: 4px;
overflow: hidden;
margin-bottom: 8px;
.progress-fill {
height: 100%;
transition: width 0.3s ease;
border-radius: 4px;
&.preparing {
background-color: #ffc107;
}
&.migrating {
background-color: #17a2b8;
background-image: linear-gradient(
45deg,
rgba(255, 255, 255, 0.1) 25%,
transparent 25%,
transparent 50%,
rgba(255, 255, 255, 0.1) 50%,
rgba(255, 255, 255, 0.1) 75%,
transparent 75%,
transparent
);
background-size: 20px 20px;
animation: progressStripes 1s linear infinite;
}
&.completed {
background-color: #28a745;
}
&.failed {
background-color: #dc3545;
}
}
}
.progress-text {
text-align: center;
color: #b0b0b0;
font-size: 14px;
font-weight: 500;
}
}
@keyframes progressStripes {
0% {
background-position: 0 0;
}
100% {
background-position: 20px 0;
}
}
.migration-details {
.message {
color: #e0e0e0;
font-size: 14px;
margin-bottom: 12px;
padding: 8px 12px;
background-color: rgba(255, 255, 255, 0.05);
border-radius: 4px;
}
.current-file {
margin-bottom: 12px;
font-size: 13px;
.label {
color: #888888;
}
.file-name {
color: #e0e0e0;
font-family: 'Consolas', 'Courier New', monospace;
word-break: break-all;
}
}
.stats {
display: flex;
flex-direction: column;
gap: 8px;
margin-top: 12px;
.stat-item {
display: flex;
justify-content: space-between;
font-size: 13px;
.label {
color: #888888;
}
.value {
color: #e0e0e0;
font-weight: 500;
}
}
}
.error-message {
margin-top: 16px;
padding: 12px;
background-color: rgba(220, 53, 69, 0.1);
border: 1px solid rgba(220, 53, 69, 0.3);
border-radius: 4px;
color: #ff6b6b;
font-size: 13px;
display: flex;
align-items: flex-start;
gap: 8px;
.error-icon {
flex-shrink: 0;
}
}
}
.migration-actions {
padding: 16px 24px 20px;
border-top: 1px solid #444444;
display: flex;
justify-content: flex-end;
gap: 12px;
.action-button {
padding: 8px 16px;
border: none;
border-radius: 4px;
font-size: 14px;
font-weight: 500;
cursor: pointer;
transition: all 0.2s ease;
&.success {
background-color: #28a745;
color: white;
&:hover {
background-color: #218838;
}
}
&.retry {
background-color: #17a2b8;
color: white;
&:hover {
background-color: #138496;
}
}
&.secondary {
background-color: #6c757d;
color: white;
&:hover {
background-color: #5a6268;
}
}
&:active {
transform: translateY(1px);
}
}
}
/* 自定义滚动条 */
.migration-content::-webkit-scrollbar {
width: 6px;
}
.migration-content::-webkit-scrollbar-track {
background: #333333;
border-radius: 3px;
}
.migration-content::-webkit-scrollbar-thumb {
background: #666666;
border-radius: 3px;
&:hover {
background: #777777;
}
}
</style>

View File

@@ -45,8 +45,38 @@ export default {
loadFailed: 'Failed to load save settings',
saveSuccess: 'Save settings updated',
saveFailed: 'Failed to update save settings'
},
migration: {
inProgress: 'Migrating data to new path...',
success: 'Data migration completed',
failed: 'Data migration failed'
}
},
migration: {
title: 'Data Migration',
preparing: 'Preparing',
migrating: 'Migrating',
completed: 'Completed',
failed: 'Failed',
cancelled: 'Cancelled',
idle: 'Idle',
currentFile: 'Current File',
files: 'Files',
size: 'Size',
timeRemaining: 'Time Remaining',
complete: 'Complete',
retry: 'Retry',
close: 'Close',
migrationInProgress: 'Migrating data to new path...',
migrationCompleted: 'Data migration completed',
migrationFailed: 'Data migration failed',
recursiveCopyError: 'Target path cannot be a subdirectory of source path, this would cause infinite recursive copying',
targetNotDirectory: 'Target path exists but is not a directory',
targetNotEmpty: 'Target directory is not empty, cannot migrate',
compressing: 'Compressing source directory...',
extracting: 'Extracting to target location...',
cleaning: 'Cleaning up source directory...'
},
settings: {
title: 'Settings',
backToEditor: 'Back to Editor',
@@ -69,13 +99,11 @@ export default {
showInSystemTray: 'Show in System Tray',
alwaysOnTop: 'Always on Top',
dataStorage: 'Data Storage',
useCustomDataPath: 'Use custom data storage path',
selectDirectory: 'Select Directory',
selectDataDirectory: 'Select Data Storage Directory',
defaultDataPath: 'Default data storage path',
bufferFiles: 'Buffer Files Path',
useCustomLocation: 'Use custom location for buffer files',
customDataPath: 'Custom Data Storage Path',
dataPath: 'Data Storage Path',
clickToSelectPath: 'Click to select path',
resetDefault: 'Reset Default',
resetToDefaultPath: 'Reset to default path',
restartRequiredForDataPath: 'Restart required',
fontSize: 'Font Size',
fontSizeDescription: 'Editor font size',
fontSettings: 'Font Settings',
@@ -95,6 +123,10 @@ export default {
restartRequired: '(Restart required)',
saveOptions: 'Save Options',
autoSaveDelay: 'Auto Save Delay (ms)',
selectDirectoryFailed: 'Failed to select directory'
selectDirectoryFailed: 'Failed to select directory',
validation: {
customPathRequired: 'A valid directory must be selected when enabling custom path',
customPathAutoDisabled: 'Custom data path has been automatically disabled due to no valid directory selected'
}
}
};

View File

@@ -45,8 +45,38 @@ export default {
loadFailed: '加载保存设置失败',
saveSuccess: '保存设置已更新',
saveFailed: '保存设置更新失败'
},
migration: {
inProgress: '正在迁移数据到新路径...',
success: '数据迁移完成',
failed: '数据迁移失败'
}
},
migration: {
title: '数据迁移',
preparing: '准备中',
migrating: '迁移中',
completed: '已完成',
failed: '失败',
cancelled: '已取消',
idle: '空闲',
currentFile: '当前文件',
files: '文件',
size: '大小',
timeRemaining: '剩余时间',
complete: '完成',
retry: '重试',
close: '关闭',
migrationInProgress: '正在迁移数据到新路径...',
migrationCompleted: '数据迁移完成',
migrationFailed: '数据迁移失败',
recursiveCopyError: '目标路径不能是源路径的子目录,这会导致无限递归复制',
targetNotDirectory: '目标路径存在但不是目录',
targetNotEmpty: '目标目录不为空,无法迁移',
compressing: '正在压缩源目录...',
extracting: '正在解压到目标位置...',
cleaning: '正在清理源目录...'
},
settings: {
title: '设置',
backToEditor: '返回编辑器',
@@ -69,13 +99,11 @@ export default {
showInSystemTray: '在系统托盘中显示',
alwaysOnTop: '窗口始终置顶',
dataStorage: '数据存储',
useCustomDataPath: '使用自定义数据存储路径',
selectDirectory: '选择目录',
selectDataDirectory: '选择数据存储目录',
defaultDataPath: '默认数据存储路径',
bufferFiles: '缓冲文件路径',
useCustomLocation: '使用自定义位置存储缓冲文件',
customDataPath: '自定义数据存储路径',
dataPath: '数据存储路径',
clickToSelectPath: '点击选择路径',
resetDefault: '恢复默认',
resetToDefaultPath: '恢复为默认路径',
restartRequiredForDataPath: '需要重启应用程序',
fontSize: '字体大小',
fontSizeDescription: '编辑器字体大小',
fontSettings: '字体设置',
@@ -95,6 +123,10 @@ export default {
restartRequired: '(需要重启)',
saveOptions: '保存选项',
autoSaveDelay: '自动保存延迟(毫秒)',
selectDirectoryFailed: '选择目录失败'
selectDirectoryFailed: '选择目录失败',
validation: {
customPathRequired: '启用自定义路径时必须选择一个有效的目录',
customPathAutoDisabled: '由于未选择有效目录,自定义数据路径已自动关闭'
}
}
};

View File

@@ -47,9 +47,7 @@ type NumberConfigKey = 'fontSize' | 'tabSize' | 'lineHeight';
// 配置键映射
const GENERAL_CONFIG_KEY_MAP: GeneralConfigKeyMap = {
alwaysOnTop: 'general.always_on_top',
defaultDataPath: 'general.default_data_path',
useCustomDataPath: 'general.use_custom_data_path',
customDataPath: 'general.custom_data_path',
dataPath: 'general.data_path',
enableGlobalHotkey: 'general.enable_global_hotkey',
globalHotkey: 'general.global_hotkey'
} as const;
@@ -115,9 +113,7 @@ const getBrowserLanguage = (): SupportedLocaleType => {
const DEFAULT_CONFIG: AppConfig = {
general: {
alwaysOnTop: false,
defaultDataPath: './data',
useCustomDataPath: false,
customDataPath: '',
dataPath: './data',
enableGlobalHotkey: false,
globalHotkey: {
ctrl: false,
@@ -333,7 +329,7 @@ export const useConfigStore = defineStore('config', () => {
const setters = {
fontFamily: (value: string) => safeCall(() => updateEditingConfig('fontFamily', value), 'config.saveFailed', 'config.saveSuccess'),
fontWeight: (value: string) => safeCall(() => updateEditingConfig('fontWeight', value), 'config.saveFailed', 'config.saveSuccess'),
defaultDataPath: (value: string) => safeCall(() => updateGeneralConfig('defaultDataPath', value), 'config.saveFailed', 'config.saveSuccess'),
dataPath: (value: string) => safeCall(() => updateGeneralConfig('dataPath', value), 'config.saveFailed', 'config.saveSuccess'),
autoSaveDelay: (value: number) => safeCall(() => updateEditingConfig('autoSaveDelay', value), 'config.saveFailed', 'config.saveSuccess')
};
@@ -382,9 +378,7 @@ export const useConfigStore = defineStore('config', () => {
setFontWeight: setters.fontWeight,
// 路径操作
setDefaultDataPath: setters.defaultDataPath,
setUseCustomDataPath: (value: boolean) => safeCall(() => updateGeneralConfig('useCustomDataPath', value), 'config.saveFailed', 'config.saveSuccess'),
setCustomDataPath: (value: string) => safeCall(() => updateGeneralConfig('customDataPath', value), 'config.saveFailed', 'config.saveSuccess'),
setDataPath: setters.dataPath,
// 保存配置相关方法
setAutoSaveDelay: setters.autoSaveDelay,

View File

@@ -24,7 +24,7 @@ export interface AutoSaveOptions {
export function createAutoSavePlugin(options: AutoSaveOptions = {}) {
const {
onSave = () => {},
debounceDelay = 1000 // 默认1000ms延迟原为300ms
debounceDelay = 2000
} = options;
return ViewPlugin.fromClass(

View File

@@ -1,12 +1,10 @@
<script setup lang="ts">
import { useConfigStore } from '@/stores/configStore';
import { useI18n } from 'vue-i18n';
import { ref, watch } from 'vue';
import { ref } from 'vue';
import { useRouter, useRoute } from 'vue-router';
import MemoryMonitor from '@/components/monitor/MemoryMonitor.vue';
const { t } = useI18n();
const configStore = useConfigStore();
const router = useRouter();
const route = useRoute();
@@ -28,9 +26,10 @@ const handleNavClick = (item: typeof navItems[0]) => {
};
// 返回编辑器
const goBackToEditor = () => {
router.push('/');
const goBackToEditor = async () => {
await router.push('/');
};
</script>
<template>

View File

@@ -1,18 +1,22 @@
<script setup lang="ts">
import { useConfigStore } from '@/stores/configStore';
import { useI18n } from 'vue-i18n';
import { computed} from 'vue';
import { computed, ref, onMounted } from 'vue';
import SettingSection from '../components/SettingSection.vue';
import SettingItem from '../components/SettingItem.vue';
import ToggleSwitch from '../components/ToggleSwitch.vue';
import MigrationProgress from '@/components/migration/MigrationProgress.vue';
import { useErrorHandler } from '@/utils/errorHandler';
import { DialogService } from '@/../bindings/voidraft/internal/services';
import { DialogService, MigrationService } from '@/../bindings/voidraft/internal/services';
import * as runtime from '@wailsio/runtime';
const { t } = useI18n();
const configStore = useConfigStore();
const { safeCall } = useErrorHandler();
// 迁移状态
const showMigrationProgress = ref(false);
// 可选键列表
const keyOptions = [
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
@@ -87,34 +91,57 @@ const hotkeyPreview = computed(() => {
return parts.join(' + ');
});
// 数据存储路径配置
const useCustomDataPath = computed({
get: () => configStore.config.general.useCustomDataPath,
set: (value: boolean) => configStore.setUseCustomDataPath(value)
});
// 数据路径配置
const currentDataPath = computed(() => configStore.config.general.dataPath);
// 自定义路径显示
const customPathDisplay = computed(() => {
return configStore.config.general.customDataPath || '';
});
const selectDirectory = async () => {
// 只有开启自定义路径时才能选择
if (!useCustomDataPath.value) return;
// 选择数据存储目录
const selectDataDirectory = async () => {
try {
const selectedPath = await DialogService.SelectDirectory();
if (selectedPath && selectedPath.trim()) {
await configStore.setCustomDataPath(selectedPath.trim());
if (selectedPath && selectedPath.trim() && selectedPath !== currentDataPath.value) {
// 显示迁移进度对话框
showMigrationProgress.value = true;
// 开始迁移
await safeCall(async () => {
const oldPath = currentDataPath.value;
const newPath = selectedPath.trim();
// 先启动迁移
await MigrationService.MigrateDirectory(oldPath, newPath);
// 迁移完成后更新配置
await configStore.setDataPath(newPath);
}, 'migration.migrationFailed');
}
} catch (error) {
// 可以添加用户友好的错误提示
await safeCall(async () => {
throw error;
}, 'settings.selectDirectoryFailed');
}
};
// 处理迁移完成
const handleMigrationComplete = () => {
showMigrationProgress.value = false;
// 显示成功消息
safeCall(async () => {
// 空的成功操作,只为了显示成功消息
}, '', 'migration.migrationCompleted');
};
// 处理迁移关闭
const handleMigrationClose = () => {
showMigrationProgress.value = false;
};
// 处理迁移重试
const handleMigrationRetry = () => {
// 重新触发路径选择
showMigrationProgress.value = false;
selectDataDirectory();
};
</script>
<template>
@@ -162,27 +189,20 @@ const selectDirectory = async () => {
</SettingSection>
<SettingSection :title="t('settings.dataStorage')">
<SettingItem :title="t('settings.useCustomDataPath')">
<ToggleSwitch v-model="useCustomDataPath" />
</SettingItem>
<!-- 路径显示区域 -->
<div class="path-section">
<div class="path-input-container">
<div class="data-path-setting">
<div class="setting-header">
<div class="setting-title">{{ t('settings.dataPath') }}</div>
</div>
<div class="data-path-controls">
<input
type="text"
:value="useCustomDataPath ? customPathDisplay : configStore.config.general.defaultDataPath"
:value="currentDataPath"
readonly
:placeholder="useCustomDataPath ? t('settings.selectDataDirectory') : t('settings.defaultDataPath')"
:class="[
'path-display-input',
{ 'clickable': useCustomDataPath, 'disabled': !useCustomDataPath }
]"
@click="selectDirectory"
:placeholder="t('settings.clickToSelectPath')"
class="path-display-input"
@click="selectDataDirectory"
:title="t('settings.clickToSelectPath')"
/>
<div class="path-label">
{{ useCustomDataPath ? t('settings.customDataPath') : t('settings.defaultDataPath') }}
</div>
</div>
</div>
</SettingSection>
@@ -200,6 +220,14 @@ const selectDirectory = async () => {
</div>
</div>
</SettingSection>
<!-- 迁移进度对话框 -->
<MigrationProgress
:visible="showMigrationProgress"
@complete="handleMigrationComplete"
@close="handleMigrationClose"
@retry="handleMigrationRetry"
/>
</div>
</template>
@@ -312,31 +340,44 @@ const selectDirectory = async () => {
}
}
.path-section {
margin-top: 10px;
padding: 0 20px;
.data-path-setting {
padding: 14px 0;
&:hover {
background-color: rgba(255, 255, 255, 0.03);
}
.setting-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12px;
.setting-title {
font-size: 14px;
font-weight: 500;
color: #e0e0e0;
}
}
}
.data-path-controls {
display: flex;
flex-direction: column;
gap: 8px;
.path-input-container {
.path-display-input {
width: 100%;
max-width: 100%;
max-width: 450px;
box-sizing: border-box;
padding: 8px 12px;
padding: 10px 12px;
background-color: #3a3a3a;
border: 1px solid #555555;
border-radius: 4px;
color: #e0e0e0;
font-size: 13px;
line-height: 1.2;
transition: all 0.2s ease;
&.disabled {
opacity: 0.6;
cursor: not-allowed;
background-color: #2a2a2a;
border-color: #444444;
}
&.clickable {
cursor: pointer;
&:hover {
@@ -348,20 +389,16 @@ const selectDirectory = async () => {
outline: none;
border-color: #4a9eff;
background-color: #404040;
}
}
}
&::placeholder {
color: #888888;
}
}
.path-label {
margin-top: 4px;
color: #888888;
font-size: 12px;
}
}
}
.danger-zone {
@@ -389,7 +426,7 @@ const selectDirectory = async () => {
p {
margin: 0;
color: #b0b0b0;
color: #cccccc;
font-size: 13px;
line-height: 1.4;
}
@@ -398,14 +435,13 @@ const selectDirectory = async () => {
.reset-button {
padding: 8px 16px;
background-color: #dc3545;
border: 1px solid #c82333;
border: 1px solid #dc3545;
border-radius: 4px;
color: #ffffff;
cursor: pointer;
color: white;
font-size: 13px;
font-weight: 500;
cursor: pointer;
transition: all 0.2s ease;
white-space: nowrap;
flex-shrink: 0;
&:hover {
background-color: #c82333;