Skip to content
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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

JasonEWNL
Copy link

Keyboard shortcut Description
Command or Ctrl + Shift + M Masks
Command or Ctrl + , Settings
Command or Ctrl + N New Chat

Copy link

vercel bot commented Mar 2, 2024

@JasonEWNL is attempting to deploy a commit to the NextChat Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

@H0llyW00dzZ H0llyW00dzZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

request changes

handleMasks();
handleSettings();
handleNewChat();
}, []);
Copy link
Contributor

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

Copy link
Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JasonEWNL cek new one

Copy link
Contributor

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

@H0llyW00dzZ
Copy link
Contributor

now it's better after bypassing that stupid warning

@H0llyW00dzZ
Copy link
Contributor

wait what it doesn't work anymore

Copy link
Contributor

@H0llyW00dzZ H0llyW00dzZ left a 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() {
Copy link
Contributor

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
  }, []);
}

@@ -143,6 +185,10 @@ export function SideBar(props: { className?: string }) {

useHotKey();

if (window.__TAURI__) {
Copy link
Contributor

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JasonEWNL remove if

Copy link
Contributor

@H0llyW00dzZ H0llyW00dzZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another request changes for fix this stupid warning

image

@@ -131,6 +131,10 @@ function useDragSideBar() {
}

function useGlobalShortcut() {
Copy link
Contributor

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.
}

Copy link
Contributor

github-actions bot commented Mar 2, 2024

Your build has completed!

Preview deployment

Copy link
Contributor

@H0llyW00dzZ H0llyW00dzZ left a 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

handleSettings();
handleNewChat();
// eslint-disable-next-line react-hooks/exhaustive-deps
if (window.__TAURI__) {
Copy link
Contributor

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

Copy link
Author

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.

@H0llyW00dzZ
Copy link
Contributor

its better now

image

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


its better now

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants