diff --git a/src-tauri/gen/android/app/src/main/java/com/helixnotes/app/MainActivity.kt b/src-tauri/gen/android/app/src/main/java/com/helixnotes/app/MainActivity.kt index cfdd649..cb6155f 100644 --- a/src-tauri/gen/android/app/src/main/java/com/helixnotes/app/MainActivity.kt +++ b/src-tauri/gen/android/app/src/main/java/com/helixnotes/app/MainActivity.kt @@ -33,6 +33,9 @@ class MainActivity : TauriActivity() { // paragraph font-size and line-height from viewport heuristics and ignores our CSS (only // size + line-height were affected; font-family was fine). NORMAL turns it off. (#100) webView.settings.layoutAlgorithm = android.webkit.WebSettings.LayoutAlgorithm.NORMAL + // Honor the viewport meta tag's scale, which is how the Interface Scale setting is applied + // on Android (WebView zoom APIs are not exposed through Tauri here). (#288) + webView.settings.useWideViewPort = true } override fun onPause() { diff --git a/src/lib/components/SettingsPanel.svelte b/src/lib/components/SettingsPanel.svelte index 6bb6d12..7c49efb 100644 --- a/src/lib/components/SettingsPanel.svelte +++ b/src/lib/components/SettingsPanel.svelte @@ -6,7 +6,7 @@ import { open as openDialog, save as saveDialog } from '@tauri-apps/plugin-dialog'; import { listen } from '@tauri-apps/api/event'; import { getVersion } from '@tauri-apps/api/app'; - import { getCurrentWebview } from '@tauri-apps/api/webview'; + import { applyUiScale, defaultUiScale, uiScalePresets } from '$lib/ui-scale'; import { openUrl } from '$lib/api'; import type { OrphanAttachment } from '$lib/api'; import type { ImportResult, BackupEntry, CustomTheme, CustomThemeColors, StartupView, VaultStats } from '$lib/types'; @@ -675,16 +675,6 @@ { label: 'Loose', value: 2.0 }, ]; - const uiScalePresets = [ - { label: '80%', value: 0.8 }, - { label: '90%', value: 0.9 }, - { label: '100%', value: 1 }, - { label: '125%', value: 1.25 }, - { label: '150%', value: 1.5 }, - { label: '175%', value: 1.75 }, - { label: '200%', value: 2 }, - ]; - const contentWidthPresets: { label: string; value: number | null }[] = [ { label: 'Narrow', value: 600 }, { label: 'Medium', value: 760 }, @@ -698,7 +688,7 @@ let scrollToChangeFontSize = $state($appConfig?.scroll_to_change_font_size ?? true); let activeFontFamily = $state($appConfig?.font_family ?? 'system'); let activeLineHeight = $state($appConfig?.line_height ?? 1.6); - let activeUiScale = $state($appConfig?.ui_scale ?? 1); + let activeUiScale = $state($appConfig?.ui_scale ?? defaultUiScale); let activeContentWidth = $state($appConfig?.content_width ?? null); let themeDropdownOpen = $state(false); let accentDropdownOpen = $state(false); @@ -1143,14 +1133,6 @@ setUiScale(value).catch((e) => console.error('Failed to save interface scale:', e)); } - async function applyUiScale(value: number) { - try { - await getCurrentWebview().setZoom(value); - } catch (e) { - console.error('Failed to apply interface scale:', e); - } - } - function selectContentWidth(value: number | null) { activeContentWidth = value; applyContentWidth(value); @@ -2059,7 +2041,7 @@ {/if} - {#if !isMobile} + {#if !isMobile || isAndroid}

Interface Scale

@@ -2073,7 +2055,7 @@ {/each}
-

Zooms the whole app: every panel, menu, and the editor. Use Default (100%) to reset.

+

Zooms the whole app: every panel, menu, and the editor. Use Default ({Math.round(defaultUiScale * 100)}%) to reset.

{/if} diff --git a/src/lib/ui-scale.ts b/src/lib/ui-scale.ts new file mode 100644 index 0000000..3adae0f --- /dev/null +++ b/src/lib/ui-scale.ts @@ -0,0 +1,57 @@ +import { getCurrentWebview } from '@tauri-apps/api/webview'; +import { isAndroid } from '$lib/platform'; + +// Interface scale (#288). The CSS is sized in desktop px, which reads too small on phones, so +// Android starts one step up when the user hasn't picked a scale yet. +export const defaultUiScale = isAndroid ? 1.15 : 1; + +// Scaling up narrows the layout viewport. Keep it at least as wide as the widest mobile menus +// (~290px) so they still fit on narrow phones. Uses the short side so rotating doesn't change it. +const minAndroidLayoutWidth = 290; +const maxAndroidUiScale = + isAndroid && typeof screen !== 'undefined' + ? Math.max(1, Math.min(screen.width, screen.height) / minAndroidLayoutWidth) + : Infinity; + +export const uiScalePresets: { label: string; value: number }[] = isAndroid + ? [ + { label: '100%', value: 1 }, + { label: '115%', value: 1.15 }, + { label: '125%', value: 1.25 }, + { label: '140%', value: 1.4 }, + ].filter((preset) => preset.value <= maxAndroidUiScale) + : [ + { label: '80%', value: 0.8 }, + { label: '90%', value: 0.9 }, + { label: '100%', value: 1 }, + { label: '125%', value: 1.25 }, + { label: '150%', value: 1.5 }, + { label: '175%', value: 1.75 }, + { label: '200%', value: 2 }, + ]; + +// Android's WebView ignores setZoom (wry no-op), and CSS `zoom` would double-scale every popup +// positioned from clientX/getBoundingClientRect. Pinning the viewport scale instead shrinks the +// layout viewport, like the system "Display size" setting, so all coordinates stay in CSS px. +// Needs useWideViewPort, which MainActivity enables. +function applyAndroidViewportScale(scale: number) { + const meta = document.querySelector('meta[name="viewport"]'); + if (!meta) return; + scale = Math.min(scale, maxAndroidUiScale); + meta.setAttribute( + 'content', + `initial-scale=${scale}, minimum-scale=${scale}, maximum-scale=${scale}, user-scalable=no, viewport-fit=cover` + ); +} + +export async function applyUiScale(scale: number) { + if (isAndroid) { + applyAndroidViewportScale(scale); + return; + } + try { + await getCurrentWebview().setZoom(scale); + } catch (e) { + console.error('Failed to apply interface scale:', e); + } +} diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index bfacede..e60ec2a 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -4,7 +4,7 @@ import { getAppConfig, openVault, restoreExternalVault, setFontSize } from '$lib/api'; import { darkThemes, isIOS, isMobile } from '$lib/platform'; import { getWheelFontSizeAction } from '$lib/utils/editor-zoom'; - import { getCurrentWebview } from '@tauri-apps/api/webview'; + import { applyUiScale, defaultUiScale } from '$lib/ui-scale'; import { listen } from '@tauri-apps/api/event'; import { getCurrentWindow } from '@tauri-apps/api/window'; import VaultPicker from '$lib/components/VaultPicker.svelte'; @@ -259,14 +259,9 @@ } } - // 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); - } - } + // Apply saved interface scale (or the platform default) to desktop windows and Android. + const uiScale = config.ui_scale ?? defaultUiScale; + if (uiScale !== 1) await applyUiScale(uiScale); await revealStartupWindow(); removeEditorZoomShortcuts = installEditorZoomShortcuts();