From 2b4014870c0ed1a8c5017e146a0648b2bfec7a38 Mon Sep 17 00:00:00 2001 From: Psychotoxical <171614930+Psychotoxical@users.noreply.github.com> Date: Fri, 8 May 2026 14:22:23 +0200 Subject: [PATCH] refactor(app_api): extract window + WebKitGTK platform tweaks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Lift set_window_decorations + linux_webkit_apply_smooth_scrolling + set_linux_webkit_smooth_scrolling out of app_api/core.rs into app_api/platform.rs (~49 LOC). These are platform-tweak Tauri commands (Linux WebKitGTK settings + Linux native-decoration toggle) — logically separate from runtime control, telemetry, cli bridge, or wire-UA setup. This is the "platform" slice from cucadmuh's plan for splitting core.rs's mixed concerns. Together with perf and cli_bridge, core.rs is now down to runtime control (greet, exit_app), logging (3 cmds), and UA setup — 56 LOC, focused. --- src-tauri/src/lib_commands/app_api/core.rs | 45 ----------------- src-tauri/src/lib_commands/app_api/mod.rs | 2 + .../src/lib_commands/app_api/platform.rs | 49 +++++++++++++++++++ 3 files changed, 51 insertions(+), 45 deletions(-) create mode 100644 src-tauri/src/lib_commands/app_api/platform.rs diff --git a/src-tauri/src/lib_commands/app_api/core.rs b/src-tauri/src/lib_commands/app_api/core.rs index 86b45976..0254a01d 100644 --- a/src-tauri/src/lib_commands/app_api/core.rs +++ b/src-tauri/src/lib_commands/app_api/core.rs @@ -11,51 +11,6 @@ pub(crate) fn exit_app(app_handle: tauri::AppHandle) { app_handle.exit(0); } -/// Toggle native window decorations at runtime (Linux custom title bar opt-out). -#[tauri::command] -pub(crate) fn set_window_decorations(enabled: bool, app_handle: tauri::AppHandle) { - if let Some(win) = app_handle.get_webview_window("main") { - let _ = win.set_decorations(enabled); - // Re-enabling native decorations on GTK causes the window manager to - // re-stack the window, which drops focus. Bring it back immediately. - if enabled { - let _ = win.set_focus(); - } - } -} - -/// WebKitGTK: `enable-smooth-scrolling` also drives deferred / kinetic wheel scrolling. -#[cfg(target_os = "linux")] -pub(crate) fn linux_webkit_apply_smooth_scrolling(win: &tauri::WebviewWindow, enabled: bool) -> Result<(), String> { - win.with_webview(move |platform| { - use webkit2gtk::{SettingsExt, WebViewExt}; - if let Some(settings) = platform.inner().settings() { - settings.set_enable_smooth_scrolling(enabled); - } - }) - .map_err(|e| e.to_string()) -} - -/// Called from the frontend settings toggle (Linux); no-op on other platforms. -#[tauri::command] -pub(crate) fn set_linux_webkit_smooth_scrolling(enabled: bool, app_handle: tauri::AppHandle) -> Result<(), String> { - #[cfg(target_os = "linux")] - { - use tauri::Manager; - // Each WebviewWindow has its own WebKitGTK Settings — main-only left the - // mini player on the default (inertial) wheel until the user toggled again. - for label in ["main", "mini"] { - if let Some(win) = app_handle.get_webview_window(label) { - linux_webkit_apply_smooth_scrolling(&win, enabled)?; - } - } - } - #[cfg(not(target_os = "linux"))] - { - let _ = (enabled, app_handle); - } - Ok(()) -} #[tauri::command] pub(crate) fn set_logging_mode(mode: String) -> Result<(), String> { diff --git a/src-tauri/src/lib_commands/app_api/mod.rs b/src-tauri/src/lib_commands/app_api/mod.rs index c23a227e..a7a95881 100644 --- a/src-tauri/src/lib_commands/app_api/mod.rs +++ b/src-tauri/src/lib_commands/app_api/mod.rs @@ -4,6 +4,7 @@ mod cli_bridge; mod core; mod navidrome; mod perf; +mod platform; mod remote; mod integration; mod analysis; @@ -12,6 +13,7 @@ pub(crate) use cli_bridge::*; pub(crate) use core::*; pub(crate) use navidrome::*; pub(crate) use perf::*; +pub(crate) use platform::*; pub(crate) use remote::*; pub(crate) use integration::*; pub(crate) use analysis::*; diff --git a/src-tauri/src/lib_commands/app_api/platform.rs b/src-tauri/src/lib_commands/app_api/platform.rs new file mode 100644 index 00000000..cc48946e --- /dev/null +++ b/src-tauri/src/lib_commands/app_api/platform.rs @@ -0,0 +1,49 @@ +//! Native-window + WebKitGTK platform tweaks exposed as Tauri commands. + +use super::*; + +/// Toggle native window decorations at runtime (Linux custom title bar opt-out). +#[tauri::command] +pub(crate) fn set_window_decorations(enabled: bool, app_handle: tauri::AppHandle) { + if let Some(win) = app_handle.get_webview_window("main") { + let _ = win.set_decorations(enabled); + // Re-enabling native decorations on GTK causes the window manager to + // re-stack the window, which drops focus. Bring it back immediately. + if enabled { + let _ = win.set_focus(); + } + } +} + +/// WebKitGTK: `enable-smooth-scrolling` also drives deferred / kinetic wheel scrolling. +#[cfg(target_os = "linux")] +pub(crate) fn linux_webkit_apply_smooth_scrolling(win: &tauri::WebviewWindow, enabled: bool) -> Result<(), String> { + win.with_webview(move |platform| { + use webkit2gtk::{SettingsExt, WebViewExt}; + if let Some(settings) = platform.inner().settings() { + settings.set_enable_smooth_scrolling(enabled); + } + }) + .map_err(|e| e.to_string()) +} + +/// Called from the frontend settings toggle (Linux); no-op on other platforms. +#[tauri::command] +pub(crate) fn set_linux_webkit_smooth_scrolling(enabled: bool, app_handle: tauri::AppHandle) -> Result<(), String> { + #[cfg(target_os = "linux")] + { + use tauri::Manager; + // Each WebviewWindow has its own WebKitGTK Settings — main-only left the + // mini player on the default (inertial) wheel until the user toggled again. + for label in ["main", "mini"] { + if let Some(win) = app_handle.get_webview_window(label) { + linux_webkit_apply_smooth_scrolling(&win, enabled)?; + } + } + } + #[cfg(not(target_os = "linux"))] + { + let _ = (enabled, app_handle); + } + Ok(()) +}