Compare commits
2 Commits
4f8272e290
...
f3bcb87828
Author | SHA1 | Date | |
---|---|---|---|
f3bcb87828 | |||
ea025e3f5d |
@@ -334,6 +334,227 @@ export class EditingConfig {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extension 单个扩展配置
|
||||
*/
|
||||
export class Extension {
|
||||
/**
|
||||
* 扩展唯一标识
|
||||
*/
|
||||
"id": ExtensionID;
|
||||
|
||||
/**
|
||||
* 扩展分类
|
||||
*/
|
||||
"category": ExtensionCategory;
|
||||
|
||||
/**
|
||||
* 是否启用
|
||||
*/
|
||||
"enabled": boolean;
|
||||
|
||||
/**
|
||||
* 是否为默认扩展
|
||||
*/
|
||||
"isDefault": boolean;
|
||||
|
||||
/**
|
||||
* 扩展配置项
|
||||
*/
|
||||
"config": ExtensionConfig;
|
||||
|
||||
/** Creates a new Extension instance. */
|
||||
constructor($$source: Partial<Extension> = {}) {
|
||||
if (!("id" in $$source)) {
|
||||
this["id"] = ("" as ExtensionID);
|
||||
}
|
||||
if (!("category" in $$source)) {
|
||||
this["category"] = ("" as ExtensionCategory);
|
||||
}
|
||||
if (!("enabled" in $$source)) {
|
||||
this["enabled"] = false;
|
||||
}
|
||||
if (!("isDefault" in $$source)) {
|
||||
this["isDefault"] = false;
|
||||
}
|
||||
if (!("config" in $$source)) {
|
||||
this["config"] = ({} as ExtensionConfig);
|
||||
}
|
||||
|
||||
Object.assign(this, $$source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Extension instance from a string or object.
|
||||
*/
|
||||
static createFrom($$source: any = {}): Extension {
|
||||
const $$createField4_0 = $$createType6;
|
||||
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
|
||||
if ("config" in $$parsedSource) {
|
||||
$$parsedSource["config"] = $$createField4_0($$parsedSource["config"]);
|
||||
}
|
||||
return new Extension($$parsedSource as Partial<Extension>);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ExtensionCategory 扩展分类
|
||||
*/
|
||||
export enum ExtensionCategory {
|
||||
/**
|
||||
* The Go zero value for the underlying type of the enum.
|
||||
*/
|
||||
$zero = "",
|
||||
|
||||
/**
|
||||
* 编辑增强
|
||||
*/
|
||||
CategoryEditing = "editing",
|
||||
|
||||
/**
|
||||
* 界面增强
|
||||
*/
|
||||
CategoryUI = "ui",
|
||||
|
||||
/**
|
||||
* 工具类
|
||||
*/
|
||||
CategoryTools = "tools",
|
||||
};
|
||||
|
||||
/**
|
||||
* ExtensionConfig 扩展配置项(动态配置)
|
||||
*/
|
||||
export type ExtensionConfig = { [_: string]: any };
|
||||
|
||||
/**
|
||||
* ExtensionID 扩展标识符
|
||||
*/
|
||||
export enum ExtensionID {
|
||||
/**
|
||||
* The Go zero value for the underlying type of the enum.
|
||||
*/
|
||||
$zero = "",
|
||||
|
||||
/**
|
||||
* 编辑增强扩展
|
||||
* 彩虹括号
|
||||
*/
|
||||
ExtensionRainbowBrackets = "rainbowBrackets",
|
||||
|
||||
/**
|
||||
* 超链接
|
||||
*/
|
||||
ExtensionHyperlink = "hyperlink",
|
||||
|
||||
/**
|
||||
* 颜色选择器
|
||||
*/
|
||||
ExtensionColorSelector = "colorSelector",
|
||||
ExtensionFold = "fold",
|
||||
ExtensionTextHighlight = "textHighlight",
|
||||
|
||||
/**
|
||||
* UI增强扩展
|
||||
* 小地图
|
||||
*/
|
||||
ExtensionMinimap = "minimap",
|
||||
|
||||
/**
|
||||
* 代码爆炸效果
|
||||
*/
|
||||
ExtensionCodeBlast = "codeBlast",
|
||||
|
||||
/**
|
||||
* 工具扩展
|
||||
* 搜索功能
|
||||
*/
|
||||
ExtensionSearch = "search",
|
||||
|
||||
/**
|
||||
* 代码块
|
||||
*/
|
||||
ExtensionCodeBlock = "codeBlock",
|
||||
};
|
||||
|
||||
/**
|
||||
* ExtensionMetadata 扩展配置元数据
|
||||
*/
|
||||
export class ExtensionMetadata {
|
||||
/**
|
||||
* 配置版本
|
||||
*/
|
||||
"version": string;
|
||||
|
||||
/**
|
||||
* 最后更新时间
|
||||
*/
|
||||
"lastUpdated": string;
|
||||
|
||||
/** Creates a new ExtensionMetadata instance. */
|
||||
constructor($$source: Partial<ExtensionMetadata> = {}) {
|
||||
if (!("version" in $$source)) {
|
||||
this["version"] = "";
|
||||
}
|
||||
if (!("lastUpdated" in $$source)) {
|
||||
this["lastUpdated"] = "";
|
||||
}
|
||||
|
||||
Object.assign(this, $$source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new ExtensionMetadata instance from a string or object.
|
||||
*/
|
||||
static createFrom($$source: any = {}): ExtensionMetadata {
|
||||
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
|
||||
return new ExtensionMetadata($$parsedSource as Partial<ExtensionMetadata>);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ExtensionSettings 扩展设置配置
|
||||
*/
|
||||
export class ExtensionSettings {
|
||||
/**
|
||||
* 扩展列表
|
||||
*/
|
||||
"extensions": Extension[];
|
||||
|
||||
/**
|
||||
* 配置元数据
|
||||
*/
|
||||
"metadata": ExtensionMetadata;
|
||||
|
||||
/** Creates a new ExtensionSettings instance. */
|
||||
constructor($$source: Partial<ExtensionSettings> = {}) {
|
||||
if (!("extensions" in $$source)) {
|
||||
this["extensions"] = [];
|
||||
}
|
||||
if (!("metadata" in $$source)) {
|
||||
this["metadata"] = (new ExtensionMetadata());
|
||||
}
|
||||
|
||||
Object.assign(this, $$source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new ExtensionSettings instance from a string or object.
|
||||
*/
|
||||
static createFrom($$source: any = {}): ExtensionSettings {
|
||||
const $$createField0_0 = $$createType9;
|
||||
const $$createField1_0 = $$createType10;
|
||||
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
|
||||
if ("extensions" in $$parsedSource) {
|
||||
$$parsedSource["extensions"] = $$createField0_0($$parsedSource["extensions"]);
|
||||
}
|
||||
if ("metadata" in $$parsedSource) {
|
||||
$$parsedSource["metadata"] = $$createField1_0($$parsedSource["metadata"]);
|
||||
}
|
||||
return new ExtensionSettings($$parsedSource as Partial<ExtensionSettings>);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* GeneralConfig 通用设置配置
|
||||
*/
|
||||
@@ -397,7 +618,7 @@ export class GeneralConfig {
|
||||
* Creates a new GeneralConfig instance from a string or object.
|
||||
*/
|
||||
static createFrom($$source: any = {}): GeneralConfig {
|
||||
const $$createField5_0 = $$createType6;
|
||||
const $$createField5_0 = $$createType11;
|
||||
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
|
||||
if ("globalHotkey" in $$parsedSource) {
|
||||
$$parsedSource["globalHotkey"] = $$createField5_0($$parsedSource["globalHotkey"]);
|
||||
@@ -874,8 +1095,8 @@ export class KeyBindingConfig {
|
||||
* Creates a new KeyBindingConfig instance from a string or object.
|
||||
*/
|
||||
static createFrom($$source: any = {}): KeyBindingConfig {
|
||||
const $$createField0_0 = $$createType8;
|
||||
const $$createField1_0 = $$createType9;
|
||||
const $$createField0_0 = $$createType13;
|
||||
const $$createField1_0 = $$createType14;
|
||||
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
|
||||
if ("keyBindings" in $$parsedSource) {
|
||||
$$parsedSource["keyBindings"] = $$createField0_0($$parsedSource["keyBindings"]);
|
||||
@@ -1001,11 +1222,6 @@ export class UpdatesConfig {
|
||||
*/
|
||||
"autoUpdate": boolean;
|
||||
|
||||
/**
|
||||
* 是否启用测试版
|
||||
*/
|
||||
"betaChannel": boolean;
|
||||
|
||||
/** Creates a new UpdatesConfig instance. */
|
||||
constructor($$source: Partial<UpdatesConfig> = {}) {
|
||||
if (!("version" in $$source)) {
|
||||
@@ -1014,9 +1230,6 @@ export class UpdatesConfig {
|
||||
if (!("autoUpdate" in $$source)) {
|
||||
this["autoUpdate"] = false;
|
||||
}
|
||||
if (!("betaChannel" in $$source)) {
|
||||
this["betaChannel"] = false;
|
||||
}
|
||||
|
||||
Object.assign(this, $$source);
|
||||
}
|
||||
@@ -1037,7 +1250,17 @@ const $$createType2 = AppearanceConfig.createFrom;
|
||||
const $$createType3 = UpdatesConfig.createFrom;
|
||||
const $$createType4 = ConfigMetadata.createFrom;
|
||||
const $$createType5 = DocumentMeta.createFrom;
|
||||
const $$createType6 = HotkeyCombo.createFrom;
|
||||
const $$createType7 = KeyBinding.createFrom;
|
||||
const $$createType8 = $Create.Array($$createType7);
|
||||
const $$createType9 = KeyBindingMetadata.createFrom;
|
||||
var $$createType6 = (function $$initCreateType6(...args): any {
|
||||
if ($$createType6 === $$initCreateType6) {
|
||||
$$createType6 = $$createType7;
|
||||
}
|
||||
return $$createType6(...args);
|
||||
});
|
||||
const $$createType7 = $Create.Map($Create.Any, $Create.Any);
|
||||
const $$createType8 = Extension.createFrom;
|
||||
const $$createType9 = $Create.Array($$createType8);
|
||||
const $$createType10 = ExtensionMetadata.createFrom;
|
||||
const $$createType11 = HotkeyCombo.createFrom;
|
||||
const $$createType12 = KeyBinding.createFrom;
|
||||
const $$createType13 = $Create.Array($$createType12);
|
||||
const $$createType14 = KeyBindingMetadata.createFrom;
|
||||
|
@@ -0,0 +1,93 @@
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
|
||||
/**
|
||||
* ExtensionService 扩展管理服务
|
||||
* @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$0 from "../models/models.js";
|
||||
|
||||
/**
|
||||
* DisableExtension 禁用扩展
|
||||
*/
|
||||
export function DisableExtension(id: models$0.ExtensionID): Promise<void> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(2040844784, id) as any;
|
||||
return $resultPromise;
|
||||
}
|
||||
|
||||
/**
|
||||
* EnableExtension 启用扩展
|
||||
*/
|
||||
export function EnableExtension(id: models$0.ExtensionID): Promise<void> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(2926319443, id) as any;
|
||||
return $resultPromise;
|
||||
}
|
||||
|
||||
/**
|
||||
* GetAllExtensions 获取所有扩展配置
|
||||
*/
|
||||
export function GetAllExtensions(): Promise<models$0.Extension[]> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(3094292124) as any;
|
||||
let $typingPromise = $resultPromise.then(($result: any) => {
|
||||
return $$createType1($result);
|
||||
}) as any;
|
||||
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
||||
return $typingPromise;
|
||||
}
|
||||
|
||||
/**
|
||||
* GetExtensionSettings 获取完整扩展配置
|
||||
*/
|
||||
export function GetExtensionSettings(): Promise<models$0.ExtensionSettings | null> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(2127854337) as any;
|
||||
let $typingPromise = $resultPromise.then(($result: any) => {
|
||||
return $$createType3($result);
|
||||
}) as any;
|
||||
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
||||
return $typingPromise;
|
||||
}
|
||||
|
||||
/**
|
||||
* ResetAllExtensionsToDefault 重置所有扩展到默认状态
|
||||
*/
|
||||
export function ResetAllExtensionsToDefault(): Promise<void> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(270611949) as any;
|
||||
return $resultPromise;
|
||||
}
|
||||
|
||||
/**
|
||||
* ResetExtensionToDefault 重置扩展到默认状态
|
||||
*/
|
||||
export function ResetExtensionToDefault(id: models$0.ExtensionID): Promise<void> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(868308101, id) as any;
|
||||
return $resultPromise;
|
||||
}
|
||||
|
||||
/**
|
||||
* ServiceShutdown 关闭服务
|
||||
*/
|
||||
export function ServiceShutdown(): Promise<void> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(4127635746) as any;
|
||||
return $resultPromise;
|
||||
}
|
||||
|
||||
/**
|
||||
* UpdateExtensionState 更新扩展状态
|
||||
*/
|
||||
export function UpdateExtensionState(id: models$0.ExtensionID, enabled: boolean, config: models$0.ExtensionConfig): Promise<void> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(2917946454, id, enabled, config) as any;
|
||||
return $resultPromise;
|
||||
}
|
||||
|
||||
// Private type creation functions
|
||||
const $$createType0 = models$0.Extension.createFrom;
|
||||
const $$createType1 = $Create.Array($$createType0);
|
||||
const $$createType2 = models$0.ExtensionSettings.createFrom;
|
||||
const $$createType3 = $Create.Nullable($$createType2);
|
@@ -4,22 +4,26 @@
|
||||
import * as ConfigService from "./configservice.js";
|
||||
import * as DialogService from "./dialogservice.js";
|
||||
import * as DocumentService from "./documentservice.js";
|
||||
import * as ExtensionService from "./extensionservice.js";
|
||||
import * as HotkeyService from "./hotkeyservice.js";
|
||||
import * as KeyBindingService from "./keybindingservice.js";
|
||||
import * as MigrationService from "./migrationservice.js";
|
||||
import * as StartupService from "./startupservice.js";
|
||||
import * as SystemService from "./systemservice.js";
|
||||
import * as TrayService from "./trayservice.js";
|
||||
import * as UpdateService from "./updateservice.js";
|
||||
export {
|
||||
ConfigService,
|
||||
DialogService,
|
||||
DocumentService,
|
||||
ExtensionService,
|
||||
HotkeyService,
|
||||
KeyBindingService,
|
||||
MigrationService,
|
||||
StartupService,
|
||||
SystemService,
|
||||
TrayService
|
||||
TrayService,
|
||||
UpdateService
|
||||
};
|
||||
|
||||
export * from "./models.js";
|
||||
|
@@ -114,3 +114,70 @@ export enum MigrationStatus {
|
||||
MigrationStatusCompleted = "completed",
|
||||
MigrationStatusFailed = "failed",
|
||||
};
|
||||
|
||||
/**
|
||||
* UpdateCheckResult 更新检查结果
|
||||
*/
|
||||
export class UpdateCheckResult {
|
||||
/**
|
||||
* 是否有更新
|
||||
*/
|
||||
"hasUpdate": boolean;
|
||||
|
||||
/**
|
||||
* 当前版本
|
||||
*/
|
||||
"currentVer": string;
|
||||
|
||||
/**
|
||||
* 最新版本
|
||||
*/
|
||||
"latestVer": string;
|
||||
|
||||
/**
|
||||
* 发布说明
|
||||
*/
|
||||
"releaseNotes": string;
|
||||
|
||||
/**
|
||||
* 发布页面URL
|
||||
*/
|
||||
"releaseURL": string;
|
||||
|
||||
/**
|
||||
* 错误信息
|
||||
*/
|
||||
"error": string;
|
||||
|
||||
/** Creates a new UpdateCheckResult instance. */
|
||||
constructor($$source: Partial<UpdateCheckResult> = {}) {
|
||||
if (!("hasUpdate" in $$source)) {
|
||||
this["hasUpdate"] = false;
|
||||
}
|
||||
if (!("currentVer" in $$source)) {
|
||||
this["currentVer"] = "";
|
||||
}
|
||||
if (!("latestVer" in $$source)) {
|
||||
this["latestVer"] = "";
|
||||
}
|
||||
if (!("releaseNotes" in $$source)) {
|
||||
this["releaseNotes"] = "";
|
||||
}
|
||||
if (!("releaseURL" in $$source)) {
|
||||
this["releaseURL"] = "";
|
||||
}
|
||||
if (!("error" in $$source)) {
|
||||
this["error"] = "";
|
||||
}
|
||||
|
||||
Object.assign(this, $$source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new UpdateCheckResult instance from a string or object.
|
||||
*/
|
||||
static createFrom($$source: any = {}): UpdateCheckResult {
|
||||
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
|
||||
return new UpdateCheckResult($$parsedSource as Partial<UpdateCheckResult>);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,30 @@
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
|
||||
/**
|
||||
* UpdateService 更新服务
|
||||
* @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";
|
||||
|
||||
/**
|
||||
* CheckForUpdates 检查更新
|
||||
*/
|
||||
export function CheckForUpdates(): Promise<$models.UpdateCheckResult> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(3024322786) as any;
|
||||
let $typingPromise = $resultPromise.then(($result: any) => {
|
||||
return $$createType0($result);
|
||||
}) as any;
|
||||
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
||||
return $typingPromise;
|
||||
}
|
||||
|
||||
// Private type creation functions
|
||||
const $$createType0 = $models.UpdateCheckResult.createFrom;
|
@@ -4,12 +4,14 @@ import { useConfigStore } from '@/stores/configStore';
|
||||
import { useSystemStore } from '@/stores/systemStore';
|
||||
import { useKeybindingStore } from '@/stores/keybindingStore';
|
||||
import { useThemeStore } from '@/stores/themeStore';
|
||||
import { useUpdateStore } from '@/stores/updateStore';
|
||||
import WindowTitleBar from '@/components/titlebar/WindowTitleBar.vue';
|
||||
|
||||
const configStore = useConfigStore();
|
||||
const systemStore = useSystemStore();
|
||||
const keybindingStore = useKeybindingStore();
|
||||
const themeStore = useThemeStore();
|
||||
const updateStore = useUpdateStore();
|
||||
|
||||
// 应用启动时加载配置和初始化系统信息
|
||||
onMounted(async () => {
|
||||
@@ -23,6 +25,9 @@ onMounted(async () => {
|
||||
// 初始化语言和主题
|
||||
await configStore.initializeLanguage();
|
||||
themeStore.initializeTheme();
|
||||
|
||||
// 启动时检查更新
|
||||
await updateStore.checkOnStartup();
|
||||
});
|
||||
</script>
|
||||
|
||||
|
@@ -3,6 +3,7 @@ import {useI18n} from 'vue-i18n';
|
||||
import {onMounted, onUnmounted, ref, watch} from 'vue';
|
||||
import {useConfigStore} from '@/stores/configStore';
|
||||
import {useEditorStore} from '@/stores/editorStore';
|
||||
import {useUpdateStore} from '@/stores/updateStore';
|
||||
import * as runtime from '@wailsio/runtime';
|
||||
import {useRouter} from 'vue-router';
|
||||
import BlockLanguageSelector from './BlockLanguageSelector.vue';
|
||||
@@ -11,6 +12,7 @@ import {getLanguage} from '@/views/editor/extensions/codeblock/lang-parser/langu
|
||||
|
||||
const editorStore = useEditorStore();
|
||||
const configStore = useConfigStore();
|
||||
const updateStore = useUpdateStore();
|
||||
const {t} = useI18n();
|
||||
const router = useRouter();
|
||||
|
||||
@@ -176,6 +178,21 @@ watch(isLoaded, async (newLoaded) => {
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<!-- 更新提示图标 -->
|
||||
<div
|
||||
v-if="updateStore.hasUpdate"
|
||||
class="update-button"
|
||||
:title="`发现新版本 ${updateStore.updateResult?.latestVer || ''}`"
|
||||
@click="updateStore.openReleaseURL"
|
||||
>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none"
|
||||
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"/>
|
||||
<polyline points="7.5,10.5 12,15 16.5,10.5"/>
|
||||
<polyline points="12,15 12,3"/>
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<!-- 窗口置顶图标按钮 -->
|
||||
<div
|
||||
class="pin-button"
|
||||
@@ -241,6 +258,39 @@ watch(isLoaded, async (newLoaded) => {
|
||||
}
|
||||
|
||||
|
||||
/* 更新提示按钮样式 */
|
||||
.update-button {
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
padding: 2px;
|
||||
border-radius: 3px;
|
||||
background-color: rgba(76, 175, 80, 0.1);
|
||||
transition: all 0.2s ease;
|
||||
animation: pulse 2s infinite;
|
||||
|
||||
&:hover {
|
||||
background-color: rgba(76, 175, 80, 0.2);
|
||||
transform: scale(1.05);
|
||||
}
|
||||
|
||||
svg {
|
||||
stroke: #4caf50;
|
||||
}
|
||||
|
||||
@keyframes pulse {
|
||||
0%, 100% {
|
||||
opacity: 1;
|
||||
}
|
||||
50% {
|
||||
opacity: 0.7;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 窗口置顶图标按钮样式 */
|
||||
.pin-button {
|
||||
cursor: pointer;
|
||||
|
@@ -135,6 +135,19 @@ export default {
|
||||
language: 'Interface Language',
|
||||
systemTheme: 'System Theme',
|
||||
saveOptions: 'Save Options',
|
||||
autoSaveDelay: 'Auto Save Delay (ms)'
|
||||
autoSaveDelay: 'Auto Save Delay (ms)',
|
||||
updateSettings: 'Update Settings',
|
||||
autoCheckUpdates: 'Auto Check Updates',
|
||||
autoCheckUpdatesDescription: 'Automatically check for updates on startup',
|
||||
manualCheck: 'Manual Check',
|
||||
currentVersion: 'Current Version',
|
||||
checkForUpdates: 'Check for Updates',
|
||||
checking: 'Checking...',
|
||||
checkFailed: 'Check Failed',
|
||||
newVersionAvailable: 'New Version Available',
|
||||
upToDate: 'You are using the latest version',
|
||||
viewUpdate: 'View Update',
|
||||
releaseNotes: 'Release Notes',
|
||||
networkError: 'Network connection error, please check your network settings'
|
||||
}
|
||||
};
|
@@ -135,6 +135,19 @@ export default {
|
||||
language: '界面语言',
|
||||
systemTheme: '系统主题',
|
||||
saveOptions: '保存选项',
|
||||
autoSaveDelay: '自动保存延迟(毫秒)'
|
||||
autoSaveDelay: '自动保存延迟(毫秒)',
|
||||
updateSettings: '更新设置',
|
||||
autoCheckUpdates: '自动检查更新',
|
||||
autoCheckUpdatesDescription: '启动应用时自动检查更新',
|
||||
manualCheck: '手动检查',
|
||||
currentVersion: '当前版本',
|
||||
checkForUpdates: '检查更新',
|
||||
checking: '检查中...',
|
||||
checkFailed: '检查失败',
|
||||
newVersionAvailable: '发现新版本',
|
||||
upToDate: '您正在使用最新版本',
|
||||
viewUpdate: '查看更新',
|
||||
releaseNotes: '更新内容',
|
||||
networkError: '网络连接错误,请检查网络设置'
|
||||
}
|
||||
};
|
@@ -9,6 +9,7 @@ import {
|
||||
LanguageType,
|
||||
SystemThemeType,
|
||||
TabType,
|
||||
UpdatesConfig,
|
||||
} from '@/../bindings/voidraft/internal/models/models';
|
||||
import {useI18n} from 'vue-i18n';
|
||||
import {ConfigUtils} from '@/utils/configUtils';
|
||||
@@ -42,6 +43,10 @@ type AppearanceConfigKeyMap = {
|
||||
readonly [K in keyof AppearanceConfig]: string;
|
||||
};
|
||||
|
||||
type UpdatesConfigKeyMap = {
|
||||
readonly [K in keyof UpdatesConfig]: string;
|
||||
};
|
||||
|
||||
type NumberConfigKey = 'fontSize' | 'tabSize' | 'lineHeight';
|
||||
|
||||
// 配置键映射
|
||||
@@ -70,6 +75,11 @@ const APPEARANCE_CONFIG_KEY_MAP: AppearanceConfigKeyMap = {
|
||||
systemTheme: 'appearance.systemTheme'
|
||||
} as const;
|
||||
|
||||
const UPDATES_CONFIG_KEY_MAP: UpdatesConfigKeyMap = {
|
||||
version: 'updates.version',
|
||||
autoUpdate: 'updates.autoUpdate'
|
||||
} as const;
|
||||
|
||||
// 配置限制
|
||||
const CONFIG_LIMITS = {
|
||||
fontSize: {min: 12, max: 28, default: 13},
|
||||
@@ -145,7 +155,6 @@ const DEFAULT_CONFIG: AppConfig = {
|
||||
updates: {
|
||||
version: "1.0.0",
|
||||
autoUpdate: true,
|
||||
betaChannel: false
|
||||
},
|
||||
metadata: {
|
||||
version: '1.0.0',
|
||||
@@ -216,6 +225,21 @@ export const useConfigStore = defineStore('config', () => {
|
||||
state.config.appearance[key] = value;
|
||||
};
|
||||
|
||||
const updateUpdatesConfig = async <K extends keyof UpdatesConfig>(key: K, value: UpdatesConfig[K]): Promise<void> => {
|
||||
// 确保配置已加载
|
||||
if (!state.configLoaded && !state.isLoading) {
|
||||
await initConfig();
|
||||
}
|
||||
|
||||
const backendKey = UPDATES_CONFIG_KEY_MAP[key];
|
||||
if (!backendKey) {
|
||||
throw new Error(`No backend key mapping found for updates.${key.toString()}`);
|
||||
}
|
||||
|
||||
await ConfigService.Set(backendKey, value);
|
||||
state.config.updates[key] = value;
|
||||
};
|
||||
|
||||
// 加载配置
|
||||
const initConfig = async (): Promise<void> => {
|
||||
if (state.isLoading) return;
|
||||
@@ -411,6 +435,9 @@ export const useConfigStore = defineStore('config', () => {
|
||||
await updateGeneralConfig('startAtLogin', value);
|
||||
// 再调用系统设置API
|
||||
await StartupService.SetEnabled(value);
|
||||
}
|
||||
},
|
||||
|
||||
// 更新配置相关方法
|
||||
setAutoUpdate: async (value: boolean) => await updateUpdatesConfig('autoUpdate', value)
|
||||
};
|
||||
});
|
@@ -8,13 +8,16 @@ import {useThemeStore} from './themeStore';
|
||||
import {SystemThemeType} from '@/../bindings/voidraft/internal/models/models';
|
||||
import {DocumentService} from '@/../bindings/voidraft/internal/services';
|
||||
import {ensureSyntaxTree} from "@codemirror/language"
|
||||
import {createBasicSetup} from '@/views/editor/extensions/basicSetup';
|
||||
import {createThemeExtension, updateEditorTheme} from '@/views/editor/extensions/themeExtension';
|
||||
import {getTabExtensions, updateTabConfig} from '@/views/editor/extensions/tabExtension';
|
||||
import {createFontExtensionFromBackend, updateFontConfig} from '@/views/editor/extensions/fontExtension';
|
||||
import {createStatsUpdateExtension} from '@/views/editor/extensions/statsExtension';
|
||||
import {createAutoSavePlugin, createSaveShortcutPlugin} from '@/views/editor/extensions/autoSaveExtension';
|
||||
import {createDynamicKeymapExtension} from '@/views/editor/extensions/keymap';
|
||||
import {createBasicSetup} from '@/views/editor/basic/basicSetup';
|
||||
import {createThemeExtension, updateEditorTheme} from '@/views/editor/basic/themeExtension';
|
||||
import {getTabExtensions, updateTabConfig} from '@/views/editor/basic/tabExtension';
|
||||
import {createFontExtensionFromBackend, updateFontConfig} from '@/views/editor/basic/fontExtension';
|
||||
import {createStatsUpdateExtension} from '@/views/editor/basic/statsExtension';
|
||||
import {createAutoSavePlugin, createSaveShortcutPlugin} from '@/views/editor/basic/autoSaveExtension';
|
||||
import {createDynamicKeymapExtension} from '@/views/editor/keymap';
|
||||
import { createDynamicExtensions, setExtensionManagerView, getExtensionManager } from '@/views/editor/manager';
|
||||
import { useExtensionStore } from './extensionStore';
|
||||
import { ExtensionService } from '@/../bindings/voidraft/internal/services';
|
||||
|
||||
export interface DocumentStats {
|
||||
lines: number;
|
||||
@@ -27,6 +30,7 @@ export const useEditorStore = defineStore('editor', () => {
|
||||
const configStore = useConfigStore();
|
||||
const documentStore = useDocumentStore();
|
||||
const themeStore = useThemeStore();
|
||||
const extensionStore = useExtensionStore();
|
||||
|
||||
// 状态
|
||||
const documentStats = ref<DocumentStats>({
|
||||
@@ -130,14 +134,14 @@ export const useEditorStore = defineStore('editor', () => {
|
||||
);
|
||||
|
||||
// 创建保存快捷键插件
|
||||
const saveShortcutPlugin = createSaveShortcutPlugin(() => {
|
||||
const saveShortcutExtension = createSaveShortcutPlugin(() => {
|
||||
if (editorView.value) {
|
||||
handleManualSave();
|
||||
}
|
||||
});
|
||||
|
||||
// 创建自动保存插件
|
||||
const autoSavePlugin = createAutoSavePlugin({
|
||||
const autoSaveExtension = createAutoSavePlugin({
|
||||
debounceDelay: 300, // 300毫秒的输入防抖
|
||||
onSave: (success) => {
|
||||
if (success) {
|
||||
@@ -148,6 +152,9 @@ export const useEditorStore = defineStore('editor', () => {
|
||||
|
||||
// 创建动态快捷键扩展
|
||||
const keymapExtension = await createDynamicKeymapExtension();
|
||||
|
||||
// 创建动态扩展
|
||||
const dynamicExtensions = await createDynamicExtensions();
|
||||
|
||||
// 组合所有扩展
|
||||
const extensions: Extension[] = [
|
||||
@@ -157,8 +164,9 @@ export const useEditorStore = defineStore('editor', () => {
|
||||
...tabExtensions,
|
||||
fontExtension,
|
||||
statsExtension,
|
||||
saveShortcutPlugin,
|
||||
autoSavePlugin
|
||||
saveShortcutExtension,
|
||||
autoSaveExtension,
|
||||
...dynamicExtensions
|
||||
];
|
||||
|
||||
// 创建编辑器状态
|
||||
@@ -175,6 +183,9 @@ export const useEditorStore = defineStore('editor', () => {
|
||||
|
||||
// 将编辑器实例保存到store
|
||||
setEditorView(view);
|
||||
|
||||
// 设置编辑器视图到扩展管理器
|
||||
setExtensionManagerView(view);
|
||||
|
||||
isEditorInitialized.value = true;
|
||||
|
||||
@@ -257,6 +268,23 @@ export const useEditorStore = defineStore('editor', () => {
|
||||
}
|
||||
});
|
||||
|
||||
// 扩展管理方法
|
||||
const updateExtension = async (id: any, enabled: boolean, config?: any) => {
|
||||
try {
|
||||
// 更新后端配置
|
||||
await ExtensionService.UpdateExtensionState(id, enabled, config || {})
|
||||
|
||||
// 更新前端编辑器
|
||||
const manager = getExtensionManager()
|
||||
manager.updateExtension(id, enabled, config || {})
|
||||
|
||||
// 重新加载扩展配置
|
||||
await extensionStore.loadExtensions()
|
||||
} catch (error) {
|
||||
console.error('Failed to update extension:', error)
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
// 状态
|
||||
documentStats,
|
||||
@@ -272,5 +300,6 @@ export const useEditorStore = defineStore('editor', () => {
|
||||
handleManualSave,
|
||||
destroyEditor,
|
||||
scrollEditorToBottom,
|
||||
updateExtension
|
||||
};
|
||||
});
|
76
frontend/src/stores/extensionStore.ts
Normal file
76
frontend/src/stores/extensionStore.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { computed, ref } from 'vue'
|
||||
import { Extension, ExtensionID, ExtensionCategory, ExtensionSettings } from '@/../bindings/voidraft/internal/models/models'
|
||||
import { ExtensionService } from '@/../bindings/voidraft/internal/services'
|
||||
|
||||
export const useExtensionStore = defineStore('extension', () => {
|
||||
// 扩展配置数据
|
||||
const extensions = ref<Extension[]>([])
|
||||
const settings = ref<ExtensionSettings | null>(null)
|
||||
|
||||
// 获取启用的扩展
|
||||
const enabledExtensions = computed(() =>
|
||||
extensions.value.filter(ext => ext.enabled)
|
||||
)
|
||||
|
||||
// 根据分类获取扩展
|
||||
const getExtensionsByCategory = computed(() =>
|
||||
(category: ExtensionCategory) =>
|
||||
extensions.value.filter(ext => ext.category === category)
|
||||
)
|
||||
|
||||
// 获取启用的扩展按分类分组
|
||||
const enabledExtensionsByCategory = computed(() => {
|
||||
const grouped = new Map<ExtensionCategory, Extension[]>()
|
||||
enabledExtensions.value.forEach(ext => {
|
||||
if (!grouped.has(ext.category)) {
|
||||
grouped.set(ext.category, [])
|
||||
}
|
||||
grouped.get(ext.category)!.push(ext)
|
||||
})
|
||||
return grouped
|
||||
})
|
||||
|
||||
/**
|
||||
* 从后端加载扩展配置
|
||||
*/
|
||||
const loadExtensions = async (): Promise<void> => {
|
||||
try {
|
||||
extensions.value = await ExtensionService.GetAllExtensions()
|
||||
} catch (err) {
|
||||
console.error('Failed to load extensions:', err)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查扩展是否启用
|
||||
*/
|
||||
const isExtensionEnabled = (id: ExtensionID): boolean => {
|
||||
const extension = extensions.value.find(ext => ext.id === id)
|
||||
return extension?.enabled ?? false
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取扩展配置
|
||||
*/
|
||||
const getExtensionConfig = (id: ExtensionID): any => {
|
||||
const extension = extensions.value.find(ext => ext.id === id)
|
||||
return extension?.config ?? {}
|
||||
}
|
||||
|
||||
return {
|
||||
// 状态
|
||||
extensions,
|
||||
settings,
|
||||
enabledExtensions,
|
||||
|
||||
// 计算属性
|
||||
getExtensionsByCategory,
|
||||
enabledExtensionsByCategory,
|
||||
|
||||
// 方法
|
||||
loadExtensions,
|
||||
isExtensionEnabled,
|
||||
getExtensionConfig
|
||||
}
|
||||
})
|
@@ -3,98 +3,64 @@ import {computed, ref} from 'vue';
|
||||
import * as runtime from '@wailsio/runtime';
|
||||
|
||||
export interface SystemEnvironment {
|
||||
OS: string;
|
||||
Arch: string;
|
||||
Debug: boolean;
|
||||
OSInfo: {
|
||||
Name: string;
|
||||
Branding: string;
|
||||
Version: string;
|
||||
ID: string;
|
||||
};
|
||||
PlatformInfo?: Record<string, string>;
|
||||
OS: string;
|
||||
Arch: string;
|
||||
Debug: boolean;
|
||||
OSInfo: {
|
||||
Name: string;
|
||||
Branding: string;
|
||||
Version: string;
|
||||
ID: string;
|
||||
};
|
||||
PlatformInfo?: Record<string, string>;
|
||||
}
|
||||
|
||||
export const useSystemStore = defineStore('system', () => {
|
||||
// 状态
|
||||
const environment = ref<SystemEnvironment | null>(null);
|
||||
const isLoading = ref(false);
|
||||
const error = ref<string | null>(null);
|
||||
|
||||
// 计算属性
|
||||
const isWindows = computed(() => environment.value?.OS === 'windows');
|
||||
const isMacOS = computed(() => environment.value?.OS === 'darwin');
|
||||
const isLinux = computed(() => environment.value?.OS === 'linux');
|
||||
|
||||
// 获取操作系统名称
|
||||
const osName = computed(() => {
|
||||
if (!environment.value) return 'Unknown';
|
||||
return environment.value.OSInfo?.Name || environment.value.OS || 'Unknown';
|
||||
});
|
||||
|
||||
// 获取架构信息
|
||||
const architecture = computed(() => environment.value?.Arch || 'Unknown');
|
||||
|
||||
// 获取标题栏高度
|
||||
const titleBarHeight = computed(() => {
|
||||
if (isWindows.value) return '32px';
|
||||
if (isMacOS.value) return '28px';
|
||||
return '34px'; // Linux 默认
|
||||
});
|
||||
|
||||
// 初始化系统信息
|
||||
const initializeSystemInfo = async (): Promise<void> => {
|
||||
if (isLoading.value) return;
|
||||
|
||||
isLoading.value = true;
|
||||
error.value = null;
|
||||
|
||||
try {
|
||||
environment.value = await runtime.System.Environment();
|
||||
} catch (err) {
|
||||
error.value = 'Failed to get system environment';
|
||||
environment.value = null;
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 获取平台特定信息
|
||||
const getPlatformInfo = () => {
|
||||
return environment.value?.PlatformInfo || {};
|
||||
};
|
||||
|
||||
// 检查是否支持某项功能(基于操作系统)
|
||||
const supportsFeature = (feature: string): boolean => {
|
||||
switch (feature) {
|
||||
case 'systemTray':
|
||||
return true; // 所有平台都支持
|
||||
case 'globalHotkeys':
|
||||
return !isLinux.value; // Linux 支持可能有限
|
||||
case 'transparency':
|
||||
return isWindows.value || isMacOS.value;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
// 状态
|
||||
environment,
|
||||
isLoading,
|
||||
error,
|
||||
const environment = ref<SystemEnvironment | null>(null);
|
||||
const isLoading = ref(false);
|
||||
|
||||
|
||||
// 计算属性
|
||||
isWindows,
|
||||
isMacOS,
|
||||
isLinux,
|
||||
osName,
|
||||
architecture,
|
||||
titleBarHeight,
|
||||
const isWindows = computed(() => environment.value?.OS === 'windows');
|
||||
const isMacOS = computed(() => environment.value?.OS === 'darwin');
|
||||
const isLinux = computed(() => environment.value?.OS === 'linux');
|
||||
|
||||
// 方法
|
||||
initializeSystemInfo,
|
||||
getPlatformInfo,
|
||||
supportsFeature
|
||||
};
|
||||
|
||||
// 获取标题栏高度
|
||||
const titleBarHeight = computed(() => {
|
||||
if (isWindows.value) return '32px';
|
||||
if (isMacOS.value) return '28px';
|
||||
return '34px'; // Linux 默认
|
||||
});
|
||||
|
||||
// 初始化系统信息
|
||||
const initializeSystemInfo = async (): Promise<void> => {
|
||||
if (isLoading.value) return;
|
||||
|
||||
isLoading.value = true;
|
||||
|
||||
try {
|
||||
environment.value = await runtime.System.Environment();
|
||||
} catch (err) {
|
||||
environment.value = null;
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
// 状态
|
||||
environment,
|
||||
isLoading,
|
||||
|
||||
// 计算属性
|
||||
isWindows,
|
||||
isMacOS,
|
||||
isLinux,
|
||||
titleBarHeight,
|
||||
|
||||
// 方法
|
||||
initializeSystemInfo,
|
||||
};
|
||||
});
|
81
frontend/src/stores/updateStore.ts
Normal file
81
frontend/src/stores/updateStore.ts
Normal file
@@ -0,0 +1,81 @@
|
||||
import {defineStore} from 'pinia'
|
||||
import {computed, ref} from 'vue'
|
||||
import {CheckForUpdates} from '@/../bindings/voidraft/internal/services/updateservice'
|
||||
import {UpdateCheckResult} from '@/../bindings/voidraft/internal/services/models'
|
||||
import {useConfigStore} from './configStore'
|
||||
|
||||
export const useUpdateStore = defineStore('update', () => {
|
||||
// 状态
|
||||
const isChecking = ref(false)
|
||||
const updateResult = ref<UpdateCheckResult | null>(null)
|
||||
const hasCheckedOnStartup = ref(false)
|
||||
|
||||
// 计算属性
|
||||
const hasUpdate = computed(() => updateResult.value?.hasUpdate || false)
|
||||
const errorMessage = computed(() => updateResult.value?.error || '')
|
||||
|
||||
// 检查更新
|
||||
const checkForUpdates = async (): Promise<boolean> => {
|
||||
if (isChecking.value) return false
|
||||
|
||||
isChecking.value = true
|
||||
try {
|
||||
const result = await CheckForUpdates()
|
||||
updateResult.value = result
|
||||
return !result.error
|
||||
} catch (error) {
|
||||
updateResult.value = new UpdateCheckResult({
|
||||
hasUpdate: false,
|
||||
currentVer: '1.0.0',
|
||||
latestVer: '',
|
||||
releaseNotes: '',
|
||||
releaseURL: '',
|
||||
error: 'Network error'
|
||||
})
|
||||
return false
|
||||
} finally {
|
||||
isChecking.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 启动时检查更新
|
||||
const checkOnStartup = async () => {
|
||||
if (hasCheckedOnStartup.value) return
|
||||
const configStore = useConfigStore()
|
||||
|
||||
if (configStore.config.updates.autoUpdate) {
|
||||
await checkForUpdates()
|
||||
}
|
||||
hasCheckedOnStartup.value = true
|
||||
}
|
||||
|
||||
// 打开发布页面
|
||||
const openReleaseURL = () => {
|
||||
if (updateResult.value?.releaseURL) {
|
||||
window.open(updateResult.value.releaseURL, '_blank')
|
||||
}
|
||||
}
|
||||
|
||||
// 重置状态
|
||||
const reset = () => {
|
||||
updateResult.value = null
|
||||
isChecking.value = false
|
||||
}
|
||||
|
||||
return {
|
||||
// 状态
|
||||
isChecking,
|
||||
updateResult,
|
||||
hasCheckedOnStartup,
|
||||
|
||||
// 计算属性
|
||||
hasUpdate,
|
||||
errorMessage,
|
||||
|
||||
// 方法
|
||||
checkForUpdates,
|
||||
checkOnStartup,
|
||||
openReleaseURL,
|
||||
reset
|
||||
}
|
||||
})
|
@@ -2,7 +2,7 @@
|
||||
import {onBeforeUnmount, onMounted, ref} from 'vue';
|
||||
import {useEditorStore} from '@/stores/editorStore';
|
||||
import {useConfigStore} from '@/stores/configStore';
|
||||
import {createWheelZoomHandler} from './extensions';
|
||||
import {createWheelZoomHandler} from './basic/wheelZoomExtension';
|
||||
import Toolbar from '@/components/toolbar/Toolbar.vue';
|
||||
|
||||
const editorStore = useEditorStore();
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { EditorView, ViewPlugin, ViewUpdate } from '@codemirror/view';
|
||||
import { DocumentService } from '../../../../bindings/voidraft/internal/services';
|
||||
import { DocumentService } from '@/../bindings/voidraft/internal/services';
|
||||
import { useDebounceFn } from '@vueuse/core';
|
||||
|
||||
// 定义自动保存配置选项
|
@@ -21,16 +21,6 @@ import {
|
||||
import {history} from '@codemirror/commands';
|
||||
import {highlightSelectionMatches} from '@codemirror/search';
|
||||
import {autocompletion, closeBrackets, closeBracketsKeymap} from '@codemirror/autocomplete';
|
||||
import {searchVisibilityField, vscodeSearch} from './vscodeSearch';
|
||||
|
||||
import {hyperLink} from './hyperlink';
|
||||
import {color} from './colorSelector';
|
||||
import {createTextHighlighter} from './textHighlightExtension';
|
||||
import {minimap} from './minimap';
|
||||
import {createCodeBlockExtension} from './codeblock/index';
|
||||
import {foldingOnIndent} from './foldExtension'
|
||||
import rainbowBrackets from "./rainbowBrackets";
|
||||
import {createCodeBlastExtension} from './codeblast';
|
||||
// 基本编辑器设置
|
||||
export const createBasicSetup = (): Extension[] => {
|
||||
return [
|
||||
@@ -63,30 +53,6 @@ export const createBasicSetup = (): Extension[] => {
|
||||
// 自动完成
|
||||
autocompletion(),
|
||||
|
||||
vscodeSearch,
|
||||
searchVisibilityField,
|
||||
foldingOnIndent,
|
||||
rainbowBrackets(),
|
||||
createCodeBlastExtension({
|
||||
effect: 1,
|
||||
shake: true,
|
||||
maxParticles: 300,
|
||||
shakeIntensity: 3
|
||||
}),
|
||||
hyperLink,
|
||||
color,
|
||||
...createTextHighlighter('hl'),
|
||||
minimap({
|
||||
displayText: 'characters',
|
||||
showOverlay: 'always',
|
||||
autohide: false,
|
||||
}),
|
||||
|
||||
createCodeBlockExtension({
|
||||
showBackground: true,
|
||||
enableAutoDetection: true,
|
||||
}),
|
||||
|
||||
// 键盘映射
|
||||
keymap.of([
|
||||
...closeBracketsKeymap,
|
@@ -81,14 +81,6 @@ export function createFontExtension(config: Partial<FontConfig> = {}): Extension
|
||||
return EditorView.theme(styles);
|
||||
}
|
||||
|
||||
// 创建响应式字体大小扩展
|
||||
export function createResponsiveFontExtension(baseFontSize: number = 14): Extension {
|
||||
return fontCompartment.of(createFontExtension({
|
||||
fontSize: baseFontSize,
|
||||
lineHeight: 1.5
|
||||
}));
|
||||
}
|
||||
|
||||
// 从后端配置创建字体扩展
|
||||
export function createFontExtensionFromBackend(backendConfig: {
|
||||
fontFamily?: string;
|
@@ -1,10 +0,0 @@
|
||||
// 统一导出所有扩展
|
||||
export * from './tabExtension';
|
||||
export * from './wheelZoomExtension';
|
||||
export * from './statsExtension';
|
||||
export * from './autoSaveExtension';
|
||||
export * from './fontExtension';
|
||||
export * from './themeExtension';
|
||||
export * from './codeblast';
|
||||
export * from './codeblock';
|
||||
export * from './keymap';
|
@@ -70,7 +70,7 @@ const rainbowBracketsPlugin = ViewPlugin.fromClass(RainbowBracketsView, {
|
||||
decorations: (v) => v.decorations,
|
||||
});
|
||||
|
||||
export default function rainbowBrackets() {
|
||||
export default function rainbowBracketsExtension() {
|
||||
return [
|
||||
rainbowBracketsPlugin,
|
||||
EditorView.baseTheme({
|
@@ -7,7 +7,7 @@ import {
|
||||
searchToggleRegex,
|
||||
searchToggleWholeWord,
|
||||
showSearchVisibilityCommand
|
||||
} from '../vscodeSearch/commands'
|
||||
} from '../extensions/vscodeSearch/commands'
|
||||
import {
|
||||
addNewBlockAfterCurrent,
|
||||
addNewBlockAfterLast,
|
||||
@@ -20,14 +20,39 @@ import {
|
||||
moveCurrentBlockUp,
|
||||
selectNextBlock,
|
||||
selectPreviousBlock
|
||||
} from '../codeblock/commands'
|
||||
import { selectAll } from '../codeblock/selectAll'
|
||||
import { deleteLineCommand } from '../codeblock/deleteLine'
|
||||
import { moveLineUp, moveLineDown } from '../codeblock/moveLines'
|
||||
import { transposeChars } from '@/views/editor/extensions'
|
||||
import { copyCommand, cutCommand, pasteCommand } from '../codeblock/copyPaste'
|
||||
import { undo, redo, undoSelection, redoSelection, cursorSyntaxLeft, cursorSyntaxRight, selectSyntaxLeft, selectSyntaxRight, copyLineUp, copyLineDown, insertBlankLine, selectLine, selectParentSyntax, indentLess, indentMore, indentSelection, cursorMatchingBracket, toggleComment, toggleBlockComment, insertNewlineAndIndent, deleteCharBackward, deleteCharForward, deleteGroupBackward, deleteGroupForward } from '@codemirror/commands'
|
||||
import { foldCode, unfoldCode, foldAll, unfoldAll } from '@codemirror/language'
|
||||
} from '../extensions/codeblock/commands'
|
||||
import {selectAll} from '../extensions/codeblock/selectAll'
|
||||
import {deleteLineCommand} from '../extensions/codeblock/deleteLine'
|
||||
import {moveLineDown, moveLineUp} from '../extensions/codeblock/moveLines'
|
||||
import {transposeChars} from '../extensions/codeblock'
|
||||
import {copyCommand, cutCommand, pasteCommand} from '../extensions/codeblock/copyPaste'
|
||||
import {
|
||||
copyLineDown,
|
||||
copyLineUp,
|
||||
cursorMatchingBracket,
|
||||
cursorSyntaxLeft,
|
||||
cursorSyntaxRight,
|
||||
deleteCharBackward,
|
||||
deleteCharForward,
|
||||
deleteGroupBackward,
|
||||
deleteGroupForward,
|
||||
indentLess,
|
||||
indentMore,
|
||||
indentSelection,
|
||||
insertBlankLine,
|
||||
insertNewlineAndIndent,
|
||||
redo,
|
||||
redoSelection,
|
||||
selectLine,
|
||||
selectParentSyntax,
|
||||
selectSyntaxLeft,
|
||||
selectSyntaxRight,
|
||||
toggleBlockComment,
|
||||
toggleComment,
|
||||
undo,
|
||||
undoSelection
|
||||
} from '@codemirror/commands'
|
||||
import {foldAll, foldCode, unfoldAll, unfoldCode} from '@codemirror/language'
|
||||
import i18n from '@/i18n'
|
||||
|
||||
// 默认编辑器选项
|
264
frontend/src/views/editor/manager/ExtensionManager.ts
Normal file
264
frontend/src/views/editor/manager/ExtensionManager.ts
Normal file
@@ -0,0 +1,264 @@
|
||||
import { Compartment, Extension, StateEffect } from '@codemirror/state'
|
||||
import { EditorView } from '@codemirror/view'
|
||||
import { ExtensionID, Extension as ExtensionConfig } from '@/../bindings/voidraft/internal/models/models'
|
||||
|
||||
/**
|
||||
* 扩展工厂接口
|
||||
* 每个扩展需要实现此接口来创建和配置扩展
|
||||
*/
|
||||
export interface ExtensionFactory {
|
||||
/**
|
||||
* 创建扩展实例
|
||||
* @param config 扩展配置
|
||||
* @returns CodeMirror扩展
|
||||
*/
|
||||
create(config: any): Extension
|
||||
|
||||
/**
|
||||
* 获取默认配置
|
||||
* @returns 默认配置对象
|
||||
*/
|
||||
getDefaultConfig(): any
|
||||
|
||||
/**
|
||||
* 验证配置
|
||||
* @param config 配置对象
|
||||
* @returns 是否有效
|
||||
*/
|
||||
validateConfig?(config: any): boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* 扩展区间信息
|
||||
*/
|
||||
interface ExtensionCompartment {
|
||||
id: ExtensionID
|
||||
compartment: Compartment
|
||||
factory: ExtensionFactory
|
||||
currentConfig?: any
|
||||
enabled: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* 扩展管理器
|
||||
* 负责管理所有动态扩展的注册、启用、禁用和配置更新
|
||||
*/
|
||||
export class ExtensionManager {
|
||||
private view: EditorView | null = null
|
||||
private compartments = new Map<ExtensionID, ExtensionCompartment>()
|
||||
private extensionFactories = new Map<ExtensionID, ExtensionFactory>()
|
||||
|
||||
/**
|
||||
* 注册扩展工厂
|
||||
* @param id 扩展ID
|
||||
* @param factory 扩展工厂
|
||||
*/
|
||||
registerExtension(id: ExtensionID, factory: ExtensionFactory): void {
|
||||
this.extensionFactories.set(id, factory)
|
||||
this.compartments.set(id, {
|
||||
id,
|
||||
compartment: new Compartment(),
|
||||
factory,
|
||||
currentConfig: factory.getDefaultConfig(),
|
||||
enabled: false
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有注册的扩展ID列表
|
||||
*/
|
||||
getRegisteredExtensions(): ExtensionID[] {
|
||||
return Array.from(this.extensionFactories.keys())
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查扩展是否已注册
|
||||
* @param id 扩展ID
|
||||
*/
|
||||
isExtensionRegistered(id: ExtensionID): boolean {
|
||||
return this.extensionFactories.has(id)
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据后端配置获取初始扩展数组
|
||||
* @param extensionConfigs 后端扩展配置列表
|
||||
* @returns CodeMirror扩展数组
|
||||
*/
|
||||
getInitialExtensions(extensionConfigs: ExtensionConfig[]): Extension[] {
|
||||
const extensions: Extension[] = []
|
||||
|
||||
for (const config of extensionConfigs) {
|
||||
const compartmentInfo = this.compartments.get(config.id)
|
||||
if (!compartmentInfo) {
|
||||
console.warn(`Extension ${config.id} is not registered`)
|
||||
continue
|
||||
}
|
||||
|
||||
// 验证配置
|
||||
if (compartmentInfo.factory.validateConfig &&
|
||||
!compartmentInfo.factory.validateConfig(config.config)) {
|
||||
console.warn(`Invalid config for extension ${config.id}`)
|
||||
continue
|
||||
}
|
||||
|
||||
try {
|
||||
const extension = config.enabled
|
||||
? compartmentInfo.factory.create(config.config)
|
||||
: [] // 空扩展表示禁用
|
||||
|
||||
extensions.push(compartmentInfo.compartment.of(extension))
|
||||
|
||||
// 更新状态
|
||||
compartmentInfo.currentConfig = config.config
|
||||
compartmentInfo.enabled = config.enabled
|
||||
} catch (error) {
|
||||
console.error(`Failed to create extension ${config.id}:`, error)
|
||||
}
|
||||
}
|
||||
|
||||
return extensions
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置编辑器视图
|
||||
* @param view 编辑器视图实例
|
||||
*/
|
||||
setView(view: EditorView): void {
|
||||
this.view = view
|
||||
}
|
||||
|
||||
/**
|
||||
* 动态更新单个扩展
|
||||
* @param id 扩展ID
|
||||
* @param enabled 是否启用
|
||||
* @param config 扩展配置
|
||||
*/
|
||||
updateExtension(id: ExtensionID, enabled: boolean, config: any = {}): void {
|
||||
if (!this.view) {
|
||||
console.warn('Editor view not set')
|
||||
return
|
||||
}
|
||||
|
||||
const compartmentInfo = this.compartments.get(id)
|
||||
if (!compartmentInfo) {
|
||||
console.warn(`Extension ${id} is not registered`)
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
// 验证配置
|
||||
if (compartmentInfo.factory.validateConfig &&
|
||||
!compartmentInfo.factory.validateConfig(config)) {
|
||||
console.warn(`Invalid config for extension ${id}`)
|
||||
return
|
||||
}
|
||||
|
||||
const extension = enabled
|
||||
? compartmentInfo.factory.create(config)
|
||||
: []
|
||||
|
||||
this.view.dispatch({
|
||||
effects: compartmentInfo.compartment.reconfigure(extension)
|
||||
})
|
||||
|
||||
// 更新状态
|
||||
compartmentInfo.currentConfig = config
|
||||
compartmentInfo.enabled = enabled
|
||||
} catch (error) {
|
||||
console.error(`Failed to update extension ${id}:`, error)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量更新扩展
|
||||
* @param updates 更新配置数组
|
||||
*/
|
||||
updateExtensions(updates: Array<{
|
||||
id: ExtensionID
|
||||
enabled: boolean
|
||||
config: any
|
||||
}>): void {
|
||||
if (!this.view) {
|
||||
console.warn('Editor view not set')
|
||||
return
|
||||
}
|
||||
|
||||
const effects: StateEffect<any>[] = []
|
||||
|
||||
for (const update of updates) {
|
||||
const compartmentInfo = this.compartments.get(update.id)
|
||||
if (!compartmentInfo) {
|
||||
console.warn(`Extension ${update.id} is not registered`)
|
||||
continue
|
||||
}
|
||||
|
||||
try {
|
||||
// 验证配置
|
||||
if (compartmentInfo.factory.validateConfig &&
|
||||
!compartmentInfo.factory.validateConfig(update.config)) {
|
||||
console.warn(`Invalid config for extension ${update.id}`)
|
||||
continue
|
||||
}
|
||||
|
||||
const extension = update.enabled
|
||||
? compartmentInfo.factory.create(update.config)
|
||||
: []
|
||||
|
||||
effects.push(compartmentInfo.compartment.reconfigure(extension))
|
||||
|
||||
// 更新状态
|
||||
compartmentInfo.currentConfig = update.config
|
||||
compartmentInfo.enabled = update.enabled
|
||||
} catch (error) {
|
||||
console.error(`Failed to update extension ${update.id}:`, error)
|
||||
}
|
||||
}
|
||||
|
||||
if (effects.length > 0) {
|
||||
this.view.dispatch({ effects })
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取扩展当前状态
|
||||
* @param id 扩展ID
|
||||
*/
|
||||
getExtensionState(id: ExtensionID): {
|
||||
enabled: boolean
|
||||
config: any
|
||||
} | null {
|
||||
const compartmentInfo = this.compartments.get(id)
|
||||
if (!compartmentInfo) {
|
||||
return null
|
||||
}
|
||||
|
||||
return {
|
||||
enabled: compartmentInfo.enabled,
|
||||
config: compartmentInfo.currentConfig
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置扩展到默认配置
|
||||
* @param id 扩展ID
|
||||
*/
|
||||
resetExtensionToDefault(id: ExtensionID): void {
|
||||
const compartmentInfo = this.compartments.get(id)
|
||||
if (!compartmentInfo) {
|
||||
console.warn(`Extension ${id} is not registered`)
|
||||
return
|
||||
}
|
||||
|
||||
const defaultConfig = compartmentInfo.factory.getDefaultConfig()
|
||||
this.updateExtension(id, true, defaultConfig)
|
||||
}
|
||||
|
||||
/**
|
||||
* 销毁管理器
|
||||
*/
|
||||
destroy(): void {
|
||||
this.view = null
|
||||
this.compartments.clear()
|
||||
this.extensionFactories.clear()
|
||||
}
|
||||
}
|
296
frontend/src/views/editor/manager/factories.ts
Normal file
296
frontend/src/views/editor/manager/factories.ts
Normal file
@@ -0,0 +1,296 @@
|
||||
import {ExtensionFactory, ExtensionManager} from './ExtensionManager'
|
||||
import {ExtensionID} from '@/../bindings/voidraft/internal/models/models'
|
||||
|
||||
// 导入现有扩展的创建函数
|
||||
import rainbowBracketsExtension from '../extensions/rainbowBracket/rainbowBracketsExtension'
|
||||
import {createTextHighlighter} from '../extensions/textHighlight/textHighlightExtension'
|
||||
import {createCodeBlastExtension} from '../extensions/codeblast'
|
||||
import {color} from '../extensions/colorSelector'
|
||||
import {hyperLink} from '../extensions/hyperlink'
|
||||
import {minimap} from '../extensions/minimap'
|
||||
import {vscodeSearch} from '../extensions/vscodeSearch'
|
||||
import {createCodeBlockExtension} from '../extensions/codeblock'
|
||||
import {foldingOnIndent} from '../extensions/fold/foldExtension'
|
||||
|
||||
/**
|
||||
* 彩虹括号扩展工厂
|
||||
*/
|
||||
export const rainbowBracketsFactory: ExtensionFactory = {
|
||||
create(config: any) {
|
||||
return rainbowBracketsExtension()
|
||||
},
|
||||
getDefaultConfig() {
|
||||
return {}
|
||||
},
|
||||
validateConfig(config: any) {
|
||||
return typeof config === 'object'
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 文本高亮扩展工厂
|
||||
*/
|
||||
export const textHighlightFactory: ExtensionFactory = {
|
||||
create(config: any) {
|
||||
return createTextHighlighter('default')
|
||||
},
|
||||
getDefaultConfig() {
|
||||
return {
|
||||
highlightClass: 'hl'
|
||||
}
|
||||
},
|
||||
validateConfig(config: any) {
|
||||
return typeof config === 'object' &&
|
||||
(!config.highlightClass || typeof config.highlightClass === 'string')
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 小地图扩展工厂
|
||||
*/
|
||||
export const minimapFactory: ExtensionFactory = {
|
||||
create(config: any) {
|
||||
const options = {
|
||||
displayText: config.displayText || 'characters',
|
||||
showOverlay: config.showOverlay || 'always',
|
||||
autohide: config.autohide || false
|
||||
}
|
||||
return minimap(options)
|
||||
},
|
||||
getDefaultConfig() {
|
||||
return {
|
||||
displayText: 'characters',
|
||||
showOverlay: 'always',
|
||||
autohide: false
|
||||
}
|
||||
},
|
||||
validateConfig(config: any) {
|
||||
return typeof config === 'object' &&
|
||||
(!config.displayText || typeof config.displayText === 'string') &&
|
||||
(!config.showOverlay || typeof config.showOverlay === 'string') &&
|
||||
(!config.autohide || typeof config.autohide === 'boolean')
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 代码爆炸效果扩展工厂
|
||||
*/
|
||||
export const codeBlastFactory: ExtensionFactory = {
|
||||
create(config: any) {
|
||||
const options = {
|
||||
effect: config.effect || 1,
|
||||
shake: config.shake !== false,
|
||||
maxParticles: config.maxParticles || 300,
|
||||
shakeIntensity: config.shakeIntensity || 3
|
||||
}
|
||||
return createCodeBlastExtension(options)
|
||||
},
|
||||
getDefaultConfig() {
|
||||
return {
|
||||
effect: 1,
|
||||
shake: true,
|
||||
maxParticles: 300,
|
||||
shakeIntensity: 3
|
||||
}
|
||||
},
|
||||
validateConfig(config: any) {
|
||||
return typeof config === 'object' &&
|
||||
(!config.effect || [1, 2].includes(config.effect)) &&
|
||||
(!config.shake || typeof config.shake === 'boolean') &&
|
||||
(!config.maxParticles || typeof config.maxParticles === 'number') &&
|
||||
(!config.shakeIntensity || typeof config.shakeIntensity === 'number')
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 超链接扩展工厂
|
||||
*/
|
||||
export const hyperlinkFactory: ExtensionFactory = {
|
||||
create(config: any) {
|
||||
return hyperLink
|
||||
},
|
||||
getDefaultConfig() {
|
||||
return {}
|
||||
},
|
||||
validateConfig(config: any) {
|
||||
return typeof config === 'object'
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 颜色选择器扩展工厂
|
||||
*/
|
||||
export const colorSelectorFactory: ExtensionFactory = {
|
||||
create(config: any) {
|
||||
return color
|
||||
},
|
||||
getDefaultConfig() {
|
||||
return {}
|
||||
},
|
||||
validateConfig(config: any) {
|
||||
return typeof config === 'object'
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索扩展工厂
|
||||
*/
|
||||
export const searchFactory: ExtensionFactory = {
|
||||
create(config: any) {
|
||||
return vscodeSearch
|
||||
},
|
||||
getDefaultConfig() {
|
||||
return {}
|
||||
},
|
||||
validateConfig(config: any) {
|
||||
return typeof config === 'object'
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 代码块扩展工厂
|
||||
*/
|
||||
export const codeBlockFactory: ExtensionFactory = {
|
||||
create(config: any) {
|
||||
const options = {
|
||||
showBackground: config.showBackground !== false,
|
||||
enableAutoDetection: config.enableAutoDetection !== false
|
||||
}
|
||||
return createCodeBlockExtension(options)
|
||||
},
|
||||
getDefaultConfig() {
|
||||
return {
|
||||
showBackground: true,
|
||||
enableAutoDetection: true
|
||||
}
|
||||
},
|
||||
validateConfig(config: any) {
|
||||
return typeof config === 'object' &&
|
||||
(!config.showBackground || typeof config.showBackground === 'boolean') &&
|
||||
(!config.enableAutoDetection || typeof config.enableAutoDetection === 'boolean')
|
||||
}
|
||||
}
|
||||
|
||||
export const foldFactory: ExtensionFactory = {
|
||||
create(config: any) {
|
||||
return foldingOnIndent;
|
||||
},
|
||||
getDefaultConfig(): any {
|
||||
return {}
|
||||
},
|
||||
validateConfig(config: any): boolean {
|
||||
return typeof config === 'object'
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 所有扩展的统一配置
|
||||
* 排除$zero值以避免TypeScript类型错误
|
||||
*/
|
||||
const EXTENSION_CONFIGS = {
|
||||
|
||||
// 编辑增强扩展
|
||||
[ExtensionID.ExtensionRainbowBrackets]: {
|
||||
factory: rainbowBracketsFactory,
|
||||
displayName: '彩虹括号',
|
||||
description: '用不同颜色显示嵌套括号'
|
||||
},
|
||||
[ExtensionID.ExtensionHyperlink]: {
|
||||
factory: hyperlinkFactory,
|
||||
displayName: '超链接',
|
||||
description: '识别并可点击超链接'
|
||||
},
|
||||
[ExtensionID.ExtensionColorSelector]: {
|
||||
factory: colorSelectorFactory,
|
||||
displayName: '颜色选择器',
|
||||
description: '颜色值的可视化和选择'
|
||||
},
|
||||
|
||||
// UI增强扩展
|
||||
[ExtensionID.ExtensionMinimap]: {
|
||||
factory: minimapFactory,
|
||||
displayName: '小地图',
|
||||
description: '显示小地图视图'
|
||||
},
|
||||
[ExtensionID.ExtensionCodeBlast]: {
|
||||
factory: codeBlastFactory,
|
||||
displayName: '爆炸效果',
|
||||
description: '编写时的动画效果'
|
||||
},
|
||||
|
||||
// 工具扩展
|
||||
[ExtensionID.ExtensionSearch]: {
|
||||
factory: searchFactory,
|
||||
displayName: '搜索功能',
|
||||
description: '文本搜索和替换功能'
|
||||
},
|
||||
[ExtensionID.ExtensionCodeBlock]: {
|
||||
factory: codeBlockFactory,
|
||||
displayName: '代码块',
|
||||
description: '代码块语法高亮和格式化'
|
||||
},
|
||||
[ExtensionID.ExtensionFold]: {
|
||||
factory: foldFactory,
|
||||
displayName: '折叠',
|
||||
description: '折叠'
|
||||
},
|
||||
[ExtensionID.ExtensionTextHighlight]:{
|
||||
factory: textHighlightFactory,
|
||||
displayName: '文本高亮',
|
||||
description: '文本高亮'
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册所有扩展工厂到管理器
|
||||
* @param manager 扩展管理器实例
|
||||
*/
|
||||
export function registerAllExtensions(manager: ExtensionManager): void {
|
||||
Object.entries(EXTENSION_CONFIGS).forEach(([id, config]) => {
|
||||
manager.registerExtension(id as ExtensionID, config.factory)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取扩展工厂的显示名称
|
||||
* @param id 扩展ID
|
||||
* @returns 显示名称
|
||||
*/
|
||||
export function getExtensionDisplayName(id: ExtensionID): string {
|
||||
if (id === ExtensionID.$zero) return ''
|
||||
return EXTENSION_CONFIGS[id as Exclude<ExtensionID, ExtensionID.$zero>]?.displayName || id
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取扩展工厂的描述
|
||||
* @param id 扩展ID
|
||||
* @returns 描述
|
||||
*/
|
||||
export function getExtensionDescription(id: ExtensionID): string {
|
||||
if (id === ExtensionID.$zero) return ''
|
||||
return EXTENSION_CONFIGS[id as Exclude<ExtensionID, ExtensionID.$zero>]?.description || '未知扩展'
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取扩展的完整信息
|
||||
* @param id 扩展ID
|
||||
* @returns 扩展信息对象
|
||||
*/
|
||||
export function getExtensionInfo(id: ExtensionID): { displayName: string; description: string } | null {
|
||||
if (id === ExtensionID.$zero) return null
|
||||
const config = EXTENSION_CONFIGS[id as Exclude<ExtensionID, ExtensionID.$zero>]
|
||||
if (!config) return null
|
||||
|
||||
return {
|
||||
displayName: config.displayName,
|
||||
description: config.description
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有可用扩展的ID列表
|
||||
* @returns 扩展ID数组
|
||||
*/
|
||||
export function getAllExtensionIds(): ExtensionID[] {
|
||||
return Object.keys(EXTENSION_CONFIGS) as ExtensionID[]
|
||||
}
|
51
frontend/src/views/editor/manager/index.ts
Normal file
51
frontend/src/views/editor/manager/index.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import {Extension} from '@codemirror/state'
|
||||
import {useExtensionStore} from '@/stores/extensionStore'
|
||||
import {ExtensionManager} from './ExtensionManager'
|
||||
import {registerAllExtensions} from './factories'
|
||||
|
||||
/**
|
||||
* 全局扩展管理器实例
|
||||
*/
|
||||
const extensionManager = new ExtensionManager()
|
||||
|
||||
/**
|
||||
* 异步创建动态扩展
|
||||
* 确保扩展配置已加载
|
||||
*/
|
||||
export const createDynamicExtensions = async (): Promise<Extension[]> => {
|
||||
const extensionStore = useExtensionStore()
|
||||
|
||||
// 注册所有扩展工厂
|
||||
registerAllExtensions(extensionManager)
|
||||
|
||||
// 确保扩展配置已加载
|
||||
if (extensionStore.extensions.length === 0) {
|
||||
await extensionStore.loadExtensions()
|
||||
}
|
||||
|
||||
// 获取启用的扩展配置
|
||||
const enabledExtensions = extensionStore.enabledExtensions
|
||||
|
||||
return extensionManager.getInitialExtensions(enabledExtensions)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取扩展管理器实例
|
||||
* @returns 扩展管理器
|
||||
*/
|
||||
export const getExtensionManager = (): ExtensionManager => {
|
||||
return extensionManager
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置编辑器视图到扩展管理器
|
||||
* @param view 编辑器视图
|
||||
*/
|
||||
export const setExtensionManagerView = (view: any): void => {
|
||||
extensionManager.setView(view)
|
||||
}
|
||||
|
||||
// 导出相关模块
|
||||
export {ExtensionManager} from './ExtensionManager'
|
||||
export {registerAllExtensions, getExtensionDisplayName, getExtensionDescription} from './factories'
|
||||
export type {ExtensionFactory} from './ExtensionManager'
|
@@ -4,7 +4,7 @@ import { onMounted, computed } from 'vue';
|
||||
import SettingSection from '../components/SettingSection.vue';
|
||||
import { useKeybindingStore } from '@/stores/keybindingStore';
|
||||
import { useSystemStore } from '@/stores/systemStore';
|
||||
import { getCommandDescription } from '@/views/editor/extensions/keymap/commandRegistry';
|
||||
import { getCommandDescription } from '@/views/editor/keymap/commandRegistry';
|
||||
import {KeyBindingCommand} from "@/../bindings/voidraft/internal/models";
|
||||
|
||||
const { t } = useI18n();
|
||||
@@ -186,11 +186,6 @@ const parseKeyBinding = (keyStr: string, command?: string): string[] => {
|
||||
return part.charAt(0).toUpperCase() + part.slice(1).toLowerCase();
|
||||
}).filter(part => part.length > 0);
|
||||
};
|
||||
|
||||
// 组件挂载时加载快捷键数据
|
||||
onMounted(async () => {
|
||||
await keybindingStore.loadKeyBindings();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
@@ -1,87 +1,123 @@
|
||||
<script setup lang="ts">
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { ref } from 'vue';
|
||||
import {useI18n} from 'vue-i18n';
|
||||
import {computed, onMounted} from 'vue';
|
||||
import {useConfigStore} from '@/stores/configStore';
|
||||
import {useUpdateStore} from '@/stores/updateStore';
|
||||
import SettingSection from '../components/SettingSection.vue';
|
||||
import SettingItem from '../components/SettingItem.vue';
|
||||
import ToggleSwitch from '../components/ToggleSwitch.vue';
|
||||
|
||||
const { t } = useI18n();
|
||||
const {t} = useI18n();
|
||||
const configStore = useConfigStore();
|
||||
const updateStore = useUpdateStore();
|
||||
|
||||
// 模拟版本数据
|
||||
const currentVersion = ref('1.0.0');
|
||||
const isCheckingForUpdates = ref(false);
|
||||
const updateAvailable = ref(false);
|
||||
const latestVersion = ref('1.1.0');
|
||||
const updateNotes = ref([
|
||||
'优化编辑器性能',
|
||||
'新增自动保存功能',
|
||||
'修复多个界面显示问题',
|
||||
'添加更多编辑器主题'
|
||||
]);
|
||||
// 计算属性
|
||||
const autoCheckUpdates = computed({
|
||||
get: () => configStore.config.updates.autoUpdate,
|
||||
set: async (value: boolean) => {
|
||||
await configStore.setAutoUpdate(value);
|
||||
}
|
||||
});
|
||||
|
||||
// 自动检查更新选项
|
||||
const autoCheckUpdates = ref(true);
|
||||
// 格式化发布说明
|
||||
const formatReleaseNotes = (notes: string) => {
|
||||
if (!notes) return [];
|
||||
|
||||
// 模拟检查更新
|
||||
const checkForUpdates = () => {
|
||||
isCheckingForUpdates.value = true;
|
||||
|
||||
// 模拟网络请求延迟
|
||||
setTimeout(() => {
|
||||
isCheckingForUpdates.value = false;
|
||||
updateAvailable.value = true;
|
||||
}, 1500);
|
||||
// 简单的Markdown列表解析
|
||||
return notes
|
||||
.split('\n')
|
||||
.filter(line => line.trim().startsWith('-') || line.trim().startsWith('*'))
|
||||
.map(line => line.replace(/^[\s\-\*]+/, '').trim())
|
||||
.filter(line => line.length > 0);
|
||||
};
|
||||
|
||||
// 模拟下载更新
|
||||
const downloadUpdate = () => {
|
||||
// 在实际应用中这里会调用后端API下载更新
|
||||
alert('开始下载更新...');
|
||||
// 处理查看更新
|
||||
const viewUpdate = () => {
|
||||
updateStore.openReleaseURL();
|
||||
};
|
||||
|
||||
// 获取错误信息的国际化文本
|
||||
const getErrorMessage = (error: string) => {
|
||||
if (error.includes('Network') || error.includes('network')) {
|
||||
return t('settings.networkError');
|
||||
}
|
||||
return error;
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="settings-page">
|
||||
<SettingSection :title="t('settings.updates')">
|
||||
<div class="update-info">
|
||||
<div class="version-info">
|
||||
<div class="current-version">
|
||||
<span class="label">当前版本:</span>
|
||||
<span class="version">{{ currentVersion }}</span>
|
||||
<!-- 自动更新设置 -->
|
||||
<SettingSection :title="t('settings.updateSettings')">
|
||||
<SettingItem
|
||||
:title="t('settings.autoCheckUpdates')"
|
||||
:description="t('settings.autoCheckUpdatesDescription')"
|
||||
>
|
||||
<ToggleSwitch v-model="autoCheckUpdates"/>
|
||||
</SettingItem>
|
||||
</SettingSection>
|
||||
|
||||
<!-- 手动检查更新 -->
|
||||
<SettingSection :title="t('settings.manualCheck')">
|
||||
<SettingItem
|
||||
:title="`${t('settings.currentVersion')}: ${updateStore.updateResult?.currentVer || configStore.config.updates.version}`"
|
||||
>
|
||||
<button
|
||||
class="check-button"
|
||||
@click="updateStore.checkForUpdates"
|
||||
:disabled="updateStore.isChecking"
|
||||
>
|
||||
<span v-if="updateStore.isChecking" class="loading-spinner"></span>
|
||||
{{ updateStore.isChecking ? t('settings.checking') : t('settings.checkForUpdates') }}
|
||||
</button>
|
||||
</SettingItem>
|
||||
|
||||
<!-- 检查结果 -->
|
||||
<div class="check-results" v-if="updateStore.updateResult || updateStore.errorMessage">
|
||||
<!-- 错误信息 -->
|
||||
<div v-if="updateStore.errorMessage" class="result-item error-result">
|
||||
<div class="result-text">
|
||||
<span class="result-icon">⚠️</span>
|
||||
<span class="result-message">{{ getErrorMessage(updateStore.errorMessage) }}</span>
|
||||
</div>
|
||||
|
||||
<button
|
||||
class="check-button"
|
||||
@click="checkForUpdates"
|
||||
:disabled="isCheckingForUpdates"
|
||||
>
|
||||
<span v-if="isCheckingForUpdates" class="loading-spinner"></span>
|
||||
{{ isCheckingForUpdates ? '检查中...' : '检查更新' }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-if="updateAvailable" class="update-available">
|
||||
<div class="update-header">
|
||||
<div class="update-title">发现新版本: {{ latestVersion }}</div>
|
||||
<button class="download-button" @click="downloadUpdate">
|
||||
下载更新
|
||||
|
||||
<!-- 有新版本 -->
|
||||
<div v-else-if="updateStore.hasUpdate" class="result-item update-result">
|
||||
<div class="result-header">
|
||||
<div class="result-text">
|
||||
<span class="result-icon">🎉</span>
|
||||
<span class="result-message">
|
||||
{{ t('settings.newVersionAvailable') }}: {{ updateStore.updateResult?.latestVer }}
|
||||
</span>
|
||||
</div>
|
||||
<button class="view-button" @click="viewUpdate">
|
||||
{{ t('settings.viewUpdate') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="update-notes">
|
||||
<div class="notes-title">更新内容:</div>
|
||||
<ul class="notes-list">
|
||||
<li v-for="(note, index) in updateNotes" :key="index">
|
||||
<div v-if="updateStore.updateResult?.releaseNotes" class="release-notes">
|
||||
<div class="notes-title">{{ t('settings.releaseNotes') }}:</div>
|
||||
<ul class="notes-list" v-if="formatReleaseNotes(updateStore.updateResult.releaseNotes).length > 0">
|
||||
<li v-for="(note, index) in formatReleaseNotes(updateStore.updateResult.releaseNotes)" :key="index">
|
||||
{{ note }}
|
||||
</li>
|
||||
</ul>
|
||||
<div v-else class="notes-text">
|
||||
{{ updateStore.updateResult.releaseNotes }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 已是最新版本 -->
|
||||
<div v-else-if="updateStore.updateResult && !updateStore.hasUpdate && !updateStore.errorMessage"
|
||||
class="result-item success-result">
|
||||
<div class="result-text">
|
||||
<span class="result-icon">✅</span>
|
||||
<span class="result-message">{{ t('settings.upToDate') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<SettingItem title="自动检查更新" description="启动应用时自动检查更新">
|
||||
<ToggleSwitch v-model="autoCheckUpdates" />
|
||||
</SettingItem>
|
||||
</SettingSection>
|
||||
</div>
|
||||
</template>
|
||||
@@ -91,133 +127,167 @@ const downloadUpdate = () => {
|
||||
max-width: 800px;
|
||||
}
|
||||
|
||||
.update-info {
|
||||
padding: 15px 16px;
|
||||
margin-bottom: 20px;
|
||||
.check-button {
|
||||
padding: 8px 16px;
|
||||
background-color: var(--settings-input-bg);
|
||||
border: 1px solid var(--settings-input-border);
|
||||
border-radius: 4px;
|
||||
color: var(--settings-text);
|
||||
cursor: pointer;
|
||||
font-size: 12px;
|
||||
transition: all 0.2s ease;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
|
||||
&:hover:not(:disabled) {
|
||||
background-color: var(--settings-hover);
|
||||
border-color: var(--settings-border);
|
||||
}
|
||||
|
||||
&:active:not(:disabled) {
|
||||
transform: translateY(1px);
|
||||
}
|
||||
|
||||
&:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.loading-spinner {
|
||||
display: inline-block;
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
border: 2px solid rgba(255, 255, 255, 0.3);
|
||||
border-radius: 50%;
|
||||
border-top-color: var(--settings-text);
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.check-results {
|
||||
padding: 0 16px;
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
.result-item {
|
||||
padding: 12px 0;
|
||||
|
||||
.version-info {
|
||||
.result-text {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 13px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.result-icon {
|
||||
font-size: 16px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.result-message {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.result-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 20px;
|
||||
|
||||
.current-version {
|
||||
font-size: 13px;
|
||||
|
||||
.label {
|
||||
color: var(--text-muted);
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
.version {
|
||||
color: var(--settings-text);
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
|
||||
.check-button {
|
||||
padding: 8px 16px;
|
||||
margin-bottom: 8px;
|
||||
|
||||
.view-button {
|
||||
padding: 4px 12px;
|
||||
background-color: var(--settings-input-bg);
|
||||
border: 1px solid var(--settings-input-border);
|
||||
border-radius: 4px;
|
||||
color: var(--settings-text);
|
||||
cursor: pointer;
|
||||
font-size: 12px;
|
||||
font-size: 11px;
|
||||
transition: all 0.2s ease;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
|
||||
&:hover:not(:disabled) {
|
||||
flex-shrink: 0;
|
||||
|
||||
&:hover {
|
||||
background-color: var(--settings-hover);
|
||||
border-color: var(--settings-border);
|
||||
}
|
||||
|
||||
&:active:not(:disabled) {
|
||||
|
||||
&:active {
|
||||
transform: translateY(1px);
|
||||
}
|
||||
|
||||
&:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.loading-spinner {
|
||||
display: inline-block;
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
border: 2px solid rgba(255, 255, 255, 0.3);
|
||||
border-radius: 50%;
|
||||
border-top-color: var(--settings-text);
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.update-available {
|
||||
background-color: var(--settings-card-bg);
|
||||
border: 1px solid var(--settings-border);
|
||||
border-radius: 6px;
|
||||
padding: 16px;
|
||||
|
||||
.update-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 16px;
|
||||
|
||||
.release-notes {
|
||||
margin-top: 8px;
|
||||
padding-left: 24px;
|
||||
|
||||
.notes-title {
|
||||
font-size: 12px;
|
||||
color: var(--text-muted);
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.notes-list {
|
||||
margin: 0;
|
||||
padding-left: 16px;
|
||||
|
||||
.update-title {
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
color: #4a9eff;
|
||||
}
|
||||
|
||||
.download-button {
|
||||
padding: 8px 16px;
|
||||
background-color: #2c5a9e;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
color: #ffffff;
|
||||
cursor: pointer;
|
||||
li {
|
||||
font-size: 12px;
|
||||
transition: all 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
background-color: #3867a9;
|
||||
}
|
||||
|
||||
&:active {
|
||||
transform: translateY(1px);
|
||||
color: var(--settings-text-secondary);
|
||||
line-height: 1.4;
|
||||
margin-bottom: 3px;
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.update-notes {
|
||||
.notes-title {
|
||||
font-size: 12px;
|
||||
color: var(--settings-text-secondary);
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.notes-list {
|
||||
margin: 0;
|
||||
padding-left: 20px;
|
||||
|
||||
li {
|
||||
font-size: 12px;
|
||||
color: var(--settings-text-secondary);
|
||||
margin-bottom: 6px;
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.notes-text {
|
||||
font-size: 12px;
|
||||
color: var(--settings-text-secondary);
|
||||
line-height: 1.4;
|
||||
white-space: pre-wrap;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.error-result {
|
||||
.result-message {
|
||||
color: #f44336;
|
||||
}
|
||||
|
||||
.result-icon {
|
||||
color: #f44336;
|
||||
}
|
||||
}
|
||||
|
||||
.update-result {
|
||||
.result-message {
|
||||
color: #2196f3;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.result-icon {
|
||||
color: #2196f3;
|
||||
}
|
||||
}
|
||||
|
||||
.success-result {
|
||||
.result-message {
|
||||
color: #4caf50;
|
||||
}
|
||||
|
||||
.result-icon {
|
||||
color: #4caf50;
|
||||
}
|
||||
}
|
||||
</style>
|
2
go.mod
2
go.mod
@@ -6,6 +6,7 @@ toolchain go1.24.2
|
||||
|
||||
require (
|
||||
github.com/Masterminds/semver/v3 v3.3.1
|
||||
github.com/google/go-github/v63 v63.0.0
|
||||
github.com/knadh/koanf/parsers/json v1.0.0
|
||||
github.com/knadh/koanf/providers/file v1.2.0
|
||||
github.com/knadh/koanf/providers/structs v1.0.0
|
||||
@@ -33,6 +34,7 @@ require (
|
||||
github.com/go-viper/mapstructure/v2 v2.3.0 // indirect
|
||||
github.com/godbus/dbus/v5 v5.1.0 // indirect
|
||||
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
|
||||
github.com/google/go-querystring v1.1.0 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
|
||||
github.com/jchv/go-winloader v0.0.0-20250406163304-c1995be93bd1 // indirect
|
||||
|
6
go.sum
6
go.sum
@@ -50,8 +50,13 @@ github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
|
||||
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 h1:f+oWsMOmNPc8JmEHVZIycC7hBoQxHH9pNKQORJNozsQ=
|
||||
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8/go.mod h1:wcDNUvekVysuuOpQKo3191zZyTpiI6se1N1ULghS0sw=
|
||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||
github.com/google/go-github/v63 v63.0.0 h1:13xwK/wk9alSokujB9lJkuzdmQuVn2QCPeck76wR3nE=
|
||||
github.com/google/go-github/v63 v63.0.0/go.mod h1:IqbcrgUmIcEaioWrGYei/09o+ge5vhffGOcxrO0AfmA=
|
||||
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
|
||||
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
|
||||
@@ -156,6 +161,7 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M=
|
||||
golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
|
@@ -84,9 +84,8 @@ type AppearanceConfig struct {
|
||||
|
||||
// UpdatesConfig 更新设置配置
|
||||
type UpdatesConfig struct {
|
||||
Version string `json:"version"` // 当前版本号
|
||||
AutoUpdate bool `json:"autoUpdate"` // 是否自动更新
|
||||
BetaChannel bool `json:"betaChannel"` // 是否启用测试版
|
||||
Version string `json:"version"` // 当前版本号
|
||||
AutoUpdate bool `json:"autoUpdate"` // 是否自动更新
|
||||
}
|
||||
|
||||
// AppConfig 应用配置 - 按照前端设置页面分类组织
|
||||
@@ -143,9 +142,8 @@ func NewDefaultAppConfig() *AppConfig {
|
||||
SystemTheme: SystemThemeAuto, // 默认使用深色系统主题
|
||||
},
|
||||
Updates: UpdatesConfig{
|
||||
Version: "1.0.0",
|
||||
AutoUpdate: true,
|
||||
BetaChannel: false,
|
||||
Version: "1.0.0",
|
||||
AutoUpdate: true,
|
||||
},
|
||||
Metadata: ConfigMetadata{
|
||||
LastUpdated: time.Now().Format(time.RFC3339),
|
||||
|
220
internal/models/extensions.go
Normal file
220
internal/models/extensions.go
Normal file
@@ -0,0 +1,220 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
// Extension 单个扩展配置
|
||||
type Extension struct {
|
||||
ID ExtensionID `json:"id"` // 扩展唯一标识
|
||||
Category ExtensionCategory `json:"category"` // 扩展分类
|
||||
Enabled bool `json:"enabled"` // 是否启用
|
||||
IsDefault bool `json:"isDefault"` // 是否为默认扩展
|
||||
Config ExtensionConfig `json:"config"` // 扩展配置项
|
||||
}
|
||||
|
||||
// ExtensionID 扩展标识符
|
||||
type ExtensionID string
|
||||
|
||||
const (
|
||||
// 编辑增强扩展
|
||||
ExtensionRainbowBrackets ExtensionID = "rainbowBrackets" // 彩虹括号
|
||||
ExtensionHyperlink ExtensionID = "hyperlink" // 超链接
|
||||
ExtensionColorSelector ExtensionID = "colorSelector" // 颜色选择器
|
||||
ExtensionFold ExtensionID = "fold"
|
||||
ExtensionTextHighlight ExtensionID = "textHighlight"
|
||||
|
||||
// UI增强扩展
|
||||
ExtensionMinimap ExtensionID = "minimap" // 小地图
|
||||
ExtensionCodeBlast ExtensionID = "codeBlast" // 代码爆炸效果
|
||||
|
||||
// 工具扩展
|
||||
ExtensionSearch ExtensionID = "search" // 搜索功能
|
||||
ExtensionCodeBlock ExtensionID = "codeBlock" // 代码块
|
||||
)
|
||||
|
||||
// ExtensionCategory 扩展分类
|
||||
type ExtensionCategory string
|
||||
|
||||
const (
|
||||
CategoryEditing ExtensionCategory = "editing" // 编辑增强
|
||||
CategoryUI ExtensionCategory = "ui" // 界面增强
|
||||
CategoryTools ExtensionCategory = "tools" // 工具类
|
||||
)
|
||||
|
||||
// ExtensionConfig 扩展配置项(动态配置)
|
||||
type ExtensionConfig map[string]interface{}
|
||||
|
||||
// ExtensionMetadata 扩展配置元数据
|
||||
type ExtensionMetadata struct {
|
||||
Version string `json:"version"` // 配置版本
|
||||
LastUpdated string `json:"lastUpdated"` // 最后更新时间
|
||||
}
|
||||
|
||||
// ExtensionSettings 扩展设置配置
|
||||
type ExtensionSettings struct {
|
||||
Extensions []Extension `json:"extensions"` // 扩展列表
|
||||
Metadata ExtensionMetadata `json:"metadata"` // 配置元数据
|
||||
}
|
||||
|
||||
// NewDefaultExtensionSettings 创建默认扩展配置
|
||||
func NewDefaultExtensionSettings() *ExtensionSettings {
|
||||
return &ExtensionSettings{
|
||||
Extensions: NewDefaultExtensions(),
|
||||
Metadata: ExtensionMetadata{
|
||||
Version: "1.0.0",
|
||||
LastUpdated: time.Now().Format(time.RFC3339),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// NewDefaultExtensions 创建默认扩展配置
|
||||
func NewDefaultExtensions() []Extension {
|
||||
return []Extension{
|
||||
// 编辑增强扩展
|
||||
{
|
||||
ID: ExtensionRainbowBrackets,
|
||||
Category: CategoryEditing,
|
||||
Enabled: true,
|
||||
IsDefault: true,
|
||||
Config: ExtensionConfig{},
|
||||
},
|
||||
{
|
||||
ID: ExtensionHyperlink,
|
||||
Category: CategoryEditing,
|
||||
Enabled: true,
|
||||
IsDefault: true,
|
||||
Config: ExtensionConfig{},
|
||||
},
|
||||
{
|
||||
ID: ExtensionColorSelector,
|
||||
Category: CategoryEditing,
|
||||
Enabled: true,
|
||||
IsDefault: true,
|
||||
Config: ExtensionConfig{},
|
||||
},
|
||||
|
||||
// UI增强扩展
|
||||
{
|
||||
ID: ExtensionMinimap,
|
||||
Category: CategoryUI,
|
||||
Enabled: true,
|
||||
IsDefault: true,
|
||||
Config: ExtensionConfig{
|
||||
"displayText": "characters",
|
||||
"showOverlay": "always",
|
||||
"autohide": false,
|
||||
},
|
||||
},
|
||||
{
|
||||
ID: ExtensionCodeBlast,
|
||||
Category: CategoryUI,
|
||||
Enabled: true,
|
||||
IsDefault: true,
|
||||
Config: ExtensionConfig{
|
||||
"effect": 1,
|
||||
"shake": true,
|
||||
"maxParticles": 300,
|
||||
"shakeIntensity": 3,
|
||||
},
|
||||
},
|
||||
|
||||
// 工具扩展
|
||||
{
|
||||
ID: ExtensionSearch,
|
||||
Category: CategoryTools,
|
||||
Enabled: true,
|
||||
IsDefault: true,
|
||||
Config: ExtensionConfig{},
|
||||
},
|
||||
{
|
||||
ID: ExtensionCodeBlock,
|
||||
Category: CategoryTools,
|
||||
Enabled: true,
|
||||
IsDefault: true,
|
||||
Config: ExtensionConfig{
|
||||
"showBackground": true,
|
||||
"enableAutoDetection": true,
|
||||
},
|
||||
},
|
||||
{
|
||||
ID: ExtensionFold,
|
||||
Category: CategoryEditing,
|
||||
Enabled: true,
|
||||
IsDefault: true,
|
||||
Config: ExtensionConfig{},
|
||||
},
|
||||
{
|
||||
ID: ExtensionTextHighlight,
|
||||
Category: CategoryEditing,
|
||||
Enabled: true,
|
||||
IsDefault: true,
|
||||
Config: ExtensionConfig{},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// GetVersion 获取配置版本
|
||||
func (es *ExtensionSettings) GetVersion() string {
|
||||
return es.Metadata.Version
|
||||
}
|
||||
|
||||
// SetVersion 设置配置版本
|
||||
func (es *ExtensionSettings) SetVersion(version string) {
|
||||
es.Metadata.Version = version
|
||||
}
|
||||
|
||||
// SetLastUpdated 设置最后更新时间
|
||||
func (es *ExtensionSettings) SetLastUpdated(timeStr string) {
|
||||
es.Metadata.LastUpdated = timeStr
|
||||
}
|
||||
|
||||
// GetDefaultConfig 获取默认配置
|
||||
func (es *ExtensionSettings) GetDefaultConfig() any {
|
||||
return NewDefaultExtensionSettings()
|
||||
}
|
||||
|
||||
// GetExtensionByID 根据ID获取扩展
|
||||
func (es *ExtensionSettings) GetExtensionByID(id ExtensionID) *Extension {
|
||||
for i := range es.Extensions {
|
||||
if es.Extensions[i].ID == id {
|
||||
return &es.Extensions[i]
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetEnabledExtensions 获取所有启用的扩展
|
||||
func (es *ExtensionSettings) GetEnabledExtensions() []Extension {
|
||||
var enabled []Extension
|
||||
for _, ext := range es.Extensions {
|
||||
if ext.Enabled {
|
||||
enabled = append(enabled, ext)
|
||||
}
|
||||
}
|
||||
return enabled
|
||||
}
|
||||
|
||||
// GetExtensionsByCategory 根据分类获取扩展
|
||||
func (es *ExtensionSettings) GetExtensionsByCategory(category ExtensionCategory) []Extension {
|
||||
var extensions []Extension
|
||||
for _, ext := range es.Extensions {
|
||||
if ext.Category == category {
|
||||
extensions = append(extensions, ext)
|
||||
}
|
||||
}
|
||||
return extensions
|
||||
}
|
||||
|
||||
// UpdateExtension 更新扩展配置
|
||||
func (es *ExtensionSettings) UpdateExtension(id ExtensionID, enabled bool, config ExtensionConfig) bool {
|
||||
for i := range es.Extensions {
|
||||
if es.Extensions[i].ID == id {
|
||||
es.Extensions[i].Enabled = enabled
|
||||
if config != nil {
|
||||
es.Extensions[i].Config = config
|
||||
}
|
||||
es.SetLastUpdated(time.Now().Format(time.RFC3339))
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
@@ -22,6 +22,9 @@ const (
|
||||
CurrentAppConfigVersion = "1.0.0"
|
||||
// CurrentKeyBindingConfigVersion 当前快捷键配置版本
|
||||
CurrentKeyBindingConfigVersion = "1.0.0"
|
||||
|
||||
CurrentExtensionConfigVersion = "1.0.0"
|
||||
|
||||
// BackupFilePattern 备份文件名模式
|
||||
BackupFilePattern = "%s.backup.%s.json"
|
||||
|
||||
@@ -323,3 +326,9 @@ func NewKeyBindingMigrationService(logger *log.LoggerService, pathManager *PathM
|
||||
return NewConfigMigrationService[*models.KeyBindingConfig](
|
||||
logger, pathManager, "keybindings", CurrentKeyBindingConfigVersion, pathManager.GetKeybindsPath())
|
||||
}
|
||||
|
||||
// NewExtensionMigrationService 创建扩展配置迁移服务
|
||||
func NewExtensionMigrationService(logger *log.LoggerService, pathManager *PathManager) *ConfigMigrationService[*models.ExtensionSettings] {
|
||||
return NewConfigMigrationService[*models.ExtensionSettings](
|
||||
logger, pathManager, "extensions", CurrentExtensionConfigVersion, pathManager.GetExtensionsPath())
|
||||
}
|
||||
|
278
internal/services/extension_service.go
Normal file
278
internal/services/extension_service.go
Normal file
@@ -0,0 +1,278 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"sync"
|
||||
"voidraft/internal/models"
|
||||
|
||||
jsonparser "github.com/knadh/koanf/parsers/json"
|
||||
"github.com/knadh/koanf/providers/file"
|
||||
"github.com/knadh/koanf/providers/structs"
|
||||
"github.com/knadh/koanf/v2"
|
||||
"github.com/wailsapp/wails/v3/pkg/services/log"
|
||||
)
|
||||
|
||||
// ExtensionService 扩展管理服务
|
||||
type ExtensionService struct {
|
||||
koanf *koanf.Koanf
|
||||
logger *log.LoggerService
|
||||
pathManager *PathManager
|
||||
fileProvider *file.File
|
||||
|
||||
mu sync.RWMutex
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
initOnce sync.Once
|
||||
|
||||
// 配置迁移服务
|
||||
migrationService *ConfigMigrationService[*models.ExtensionSettings]
|
||||
}
|
||||
|
||||
// ExtensionError 扩展错误
|
||||
type ExtensionError struct {
|
||||
Operation string
|
||||
Extension string
|
||||
Err error
|
||||
}
|
||||
|
||||
func (e *ExtensionError) Error() string {
|
||||
if e.Extension != "" {
|
||||
return fmt.Sprintf("extension %s for %s: %v", e.Operation, e.Extension, e.Err)
|
||||
}
|
||||
return fmt.Sprintf("extension %s: %v", e.Operation, e.Err)
|
||||
}
|
||||
|
||||
func (e *ExtensionError) Unwrap() error {
|
||||
return e.Err
|
||||
}
|
||||
|
||||
func (e *ExtensionError) Is(target error) bool {
|
||||
var extensionError *ExtensionError
|
||||
return errors.As(target, &extensionError)
|
||||
}
|
||||
|
||||
// NewExtensionService 创建扩展服务实例
|
||||
func NewExtensionService(logger *log.LoggerService, pathManager *PathManager) *ExtensionService {
|
||||
if logger == nil {
|
||||
logger = log.New()
|
||||
}
|
||||
if pathManager == nil {
|
||||
pathManager = NewPathManager()
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
k := koanf.New(".")
|
||||
|
||||
migrationService := NewExtensionMigrationService(logger, pathManager)
|
||||
|
||||
service := &ExtensionService{
|
||||
koanf: k,
|
||||
logger: logger,
|
||||
pathManager: pathManager,
|
||||
ctx: ctx,
|
||||
cancel: cancel,
|
||||
migrationService: migrationService,
|
||||
}
|
||||
|
||||
// 异步初始化
|
||||
go service.initialize()
|
||||
|
||||
return service
|
||||
}
|
||||
|
||||
// initialize 初始化配置
|
||||
func (es *ExtensionService) initialize() {
|
||||
es.initOnce.Do(func() {
|
||||
if err := es.initConfig(); err != nil {
|
||||
es.logger.Error("failed to initialize extension config", "error", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// setDefaults 设置默认值
|
||||
func (es *ExtensionService) setDefaults() error {
|
||||
defaultConfig := models.NewDefaultExtensionSettings()
|
||||
|
||||
if err := es.koanf.Load(structs.Provider(defaultConfig, "json"), nil); err != nil {
|
||||
return &ExtensionError{"load_defaults", "", err}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// initConfig 初始化配置
|
||||
func (es *ExtensionService) initConfig() error {
|
||||
es.mu.Lock()
|
||||
defer es.mu.Unlock()
|
||||
|
||||
// 检查配置文件是否存在
|
||||
configPath := es.pathManager.GetExtensionsPath()
|
||||
if _, err := os.Stat(configPath); os.IsNotExist(err) {
|
||||
return es.createDefaultConfig()
|
||||
}
|
||||
|
||||
// 配置文件存在,先加载现有配置
|
||||
es.fileProvider = file.Provider(configPath)
|
||||
if err := es.koanf.Load(es.fileProvider, jsonparser.Parser()); err != nil {
|
||||
return &ExtensionError{"load_config_file", "", err}
|
||||
}
|
||||
|
||||
// 检查并执行配置迁移
|
||||
if es.migrationService != nil {
|
||||
result, err := es.migrationService.MigrateConfig(es.koanf)
|
||||
if err != nil {
|
||||
return &ExtensionError{"migrate_config", "", err}
|
||||
}
|
||||
|
||||
if result.Migrated && result.ConfigUpdated {
|
||||
// 迁移完成且配置已更新,重新创建文件提供器以监听新文件
|
||||
es.fileProvider = file.Provider(configPath)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// createDefaultConfig 创建默认配置文件
|
||||
func (es *ExtensionService) createDefaultConfig() error {
|
||||
if err := es.pathManager.EnsureConfigDir(); err != nil {
|
||||
return &ExtensionError{"create_config_dir", "", err}
|
||||
}
|
||||
|
||||
if err := es.setDefaults(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
configBytes, err := es.koanf.Marshal(jsonparser.Parser())
|
||||
if err != nil {
|
||||
return &ExtensionError{"marshal_config", "", err}
|
||||
}
|
||||
|
||||
if err := os.WriteFile(es.pathManager.GetExtensionsPath(), configBytes, 0644); err != nil {
|
||||
return &ExtensionError{"write_config", "", err}
|
||||
}
|
||||
|
||||
// 创建文件提供器
|
||||
es.fileProvider = file.Provider(es.pathManager.GetExtensionsPath())
|
||||
if err = es.koanf.Load(es.fileProvider, jsonparser.Parser()); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// saveConfig 保存配置到文件
|
||||
func (es *ExtensionService) saveExtensionConfig() error {
|
||||
configBytes, err := es.koanf.Marshal(jsonparser.Parser())
|
||||
if err != nil {
|
||||
return &ExtensionError{"marshal_config", "", err}
|
||||
}
|
||||
|
||||
if err := os.WriteFile(es.pathManager.GetExtensionsPath(), configBytes, 0644); err != nil {
|
||||
return &ExtensionError{"write_config", "", err}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetExtensionSettings 获取完整扩展配置
|
||||
func (es *ExtensionService) GetExtensionSettings() (*models.ExtensionSettings, error) {
|
||||
es.mu.RLock()
|
||||
defer es.mu.RUnlock()
|
||||
|
||||
var settings models.ExtensionSettings
|
||||
if err := es.koanf.Unmarshal("", &settings); err != nil {
|
||||
return nil, &ExtensionError{"unmarshal_config", "", err}
|
||||
}
|
||||
return &settings, nil
|
||||
}
|
||||
|
||||
// GetAllExtensions 获取所有扩展配置
|
||||
func (es *ExtensionService) GetAllExtensions() ([]models.Extension, error) {
|
||||
settings, err := es.GetExtensionSettings()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return settings.Extensions, nil
|
||||
}
|
||||
|
||||
// EnableExtension 启用扩展
|
||||
func (es *ExtensionService) EnableExtension(id models.ExtensionID) error {
|
||||
return es.UpdateExtensionState(id, true, nil)
|
||||
}
|
||||
|
||||
// DisableExtension 禁用扩展
|
||||
func (es *ExtensionService) DisableExtension(id models.ExtensionID) error {
|
||||
return es.UpdateExtensionState(id, false, nil)
|
||||
}
|
||||
|
||||
// UpdateExtensionState 更新扩展状态
|
||||
func (es *ExtensionService) UpdateExtensionState(id models.ExtensionID, enabled bool, config models.ExtensionConfig) error {
|
||||
es.mu.Lock()
|
||||
defer es.mu.Unlock()
|
||||
|
||||
// 获取当前配置
|
||||
var settings models.ExtensionSettings
|
||||
if err := es.koanf.Unmarshal("", &settings); err != nil {
|
||||
return &ExtensionError{"unmarshal_config", string(id), err}
|
||||
}
|
||||
|
||||
// 更新扩展状态
|
||||
if !settings.UpdateExtension(id, enabled, config) {
|
||||
return &ExtensionError{"extension_not_found", string(id), nil}
|
||||
}
|
||||
|
||||
// 重新加载到koanf
|
||||
if err := es.koanf.Load(structs.Provider(&settings, "json"), nil); err != nil {
|
||||
return &ExtensionError{"reload_config", string(id), err}
|
||||
}
|
||||
|
||||
// 保存到文件
|
||||
if err := es.saveExtensionConfig(); err != nil {
|
||||
return &ExtensionError{"save_config", string(id), err}
|
||||
}
|
||||
|
||||
es.logger.Info("extension state updated", "id", id, "enabled", enabled)
|
||||
return nil
|
||||
}
|
||||
|
||||
// ResetExtensionToDefault 重置扩展到默认状态
|
||||
func (es *ExtensionService) ResetExtensionToDefault(id models.ExtensionID) error {
|
||||
// 获取默认配置
|
||||
defaultSettings := models.NewDefaultExtensionSettings()
|
||||
defaultExtension := defaultSettings.GetExtensionByID(id)
|
||||
if defaultExtension == nil {
|
||||
return &ExtensionError{"default_extension_not_found", string(id), nil}
|
||||
}
|
||||
|
||||
return es.UpdateExtensionState(id, defaultExtension.Enabled, defaultExtension.Config)
|
||||
}
|
||||
|
||||
// ResetAllExtensionsToDefault 重置所有扩展到默认状态
|
||||
func (es *ExtensionService) ResetAllExtensionsToDefault() error {
|
||||
es.mu.Lock()
|
||||
defer es.mu.Unlock()
|
||||
|
||||
// 加载默认配置
|
||||
defaultSettings := models.NewDefaultExtensionSettings()
|
||||
if err := es.koanf.Load(structs.Provider(defaultSettings, "json"), nil); err != nil {
|
||||
return &ExtensionError{"load_defaults", "", err}
|
||||
}
|
||||
|
||||
// 保存到文件
|
||||
if err := es.saveExtensionConfig(); err != nil {
|
||||
return &ExtensionError{"save_config", "", err}
|
||||
}
|
||||
|
||||
es.logger.Info("all extensions reset to default")
|
||||
return nil
|
||||
}
|
||||
|
||||
// ServiceShutdown 关闭服务
|
||||
func (es *ExtensionService) ServiceShutdown() error {
|
||||
es.cancel()
|
||||
return nil
|
||||
}
|
@@ -1,84 +0,0 @@
|
||||
//go:build !windows && !darwin && !linux
|
||||
|
||||
package services
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"voidraft/internal/models"
|
||||
|
||||
"github.com/wailsapp/wails/v3/pkg/application"
|
||||
"github.com/wailsapp/wails/v3/pkg/services/log"
|
||||
)
|
||||
|
||||
// HotkeyService 存根热键服务
|
||||
type HotkeyService struct {
|
||||
logger *log.LoggerService
|
||||
configService *ConfigService
|
||||
}
|
||||
|
||||
// HotkeyError 热键错误
|
||||
type HotkeyError struct {
|
||||
Operation string
|
||||
Err error
|
||||
}
|
||||
|
||||
// Error 实现error接口
|
||||
func (e *HotkeyError) Error() string {
|
||||
return fmt.Sprintf("hotkey %s: %v", e.Operation, e.Err)
|
||||
}
|
||||
|
||||
// Unwrap 获取原始错误
|
||||
func (e *HotkeyError) Unwrap() error {
|
||||
return e.Err
|
||||
}
|
||||
|
||||
// NewHotkeyService 创建热键服务实例
|
||||
func NewHotkeyService(configService *ConfigService, logger *log.LoggerService) *HotkeyService {
|
||||
if logger == nil {
|
||||
logger = log.New()
|
||||
}
|
||||
|
||||
return &HotkeyService{
|
||||
logger: logger,
|
||||
configService: configService,
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize 初始化热键服务
|
||||
func (hs *HotkeyService) Initialize(app *application.App) error {
|
||||
hs.logger.Warning("Global hotkey is not supported on this platform")
|
||||
return nil
|
||||
}
|
||||
|
||||
// RegisterHotkey 注册全局热键
|
||||
func (hs *HotkeyService) RegisterHotkey(hotkey *models.HotkeyCombo) error {
|
||||
return &HotkeyError{"register", fmt.Errorf("not supported on this platform")}
|
||||
}
|
||||
|
||||
// UnregisterHotkey 取消注册全局热键
|
||||
func (hs *HotkeyService) UnregisterHotkey() error {
|
||||
return &HotkeyError{"unregister", fmt.Errorf("not supported on this platform")}
|
||||
}
|
||||
|
||||
// UpdateHotkey 更新热键配置
|
||||
func (hs *HotkeyService) UpdateHotkey(enable bool, hotkey *models.HotkeyCombo) error {
|
||||
if enable {
|
||||
return hs.RegisterHotkey(hotkey)
|
||||
}
|
||||
return hs.UnregisterHotkey()
|
||||
}
|
||||
|
||||
// GetCurrentHotkey 获取当前热键
|
||||
func (hs *HotkeyService) GetCurrentHotkey() *models.HotkeyCombo {
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsRegistered 检查是否已注册
|
||||
func (hs *HotkeyService) IsRegistered() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// ServiceShutdown 关闭服务
|
||||
func (hs *HotkeyService) ServiceShutdown() error {
|
||||
return nil
|
||||
}
|
@@ -7,9 +7,10 @@ import (
|
||||
|
||||
// PathManager 路径管理器
|
||||
type PathManager struct {
|
||||
configDir string // 配置目录
|
||||
settingsPath string // 设置文件路径
|
||||
keybindsPath string // 快捷键配置文件路径
|
||||
configDir string // 配置目录
|
||||
settingsPath string // 设置文件路径
|
||||
keybindsPath string // 快捷键配置文件路径
|
||||
extensionsPath string // 扩展配置文件路径
|
||||
}
|
||||
|
||||
// NewPathManager 创建新的路径管理器
|
||||
@@ -25,9 +26,10 @@ func NewPathManager() *PathManager {
|
||||
configDir := filepath.Join(userConfigDir, ".voidraft", "config")
|
||||
|
||||
return &PathManager{
|
||||
configDir: configDir,
|
||||
settingsPath: filepath.Join(configDir, "settings.json"),
|
||||
keybindsPath: filepath.Join(configDir, "keybindings.json"),
|
||||
configDir: configDir,
|
||||
settingsPath: filepath.Join(configDir, "settings.json"),
|
||||
keybindsPath: filepath.Join(configDir, "keybindings.json"),
|
||||
extensionsPath: filepath.Join(configDir, "extensions.json"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +48,11 @@ func (pm *PathManager) GetConfigDir() string {
|
||||
return pm.configDir
|
||||
}
|
||||
|
||||
// GetExtensionsPath 获取扩展配置文件路径
|
||||
func (pm *PathManager) GetExtensionsPath() string {
|
||||
return pm.extensionsPath
|
||||
}
|
||||
|
||||
// EnsureConfigDir 确保配置目录存在
|
||||
func (pm *PathManager) EnsureConfigDir() error {
|
||||
return os.MkdirAll(pm.configDir, 0755)
|
||||
|
@@ -18,7 +18,9 @@ type ServiceManager struct {
|
||||
dialogService *DialogService
|
||||
trayService *TrayService
|
||||
keyBindingService *KeyBindingService
|
||||
extensionService *ExtensionService
|
||||
startupService *StartupService
|
||||
updateService *UpdateService
|
||||
logger *log.LoggerService
|
||||
}
|
||||
|
||||
@@ -54,9 +56,15 @@ func NewServiceManager() *ServiceManager {
|
||||
// 初始化快捷键服务
|
||||
keyBindingService := NewKeyBindingService(logger, pathManager)
|
||||
|
||||
// 初始化扩展服务
|
||||
extensionService := NewExtensionService(logger, pathManager)
|
||||
|
||||
// 初始化开机启动服务
|
||||
startupService := NewStartupService(configService, logger)
|
||||
|
||||
// 初始化更新服务
|
||||
updateService := NewUpdateService(configService, logger)
|
||||
|
||||
// 使用新的配置通知系统设置热键配置变更监听
|
||||
err := configService.SetHotkeyChangeCallback(func(enable bool, hotkey *models.HotkeyCombo) error {
|
||||
return hotkeyService.UpdateHotkey(enable, hotkey)
|
||||
@@ -88,7 +96,9 @@ func NewServiceManager() *ServiceManager {
|
||||
dialogService: dialogService,
|
||||
trayService: trayService,
|
||||
keyBindingService: keyBindingService,
|
||||
extensionService: extensionService,
|
||||
startupService: startupService,
|
||||
updateService: updateService,
|
||||
logger: logger,
|
||||
}
|
||||
}
|
||||
@@ -104,7 +114,9 @@ func (sm *ServiceManager) GetServices() []application.Service {
|
||||
application.NewService(sm.dialogService),
|
||||
application.NewService(sm.trayService),
|
||||
application.NewService(sm.keyBindingService),
|
||||
application.NewService(sm.extensionService),
|
||||
application.NewService(sm.startupService),
|
||||
application.NewService(sm.updateService),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,3 +154,13 @@ func (sm *ServiceManager) GetKeyBindingService() *KeyBindingService {
|
||||
func (sm *ServiceManager) GetStartupService() *StartupService {
|
||||
return sm.startupService
|
||||
}
|
||||
|
||||
// GetExtensionService 获取扩展服务实例
|
||||
func (sm *ServiceManager) GetExtensionService() *ExtensionService {
|
||||
return sm.extensionService
|
||||
}
|
||||
|
||||
// GetUpdateService 获取更新服务实例
|
||||
func (sm *ServiceManager) GetUpdateService() *UpdateService {
|
||||
return sm.updateService
|
||||
}
|
||||
|
89
internal/services/update_service.go
Normal file
89
internal/services/update_service.go
Normal file
@@ -0,0 +1,89 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/google/go-github/v63/github"
|
||||
"github.com/wailsapp/wails/v3/pkg/services/log"
|
||||
)
|
||||
|
||||
// UpdateCheckResult 更新检查结果
|
||||
type UpdateCheckResult struct {
|
||||
HasUpdate bool `json:"hasUpdate"` // 是否有更新
|
||||
CurrentVer string `json:"currentVer"` // 当前版本
|
||||
LatestVer string `json:"latestVer"` // 最新版本
|
||||
ReleaseNotes string `json:"releaseNotes"` // 发布说明
|
||||
ReleaseURL string `json:"releaseURL"` // 发布页面URL
|
||||
Error string `json:"error"` // 错误信息
|
||||
}
|
||||
|
||||
// UpdateService 更新服务
|
||||
type UpdateService struct {
|
||||
logger *log.LoggerService
|
||||
configService *ConfigService
|
||||
githubClient *github.Client
|
||||
currentVersion string
|
||||
}
|
||||
|
||||
// NewUpdateService 创建更新服务实例
|
||||
func NewUpdateService(configService *ConfigService, logger *log.LoggerService) *UpdateService {
|
||||
config, err := configService.GetConfig()
|
||||
if err != nil {
|
||||
logger.Error("Failed to get config", "error", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
currentVersion := config.Updates.Version
|
||||
if currentVersion == "" {
|
||||
currentVersion = "1.0.0"
|
||||
}
|
||||
|
||||
httpClient := &http.Client{Timeout: 30 * time.Second}
|
||||
githubClient := github.NewClient(httpClient)
|
||||
|
||||
return &UpdateService{
|
||||
logger: logger,
|
||||
configService: configService,
|
||||
githubClient: githubClient,
|
||||
currentVersion: currentVersion,
|
||||
}
|
||||
}
|
||||
|
||||
// CheckForUpdates 检查更新
|
||||
func (us *UpdateService) CheckForUpdates() UpdateCheckResult {
|
||||
result := UpdateCheckResult{
|
||||
CurrentVer: us.currentVersion,
|
||||
HasUpdate: false,
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
|
||||
release, _, err := us.githubClient.Repositories.GetLatestRelease(ctx, "landaiqing", "voidraft")
|
||||
if err != nil {
|
||||
result.Error = fmt.Sprintf("Failed to check for updates: %v", err)
|
||||
return result
|
||||
}
|
||||
|
||||
if release.GetDraft() || release.GetPrerelease() {
|
||||
result.Error = "Latest release is draft or prerelease"
|
||||
return result
|
||||
}
|
||||
|
||||
latestVer := strings.TrimPrefix(release.GetTagName(), "v")
|
||||
currentVer := strings.TrimPrefix(us.currentVersion, "v")
|
||||
|
||||
result.LatestVer = latestVer
|
||||
result.ReleaseNotes = release.GetBody()
|
||||
result.ReleaseURL = release.GetHTMLURL()
|
||||
|
||||
if latestVer != currentVer && latestVer > currentVer {
|
||||
result.HasUpdate = true
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
2
main.go
2
main.go
@@ -4,6 +4,7 @@ import (
|
||||
"embed"
|
||||
_ "embed"
|
||||
"log"
|
||||
"log/slog"
|
||||
"time"
|
||||
"voidraft/internal/services"
|
||||
"voidraft/internal/systray"
|
||||
@@ -44,6 +45,7 @@ func main() {
|
||||
Assets: application.AssetOptions{
|
||||
Handler: application.AssetFileServerFS(assets),
|
||||
},
|
||||
LogLevel: slog.LevelDebug,
|
||||
Mac: application.MacOptions{
|
||||
ApplicationShouldTerminateAfterLastWindowClosed: true,
|
||||
},
|
||||
|
Reference in New Issue
Block a user