From 0e5b380f8c777778958f673fb961003f6be48143 Mon Sep 17 00:00:00 2001 From: Yuri Karamian Date: Fri, 24 Jul 2026 20:55:57 +0200 Subject: [PATCH] Sync detached window typography --- src-tauri/src/commands.rs | 8 ++++++-- src/routes/+page.svelte | 23 ++++++++++++++++------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index adc9fce..761e458 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -392,11 +392,15 @@ pub fn import_custom_themes(state: State<'_, AppState>, path: String) -> Result< } #[tauri::command] -pub fn set_font_size(state: State<'_, AppState>, size: u32) -> Result<(), String> { +pub fn set_font_size(app: AppHandle, state: State<'_, AppState>, size: u32) -> Result<(), String> { let mut config = state.config.lock().map_err(|e| e.to_string())?; config.font_size = Some(size); save_app_config(&config)?; - Ok(()) + drop(config); + + use tauri::Emitter; + app.emit("editor-font-size-changed", size) + .map_err(|e| e.to_string()) } #[tauri::command] diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index e17b1ed..ee9d01a 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -4,6 +4,7 @@ import { getAppConfig, openVault, restoreExternalVault, setFontSize } from '$lib/api'; import { darkThemes, isIOS } from '$lib/platform'; import { getCurrentWebview } from '@tauri-apps/api/webview'; + import { listen } from '@tauri-apps/api/event'; import VaultPicker from '$lib/components/VaultPicker.svelte'; import AppLayout from '$lib/components/AppLayout.svelte'; import NoteWindow from '$lib/components/NoteWindow.svelte'; @@ -13,6 +14,7 @@ let startupVaultError = $state(''); let fontSizeSaveTimer: ReturnType | null = null; let removeEditorZoomShortcuts: (() => void) | null = null; + let removeFontSizeListener: (() => void) | null = null; const defaultEditorFontSize = 14; const minEditorFontSize = 10; @@ -56,12 +58,17 @@ }; } - function setEditorFontSize(value: number) { + function applyEditorFontSize(value: number) { const nextSize = Math.max(minEditorFontSize, Math.min(maxEditorFontSize, Math.round(value))); const restoreEditorViewport = preserveEditorViewportAfterLayout(getEditorScrollSurface()); if ($appConfig) $appConfig.font_size = nextSize; document.documentElement.style.setProperty('--editor-font-size', `${nextSize}px`); restoreEditorViewport(); + return nextSize; + } + + function setEditorFontSize(value: number) { + const nextSize = applyEditorFontSize(value); if (fontSizeSaveTimer) clearTimeout(fontSizeSaveTimer); fontSizeSaveTimer = setTimeout(() => { setFontSize(nextSize).catch((e) => console.error('Failed to save font size:', e)); @@ -117,6 +124,9 @@ try { const config = await getAppConfig(); $appConfig = config; + removeFontSizeListener = await listen('editor-font-size-changed', (event) => { + if ($appConfig?.font_size !== event.payload) applyEditorFontSize(event.payload); + }); $theme = config.theme || 'system'; // Apply theme immediately to prevent flash @@ -133,9 +143,7 @@ } // Apply saved font settings - if (config.font_size) { - document.documentElement.style.setProperty('--editor-font-size', `${config.font_size}px`); - } + if (config.font_size) applyEditorFontSize(config.font_size); if (config.line_height) { document.documentElement.style.setProperty('--editor-line-height', String(config.line_height)); } @@ -193,15 +201,15 @@ } } - // Apply saved interface scale (desktop main window only; no-ops gracefully elsewhere) - if (!noteWindowPath && config.ui_scale && config.ui_scale !== 1) { + // Apply saved interface scale to every desktop window; no-ops gracefully elsewhere. + if (config.ui_scale && config.ui_scale !== 1) { try { await getCurrentWebview().setZoom(config.ui_scale); } catch (e) { console.error('Failed to apply interface scale:', e); } } - if (!noteWindowPath) removeEditorZoomShortcuts = installEditorZoomShortcuts(); + removeEditorZoomShortcuts = installEditorZoomShortcuts(); // Auto-open last vault if available if (config.active_vault) { @@ -240,6 +248,7 @@ onDestroy(() => { removeEditorZoomShortcuts?.(); + removeFontSizeListener?.(); if (fontSizeSaveTimer) clearTimeout(fontSizeSaveTimer); });