Skip to content

Commit

Permalink
disable cmd + q (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
web3nomad committed Mar 17, 2024
1 parent 1a7ee72 commit dafff26
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion apps/desktop/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion apps/desktop/src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
},
"dialog": {
"ask": true,
"open": true
"open": true,
"message": true
},

"protocol": {
Expand Down
18 changes: 16 additions & 2 deletions apps/web/src/components/ClientLayout.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -14,7 +14,21 @@ export default function ClientLayout({
const [libraryId, setLibraryId] = useState<string|null>(null);
const [homeDir, setHomeDir] = useState<string|null>(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 => {
Expand All @@ -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);
Expand Down

0 comments on commit dafff26

Please sign in to comment.