From 80d60266c2bbf1d16e41f10f3d261fb6f7db12f4 Mon Sep 17 00:00:00 2001 From: Huang Xin Date: Sat, 6 Sep 2025 16:40:18 +0800 Subject: [PATCH] settings: default to override background color in fixed layout documents (#1974) --- apps/readest-app/src/services/appService.ts | 20 +++++++++++++++++--- apps/readest-app/src/services/constants.ts | 4 ++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/apps/readest-app/src/services/appService.ts b/apps/readest-app/src/services/appService.ts index a618f5e5..c143c4f7 100644 --- a/apps/readest-app/src/services/appService.ts +++ b/apps/readest-app/src/services/appService.ts @@ -2,7 +2,14 @@ import { v4 as uuidv4 } from 'uuid'; import { SystemSettings } from '@/types/settings'; import { AppPlatform, AppService, OsPlatform } from '@/types/system'; import { FileSystem, BaseDir, DeleteAction } from '@/types/system'; -import { Book, BookConfig, BookContent, BookFormat, ViewSettings } from '@/types/book'; +import { + Book, + BookConfig, + BookContent, + BookFormat, + FIXED_LAYOUT_FORMATS, + ViewSettings, +} from '@/types/book'; import { getDir, getLocalBookFilename, @@ -35,6 +42,7 @@ import { DEFAULT_MOBILE_READSETTINGS, DEFAULT_SCREEN_CONFIG, DEFAULT_TRANSLATOR_CONFIG, + DEFAULT_FIXED_LAYOUT_VIEW_SETTINGS, } from './constants'; import { fetch as tauriFetch } from '@tauri-apps/plugin-http'; import { getOSPlatform, getTargetLang, isCJKEnv, isContentURI, isValidURL } from '@/utils/misc'; @@ -503,7 +511,10 @@ export abstract class BaseAppService implements AppService { } async loadBookConfig(book: Book, settings: SystemSettings): Promise { - const { globalViewSettings } = settings; + const globalViewSettings = { + ...settings.globalViewSettings, + ...(FIXED_LAYOUT_FORMATS.has(book.format) ? DEFAULT_FIXED_LAYOUT_VIEW_SETTINGS : {}), + }; try { let str = '{}'; if (await this.fs.exists(getConfigFilename(book), 'Books')) { @@ -532,7 +543,10 @@ export abstract class BaseAppService implements AppService { async saveBookConfig(book: Book, config: BookConfig, settings?: SystemSettings) { let serializedConfig: string; if (settings) { - const { globalViewSettings } = settings; + const globalViewSettings = { + ...settings.globalViewSettings, + ...(FIXED_LAYOUT_FORMATS.has(book.format) ? DEFAULT_FIXED_LAYOUT_VIEW_SETTINGS : {}), + }; serializedConfig = serializeConfig(config, globalViewSettings, DEFAULT_BOOK_SEARCH_CONFIG); } else { serializedConfig = JSON.stringify(config); diff --git a/apps/readest-app/src/services/constants.ts b/apps/readest-app/src/services/constants.ts index 1ef389f8..1137426d 100644 --- a/apps/readest-app/src/services/constants.ts +++ b/apps/readest-app/src/services/constants.ts @@ -170,6 +170,10 @@ export const DEFAULT_CJK_VIEW_SETTINGS: Partial = { textIndent: 2, }; +export const DEFAULT_FIXED_LAYOUT_VIEW_SETTINGS: Partial = { + overrideColor: true, +}; + export const DEFAULT_VIEW_CONFIG: ViewConfig = { sideBarTab: 'toc', uiLanguage: '',