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?
Conversation
@JasonEWNL is attempting to deploy a commit to the NextChat Team on Vercel. A member of the Team first needs to authorize it. |
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.
request changes
app/components/sidebar.tsx
Outdated
handleMasks(); | ||
handleSettings(); | ||
handleNewChat(); | ||
}, []); |
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.
add this comment
// eslint-disable-next-line react-hooks/exhaustive-deps
for example:
useEffect(() => {
handleMasks();
handleSettings();
handleNewChat();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
for ignore/bypass that stupid react/nextjs
warning
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.
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 comment
The 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 comment
The 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.
@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
now it's better after bypassing that stupid warning |
wait what it doesn't work anymore |
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.
it's should be fix
@@ -128,6 +130,46 @@ function useDragSideBar() { | |||
}; | |||
} | |||
|
|||
function useGlobalShortcut() { |
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
function useGlobalShortcut() {
// Early return if not in a Tauri environment
if (!window.__TAURI__) {
return;
}
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();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}
app/components/sidebar.tsx
Outdated
@@ -143,6 +185,10 @@ export function SideBar(props: { className?: string }) { | |||
|
|||
useHotKey(); | |||
|
|||
if (window.__TAURI__) { |
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
useGlobalShortcut(); // Always called, regardless of environment
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.
@JasonEWNL remove if
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.
@@ -131,6 +131,10 @@ function useDragSideBar() { | |||
} | |||
|
|||
function useGlobalShortcut() { |
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.
@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.
}
Your build has completed! |
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 still need put // eslint-disable-next-line react-hooks/exhaustive-deps
app/components/sidebar.tsx
Outdated
handleSettings(); | ||
handleNewChat(); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
if (window.__TAURI__) { |
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.
you still need to put // eslint-disable-next-line react-hooks/exhaustive-deps
for bypass/ignore stupid react/nextjs warning
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.
Thanks for your patience! All changes are cleaned and submitted.
Command
orCtrl
+Shift
+M
Command
orCtrl
+,
Command
orCtrl
+N