From 2bb6ed2602fbf69bf75a841949cff04a311ffa4a Mon Sep 17 00:00:00 2001 From: Huang Xin Date: Sat, 22 Feb 2025 00:18:06 +0100 Subject: [PATCH] feat: add haptics feedback when entering select mode (#428) --- Cargo.lock | 15 +++++++++++++++ apps/readest-app/package.json | 1 + apps/readest-app/src-tauri/Cargo.toml | 1 + .../src-tauri/capabilities/default.json | 4 ++++ apps/readest-app/src-tauri/src/lib.rs | 7 +++++-- .../{traffic_light_plugin.rs => traffic_light.rs} | 2 +- .../src/app/library/components/BookshelfItem.tsx | 2 +- .../src/app/library/components/LibraryHeader.tsx | 2 +- apps/readest-app/src/app/library/page.tsx | 7 +++++++ pnpm-lock.yaml | 10 ++++++++++ 10 files changed, 46 insertions(+), 5 deletions(-) rename apps/readest-app/src-tauri/src/{traffic_light_plugin.rs => traffic_light.rs} (99%) diff --git a/Cargo.lock b/Cargo.lock index 8e7e4cf8..7affd673 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -23,6 +23,7 @@ dependencies = [ "tauri-plugin-devtools", "tauri-plugin-dialog", "tauri-plugin-fs", + "tauri-plugin-haptics", "tauri-plugin-http", "tauri-plugin-log", "tauri-plugin-oauth", @@ -5207,6 +5208,20 @@ dependencies = [ "uuid", ] +[[package]] +name = "tauri-plugin-haptics" +version = "2.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52db8ae1bb6eab8502ee5c32acb905323c9651491c7f229d84f45b8c57d12327" +dependencies = [ + "log", + "serde", + "serde_json", + "tauri", + "tauri-plugin", + "thiserror 2.0.11", +] + [[package]] name = "tauri-plugin-http" version = "2.3.0" diff --git a/apps/readest-app/package.json b/apps/readest-app/package.json index 4f0d0d85..0029ca6d 100644 --- a/apps/readest-app/package.json +++ b/apps/readest-app/package.json @@ -47,6 +47,7 @@ "@tauri-apps/plugin-deep-link": "^2.2.0", "@tauri-apps/plugin-dialog": "^2.2.0", "@tauri-apps/plugin-fs": "^2.2.0", + "@tauri-apps/plugin-haptics": "^2.2.3", "@tauri-apps/plugin-http": "^2.3.0", "@tauri-apps/plugin-log": "^2.2.1", "@tauri-apps/plugin-opener": "^2.2.5", diff --git a/apps/readest-app/src-tauri/Cargo.toml b/apps/readest-app/src-tauri/Cargo.toml index a5357bf5..5549c33c 100644 --- a/apps/readest-app/src-tauri/Cargo.toml +++ b/apps/readest-app/src-tauri/Cargo.toml @@ -45,6 +45,7 @@ tauri-plugin-oauth = "2" tauri-plugin-opener = "2.2.2" tauri-plugin-deep-link = "2" tauri-plugin-sign-in-with-apple = "1.0.2" +tauri-plugin-haptics = "2.2.3" [patch.crates-io] tauri = { path = "../../../packages/tauri/crates/tauri" } diff --git a/apps/readest-app/src-tauri/capabilities/default.json b/apps/readest-app/src-tauri/capabilities/default.json index 464d15a1..cfdd2115 100644 --- a/apps/readest-app/src-tauri/capabilities/default.json +++ b/apps/readest-app/src-tauri/capabilities/default.json @@ -70,6 +70,10 @@ "oauth:allow-cancel", "sign-in-with-apple:default", "opener:default", + "haptics:allow-vibrate", + "haptics:allow-impact-feedback", + "haptics:allow-notification-feedback", + "haptics:allow-selection-feedback", "deep-link:default" ] } diff --git a/apps/readest-app/src-tauri/src/lib.rs b/apps/readest-app/src-tauri/src/lib.rs index a37aabf6..00010272 100644 --- a/apps/readest-app/src-tauri/src/lib.rs +++ b/apps/readest-app/src-tauri/src/lib.rs @@ -9,7 +9,7 @@ extern crate objc; #[cfg(target_os = "macos")] mod menu; #[cfg(target_os = "macos")] -mod traffic_light_plugin; +mod traffic_light; #[cfg(target_os = "macos")] use tauri::TitleBarStyle; @@ -127,11 +127,14 @@ pub fn run() { let builder = builder.plugin(tauri_plugin_window_state::Builder::default().build()); #[cfg(target_os = "macos")] - let builder = builder.plugin(traffic_light_plugin::init()); + let builder = builder.plugin(traffic_light::init()); #[cfg(target_os = "ios")] let builder = builder.plugin(tauri_plugin_sign_in_with_apple::init()); + #[cfg(any(target_os = "ios", target_os = "android"))] + let builder = builder.plugin(tauri_plugin_haptics::init()); + builder .setup(|#[allow(unused_variables)] app| { #[cfg(desktop)] diff --git a/apps/readest-app/src-tauri/src/traffic_light_plugin.rs b/apps/readest-app/src-tauri/src/traffic_light.rs similarity index 99% rename from apps/readest-app/src-tauri/src/traffic_light_plugin.rs rename to apps/readest-app/src-tauri/src/traffic_light.rs index 2853b05e..998f44d8 100644 --- a/apps/readest-app/src-tauri/src/traffic_light_plugin.rs +++ b/apps/readest-app/src-tauri/src/traffic_light.rs @@ -14,7 +14,7 @@ unsafe impl Send for UnsafeWindowHandle {} unsafe impl Sync for UnsafeWindowHandle {} pub fn init() -> TauriPlugin { - Builder::new("traffic_light_positioner") + Builder::new("traffic_light") .on_window_ready(|window| { #[cfg(target_os = "macos")] setup_traffic_light_positioner(window.clone()); diff --git a/apps/readest-app/src/app/library/components/BookshelfItem.tsx b/apps/readest-app/src/app/library/components/BookshelfItem.tsx index 335c2334..297a2b43 100644 --- a/apps/readest-app/src/app/library/components/BookshelfItem.tsx +++ b/apps/readest-app/src/app/library/components/BookshelfItem.tsx @@ -219,7 +219,7 @@ const BookshelfItem: React.FC = ({ }; const { pressing, handlers } = useLongPress({ - onLongPress: () => { + onLongPress: async () => { if (!isSelectMode) { handleSetSelectMode(true); } diff --git a/apps/readest-app/src/app/library/components/LibraryHeader.tsx b/apps/readest-app/src/app/library/components/LibraryHeader.tsx index ea3bb4cb..6798b9cc 100644 --- a/apps/readest-app/src/app/library/components/LibraryHeader.tsx +++ b/apps/readest-app/src/app/library/components/LibraryHeader.tsx @@ -91,7 +91,7 @@ const LibraryHeader: React.FC = ({ />
- + { }; const handleToggleSelectMode = () => { + if (!isSelectMode && appService?.isMobile) { + impactFeedback('medium'); + } setIsSelectMode(!isSelectMode); }; const handleSetSelectMode = (selectMode: boolean) => { + if (selectMode && appService?.isMobile) { + impactFeedback('medium'); + } setIsSelectMode(selectMode); }; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1dc396e4..aaabfca0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -68,6 +68,9 @@ importers: '@tauri-apps/plugin-fs': specifier: ^2.2.0 version: 2.2.0 + '@tauri-apps/plugin-haptics': + specifier: ^2.2.3 + version: 2.2.3 '@tauri-apps/plugin-http': specifier: ^2.3.0 version: 2.3.0 @@ -1735,6 +1738,9 @@ packages: '@tauri-apps/plugin-fs@2.2.0': resolution: {integrity: sha512-+08mApuONKI8/sCNEZ6AR8vf5vI9DXD4YfrQ9NQmhRxYKMLVhRW164vdW5BSLmMpuevftpQ2FVoL9EFkfG9Z+g==} + '@tauri-apps/plugin-haptics@2.2.3': + resolution: {integrity: sha512-tHWAOR0TSOuWIdJ4Fh/4z+L8CvSfHdg5i7XfCqjErPu63PMf+2n856VIGcC6fjF29hf/vq+BiGApWt38n66Gvg==} + '@tauri-apps/plugin-http@2.3.0': resolution: {integrity: sha512-pigTvz+zzAqbIhCzRiR1GE98Jw7A03j2V+Eiexr9thBI8VfMiwFQMcbgON51xlwnVaI72LdbYKNajU84im8tlg==} @@ -6636,6 +6642,10 @@ snapshots: dependencies: '@tauri-apps/api': 2.2.0 + '@tauri-apps/plugin-haptics@2.2.3': + dependencies: + '@tauri-apps/api': 2.2.0 + '@tauri-apps/plugin-http@2.3.0': dependencies: '@tauri-apps/api': 2.2.0