fix: 修复移动端终端字号加载异常的问题

#53
This commit is contained in:
Baobhan Sith
2025-05-29 18:28:12 +08:00
parent c44f1606d6
commit ef33726a11
3 changed files with 17 additions and 0 deletions
@@ -49,6 +49,9 @@ let terminalTextStrokeEnabledFound = false;
case 'terminalFontSize':
settings.terminalFontSize = parseInt(row.value, 10);
break;
case 'terminalFontSizeMobile':
settings.terminalFontSizeMobile = parseInt(row.value, 10);
break;
case 'editorFontSize':
settings.editorFontSize = parseInt(row.value, 10);
break;
@@ -117,6 +120,7 @@ case 'terminalTextStrokeEnabled':
activeTerminalThemeId: settings.activeTerminalThemeId ?? defaults.activeTerminalThemeId,
terminalFontFamily: settings.terminalFontFamily ?? defaults.terminalFontFamily,
terminalFontSize: settings.terminalFontSize ?? defaults.terminalFontSize,
terminalFontSizeMobile: settings.terminalFontSizeMobile ?? defaults.terminalFontSizeMobile,
editorFontSize: settings.editorFontSize ?? defaults.editorFontSize,
editorFontFamily: settings.editorFontFamily ?? defaults.editorFontFamily,
terminalBackgroundImage: settings.terminalBackgroundImage ?? defaults.terminalBackgroundImage,
@@ -166,6 +170,7 @@ const getDefaultAppearanceSettings = (): Omit<AppearanceSettings, '_id'> => {
activeTerminalThemeId: null, // 初始默认应为 null
terminalFontFamily: 'Consolas, "Courier New", monospace, "Microsoft YaHei", "微软雅黑"',
terminalFontSize: 14,
terminalFontSizeMobile: 14, // 移动端默认字体大小
editorFontSize: 14,
editorFontFamily: 'Consolas, "Noto Sans SC", "Microsoft YaHei"',
terminalBackgroundImage: undefined,
@@ -206,6 +211,7 @@ export const ensureDefaultSettingsExist = async (db: sqlite3.Database): Promise<
{ key: 'activeTerminalThemeId', value: null }, // 以 null 开始
{ key: 'terminalFontFamily', value: defaults.terminalFontFamily },
{ key: 'terminalFontSize', value: defaults.terminalFontSize },
{ key: 'terminalFontSizeMobile', value: defaults.terminalFontSizeMobile },
{ key: 'editorFontSize', value: defaults.editorFontSize },
{ key: 'editorFontFamily', value: defaults.editorFontFamily },
{ key: 'terminalBackgroundImage', value: defaults.terminalBackgroundImage ?? '' }, // 数据库中使用空字符串
@@ -94,6 +94,16 @@ export const updateSettings = async (settingsDto: UpdateAppearanceDto): Promise<
settingsDto.terminalFontSize = size;
}
// 验证 terminalFontSizeMobile (如果提供了)
if (settingsDto.terminalFontSizeMobile !== undefined && settingsDto.terminalFontSizeMobile !== null) {
const size = Number(settingsDto.terminalFontSizeMobile);
if (isNaN(size) || size <= 0) {
throw new Error(`无效的移动端终端字体大小: ${settingsDto.terminalFontSizeMobile}。必须是一个正数。`);
}
// 确保类型正确传递给仓库层
settingsDto.terminalFontSizeMobile = size;
}
// 验证 editorFontSize (如果提供了)
if (settingsDto.editorFontSize !== undefined && settingsDto.editorFontSize !== null) {
const size = Number(settingsDto.editorFontSize);
@@ -13,6 +13,7 @@ export interface AppearanceSettings {
activeTerminalThemeId?: number | null; // 修改为数字 ID 或 null
terminalFontFamily?: string; // 终端字体列表字符串
terminalFontSize?: number; // 终端字体大小 (px)
terminalFontSizeMobile?: number; // 移动端终端字体大小 (px)
terminalBackgroundImage?: string; // 终端背景图片 URL 或路径
pageBackgroundImage?: string; // 页面背景图片 URL 或路径
editorFontSize?: number; // 编辑器字体大小 (px)