From c9aa8aebcb4d1388c76760a8fc5eacea06e8ebb1 Mon Sep 17 00:00:00 2001 From: landaiqing Date: Thu, 1 May 2025 00:51:16 +0800 Subject: [PATCH] :art: Refactor config service --- .../voidraft/internal/models/models.ts | 104 ++---- .../services/{ => config}/configservice.ts | 50 ++- .../internal/services/{ => config}/index.ts | 0 frontend/src/components/toolbar/Toolbar.vue | 54 ---- frontend/src/i18n/index.ts | 6 +- frontend/src/stores/configStore.ts | 52 +-- go.mod | 2 +- go.sum | 4 +- internal/models/config.go | 53 ++- internal/services/config/config_locator.go | 93 ++++++ internal/services/config/config_service.go | 302 ++++++++++++++++++ internal/services/config/config_storage.go | 117 +++++++ internal/services/config_service.go | 228 ------------- internal/services/service_manager.go | 7 +- .../services/{ => store}/store_service.go | 6 +- main.go | 23 +- 16 files changed, 630 insertions(+), 471 deletions(-) rename frontend/bindings/voidraft/internal/services/{ => config}/configservice.ts (67%) rename frontend/bindings/voidraft/internal/services/{ => config}/index.ts (100%) create mode 100644 internal/services/config/config_locator.go create mode 100644 internal/services/config/config_service.go create mode 100644 internal/services/config/config_storage.go delete mode 100644 internal/services/config_service.go rename internal/services/{ => store}/store_service.go (98%) diff --git a/frontend/bindings/voidraft/internal/models/models.ts b/frontend/bindings/voidraft/internal/models/models.ts index e4eafd4..9ccb216 100644 --- a/frontend/bindings/voidraft/internal/models/models.ts +++ b/frontend/bindings/voidraft/internal/models/models.ts @@ -10,7 +10,7 @@ import {Create as $Create} from "@wailsio/runtime"; import * as time$0 from "../../../time/models.js"; /** - * AppConfig 应用配置 + * AppConfig 应用配置 - 包含业务配置和路径配置 */ export class AppConfig { /** @@ -21,7 +21,7 @@ export class AppConfig { /** * 路径配置 */ - "paths": PathConfig; + "paths": PathsConfig; /** * 配置元数据 @@ -34,7 +34,7 @@ export class AppConfig { this["editor"] = (new EditorConfig()); } if (!("paths" in $$source)) { - this["paths"] = (new PathConfig()); + this["paths"] = (new PathsConfig()); } if (!("metadata" in $$source)) { this["metadata"] = (new ConfigMetadata()); @@ -108,11 +108,6 @@ export class EditorConfig { */ "fontSize": number; - /** - * 文件保存的编码 - */ - "encoding": EncodingType; - /** * 是否启用Tab缩进 */ @@ -138,9 +133,6 @@ export class EditorConfig { if (!("fontSize" in $$source)) { this["fontSize"] = 0; } - if (!("encoding" in $$source)) { - this["encoding"] = ("" as EncodingType); - } if (!("enableTabIndent" in $$source)) { this["enableTabIndent"] = false; } @@ -166,56 +158,6 @@ export class EditorConfig { } } -/** - * EncodingType 定义文件编码格式类型 - */ -export enum EncodingType { - /** - * The Go zero value for the underlying type of the enum. - */ - $zero = "", - - /** - * EncodingUTF8 UTF-8编码 - */ - EncodingUTF8 = "UTF-8", - - /** - * EncodingUTF8BOM UTF-8带BOM编码 - */ - EncodingUTF8BOM = "UTF-8-BOM", - - /** - * EncodingUTF16LE UTF-16小端编码 - */ - EncodingUTF16LE = "UTF-16 LE", - - /** - * EncodingUTF16BE UTF-16大端编码 - */ - EncodingUTF16BE = "UTF-16 BE", - - /** - * EncodingISO88591 ISO-8859-1编码 - */ - EncodingISO88591 = "ISO-8859-1", - - /** - * EncodingGB18030 GB18030编码 - */ - EncodingGB18030 = "GB18030", - - /** - * EncodingGBK GBK编码 - */ - EncodingGBK = "GBK", - - /** - * EncodingBig5 Big5编码 - */ - EncodingBig5 = "Big5", -}; - /** * LanguageType 语言类型定义 */ @@ -237,37 +179,45 @@ export enum LanguageType { }; /** - * PathConfig 定义配置文件路径相关配置 + * PathsConfig 路径配置集合 */ -export class PathConfig { - /** - * 根目录 - */ - "rootDir": string; - +export class PathsConfig { /** * 配置文件路径 */ "configPath": string; - /** Creates a new PathConfig instance. */ - constructor($$source: Partial = {}) { - if (!("rootDir" in $$source)) { - this["rootDir"] = ""; - } + /** + * 日志文件路径 + */ + "logPath": string; + + /** + * 数据存储路径 + */ + "dataPath": string; + + /** Creates a new PathsConfig instance. */ + constructor($$source: Partial = {}) { if (!("configPath" in $$source)) { this["configPath"] = ""; } + if (!("logPath" in $$source)) { + this["logPath"] = ""; + } + if (!("dataPath" in $$source)) { + this["dataPath"] = ""; + } Object.assign(this, $$source); } /** - * Creates a new PathConfig instance from a string or object. + * Creates a new PathsConfig instance from a string or object. */ - static createFrom($$source: any = {}): PathConfig { + static createFrom($$source: any = {}): PathsConfig { let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source; - return new PathConfig($$parsedSource as Partial); + return new PathsConfig($$parsedSource as Partial); } } @@ -293,5 +243,5 @@ export enum TabType { // Private type creation functions const $$createType0 = EditorConfig.createFrom; -const $$createType1 = PathConfig.createFrom; +const $$createType1 = PathsConfig.createFrom; const $$createType2 = ConfigMetadata.createFrom; diff --git a/frontend/bindings/voidraft/internal/services/configservice.ts b/frontend/bindings/voidraft/internal/services/config/configservice.ts similarity index 67% rename from frontend/bindings/voidraft/internal/services/configservice.ts rename to frontend/bindings/voidraft/internal/services/config/configservice.ts index e3358c8..67ee1bf 100644 --- a/frontend/bindings/voidraft/internal/services/configservice.ts +++ b/frontend/bindings/voidraft/internal/services/config/configservice.ts @@ -12,13 +12,13 @@ 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$0 from "../models/models.js"; +import * as models$0 from "../../models/models.js"; /** * GetConfig 获取完整应用配置 */ export function GetConfig(): Promise & { cancel(): void } { - let $resultPromise = $Call.ByID(1013336538) as any; + let $resultPromise = $Call.ByID(3332910023) as any; let $typingPromise = $resultPromise.then(($result: any) => { return $$createType1($result); }) as any; @@ -26,11 +26,19 @@ export function GetConfig(): Promise & { cancel(): vo return $typingPromise; } +/** + * GetConfigPath 获取当前配置文件路径 + */ +export function GetConfigPath(): Promise & { cancel(): void } { + let $resultPromise = $Call.ByID(2145796624) as any; + return $resultPromise; +} + /** * GetEditorConfig 获取编辑器配置 */ export function GetEditorConfig(): Promise & { cancel(): void } { - let $resultPromise = $Call.ByID(3648153351) as any; + let $resultPromise = $Call.ByID(3738882774) as any; let $typingPromise = $resultPromise.then(($result: any) => { return $$createType2($result); }) as any; @@ -42,7 +50,7 @@ export function GetEditorConfig(): Promise & { cancel(): * GetLanguage 获取当前语言设置 */ export function GetLanguage(): Promise & { cancel(): void } { - let $resultPromise = $Call.ByID(3409375894) as any; + let $resultPromise = $Call.ByID(1762264443) as any; return $resultPromise; } @@ -50,7 +58,7 @@ export function GetLanguage(): Promise & { cancel(): void * GetMetadata 获取配置元数据 */ export function GetMetadata(): Promise & { cancel(): void } { - let $resultPromise = $Call.ByID(3276720617) as any; + let $resultPromise = $Call.ByID(356327488) as any; let $typingPromise = $resultPromise.then(($result: any) => { return $$createType3($result); }) as any; @@ -59,10 +67,10 @@ export function GetMetadata(): Promise & { cancel(): vo } /** - * GetPathConfig 获取路径配置 + * GetPaths 获取路径配置 */ -export function GetPathConfig(): Promise & { cancel(): void } { - let $resultPromise = $Call.ByID(2053285689) as any; +export function GetPaths(): Promise & { cancel(): void } { + let $resultPromise = $Call.ByID(1115810463) as any; let $typingPromise = $resultPromise.then(($result: any) => { return $$createType4($result); }) as any; @@ -74,7 +82,7 @@ export function GetPathConfig(): Promise & { cancel(): void * ResetConfig 重置为默认配置 */ export function ResetConfig(): Promise & { cancel(): void } { - let $resultPromise = $Call.ByID(3593047389) as any; + let $resultPromise = $Call.ByID(2265390548) as any; return $resultPromise; } @@ -82,7 +90,7 @@ export function ResetConfig(): Promise & { cancel(): void } { * SaveConfig 保存完整应用配置 */ export function SaveConfig(config: models$0.AppConfig | null): Promise & { cancel(): void } { - let $resultPromise = $Call.ByID(616684383, config) as any; + let $resultPromise = $Call.ByID(2710445504, config) as any; return $resultPromise; } @@ -90,7 +98,15 @@ export function SaveConfig(config: models$0.AppConfig | null): Promise & { * SetLanguage 设置语言 */ export function SetLanguage(language: models$0.LanguageType): Promise & { cancel(): void } { - let $resultPromise = $Call.ByID(814725002, language) as any; + let $resultPromise = $Call.ByID(2553541807, language) as any; + return $resultPromise; +} + +/** + * UpdateConfigPath 更新配置文件路径 + */ +export function UpdateConfigPath(newPath: string): Promise & { cancel(): void } { + let $resultPromise = $Call.ByID(251712339, newPath) as any; return $resultPromise; } @@ -98,7 +114,7 @@ export function SetLanguage(language: models$0.LanguageType): Promise & { * UpdateEditorConfig 更新编辑器配置 */ export function UpdateEditorConfig(editorConfig: models$0.EditorConfig): Promise & { cancel(): void } { - let $resultPromise = $Call.ByID(1237949666, editorConfig) as any; + let $resultPromise = $Call.ByID(420530601, editorConfig) as any; return $resultPromise; } @@ -106,15 +122,15 @@ export function UpdateEditorConfig(editorConfig: models$0.EditorConfig): Promise * UpdateMetadata 更新配置元数据 */ export function UpdateMetadata(metadata: models$0.ConfigMetadata): Promise & { cancel(): void } { - let $resultPromise = $Call.ByID(3353893284, metadata) as any; + let $resultPromise = $Call.ByID(1687760751, metadata) as any; return $resultPromise; } /** - * UpdatePathConfig 更新路径配置 + * UpdatePaths 更新路径配置 */ -export function UpdatePathConfig(pathConfig: models$0.PathConfig): Promise & { cancel(): void } { - let $resultPromise = $Call.ByID(1492772004, pathConfig) as any; +export function UpdatePaths(paths: models$0.PathsConfig): Promise & { cancel(): void } { + let $resultPromise = $Call.ByID(3466187518, paths) as any; return $resultPromise; } @@ -123,4 +139,4 @@ 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.PathConfig.createFrom; +const $$createType4 = models$0.PathsConfig.createFrom; diff --git a/frontend/bindings/voidraft/internal/services/index.ts b/frontend/bindings/voidraft/internal/services/config/index.ts similarity index 100% rename from frontend/bindings/voidraft/internal/services/index.ts rename to frontend/bindings/voidraft/internal/services/config/index.ts diff --git a/frontend/src/components/toolbar/Toolbar.vue b/frontend/src/components/toolbar/Toolbar.vue index c9d4153..d81d0fc 100644 --- a/frontend/src/components/toolbar/Toolbar.vue +++ b/frontend/src/components/toolbar/Toolbar.vue @@ -5,7 +5,6 @@ import {useLogStore} from '@/stores/logStore'; import { useI18n } from 'vue-i18n'; import { ref } from 'vue'; import {SUPPORTED_LOCALES, setLocale, SupportedLocaleType} from '@/i18n'; -import { EncodingType } from '@/../bindings/voidraft/internal/models/models'; const editorStore = useEditorStore(); const configStore = useConfigStore(); @@ -14,20 +13,6 @@ const { t, locale } = useI18n(); // 语言下拉菜单 const showLanguageMenu = ref(false); -// 编码下拉菜单 -const showEncodingMenu = ref(false); - -// 支持的编码格式 -const SUPPORTED_ENCODINGS = [ - { code: EncodingType.EncodingUTF8, name: 'UTF-8' }, - { code: EncodingType.EncodingUTF8BOM, name: 'UTF-8 with BOM' }, - { code: EncodingType.EncodingUTF16LE, name: 'UTF-16 LE' }, - { code: EncodingType.EncodingUTF16BE, name: 'UTF-16 BE' }, - { code: EncodingType.EncodingISO88591, name: 'ISO-8859-1' }, - { code: EncodingType.EncodingGB18030, name: 'GB18030' }, - { code: EncodingType.EncodingGBK, name: 'GBK' }, - { code: EncodingType.EncodingBig5, name: 'Big5' } -]; // 切换语言 const changeLanguage = (localeCode: SupportedLocaleType) => { @@ -38,30 +23,10 @@ const changeLanguage = (localeCode: SupportedLocaleType) => { // 切换语言菜单显示 const toggleLanguageMenu = () => { showLanguageMenu.value = !showLanguageMenu.value; - if (showLanguageMenu.value) { - showEncodingMenu.value = false; - } }; -// 切换编码 -const changeEncoding = (encoding: EncodingType) => { - configStore.setEncoding(encoding); - showEncodingMenu.value = false; -}; -// 切换编码菜单显示 -const toggleEncodingMenu = () => { - showEncodingMenu.value = !showEncodingMenu.value; - if (showEncodingMenu.value) { - showLanguageMenu.value = false; - } -}; -// 获取编码名称 -const getEncodingDisplayName = (encoding: EncodingType) => { - const encodingItem = SUPPORTED_ENCODINGS.find(item => item.code === encoding); - return encodingItem ? encodingItem.name : encoding; -};