//! Google Fonts, native side, for every app that sets [`crate::app::AppConfig::fonts`]: the //! shell-only `gfonts_*` commands ([`crate::commands::GFONTS`]) over [`crate::fonts`]'s downloads //! and cache (`fonts.googleapis.com` and `fonts.gstatic.com` only, app-data `fonts/`). Site tabs //! never request fonts and gain no command: native code hands them cached bytes //! ([`crate::fonts::page_script_for`]). //! //! When a font is installed or removed the app's [`crate::app::SiteHooks::fonts_changed`] runs, so //! it can give every site tab its theme (and the font bytes) again. use crate::fonts::{self, InstalledFont}; use crate::gfonts::Weights; use crate::host::shell_only; use tauri::{AppHandle, Manager, Webview}; /// Opens the font cache in app data. Does nothing unless the app set [`crate::app::AppConfig::fonts`]. pub(crate) fn init(app: &AppHandle) { if !crate::app::config(app).fonts { return; } if let Ok(dir) = app.path().app_data_dir() { fonts::init(&dir); } } fn changed(app: &AppHandle) { crate::theme_commands::apply(app); crate::app::hooks(app).fonts_changed(app); } #[tauri::command] pub(crate) async fn gfonts_installed(webview: Webview) -> Result, String> { shell_only(&webview)?; fonts::installed() } #[tauri::command] pub(crate) async fn gfonts_install(webview: Webview, app: AppHandle, family: String, weights: Weights) -> Result { shell_only(&webview)?; let installed = fonts::install(family, weights).await?; changed(&app); Ok(installed) } #[tauri::command] pub(crate) async fn gfonts_remove(webview: Webview, app: AppHandle, family: String) -> Result<(), String> { shell_only(&webview)?; fonts::remove(&family)?; changed(&app); Ok(()) } #[tauri::command] pub(crate) async fn gfonts_faces(webview: Webview, family: String) -> Result { shell_only(&webview)?; fonts::faces(&family) } #[tauri::command] pub(crate) async fn gfonts_preview(webview: Webview, family: String, weights: Weights, text: String) -> Result, String> { shell_only(&webview)?; fonts::preview(family, weights, text).await } /// The fonts commands ([`crate::commands::GFONTS`]). pub(crate) fn handler() -> impl Fn(tauri::ipc::Invoke) -> bool + Send + Sync + 'static { tauri::generate_handler![gfonts_installed, gfonts_install, gfonts_remove, gfonts_faces, gfonts_preview] }