add composer shortcut

This commit is contained in:
Ren Amamiya 2023-06-19 14:41:02 +07:00
parent f944693a2a
commit ad51971239
5 changed files with 19 additions and 3 deletions

View File

@ -16,7 +16,7 @@ tauri-build = { version = "1.2", features = [] }
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.2", features = ["clipboard-read-text", "clipboard-write-text", "dialog-open", "fs-read-dir", "fs-read-file", "http-all", "http-multipart", "notification-all", "os-all", "process-relaunch", "shell-open", "system-tray", "updater", "window-close", "window-start-dragging"] }
tauri = { version = "1.2", features = [ "global-shortcut-all", "clipboard-read-text", "clipboard-write-text", "dialog-open", "fs-read-dir", "fs-read-file", "http-all", "http-multipart", "notification-all", "os-all", "process-relaunch", "shell-open", "system-tray", "updater", "window-close", "window-start-dragging"] }
tauri-plugin-single-instance = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "dev" }
tauri-plugin-store = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "dev" }
sqlx-cli = {version = "0.6.3", default-features = false, features = ["sqlite"] }

View File

@ -66,6 +66,9 @@
"exit": false,
"relaunch": true,
"relaunchDangerousAllowSymlinkMacos": false
},
"globalShortcut": {
"all": true
}
},
"bundle": {

View File

@ -9,7 +9,7 @@ export function Button({
}: {
preset: "small" | "publish" | "large";
children: ReactNode;
disabled: boolean;
disabled?: boolean;
onClick?: () => void;
}) {
let preClass: string;

View File

@ -10,7 +10,9 @@ import {
} from "@shared/icons";
import { useActiveAccount } from "@stores/accounts";
import { useComposer } from "@stores/composer";
import { Fragment } from "react";
import { COMPOSE_SHORTCUT } from "@stores/shortcuts";
import { register } from "@tauri-apps/api/globalShortcut";
import { Fragment, useEffect } from "react";
export function Composer() {
const account = useActiveAccount((state: any) => state.account);
@ -23,6 +25,16 @@ export function Composer() {
toggle(false);
};
const registerShortcut = async () => {
await register(COMPOSE_SHORTCUT, () => {
toggle(true);
});
};
useEffect(() => {
registerShortcut();
}, [registerShortcut]);
return (
<>
<Button onClick={() => toggle(true)} preset="small">

1
src/stores/shortcuts.tsx Normal file
View File

@ -0,0 +1 @@
export const COMPOSE_SHORTCUT = "CommandOrControl+N";