From 308620170e3a10685e45c9a3bc0c12c68ceaa8cf Mon Sep 17 00:00:00 2001 From: Huakun Shen Date: Wed, 19 Feb 2025 20:55:58 -0500 Subject: [PATCH] feat(desktop): add get selected text functionality. Only works when focus is not on Kunkun --- Cargo.lock | 287 ++++++++++++++++-- apps/desktop/src-tauri/Cargo.toml | 1 + apps/desktop/src/routes/app/+page.svelte | 13 +- packages/api/src/commands/system.ts | 4 + packages/tauri-plugins/jarvis/Cargo.toml | 2 +- packages/tauri-plugins/jarvis/build.rs | 1 + .../tauri-plugins/jarvis/permissions/all.toml | 1 + .../commands/get_selected_text.toml | 13 + .../permissions/autogenerated/reference.md | 26 ++ .../jarvis/permissions/schemas/schema.json | 10 + .../jarvis/src/commands/system.rs | 6 + packages/tauri-plugins/jarvis/src/lib.rs | 1 + 12 files changed, 343 insertions(+), 22 deletions(-) create mode 100644 packages/tauri-plugins/jarvis/permissions/autogenerated/commands/get_selected_text.toml diff --git a/Cargo.lock b/Cargo.lock index a0a409a..dbc796a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,43 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "accessibility-ng" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7cb28d49c934e5f32a0b2227510e00999423596eff62f257962db130c3fa716" +dependencies = [ + "accessibility-sys-ng", + "cocoa 0.24.1", + "core-foundation 0.9.4", + "core-graphics-types 0.1.3", + "objc", + "thiserror 1.0.66", +] + +[[package]] +name = "accessibility-sys-ng" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02eadf4b9910301a47799cea1a8eefa659536fec71f5b8496b583b5e521db0b3" +dependencies = [ + "core-foundation-sys", +] + +[[package]] +name = "active-win-pos-rs" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e227f8493de9f5e493f8e762ac7516d2ae42464df2e8122fcafd604f0b16c634" +dependencies = [ + "appkit-nsworkspace-bindings", + "core-foundation 0.9.4", + "core-graphics 0.23.2", + "objc", + "windows 0.48.0", + "xcb", +] + [[package]] name = "addr2line" version = "0.24.2" @@ -204,6 +241,16 @@ version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "74f37166d7d48a0284b99dd824694c26119c700b53bf0d1540cdb147dbdaaf13" +[[package]] +name = "appkit-nsworkspace-bindings" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "062382938604cfa02c03689ab75af0e7eb79175ba0d0b2bcfad18f5190702dd7" +dependencies = [ + "bindgen 0.68.1", + "objc", +] + [[package]] name = "applications" version = "0.2.3" @@ -237,6 +284,24 @@ dependencies = [ "derive_arbitrary", ] +[[package]] +name = "arboard" +version = "3.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df099ccb16cd014ff054ac1bf392c67feeef57164b05c42f037cd40f5d4357f4" +dependencies = [ + "clipboard-win", + "core-graphics 0.23.2", + "image", + "log", + "objc2", + "objc2-app-kit", + "objc2-foundation", + "parking_lot", + "windows-sys 0.48.0", + "x11rb", +] + [[package]] name = "arc-swap" version = "1.7.1" @@ -539,7 +604,7 @@ version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ad3a619a9de81e1d7de1f1186dcba4506ed661a0e483d84410fdef0ee87b2f96" dependencies = [ - "bindgen", + "bindgen 0.69.5", "cc", "cmake", "dunce", @@ -692,6 +757,29 @@ dependencies = [ "serde", ] +[[package]] +name = "bindgen" +version = "0.68.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "726e4313eb6ec35d2730258ad4e15b547ee75d6afaa1361a922e78e59b7d8078" +dependencies = [ + "bitflags 2.6.0", + "cexpr", + "clang-sys", + "lazy_static", + "lazycell", + "log", + "peeking_take_while", + "prettyplease", + "proc-macro2", + "quote", + "regex", + "rustc-hash 1.1.0", + "shlex", + "syn 2.0.87", + "which", +] + [[package]] name = "bindgen" version = "0.69.5" @@ -798,6 +886,25 @@ dependencies = [ "generic-array", ] +[[package]] +name = "block-sys" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae85a0696e7ea3b835a453750bf002770776609115e6d25c6d2ff28a8200f7e7" +dependencies = [ + "objc-sys", +] + +[[package]] +name = "block2" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e58aa60e59d8dbfcc36138f5f18be5f24394d33b38b24f7fd0b1caa33095f22f" +dependencies = [ + "block-sys", + "objc2", +] + [[package]] name = "block2" version = "0.5.1" @@ -1791,6 +1898,12 @@ dependencies = [ "rand 0.8.5", ] +[[package]] +name = "debug_print" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f215f9b7224f49fb73256115331f677d868b34d18b65dbe4db392e6021eea90" + [[package]] name = "deflate64" version = "0.1.9" @@ -2124,6 +2237,23 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3d8a32ae18130a3c84dd492d4215c3d913c3b07c6b63c2eb3eb7ff1101ab7bf" +[[package]] +name = "enigo" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0087a01fc8591217447d28005379fb5a183683cc83f0a4707af28cc6603f70fb" +dependencies = [ + "core-graphics 0.23.2", + "foreign-types-shared 0.3.1", + "icrate", + "libc", + "log", + "objc2", + "windows 0.56.0", + "xkbcommon 0.7.0", + "xkeysym", +] + [[package]] name = "enigo" version = "0.3.0" @@ -2140,7 +2270,7 @@ dependencies = [ "objc2-foundation", "serde", "windows 0.58.0", - "xkbcommon", + "xkbcommon 0.8.0", "xkeysym", ] @@ -2382,6 +2512,12 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foldhash" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0d2fde1f7b3d48b8395d5f2de76c18a528bd6a9cdde438df747bfcba3e05d6f" + [[package]] name = "foreign-types" version = "0.3.2" @@ -2676,6 +2812,27 @@ dependencies = [ "zeroize", ] +[[package]] +name = "get-selected-text" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c549df57295e7308958f904f0444a35507e33bba9ec2d58fbae45db58eba72d" +dependencies = [ + "accessibility-ng", + "accessibility-sys-ng", + "active-win-pos-rs", + "arboard", + "cocoa 0.24.1", + "core-foundation 0.9.4", + "core-graphics 0.22.3", + "debug_print", + "enigo 0.2.1", + "lru", + "macos-accessibility-client", + "objc", + "parking_lot", +] + [[package]] name = "gethostname" version = "0.4.3" @@ -3020,6 +3177,11 @@ name = "hashbrown" version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" +dependencies = [ + "allocator-api2", + "equivalent", + "foldhash", +] [[package]] name = "hashlink" @@ -3330,6 +3492,16 @@ dependencies = [ "png", ] +[[package]] +name = "icrate" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fb69199826926eb864697bddd27f73d9fddcffc004f5733131e15b465e30642" +dependencies = [ + "block2 0.4.0", + "objc2", +] + [[package]] name = "ident_case" version = "1.0.1" @@ -4067,6 +4239,15 @@ dependencies = [ "imgref", ] +[[package]] +name = "lru" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "234cf4f4a04dc1f57e24b96cc0cd600cf2af460d4161ac5ecdd0af8e1f3b2a38" +dependencies = [ + "hashbrown 0.15.0", +] + [[package]] name = "lzma-rs" version = "0.3.0" @@ -4115,6 +4296,16 @@ dependencies = [ "libc", ] +[[package]] +name = "macos-accessibility-client" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edf7710fbff50c24124331760978fb9086d6de6288dcdb38b25a97f8b1bdebbb" +dependencies = [ + "core-foundation 0.9.4", + "core-foundation-sys", +] + [[package]] name = "malloc_buf" version = "0.0.6" @@ -4178,6 +4369,15 @@ version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +[[package]] +name = "memmap2" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43a5a03cefb0d953ec0be133036f14e109412fa594edc2f77227249db66cc3ed" +dependencies = [ + "libc", +] + [[package]] name = "memmap2" version = "0.9.5" @@ -4663,7 +4863,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e4e89ad9e3d7d297152b17d39ed92cd50ca8063a89a9fa569046d41568891eff" dependencies = [ "bitflags 2.6.0", - "block2", + "block2 0.5.1", "libc", "objc2", "objc2-core-data", @@ -4679,7 +4879,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "74dd3b56391c7a0596a295029734d3c1c5e7e510a4cb30245f8221ccea96b009" dependencies = [ "bitflags 2.6.0", - "block2", + "block2 0.5.1", "objc2", "objc2-core-location", "objc2-foundation", @@ -4691,7 +4891,7 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a5ff520e9c33812fd374d8deecef01d4a840e7b41862d849513de77e44aa4889" dependencies = [ - "block2", + "block2 0.5.1", "objc2", "objc2-foundation", ] @@ -4703,7 +4903,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "617fbf49e071c178c0b24c080767db52958f716d9eabdf0890523aeae54773ef" dependencies = [ "bitflags 2.6.0", - "block2", + "block2 0.5.1", "objc2", "objc2-foundation", ] @@ -4714,7 +4914,7 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55260963a527c99f1819c4f8e3b47fe04f9650694ef348ffd2227e8196d34c80" dependencies = [ - "block2", + "block2 0.5.1", "objc2", "objc2-foundation", "objc2-metal", @@ -4726,7 +4926,7 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "000cfee34e683244f284252ee206a27953279d370e309649dc3ee317b37e5781" dependencies = [ - "block2", + "block2 0.5.1", "objc2", "objc2-contacts", "objc2-foundation", @@ -4745,7 +4945,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ee638a5da3799329310ad4cfa62fbf045d5f56e3ef5ba4149e7452dcf89d5a8" dependencies = [ "bitflags 2.6.0", - "block2", + "block2 0.5.1", "dispatch", "libc", "objc2", @@ -4757,7 +4957,7 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1a1ae721c5e35be65f01a03b6d2ac13a54cb4fa70d8a5da293d7b0020261398" dependencies = [ - "block2", + "block2 0.5.1", "objc2", "objc2-app-kit", "objc2-foundation", @@ -4770,7 +4970,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd0cba1276f6023976a406a14ffa85e1fdd19df6b0f737b063b95f6c8c7aadd6" dependencies = [ "bitflags 2.6.0", - "block2", + "block2 0.5.1", "objc2", "objc2-foundation", ] @@ -4782,7 +4982,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e42bee7bff906b14b167da2bac5efe6b6a07e6f7c0a21a7308d40c960242dc7a" dependencies = [ "bitflags 2.6.0", - "block2", + "block2 0.5.1", "objc2", "objc2-foundation", "objc2-metal", @@ -4805,7 +5005,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b8bb46798b20cd6b91cbd113524c490f1686f4c4e8f49502431415f3512e2b6f" dependencies = [ "bitflags 2.6.0", - "block2", + "block2 0.5.1", "objc2", "objc2-cloud-kit", "objc2-core-data", @@ -4825,7 +5025,7 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44fa5f9748dbfe1ca6c0b79ad20725a11eca7c2218bceb4b005cb1be26273bfe" dependencies = [ - "block2", + "block2 0.5.1", "objc2", "objc2-foundation", ] @@ -4837,7 +5037,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "76cfcbf642358e8689af64cee815d139339f3ed8ad05103ed5eaf73db8d84cb3" dependencies = [ "bitflags 2.6.0", - "block2", + "block2 0.5.1", "objc2", "objc2-core-location", "objc2-foundation", @@ -4850,7 +5050,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68bc69301064cebefc6c4c90ce9cba69225239e4b8ff99d445a2b5563797da65" dependencies = [ "bitflags 2.6.0", - "block2", + "block2 0.5.1", "objc2", "objc2-app-kit", "objc2-foundation", @@ -5087,6 +5287,12 @@ dependencies = [ "hmac", ] +[[package]] +name = "peeking_take_while" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" + [[package]] name = "percent-encoding" version = "2.3.1" @@ -5589,6 +5795,15 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3" +[[package]] +name = "quick-xml" +version = "0.30.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eff6510e86862b57b210fd8cbe8ed3f0d7d600b9c2863cd4549a2e033c66e956" +dependencies = [ + "memchr", +] + [[package]] name = "quick-xml" version = "0.31.0" @@ -6039,7 +6254,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8af382a047821a08aa6bfc09ab0d80ff48d45d8726f7cd8e44891f7cb4a4278e" dependencies = [ "ashpd", - "block2", + "block2 0.5.1", "glib-sys", "gobject-sys", "gtk-sys", @@ -7537,6 +7752,7 @@ dependencies = [ "db", "flate2", "futures-util", + "get-selected-text", "grpc", "ico", "local-ip-address", @@ -7839,7 +8055,7 @@ dependencies = [ name = "tauri-plugin-user-input" version = "0.1.0" dependencies = [ - "enigo", + "enigo 0.3.0", "lazy_static", "rdev", "serde", @@ -9069,6 +9285,15 @@ dependencies = [ "windows_x86_64_msvc 0.36.1", ] +[[package]] +name = "windows" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" +dependencies = [ + "windows-targets 0.48.5", +] + [[package]] name = "windows" version = "0.52.0" @@ -9543,7 +9768,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "553ca1ce149982123962fac2506aa75b8b76288779a77e72b12fa2fc34938647" dependencies = [ "base64 0.22.1", - "block2", + "block2 0.5.1", "cookie", "crossbeam-channel", "dpi", @@ -9648,6 +9873,17 @@ dependencies = [ "rustix", ] +[[package]] +name = "xcb" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1e2f212bb1a92cd8caac8051b829a6582ede155ccb60b5d5908b81b100952be" +dependencies = [ + "bitflags 1.3.2", + "libc", + "quick-xml 0.30.0", +] + [[package]] name = "xdg-home" version = "1.3.0" @@ -9658,6 +9894,17 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "xkbcommon" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13867d259930edc7091a6c41b4ce6eee464328c6ff9659b7e4c668ca20d4c91e" +dependencies = [ + "libc", + "memmap2 0.8.0", + "xkeysym", +] + [[package]] name = "xkbcommon" version = "0.8.0" @@ -9665,7 +9912,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d66ca9352cbd4eecbbc40871d8a11b4ac8107cfc528a6e14d7c19c69d0e1ac9" dependencies = [ "libc", - "memmap2", + "memmap2 0.9.5", "xkeysym", ] diff --git a/apps/desktop/src-tauri/Cargo.toml b/apps/desktop/src-tauri/Cargo.toml index 7b6b186..878ff40 100644 --- a/apps/desktop/src-tauri/Cargo.toml +++ b/apps/desktop/src-tauri/Cargo.toml @@ -59,6 +59,7 @@ obfstr = { workspace = true } base64 = { workspace = true } tauri-plugin-stronghold = "2.2.0" + [target."cfg(target_os = \"macos\")".dependencies] cocoa = "0.24.1" mac-security-rs = { workspace = true } diff --git a/apps/desktop/src/routes/app/+page.svelte b/apps/desktop/src/routes/app/+page.svelte index ca0a2f7..2d61e81 100644 --- a/apps/desktop/src/routes/app/+page.svelte +++ b/apps/desktop/src/routes/app/+page.svelte @@ -22,7 +22,7 @@ import { cmdQueries } from "@/stores/cmdQuery" import { isKeyboardEventFromInputElement } from "@/utils/dom" import Icon from "@iconify/svelte" - import { toggleDevTools } from "@kksh/api/commands" + import { getSelectedText, toggleDevTools } from "@kksh/api/commands" import { Button, Command, DropdownMenu } from "@kksh/svelte5" import { BuiltinCmds, @@ -196,6 +196,17 @@ {/snippet} + No results found. {#if $appConfig.extensionsInstallDir && $devStoreExts.length > 0} diff --git a/packages/api/src/commands/system.ts b/packages/api/src/commands/system.ts index 21e0be4..5423459 100644 --- a/packages/api/src/commands/system.ts +++ b/packages/api/src/commands/system.ts @@ -116,6 +116,10 @@ export function getSelectedFilesInFileExplorer(): Promise { return invoke(generateJarvisPluginCommand("get_selected_files_in_file_explorer")) } +export function getSelectedText(): Promise { + return invoke(generateJarvisPluginCommand("get_selected_text")) +} + export const rawSystemCommands = [ { name: "Open Trash", diff --git a/packages/tauri-plugins/jarvis/Cargo.toml b/packages/tauri-plugins/jarvis/Cargo.toml index 27f37d6..abc0e16 100644 --- a/packages/tauri-plugins/jarvis/Cargo.toml +++ b/packages/tauri-plugins/jarvis/Cargo.toml @@ -56,7 +56,7 @@ grpc = { workspace = true } futures-util = "0.3.31" rayon = { workspace = true } local-ip-address = "0.6.3" - +get-selected-text = "0.1.6" [target.'cfg(target_os = "macos")'.dependencies] tauri-icns = "0.1.0" diff --git a/packages/tauri-plugins/jarvis/build.rs b/packages/tauri-plugins/jarvis/build.rs index 2b29e07..e00642a 100644 --- a/packages/tauri-plugins/jarvis/build.rs +++ b/packages/tauri-plugins/jarvis/build.rs @@ -28,6 +28,7 @@ const COMMANDS: &[&str] = &[ "unmute", "hide_all_apps_except_frontmost", "get_selected_files_in_file_explorer", + "get_selected_text", "run_apple_script", "run_powershell", "get_applications", diff --git a/packages/tauri-plugins/jarvis/permissions/all.toml b/packages/tauri-plugins/jarvis/permissions/all.toml index 011b085..c860b6d 100644 --- a/packages/tauri-plugins/jarvis/permissions/all.toml +++ b/packages/tauri-plugins/jarvis/permissions/all.toml @@ -31,6 +31,7 @@ commands.allow = [ "unmute", "hide_all_apps_except_frontmost", "get_selected_files_in_file_explorer", + "get_selected_text", "run_apple_script", "run_powershell", "get_applications", diff --git a/packages/tauri-plugins/jarvis/permissions/autogenerated/commands/get_selected_text.toml b/packages/tauri-plugins/jarvis/permissions/autogenerated/commands/get_selected_text.toml new file mode 100644 index 0000000..0fcbf8a --- /dev/null +++ b/packages/tauri-plugins/jarvis/permissions/autogenerated/commands/get_selected_text.toml @@ -0,0 +1,13 @@ +# Automatically generated - DO NOT EDIT! + +"$schema" = "../../schemas/schema.json" + +[[permission]] +identifier = "allow-get-selected-text" +description = "Enables the get_selected_text command without any pre-configured scope." +commands.allow = ["get_selected_text"] + +[[permission]] +identifier = "deny-get-selected-text" +description = "Denies the get_selected_text command without any pre-configured scope." +commands.deny = ["get_selected_text"] diff --git a/packages/tauri-plugins/jarvis/permissions/autogenerated/reference.md b/packages/tauri-plugins/jarvis/permissions/autogenerated/reference.md index 19f9805..b77ba59 100644 --- a/packages/tauri-plugins/jarvis/permissions/autogenerated/reference.md +++ b/packages/tauri-plugins/jarvis/permissions/autogenerated/reference.md @@ -960,6 +960,32 @@ Denies the get_selected_files_in_file_explorer command without any pre-configure +`jarvis:allow-get-selected-text` + + + + +Enables the get_selected_text command without any pre-configured scope. + + + + + + + +`jarvis:deny-get-selected-text` + + + + +Denies the get_selected_text command without any pre-configured scope. + + + + + + + `jarvis:allow-get-server-port` diff --git a/packages/tauri-plugins/jarvis/permissions/schemas/schema.json b/packages/tauri-plugins/jarvis/permissions/schemas/schema.json index 49bd95c..a38a59c 100644 --- a/packages/tauri-plugins/jarvis/permissions/schemas/schema.json +++ b/packages/tauri-plugins/jarvis/permissions/schemas/schema.json @@ -659,6 +659,16 @@ "type": "string", "const": "deny-get-selected-files-in-file-explorer" }, + { + "description": "Enables the get_selected_text command without any pre-configured scope.", + "type": "string", + "const": "allow-get-selected-text" + }, + { + "description": "Denies the get_selected_text command without any pre-configured scope.", + "type": "string", + "const": "deny-get-selected-text" + }, { "description": "Enables the get_server_port command without any pre-configured scope.", "type": "string", diff --git a/packages/tauri-plugins/jarvis/src/commands/system.rs b/packages/tauri-plugins/jarvis/src/commands/system.rs index 9c2e386..cc7609b 100644 --- a/packages/tauri-plugins/jarvis/src/commands/system.rs +++ b/packages/tauri-plugins/jarvis/src/commands/system.rs @@ -1,6 +1,7 @@ use crate::syscmds::{CommonSystemCmds, SystemCmds}; use crate::utils::script::run_apple_script; use applications::AppInfo; +use get_selected_text::get_selected_text as get_selected_text_impl; #[tauri::command] pub async fn open_trash() -> Result<(), String> { @@ -156,3 +157,8 @@ pub async fn hide_all_apps_except_frontmost() -> Result<(), String> { pub async fn get_selected_files_in_file_explorer() -> Result, String> { SystemCmds::get_selected_files().map_err(|err| err.to_string()) } + +#[tauri::command] +pub async fn get_selected_text() -> Result { + get_selected_text_impl().map_err(|err| err.to_string()) +} diff --git a/packages/tauri-plugins/jarvis/src/lib.rs b/packages/tauri-plugins/jarvis/src/lib.rs index 16aabde..e4cf748 100644 --- a/packages/tauri-plugins/jarvis/src/lib.rs +++ b/packages/tauri-plugins/jarvis/src/lib.rs @@ -89,6 +89,7 @@ pub fn init() -> TauriPlugin { commands::system::hide_all_apps_except_frontmost, commands::system::get_frontmost_app, commands::system::get_selected_files_in_file_explorer, + commands::system::get_selected_text, /* ------------------------------ applications ------------------------------ */ commands::apps::get_applications, commands::apps::refresh_applications_list,