fix(settings): ensure global settings sync across all open panes (#2818)

* fix(settings): ensure global settings sync across all open panes

Previously, changing a global setting (like font size) only updated the currently active book pane, causing split-view panes to desynchronize.

This commit updates the settings logic to propagate global changes to all open book instances immediately. It also ensures that settings UI panels correctly re-render when preferences are updated from outside the component.

* refactor to reuse some code

* fix: pointer in doc check

---------

Co-authored-by: André Angelantoni <andre.angelantoni@performantlabs.com>
Co-authored-by: Huang Xin <chrox.huang@gmail.com>
This commit is contained in:
André Angelantoni
2025-12-31 23:12:07 -07:00
committed by GitHub
parent 71e97998b6
commit e21ef53a3d
2 changed files with 23 additions and 15 deletions
@@ -62,7 +62,7 @@ const HeaderBar: React.FC<HeaderBarProps> = ({
const windowButtonVisible = appService?.hasWindowBar && !isTrafficLightVisible;
const docs = view?.renderer.getContents() ?? [];
const pointerInDoc = docs.some(({ doc }) => doc.body.style.cursor === 'pointer');
const pointerInDoc = docs.some(({ doc }) => doc.body?.style.cursor === 'pointer');
const enableAnnotationQuickActions = viewSettings?.enableAnnotationQuickActions;
const annotationQuickActionButton =
+22 -14
View File
@@ -15,29 +15,37 @@ export const saveViewSettings = async <K extends keyof ViewSettings>(
applyStyles = true,
) => {
const { settings, isSettingsGlobal, setSettings, saveSettings } = useSettingsStore.getState();
const { getView, getViewSettings, setViewSettings } = useReaderStore.getState();
const { bookKeys, getView, getViewState, getViewSettings, setViewSettings } =
useReaderStore.getState();
const { getConfig, saveConfig } = useBookDataStore.getState();
const viewSettings = getViewSettings(bookKey);
if (bookKey && viewSettings && viewSettings[key] !== value) {
viewSettings[key] = value;
if (applyStyles) {
const view = getView(bookKey);
view?.renderer.setStyles?.(getStyles(viewSettings));
const applyViewSettings = async (bookKey: string) => {
const viewSettings = getViewSettings(bookKey);
const viewState = getViewState(bookKey);
if (bookKey && viewSettings && viewSettings[key] !== value) {
viewSettings[key] = value;
setViewSettings(bookKey, viewSettings);
if (applyStyles) {
const view = getView(bookKey);
view?.renderer.setStyles?.(getStyles(viewSettings));
}
const config = getConfig(bookKey);
if (viewState?.isPrimary && config) {
await saveConfig(envConfig, bookKey, config, settings);
}
}
}
};
if (isSettingsGlobal && !skipGlobal) {
settings.globalViewSettings[key] = value;
setSettings(settings);
await saveSettings(envConfig, settings);
}
if (bookKey && viewSettings) {
setViewSettings(bookKey, viewSettings);
const config = getConfig(bookKey);
if (config) {
await saveConfig(envConfig, bookKey, config, settings);
for (const bookKey of bookKeys) {
await applyViewSettings(bookKey);
}
} else if (bookKey) {
await applyViewSettings(bookKey);
}
};