Skip to content

useLongPress 在 macOS 的 Tauri 应用中无法生效。 #2861

@ayangweb

Description

@ayangweb
iShot_2025-09-24_22.53.52.mp4
import { convertFileSrc } from "@tauri-apps/api/core";
import { openPath } from "@tauri-apps/plugin-opener";
import { useLongPress } from "ahooks";
import { type FC, useRef } from "react";
import type { App as AppProps } from "@/stores/app";
import { hidePanel } from "@/utils/nsPanel";

const App: FC<AppProps> = (props) => {
  const { name, icon, path } = props;
  const containerRef = useRef<HTMLDivElement>(null);

  const handleLongPress = () => {
    console.log("handleLongPress");
  };

  const openApp = () => {
    console.log("openApp");

    openPath(path);

    hidePanel();
  };

  useLongPress(handleLongPress, containerRef, {
    onClick: openApp,
  });

  return (
    <div
      className="grid place-items-center active:opacity-70"
      ref={containerRef}
    >
      <img alt={name} className="size-24" src={convertFileSrc(icon)} />

      <span className="truncate">{name}</span>
    </div>
  );
};

export default App;

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions