From ab1176993b9ace04e8caf9e98b0c795be5731a2e Mon Sep 17 00:00:00 2001 From: Baobhan Sith <80159437+Heavrnl@users.noreply.github.com> Date: Thu, 24 Apr 2025 21:56:11 +0800 Subject: [PATCH] update --- packages/backend/src/database/connection.ts | 4 ++ .../src/repositories/settings.repository.ts | 53 +++++++++++++++++-- packages/backend/src/types/settings.types.ts | 12 +++++ 3 files changed, 66 insertions(+), 3 deletions(-) diff --git a/packages/backend/src/database/connection.ts b/packages/backend/src/database/connection.ts index 27073c9..c8fdb80 100644 --- a/packages/backend/src/database/connection.ts +++ b/packages/backend/src/database/connection.ts @@ -7,6 +7,7 @@ import * as schema from './schema'; import { tableDefinitions } from './schema.registry'; // presetTerminalThemes might still be needed if passed directly, but likely handled in registry now // import { presetTerminalThemes } from '../config/preset-themes-definition'; +// Removed import for default-layout-data as logic is now in settings repository // --- Revert to original path and filename --- // 使用 process.cwd() 获取项目根目录,然后拼接路径,确保路径一致性 @@ -117,6 +118,9 @@ const runDatabaseInitializations = async (db: sqlite3.Database): Promise = } } + // Default layout/sidebar data is now handled within settingsRepository.ensureDefaultSettingsExist + // No separate call needed here anymore. + // Migrations (if any) would run after initial schema setup // import { runMigrations } from './migrations'; // await runMigrations(db); diff --git a/packages/backend/src/repositories/settings.repository.ts b/packages/backend/src/repositories/settings.repository.ts index e60cf1b..968388c 100644 --- a/packages/backend/src/repositories/settings.repository.ts +++ b/packages/backend/src/repositories/settings.repository.ts @@ -1,6 +1,6 @@ // packages/backend/src/repositories/settings.repository.ts import { getDbInstance, runDb, getDb as getDbRow, allDb } from '../database/connection'; -import { SidebarConfig } from '../types/settings.types'; // <-- Correct import path +import { SidebarConfig, LayoutNode, PaneName } from '../types/settings.types'; // <-- Import LayoutNode and PaneName import * as sqlite3 from 'sqlite3'; // Import sqlite3 for Database type hint // Define keys for specific settings @@ -154,6 +154,53 @@ export const setSidebarConfig = async (config: SidebarConfig): Promise => * @param db - The active database instance */ export const ensureDefaultSettingsExist = async (db: sqlite3.Database): Promise => { + // --- Define Default Structures Here --- + // Use OmitIdRecursive helper type if needed, or define structure without IDs + type OmitIdRecursive = T extends object + ? { [K in keyof Omit]: OmitIdRecursive } + : T; + + const defaultLayoutTreeStructure: OmitIdRecursive = { + type: "container", + direction: "horizontal", + children: [ + { + type: "container", + direction: "vertical", + children: [ + { type: "pane", component: "statusMonitor", size: 44.56 }, + { type: "pane", component: "commandHistory", size: 26.24 }, + { type: "pane", component: "quickCommands", size: 29.20 } + ], + size: 14.59 + }, + { + type: "container", + direction: "vertical", + size: 58.03, + children: [ + { type: "pane", component: "terminal", size: 59.95 }, + { type: "pane", component: "commandBar", size: 5 }, + { type: "pane", component: "fileManager", size: 35.05 } + ] + }, + { + type: "container", + direction: "vertical", + size: 27.38, + children: [ + { type: "pane", component: "editor", size: 100 } + ] + } + ] + }; + + const defaultSidebarPanesStructure: SidebarConfig = { + left: ["connections", "dockerManager"], + right: [] + }; + + // --- Define All Default Settings --- const defaultSettings: Record = { language: 'en', // Default language ipWhitelistEnabled: 'false', @@ -162,14 +209,14 @@ export const ensureDefaultSettingsExist = async (db: sqlite3.Database): Promise< loginBanDuration: '300', // 5 minutes in seconds focusSwitcherSequence: JSON.stringify(["quickCommandsSearch", "commandHistorySearch", "fileManagerSearch", "commandInput", "terminalSearch"]), // Default focus sequence navBarVisible: 'true', // Default nav bar visibility - layoutTree: 'null', // Default layout tree (null initially) + layoutTree: JSON.stringify(defaultLayoutTreeStructure), // Use the defined structure autoCopyOnSelect: 'false', // Default auto copy setting showPopupFileEditor: 'false', // Default popup editor setting shareFileEditorTabs: 'true', // Default editor tab sharing dockerStatusIntervalSeconds: '5', // Default Docker refresh interval dockerDefaultExpand: 'false', // Default Docker expand state statusMonitorIntervalSeconds: '3', // Default Status Monitor interval - [SIDEBAR_CONFIG_KEY]: JSON.stringify({ left: [], right: [] }), // Default sidebar config + [SIDEBAR_CONFIG_KEY]: JSON.stringify(defaultSidebarPanesStructure), // Use the defined structure // Add other default settings here }; const nowSeconds = Math.floor(Date.now() / 1000); diff --git a/packages/backend/src/types/settings.types.ts b/packages/backend/src/types/settings.types.ts index ce76996..b44f0fe 100644 --- a/packages/backend/src/types/settings.types.ts +++ b/packages/backend/src/types/settings.types.ts @@ -3,6 +3,18 @@ // Define PaneName here as it's logically related to layout/sidebar settings export type PaneName = 'connections' | 'terminal' | 'commandBar' | 'fileManager' | 'editor' | 'statusMonitor' | 'commandHistory' | 'quickCommands' | 'dockerManager'; +/** + * 布局节点接口 (Mirrors frontend definition for backend use) + */ +export interface LayoutNode { + id: string; // 唯一 ID (Note: Backend might not always use/store this) + type: 'pane' | 'container'; // 节点类型:面板或容器 + component?: PaneName; // 如果 type 是 'pane',指定要渲染的组件 + direction?: 'horizontal' | 'vertical'; // 如果 type 是 'container',指定分割方向 + children?: LayoutNode[]; // 如果 type 是 'container',包含子节点数组 + size?: number; // 节点在父容器中的大小比例 (例如 20, 50, 30) +} + /** * 侧栏配置数据结构 (Managed by Settings Repository/Service) */