feat: 添加调整终端字体大小设置

This commit is contained in:
Baobhan Sith
2025-04-18 09:17:56 +08:00
parent fdc613e12d
commit f8c651dafa
8 changed files with 103 additions and 24 deletions
@@ -16,6 +16,7 @@ const createTableIfNotExists = () => {
custom_ui_theme TEXT,
active_terminal_theme_id TEXT,
terminal_font_family TEXT,
terminal_font_size INTEGER, -- 添加字体大小列
terminal_background_image TEXT,
page_background_image TEXT,
updated_at INTEGER NOT NULL
@@ -39,6 +40,7 @@ const mapRowToAppearanceSettings = (row: any): AppearanceSettings => {
customUiTheme: row.custom_ui_theme,
activeTerminalThemeId: row.active_terminal_theme_id,
terminalFontFamily: row.terminal_font_family,
terminalFontSize: row.terminal_font_size, // 添加字体大小映射
terminalBackgroundImage: row.terminal_background_image,
// terminalBackgroundOpacity: row.terminal_background_opacity, // Removed
pageBackgroundImage: row.page_background_image,
@@ -56,6 +58,7 @@ const getDefaultAppearanceSettings = (): AppearanceSettings => {
customUiTheme: JSON.stringify(defaultUiTheme), // Use default UI theme
activeTerminalThemeId: undefined, // Needs to be set after querying default theme ID
terminalFontFamily: 'Consolas, "Courier New", monospace, "Microsoft YaHei", "微软雅黑"', // Default font
terminalFontSize: 14, // 添加默认字体大小
terminalBackgroundImage: undefined,
// terminalBackgroundOpacity: 1.0, // Removed
pageBackgroundImage: undefined,
@@ -79,17 +82,18 @@ const ensureDefaultSettingsExist = () => {
if (!row) {
const sqlInsert = `
INSERT INTO ${TABLE_NAME} (
id, custom_ui_theme, active_terminal_theme_id, terminal_font_family,
id, custom_ui_theme, active_terminal_theme_id, terminal_font_family, terminal_font_size, -- 添加列
terminal_background_image, -- terminal_background_opacity, -- Removed
page_background_image, -- page_background_opacity, -- Removed
updated_at
) VALUES (?, ?, ?, ?, ?, ?, ?) -- Adjusted placeholder count
) VALUES (?, ?, ?, ?, ?, ?, ?, ?) -- 调整占位符数量
`;
db.run(sqlInsert, [
SETTINGS_ID,
defaults.customUiTheme,
defaults.activeTerminalThemeId, // Initially undefined
defaults.terminalFontFamily,
defaults.terminalFontSize, // 添加默认值参数
defaults.terminalBackgroundImage,
// defaults.terminalBackgroundOpacity, // Removed
defaults.pageBackgroundImage,
@@ -175,8 +179,8 @@ export const updateAppearanceSettings = async (settingsDto: UpdateAppearanceDto)
for (const key in settingsDto) {
if (Object.prototype.hasOwnProperty.call(settingsDto, key)) {
const dbKey = key.replace(/[A-Z]/g, letter => `_${letter.toLowerCase()}`); // Convert camelCase to snake_case
// Ensure only valid keys are updated (Removed opacity keys)
if (['custom_ui_theme', 'active_terminal_theme_id', 'terminal_font_family', 'terminal_background_image', 'page_background_image'].includes(dbKey)) {
// Ensure only valid keys are updated (Added terminal_font_size)
if (['custom_ui_theme', 'active_terminal_theme_id', 'terminal_font_family', 'terminal_font_size', 'terminal_background_image', 'page_background_image'].includes(dbKey)) {
updates.push(`${dbKey} = ?`);
params.push((settingsDto as any)[key]);
}
@@ -38,6 +38,16 @@ export const updateSettings = async (settingsDto: UpdateAppearanceDto): Promise<
// We just need to ensure the key exists in the DTO if it's meant to be cleared.
}
// 验证 terminalFontSize (如果提供了)
if (settingsDto.terminalFontSize !== undefined && settingsDto.terminalFontSize !== null) {
const size = Number(settingsDto.terminalFontSize);
if (isNaN(size) || size <= 0) {
throw new Error(`无效的终端字体大小: ${settingsDto.terminalFontSize}。必须是一个正数。`);
}
// 可以选择将验证后的数字类型赋值回 DTO,以确保类型正确传递给仓库层
settingsDto.terminalFontSize = size;
}
// TODO: 如果实现了背景图片上传,这里需要处理文件路径或 URL 的验证/保存逻辑
return appearanceRepository.updateAppearanceSettings(settingsDto);
@@ -9,6 +9,7 @@ export interface AppearanceSettings {
customUiTheme?: string; // UI 主题 (CSS 变量 JSON 字符串)
activeTerminalThemeId?: string; // 当前激活的终端主题 ID (对应 terminal_themes 表的 _id)
terminalFontFamily?: string; // 终端字体列表字符串
terminalFontSize?: number; // 终端字体大小 (px)
terminalBackgroundImage?: string; // 终端背景图片 URL 或路径
pageBackgroundImage?: string; // 页面背景图片 URL 或路径
updatedAt?: number;