-
Notifications
You must be signed in to change notification settings - Fork 57.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add desktop shortcut support #4194
base: main
Are you sure you want to change the base?
Changes from 1 commit
18d5ff8
3b2bc86
96f7db1
75c5812
80ef6a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,8 @@ import { isIOS, useMobileScreen } from "../utils"; | |
import dynamic from "next/dynamic"; | ||
import { showConfirm, showToast } from "./ui-lib"; | ||
|
||
import { register } from "@tauri-apps/api/globalShortcut"; | ||
|
||
const ChatList = dynamic(async () => (await import("./chat-list")).ChatList, { | ||
loading: () => null, | ||
}); | ||
|
@@ -128,6 +130,45 @@ function useDragSideBar() { | |
}; | ||
} | ||
|
||
function useGlobalShortcut() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @JasonEWNL there is another one function useGlobalShortcut() {
// Call hooks at the top level to comply with the rules of hooks.
const chatStore = useChatStore();
const navigate = useNavigate();
const config = useAppConfig();
useEffect(() => {
// Early return if not in a Tauri environment. This way, the hooks are called unconditionally,
// but the code inside useEffect only runs conditionally.
if (!window.__TAURI__) {
return;
}
const handleMasks = async () => {
await register("CommandOrControl+Shift+M", () => {
if (config.dontShowMaskSplashScreen !== true) {
navigate(Path.NewChat, { state: { fromHome: true } });
} else {
navigate(Path.Masks, { state: { fromHome: true } });
}
});
};
const handleSettings = async () => {
await register("CommandOrControl+,", () => {
navigate(Path.Settings);
});
};
const handleNewChat = async () => {
await register("CommandOrControl+N", () => {
if (config.dontShowMaskSplashScreen) {
chatStore.newSession();
navigate(Path.Chat);
} else {
navigate(Path.NewChat);
}
});
};
// Execute the registration functions.
handleMasks();
handleSettings();
handleNewChat();
// Remember to return a cleanup function if necessary, for example, to unregister the shortcuts.
}, [chatStore, navigate, config]); // Include all dependencies here.
} |
||
const chatStore = useChatStore(); | ||
const navigate = useNavigate(); | ||
const config = useAppConfig(); | ||
|
||
const handleMasks = async () => { | ||
await register("CommandOrControl+Shift+M", () => { | ||
if (config.dontShowMaskSplashScreen !== true) { | ||
navigate(Path.NewChat, { state: { fromHome: true } }); | ||
} else { | ||
navigate(Path.Masks, { state: { fromHome: true } }); | ||
} | ||
}); | ||
}; | ||
|
||
const handleSettings = async () => { | ||
await register("CommandOrControl+,", () => { | ||
navigate(Path.Settings); | ||
}); | ||
}; | ||
|
||
const handleNewChat = async () => { | ||
await register("CommandOrControl+N", () => { | ||
if (config.dontShowMaskSplashScreen) { | ||
chatStore.newSession(); | ||
navigate(Path.Chat); | ||
} else { | ||
navigate(Path.NewChat); | ||
} | ||
}); | ||
}; | ||
|
||
useEffect(() => { | ||
handleMasks(); | ||
handleSettings(); | ||
handleNewChat(); | ||
}, []); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add this comment for example: useEffect(() => {
handleMasks();
handleSettings();
handleNewChat();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []); for ignore/bypass that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for your review! It might be refactored into a modular structure if desktop shortcut feature is accepted. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @JasonEWNL cek new one There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@JasonEWNL The desktop version is actually quite useful compared to the web version, which has limitations. For instance, you can't leverage certain features on the web version, but you can definitely leverage them on the desktop version. since it's safe through memory leaks and other |
||
} | ||
|
||
export function SideBar(props: { className?: string }) { | ||
const chatStore = useChatStore(); | ||
|
||
|
@@ -143,6 +184,10 @@ export function SideBar(props: { className?: string }) { | |
|
||
useHotKey(); | ||
|
||
if (window.__TAURI__) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this the correct useGlobalShortcut(); // Always called, regardless of environment There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @JasonEWNL remove |
||
useGlobalShortcut(); | ||
} | ||
|
||
return ( | ||
<div | ||
className={`${styles.sidebar} ${props.className} ${ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,9 @@ | |
}, | ||
"notification": { | ||
"all": true | ||
}, | ||
"globalShortcut": { | ||
"all": true | ||
} | ||
}, | ||
"bundle": { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this the correct