Turn any website into a lightweight desktop app with one command, on macOS, Windows and Linux.
Rust chatgptclaudeclidesktopdesktop-appelectron-alternativegeminilinuxmacosnativefierno-electronrusttauriweb-to-desktopwebsite-to-appwebviewwindowsyoutube
feat: enable trackpad swipes for history on macOS
Tw93b690a8eb49d2
diff --git a/src-tauri/src/app/navigation.rs b/src-tauri/src/app/navigation.rsindex 71da1a7c..2c4ab75e 100644--- a/src-tauri/src/app/navigation.rs+++ b/src-tauri/src/app/navigation.rs@@ -54,6 +54,25 @@ pub fn set_password_autosave(webview: &tauri::webview::PlatformWebview, enabled:}}+/// Let a two-finger horizontal trackpad swipe step history, as in Safari.+///+/// WKWebView leaves `allowsBackForwardNavigationGestures` off, and Tauri does+/// not expose Wry's builder switch, so set it on the native view directly.+#[cfg(target_os = "macos")]+pub fn enable_back_forward_gestures(webview: &tauri::webview::PlatformWebview) {+ use objc2::msg_send;+ use objc2::runtime::{AnyObject, Bool};++ let ptr = webview.inner() as *mut AnyObject;+ if ptr.is_null() {+ eprintln!("[Pake] Failed to access WKWebView for history swipe gestures");+ return;+ }+ unsafe {+ let _: () = msg_send![ptr, setAllowsBackForwardNavigationGestures: Bool::YES];+ }+}+#[cfg(target_os = "macos")]fn history_step_platform(webview: &tauri::webview::PlatformWebview, back: bool) {use objc2::msg_send;diff --git a/src-tauri/src/app/window.rs b/src-tauri/src/app/window.rsindex b83187bc..6e206e6a 100644--- a/src-tauri/src/app/window.rs+++ b/src-tauri/src/app/window.rs@@ -830,6 +830,15 @@ fn build_window(}}+ // Every webview is built here (main window, Cmd+N clones, --new-window and+ // blank two-stage popups), so trackpad history swipes match in all of them.+ #[cfg(target_os = "macos")]+ if let Err(error) = window.with_webview(|webview| {+ crate::app::navigation::enable_back_forward_gestures(&webview);+ }) {+ eprintln!("[Pake] Failed to access WKWebView for history swipe gestures: {error}");+ }+// The tab bar's + button exists only while some window class answers// `newWindowForTab:`. Install it for every tabbing window, the main one// included: its tab bar is the one the user sees first.diff --git a/tests/unit/macos-history-gestures.test.ts b/tests/unit/macos-history-gestures.test.tsnew file mode 100644index 00000000..52000ca1--- /dev/null+++ b/tests/unit/macos-history-gestures.test.ts@@ -0,0 +1,62 @@+import fs from 'node:fs';+import path from 'node:path';+import { describe, expect, it } from 'vitest';++const rustRoot = path.join(process.cwd(), 'src-tauri', 'src');+const read = (relative: string) =>+ fs.readFileSync(path.join(rustRoot, relative), 'utf8');++function rustSources(directory: string): string[] {+ return fs.readdirSync(directory, { withFileTypes: true }).flatMap((entry) => {+ const full = path.join(directory, entry.name);+ if (entry.isDirectory()) return rustSources(full);+ return entry.name.endsWith('.rs') ? [full] : [];+ });+}++describe('macOS trackpad history gestures (#1401)', () => {+ it('turns on the native WKWebView switch, gated to macOS', () => {+ const navigation = read('app/navigation.rs');+ const helper = navigation.indexOf('pub fn enable_back_forward_gestures(');+ expect(helper).toBeGreaterThan(-1);+ expect(navigation.slice(Math.max(0, helper - 400), helper)).toMatch(+ /#\[cfg\(target_os = "macos"\)\]\s*$/,+ );+ expect(navigation).toContain(+ 'msg_send![ptr, setAllowsBackForwardNavigationGestures: Bool::YES]',+ );+ });++ it('applies it to the one builder every window path goes through', () => {+ const builders = rustSources(rustRoot).filter((file) =>+ fs.readFileSync(file, 'utf8').includes('WebviewWindowBuilder::new('),+ );+ expect(builders.map((file) => path.relative(rustRoot, file))).toEqual([+ path.join('app', 'window.rs'),+ ]);++ const window = read('app/window.rs');+ const start = window.indexOf('fn build_window(');+ const end = window.indexOf('\n}\n', start);+ const body = window.slice(start, end);+ const built = body.indexOf('let window = window_builder.build()?;');+ const gesture = body.indexOf(+ 'crate::app::navigation::enable_back_forward_gestures(&webview);',+ );+ expect(built).toBeGreaterThan(-1);+ expect(gesture).toBeGreaterThan(built);+ expect(body.slice(Math.max(0, gesture - 300), gesture)).toMatch(+ /#\[cfg\(target_os = "macos"\)\]\s*if let Err\(error\) = window\.with_webview\(/,+ );++ // Main window, Cmd+N clones and popups must all reach build_window.+ expect(window).toMatch(/fn build_window_with_label[\s\S]*?build_window\(/);+ expect(window).toMatch(/fn open_requested_window[\s\S]*?build_window\(/);+ expect(window).toMatch(+ /pub fn set_window[\s\S]*?build_window_with_label\(app, config, tauri_config, "pake"\)/,+ );+ expect(window).toMatch(+ /pub fn open_additional_window\([\s\S]*?build_window_with_label\(/,+ );+ });+});