tauri: [bug] use `enigo` in tauri cause app crashed
Describe the bug
I try to use enigo to do some keyboard event mock in my tauri app, and it will crash when the macOS api TISCopyCurrentKeyboardInputSource or TISGetInputSourceProperty execute in enigo.
I start an issue in enigo before, but we found the crash will only appear in my Tauri app.
Reproduction
- register a shortcut
import { isRegistered, register, unregister } from '@tauri-apps/api/globalShortcut';
export async function registerShortcut(shortcut: string, callback: (shortcut?: string) => void) {
await register(shortcut, (shortcut) => {
callback(shortcut);
});
}
and there is a log in shell:
register Accelerator { id: Some(AcceleratorId(29420)), mods: ALT, key: KeyS }
- write a tauri command, and invoke in javascript
#[tauri::command]
async fn paste_content(window: tauri::Window) {
let mut enigo = Enigo::new();
let trusted = accessibility::query_accessibility_permissions();
if trusted {
enigo.key_down(Key::Meta);
enigo.key_click(Key::Layout('v'));
enigo.key_up(Key::Meta);
}
}
invoke("paste_content").then(async _ => {
})
I use accessibility to help me request the macOS accessibility permission, and it returns true.
3. the application crashed
Expected behavior
The app does not crash.
Platform and versions
Environment
› OS: Mac OS 13.0.0 X64
› Node.js: 16.14.0
› npm: 8.3.1
› pnpm: 7.9.5
› yarn: 3.1.1
› rustup: 1.25.2
› rustc: 1.68.0
› cargo: 1.68.0
› Rust toolchain: stable-aarch64-apple-darwin
Packages
› @tauri-apps/cli [NPM]: 1.2.3
› @tauri-apps/api [NPM]: 1.2.0
› tauri [RUST]: 1.2.4,
› tauri-build [RUST]: 1.2.1,
› tao [RUST]: 0.15.8,
› wry [RUST]: 0.23.4,
App
› build-type: bundle
› CSP: unset
› distDir: ../dist
› devPath: http://localhost:1420/
› framework: React
› bundler: Vite
App directory structure
├─ dist
├─ node_modules
├─ public
├─ .github
├─ src-tauri
├─ api
├─ .git
├─ .vscode
├─ assets
└─ src
Stack trace
There is no output in my shell when it crashed, I try to debug it and set some breakpoints, I put the screenshots [here](https://github.com/enigo-rs/enigo/pull/161#issuecomment-1460236620)
Additional context
No response
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 6
- Comments: 15 (2 by maintainers)
Have the same problem, though the app doesn’t crash in my case
For me, this helped: