This commit is contained in:
Baobhan Sith
2025-04-17 20:33:14 +08:00
parent 9eb0bcc5f3
commit 636ed5a2bb
8 changed files with 37 additions and 94 deletions
@@ -17,9 +17,7 @@ const createTableIfNotExists = () => {
active_terminal_theme_id TEXT,
terminal_font_family TEXT,
terminal_background_image TEXT,
terminal_background_opacity REAL, -- Use REAL for floating point numbers
page_background_image TEXT,
page_background_opacity REAL,
updated_at INTEGER NOT NULL
);
`;
@@ -42,9 +40,9 @@ const mapRowToAppearanceSettings = (row: any): AppearanceSettings => {
activeTerminalThemeId: row.active_terminal_theme_id,
terminalFontFamily: row.terminal_font_family,
terminalBackgroundImage: row.terminal_background_image,
terminalBackgroundOpacity: row.terminal_background_opacity,
// terminalBackgroundOpacity: row.terminal_background_opacity, // Removed
pageBackgroundImage: row.page_background_image,
pageBackgroundOpacity: row.page_background_opacity,
// pageBackgroundOpacity: row.page_background_opacity, // Removed
updatedAt: row.updated_at,
};
};
@@ -59,9 +57,9 @@ const getDefaultAppearanceSettings = (): AppearanceSettings => {
activeTerminalThemeId: undefined, // Needs to be set after querying default theme ID
terminalFontFamily: 'Consolas, "Courier New", monospace, "Microsoft YaHei", "微软雅黑"', // Default font
terminalBackgroundImage: undefined,
terminalBackgroundOpacity: 1.0,
// terminalBackgroundOpacity: 1.0, // Removed
pageBackgroundImage: undefined,
pageBackgroundOpacity: 1.0,
// pageBackgroundOpacity: 1.0, // Removed
updatedAt: Date.now(),
};
};
@@ -82,9 +80,10 @@ const ensureDefaultSettingsExist = () => {
const sqlInsert = `
INSERT INTO ${TABLE_NAME} (
id, custom_ui_theme, active_terminal_theme_id, terminal_font_family,
terminal_background_image, terminal_background_opacity,
page_background_image, page_background_opacity, updated_at
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
terminal_background_image, -- terminal_background_opacity, -- Removed
page_background_image, -- page_background_opacity, -- Removed
updated_at
) VALUES (?, ?, ?, ?, ?, ?, ?) -- Adjusted placeholder count
`;
db.run(sqlInsert, [
SETTINGS_ID,
@@ -92,9 +91,9 @@ const ensureDefaultSettingsExist = () => {
defaults.activeTerminalThemeId, // Initially undefined
defaults.terminalFontFamily,
defaults.terminalBackgroundImage,
defaults.terminalBackgroundOpacity,
// defaults.terminalBackgroundOpacity, // Removed
defaults.pageBackgroundImage,
defaults.pageBackgroundOpacity,
// defaults.pageBackgroundOpacity, // Removed
defaults.updatedAt
], (insertErr) => {
if (insertErr) {
@@ -176,8 +175,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
if (['custom_ui_theme', 'active_terminal_theme_id', 'terminal_font_family', 'terminal_background_image', 'terminal_background_opacity', 'page_background_image', 'page_background_opacity'].includes(dbKey)) {
// 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)) {
updates.push(`${dbKey} = ?`);
params.push((settingsDto as any)[key]);
}
@@ -38,15 +38,6 @@ 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.
}
// 验证透明度值 (如果提供了)
if (settingsDto.terminalBackgroundOpacity !== undefined && (settingsDto.terminalBackgroundOpacity < 0 || settingsDto.terminalBackgroundOpacity > 1)) {
throw new Error('终端背景透明度必须在 0 和 1 之间');
}
if (settingsDto.pageBackgroundOpacity !== undefined && (settingsDto.pageBackgroundOpacity < 0 || settingsDto.pageBackgroundOpacity > 1)) {
throw new Error('页面背景透明度必须在 0 和 1 之间');
}
// TODO: 如果实现了背景图片上传,这里需要处理文件路径或 URL 的验证/保存逻辑
return appearanceRepository.updateAppearanceSettings(settingsDto);
@@ -10,9 +10,7 @@ export interface AppearanceSettings {
activeTerminalThemeId?: string; // 当前激活的终端主题 ID (对应 terminal_themes 表的 _id)
terminalFontFamily?: string; // 终端字体列表字符串
terminalBackgroundImage?: string; // 终端背景图片 URL 或路径
terminalBackgroundOpacity?: number; // 终端背景透明度 (0-1)
pageBackgroundImage?: string; // 页面背景图片 URL 或路径
pageBackgroundOpacity?: number; // 页面背景透明度 (0-1)
updatedAt?: number;
}