From dafff2680e256d79ef3a8fed50f768e0eea5667b Mon Sep 17 00:00:00 2001 From: "web3nomad.eth" Date: Mon, 18 Mar 2024 03:23:09 +0800 Subject: [PATCH] disable cmd + q (#21) --- apps/desktop/src-tauri/Cargo.toml | 2 +- apps/desktop/src-tauri/tauri.conf.json | 3 ++- apps/web/src/components/ClientLayout.tsx | 18 ++++++++++++++++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/apps/desktop/src-tauri/Cargo.toml b/apps/desktop/src-tauri/Cargo.toml index 9591e958..9f1b1071 100644 --- a/apps/desktop/src-tauri/Cargo.toml +++ b/apps/desktop/src-tauri/Cargo.toml @@ -13,7 +13,7 @@ rust-version = "1.60" tauri-build = { version = "1.5.1", features = [] } [dependencies] -tauri = { version = "1.5.4", features = [ "os-all", "path-all", +tauri = { version = "1.5.4", features = [ "dialog-message", "os-all", "path-all", "dialog-ask", "dialog-open", "protocol-all", diff --git a/apps/desktop/src-tauri/tauri.conf.json b/apps/desktop/src-tauri/tauri.conf.json index d6b28cd5..9c750c76 100644 --- a/apps/desktop/src-tauri/tauri.conf.json +++ b/apps/desktop/src-tauri/tauri.conf.json @@ -53,7 +53,8 @@ }, "dialog": { "ask": true, - "open": true + "open": true, + "message": true }, "protocol": { diff --git a/apps/web/src/components/ClientLayout.tsx b/apps/web/src/components/ClientLayout.tsx index 0ae62f5f..8149780c 100644 --- a/apps/web/src/components/ClientLayout.tsx +++ b/apps/web/src/components/ClientLayout.tsx @@ -1,5 +1,5 @@ "use client"; -import { useCallback, useEffect, useState, useMemo } from "react"; +import { useCallback, useEffect, useState, useMemo, use } from "react"; import { client, queryClient, rspc } from "@/lib/rspc"; import { convertFileSrc } from '@tauri-apps/api/tauri'; import { CurrentLibrary } from "@/lib/library"; @@ -14,7 +14,21 @@ export default function ClientLayout({ const [libraryId, setLibraryId] = useState(null); const [homeDir, setHomeDir] = useState(null); + const blockCmdQ = useCallback(() => { + document.addEventListener('keydown', event => { + if (event.metaKey && (event.key === 'q' || event.key === 'w')) { + event.preventDefault() + console.log('Cmd + Q is pressed.') + alert('Cmd + Q 暂时禁用了,因为会导致 qdrant 不正常停止,TODO:实现 Cmd + Q 按了以后自行处理 app 退出') + /** + * https://github.com/bmrlab/tauri-dam-test-playground/issues/21#issuecomment-2002549684 + */ + } + }) + }, []) + useEffect(() => { + blockCmdQ() const p1 = client.query(["libraries.get_current_library"]).then((libraryIdInStorage) => { setLibraryId(libraryIdInStorage); }).catch(error => { @@ -28,7 +42,7 @@ export default function ClientLayout({ setHomeDir(null); }); Promise.all([p1, p2]).then(() => setPending(false)); - }, [setLibraryId, setPending]); + }, [setLibraryId, setPending, blockCmdQ]); const setContext = useCallback(async (id: string) => { setLibraryId(id);