mirror of
https://github.com/kilyabin/psysonic.git
synced 2026-07-22 06:25:41 +00:00
refactor(app_api): extract window + WebKitGTK platform tweaks
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.
This commit is contained in:
@@ -11,51 +11,6 @@ pub(crate) fn exit_app(app_handle: tauri::AppHandle) {
|
|||||||
app_handle.exit(0);
|
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]
|
#[tauri::command]
|
||||||
pub(crate) fn set_logging_mode(mode: String) -> Result<(), String> {
|
pub(crate) fn set_logging_mode(mode: String) -> Result<(), String> {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ mod cli_bridge;
|
|||||||
mod core;
|
mod core;
|
||||||
mod navidrome;
|
mod navidrome;
|
||||||
mod perf;
|
mod perf;
|
||||||
|
mod platform;
|
||||||
mod remote;
|
mod remote;
|
||||||
mod integration;
|
mod integration;
|
||||||
mod analysis;
|
mod analysis;
|
||||||
@@ -12,6 +13,7 @@ pub(crate) use cli_bridge::*;
|
|||||||
pub(crate) use core::*;
|
pub(crate) use core::*;
|
||||||
pub(crate) use navidrome::*;
|
pub(crate) use navidrome::*;
|
||||||
pub(crate) use perf::*;
|
pub(crate) use perf::*;
|
||||||
|
pub(crate) use platform::*;
|
||||||
pub(crate) use remote::*;
|
pub(crate) use remote::*;
|
||||||
pub(crate) use integration::*;
|
pub(crate) use integration::*;
|
||||||
pub(crate) use analysis::*;
|
pub(crate) use analysis::*;
|
||||||
|
|||||||
@@ -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(())
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user