From ad519712392a012bec75ba11aa994569e666fe47 Mon Sep 17 00:00:00 2001 From: Ren Amamiya <123083837+reyamir@users.noreply.github.com> Date: Mon, 19 Jun 2023 14:41:02 +0700 Subject: [PATCH] add composer shortcut --- src-tauri/Cargo.toml | 2 +- src-tauri/tauri.conf.json | 3 +++ src/shared/button.tsx | 2 +- src/shared/composer/modal.tsx | 14 +++++++++++++- src/stores/shortcuts.tsx | 1 + 5 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 src/stores/shortcuts.tsx diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 4950aa95..5f1be2f5 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -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"] } diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 4a7729e8..15cb0cd5 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -66,6 +66,9 @@ "exit": false, "relaunch": true, "relaunchDangerousAllowSymlinkMacos": false + }, + "globalShortcut": { + "all": true } }, "bundle": { diff --git a/src/shared/button.tsx b/src/shared/button.tsx index d4a2c2c3..4a557a34 100644 --- a/src/shared/button.tsx +++ b/src/shared/button.tsx @@ -9,7 +9,7 @@ export function Button({ }: { preset: "small" | "publish" | "large"; children: ReactNode; - disabled: boolean; + disabled?: boolean; onClick?: () => void; }) { let preClass: string; diff --git a/src/shared/composer/modal.tsx b/src/shared/composer/modal.tsx index 991e29d7..f874c4cf 100644 --- a/src/shared/composer/modal.tsx +++ b/src/shared/composer/modal.tsx @@ -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 ( <>