From 5f102edcf72529fff90ef62539c86dd974a99baa Mon Sep 17 00:00:00 2001 From: landaiqing Date: Wed, 28 May 2025 00:37:18 +0800 Subject: [PATCH] :recycle: Refactor configuration service --- .../voidraft/internal/models/models.ts | 80 +-- .../internal/services/configservice.ts | 95 +-- frontend/src/App.vue | 7 - frontend/src/components/toolbar/Toolbar.vue | 54 +- frontend/src/i18n/index.ts | 63 +- frontend/src/i18n/locales/en-US.ts | 37 +- frontend/src/i18n/locales/zh-CN.ts | 4 +- frontend/src/router/index.ts | 1 + frontend/src/settings/Settings.vue | 7 +- .../src/settings/pages/AppearancePage.vue | 21 +- frontend/src/stores/configStore.ts | 243 +++----- frontend/src/utils/configUtils.ts | 42 ++ go.mod | 14 +- go.sum | 24 + internal/models/config.go | 64 +- internal/services/config_service.go | 581 ++++++++++-------- internal/services/document_service.go | 34 +- internal/services/service_manager.go | 7 +- 18 files changed, 721 insertions(+), 657 deletions(-) create mode 100644 frontend/src/utils/configUtils.ts diff --git a/frontend/bindings/voidraft/internal/models/models.ts b/frontend/bindings/voidraft/internal/models/models.ts index 98f27ad..810f45d 100644 --- a/frontend/bindings/voidraft/internal/models/models.ts +++ b/frontend/bindings/voidraft/internal/models/models.ts @@ -155,14 +155,30 @@ export class Document { */ export class DocumentConfig { /** - * 详细保存选项 + * 自动保存延迟(毫秒)- 内容变更后多久自动保存 */ - "saveOptions": SaveOptions; + "autoSaveDelay": number; + + /** + * 变更字符阈值,超过此阈值立即触发保存 + */ + "changeThreshold": number; + + /** + * 最小保存间隔(毫秒)- 两次保存之间的最小时间间隔,避免频繁IO + */ + "minSaveInterval": number; /** Creates a new DocumentConfig instance. */ constructor($$source: Partial = {}) { - if (!("saveOptions" in $$source)) { - this["saveOptions"] = (new SaveOptions()); + if (!("autoSaveDelay" in $$source)) { + this["autoSaveDelay"] = 0; + } + if (!("changeThreshold" in $$source)) { + this["changeThreshold"] = 0; + } + if (!("minSaveInterval" in $$source)) { + this["minSaveInterval"] = 0; } Object.assign(this, $$source); @@ -172,11 +188,7 @@ export class DocumentConfig { * Creates a new DocumentConfig instance from a string or object. */ static createFrom($$source: any = {}): DocumentConfig { - const $$createField0_0 = $$createType5; let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source; - if ("saveOptions" in $$parsedSource) { - $$parsedSource["saveOptions"] = $$createField0_0($$parsedSource["saveOptions"]); - } return new DocumentConfig($$parsedSource as Partial); } } @@ -323,11 +335,6 @@ export enum LanguageType { * PathsConfig 路径配置集合 */ export class PathsConfig { - /** - * 日志文件路径 - */ - "logPath": string; - /** * 数据存储路径 */ @@ -335,9 +342,6 @@ export class PathsConfig { /** Creates a new PathsConfig instance. */ constructor($$source: Partial = {}) { - if (!("logPath" in $$source)) { - this["logPath"] = ""; - } if (!("dataPath" in $$source)) { this["dataPath"] = ""; } @@ -354,49 +358,6 @@ export class PathsConfig { } } -/** - * SaveOptions 保存选项 - */ -export class SaveOptions { - /** - * 自动保存延迟(毫秒)- 内容变更后多久自动保存 - */ - "autoSaveDelay": number; - - /** - * 变更字符阈值,超过此阈值立即触发保存 - */ - "changeThreshold": number; - - /** - * 最小保存间隔(毫秒)- 两次保存之间的最小时间间隔,避免频繁IO - */ - "minSaveInterval": number; - - /** Creates a new SaveOptions instance. */ - constructor($$source: Partial = {}) { - if (!("autoSaveDelay" in $$source)) { - this["autoSaveDelay"] = 0; - } - if (!("changeThreshold" in $$source)) { - this["changeThreshold"] = 0; - } - if (!("minSaveInterval" in $$source)) { - this["minSaveInterval"] = 0; - } - - Object.assign(this, $$source); - } - - /** - * Creates a new SaveOptions instance from a string or object. - */ - static createFrom($$source: any = {}): SaveOptions { - let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source; - return new SaveOptions($$parsedSource as Partial); - } -} - /** * TabType 定义了制表符类型 */ @@ -423,4 +384,3 @@ const $$createType1 = DocumentConfig.createFrom; const $$createType2 = PathsConfig.createFrom; const $$createType3 = ConfigMetadata.createFrom; const $$createType4 = DocumentMeta.createFrom; -const $$createType5 = SaveOptions.createFrom; diff --git a/frontend/bindings/voidraft/internal/services/configservice.ts b/frontend/bindings/voidraft/internal/services/configservice.ts index a1153bd..1dfcef0 100644 --- a/frontend/bindings/voidraft/internal/services/configservice.ts +++ b/frontend/bindings/voidraft/internal/services/configservice.ts @@ -2,7 +2,7 @@ // This file is automatically generated. DO NOT EDIT /** - * ConfigService 提供配置管理功能 + * ConfigService 提供基于 Viper 的配置管理功能 * @module */ @@ -14,6 +14,14 @@ import {Call as $Call, Create as $Create} from "@wailsio/runtime"; // @ts-ignore: Unused imports import * as models$0 from "../models/models.js"; +/** + * Get 获取配置项 + */ +export function Get(key: string): Promise & { cancel(): void } { + let $resultPromise = $Call.ByID(807201772, key) as any; + return $resultPromise; +} + /** * GetConfig 获取完整应用配置 */ @@ -26,50 +34,6 @@ export function GetConfig(): Promise & { cancel(): vo return $typingPromise; } -/** - * GetEditorConfig 获取编辑器配置 - */ -export function GetEditorConfig(): Promise & { cancel(): void } { - let $resultPromise = $Call.ByID(3648153351) as any; - let $typingPromise = $resultPromise.then(($result: any) => { - return $$createType2($result); - }) as any; - $typingPromise.cancel = $resultPromise.cancel.bind($resultPromise); - return $typingPromise; -} - -/** - * GetLanguage 获取当前语言设置 - */ -export function GetLanguage(): Promise & { cancel(): void } { - let $resultPromise = $Call.ByID(3409375894) as any; - return $resultPromise; -} - -/** - * GetMetadata 获取配置元数据 - */ -export function GetMetadata(): Promise & { cancel(): void } { - let $resultPromise = $Call.ByID(3276720617) as any; - let $typingPromise = $resultPromise.then(($result: any) => { - return $$createType3($result); - }) as any; - $typingPromise.cancel = $resultPromise.cancel.bind($resultPromise); - return $typingPromise; -} - -/** - * GetPaths 获取路径配置 - */ -export function GetPaths(): Promise & { cancel(): void } { - let $resultPromise = $Call.ByID(1096257096) as any; - let $typingPromise = $resultPromise.then(($result: any) => { - return $$createType4($result); - }) as any; - $typingPromise.cancel = $resultPromise.cancel.bind($resultPromise); - return $typingPromise; -} - /** * ResetConfig 重置为默认配置 */ @@ -79,48 +43,13 @@ export function ResetConfig(): Promise & { cancel(): void } { } /** - * SaveConfig 保存完整应用配置 + * Set 设置配置项 */ -export function SaveConfig(config: models$0.AppConfig | null): Promise & { cancel(): void } { - let $resultPromise = $Call.ByID(616684383, config) as any; - return $resultPromise; -} - -/** - * SetLanguage 设置语言 - */ -export function SetLanguage(language: models$0.LanguageType): Promise & { cancel(): void } { - let $resultPromise = $Call.ByID(814725002, language) as any; - return $resultPromise; -} - -/** - * UpdateEditorConfig 更新编辑器配置 - */ -export function UpdateEditorConfig(editorConfig: models$0.EditorConfig): Promise & { cancel(): void } { - let $resultPromise = $Call.ByID(1237949666, editorConfig) as any; - return $resultPromise; -} - -/** - * UpdateMetadata 更新配置元数据 - */ -export function UpdateMetadata(metadata: models$0.ConfigMetadata): Promise & { cancel(): void } { - let $resultPromise = $Call.ByID(3353893284, metadata) as any; - return $resultPromise; -} - -/** - * UpdatePaths 更新路径配置 - */ -export function UpdatePaths(paths: models$0.PathsConfig): Promise & { cancel(): void } { - let $resultPromise = $Call.ByID(3650847675, paths) as any; +export function Set(key: string, value: any): Promise & { cancel(): void } { + let $resultPromise = $Call.ByID(2921955968, key, value) as any; return $resultPromise; } // Private type creation functions const $$createType0 = models$0.AppConfig.createFrom; const $$createType1 = $Create.Nullable($$createType0); -const $$createType2 = models$0.EditorConfig.createFrom; -const $$createType3 = models$0.ConfigMetadata.createFrom; -const $$createType4 = models$0.PathsConfig.createFrom; diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 7a5914c..2e45ee7 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -1,12 +1,5 @@