Sync detached window typography

This commit is contained in:
Yuri Karamian
2026-07-24 20:55:57 +02:00
parent e76919ab5c
commit 0e5b380f8c
2 changed files with 22 additions and 9 deletions
+6 -2
View File
@@ -392,11 +392,15 @@ pub fn import_custom_themes(state: State<'_, AppState>, path: String) -> Result<
} }
#[tauri::command] #[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())?; let mut config = state.config.lock().map_err(|e| e.to_string())?;
config.font_size = Some(size); config.font_size = Some(size);
save_app_config(&config)?; 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] #[tauri::command]
+16 -7
View File
@@ -4,6 +4,7 @@
import { getAppConfig, openVault, restoreExternalVault, setFontSize } from '$lib/api'; import { getAppConfig, openVault, restoreExternalVault, setFontSize } from '$lib/api';
import { darkThemes, isIOS } from '$lib/platform'; import { darkThemes, isIOS } from '$lib/platform';
import { getCurrentWebview } from '@tauri-apps/api/webview'; import { getCurrentWebview } from '@tauri-apps/api/webview';
import { listen } from '@tauri-apps/api/event';
import VaultPicker from '$lib/components/VaultPicker.svelte'; import VaultPicker from '$lib/components/VaultPicker.svelte';
import AppLayout from '$lib/components/AppLayout.svelte'; import AppLayout from '$lib/components/AppLayout.svelte';
import NoteWindow from '$lib/components/NoteWindow.svelte'; import NoteWindow from '$lib/components/NoteWindow.svelte';
@@ -13,6 +14,7 @@
let startupVaultError = $state(''); let startupVaultError = $state('');
let fontSizeSaveTimer: ReturnType<typeof setTimeout> | null = null; let fontSizeSaveTimer: ReturnType<typeof setTimeout> | null = null;
let removeEditorZoomShortcuts: (() => void) | null = null; let removeEditorZoomShortcuts: (() => void) | null = null;
let removeFontSizeListener: (() => void) | null = null;
const defaultEditorFontSize = 14; const defaultEditorFontSize = 14;
const minEditorFontSize = 10; 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 nextSize = Math.max(minEditorFontSize, Math.min(maxEditorFontSize, Math.round(value)));
const restoreEditorViewport = preserveEditorViewportAfterLayout(getEditorScrollSurface()); const restoreEditorViewport = preserveEditorViewportAfterLayout(getEditorScrollSurface());
if ($appConfig) $appConfig.font_size = nextSize; if ($appConfig) $appConfig.font_size = nextSize;
document.documentElement.style.setProperty('--editor-font-size', `${nextSize}px`); document.documentElement.style.setProperty('--editor-font-size', `${nextSize}px`);
restoreEditorViewport(); restoreEditorViewport();
return nextSize;
}
function setEditorFontSize(value: number) {
const nextSize = applyEditorFontSize(value);
if (fontSizeSaveTimer) clearTimeout(fontSizeSaveTimer); if (fontSizeSaveTimer) clearTimeout(fontSizeSaveTimer);
fontSizeSaveTimer = setTimeout(() => { fontSizeSaveTimer = setTimeout(() => {
setFontSize(nextSize).catch((e) => console.error('Failed to save font size:', e)); setFontSize(nextSize).catch((e) => console.error('Failed to save font size:', e));
@@ -117,6 +124,9 @@
try { try {
const config = await getAppConfig(); const config = await getAppConfig();
$appConfig = config; $appConfig = config;
removeFontSizeListener = await listen<number>('editor-font-size-changed', (event) => {
if ($appConfig?.font_size !== event.payload) applyEditorFontSize(event.payload);
});
$theme = config.theme || 'system'; $theme = config.theme || 'system';
// Apply theme immediately to prevent flash // Apply theme immediately to prevent flash
@@ -133,9 +143,7 @@
} }
// Apply saved font settings // Apply saved font settings
if (config.font_size) { if (config.font_size) applyEditorFontSize(config.font_size);
document.documentElement.style.setProperty('--editor-font-size', `${config.font_size}px`);
}
if (config.line_height) { if (config.line_height) {
document.documentElement.style.setProperty('--editor-line-height', String(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) // Apply saved interface scale to every desktop window; no-ops gracefully elsewhere.
if (!noteWindowPath && config.ui_scale && config.ui_scale !== 1) { if (config.ui_scale && config.ui_scale !== 1) {
try { try {
await getCurrentWebview().setZoom(config.ui_scale); await getCurrentWebview().setZoom(config.ui_scale);
} catch (e) { } catch (e) {
console.error('Failed to apply interface scale:', e); console.error('Failed to apply interface scale:', e);
} }
} }
if (!noteWindowPath) removeEditorZoomShortcuts = installEditorZoomShortcuts(); removeEditorZoomShortcuts = installEditorZoomShortcuts();
// Auto-open last vault if available // Auto-open last vault if available
if (config.active_vault) { if (config.active_vault) {
@@ -240,6 +248,7 @@
onDestroy(() => { onDestroy(() => {
removeEditorZoomShortcuts?.(); removeEditorZoomShortcuts?.();
removeFontSizeListener?.();
if (fontSizeSaveTimer) clearTimeout(fontSizeSaveTimer); if (fontSizeSaveTimer) clearTimeout(fontSizeSaveTimer);
}); });
</script> </script>