Skip to content

Commit

Permalink
Add desktop shortcut support
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonEWNL committed Mar 2, 2024
1 parent 99fb9dc commit 18d5ff8
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 1 deletion.
45 changes: 45 additions & 0 deletions app/components/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down Expand Up @@ -128,6 +130,45 @@ function useDragSideBar() {
};
}

function useGlobalShortcut() {
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();
}, []);
}

export function SideBar(props: { className?: string }) {
const chatStore = useChatStore();

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

useHotKey();

if (window.__TAURI__) {
useGlobalShortcut();
}

return (
<div
className={`${styles.sidebar} ${props.className} ${
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@hello-pangea/dnd": "^16.5.0",
"@next/third-parties": "^14.1.0",
"@svgr/webpack": "^6.5.1",
"@tauri-apps/api": "^1.5.3",
"@vercel/analytics": "^0.1.11",
"@vercel/speed-insights": "^1.0.2",
"emoji-picker-react": "^4.5.15",
Expand Down Expand Up @@ -64,4 +65,4 @@
"resolutions": {
"lint-staged/yaml": "^2.2.2"
}
}
}
1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ tauri = { version = "1.5.4", features = [
"window-start-dragging",
"window-unmaximize",
"window-unminimize",
"global-shortcut-all",
] }
tauri-plugin-window-state = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }

Expand Down
3 changes: 3 additions & 0 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
},
"notification": {
"all": true
},
"globalShortcut": {
"all": true
}
},
"bundle": {
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1438,6 +1438,11 @@
dependencies:
tslib "^2.4.0"

"@tauri-apps/api@^1.5.3":
version "1.5.3"
resolved "https://registry.yarnpkg.com/@tauri-apps/api/-/api-1.5.3.tgz#f7b362b1f30aadb0a8bbeb7ae111755c0ed33d73"
integrity sha512-zxnDjHHKjOsrIzZm6nO5Xapb/BxqUq1tc7cGkFXsFkGTsSWgCPH1D8mm0XS9weJY2OaR73I3k3S+b7eSzJDfqA==

"@tauri-apps/cli-darwin-arm64@1.5.7":
version "1.5.7"
resolved "https://registry.yarnpkg.com/@tauri-apps/cli-darwin-arm64/-/cli-darwin-arm64-1.5.7.tgz#3435f1b6c4b431e0283f94c3a0bd486be66b24ee"
Expand Down

0 comments on commit 18d5ff8

Please sign in to comment.